From d2e48ef153ed87bc75460b41325369d8ab305dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Fri, 4 May 2018 14:06:42 +0200 Subject: [PATCH] Update ecllib from statoil master repo commit 0188b08081eb1ac4ade89ac224b8128b4c9b0481 --- ResInsightVersion.cmake | 2 +- ThirdParty/Ert/.travis.yml | 2 - ThirdParty/Ert/CMakeLists.txt | 12 +- ThirdParty/Ert/applications/ecl/esummary.c | 198 -- .../cmake/Tests/test_have_readlinkat_decl.c | 17 + ThirdParty/Ert/lib/CMakeLists.txt | 186 +- ThirdParty/Ert/lib/build_config.hpp.in | 1 + ThirdParty/Ert/lib/ecl/FortIO.cpp | 3 +- ThirdParty/Ert/lib/ecl/Smspec.cpp | 2 +- .../Ert/lib/ecl/{ecl_box.c => ecl_box.cpp} | 14 +- ...{ecl_coarse_cell.c => ecl_coarse_cell.cpp} | 12 +- .../Ert/lib/ecl/{ecl_file.c => ecl_file.cpp} | 31 +- .../ecl/{ecl_file_kw.c => ecl_file_kw.cpp} | 22 +- .../{ecl_file_view.c => ecl_file_view.cpp} | 56 +- .../Ert/lib/ecl/{ecl_grav.c => ecl_grav.cpp} | 46 +- .../{ecl_grav_calc.c => ecl_grav_calc.cpp} | 10 +- ...{ecl_grav_common.c => ecl_grav_common.cpp} | 15 +- .../Ert/lib/ecl/{ecl_grid.c => ecl_grid.cpp} | 147 +- .../{ecl_grid_cache.c => ecl_grid_cache.cpp} | 24 +- .../{ecl_grid_dims.c => ecl_grid_dims.cpp} | 18 +- .../{ecl_init_file.c => ecl_init_file.cpp} | 13 +- .../{ecl_io_config.c => ecl_io_config.cpp} | 8 +- .../Ert/lib/ecl/{ecl_kw.c => ecl_kw.cpp} | 451 ++--- ...cl_kw_functions.c => ecl_kw_functions.cpp} | 2 +- .../{ecl_kw_grdecl.c => ecl_kw_grdecl.cpp} | 16 +- .../ecl/{ecl_nnc_data.c => ecl_nnc_data.cpp} | 16 +- .../{ecl_nnc_export.c => ecl_nnc_export.cpp} | 14 +- ...cl_nnc_geometry.c => ecl_nnc_geometry.cpp} | 18 +- .../lib/ecl/{ecl_region.c => ecl_region.cpp} | 18 +- .../ecl/{ecl_rft_cell.c => ecl_rft_cell.cpp} | 22 +- .../ecl/{ecl_rft_file.c => ecl_rft_file.cpp} | 34 +- .../ecl/{ecl_rft_node.c => ecl_rft_node.cpp} | 48 +- .../ecl/{ecl_rst_file.c => ecl_rst_file.cpp} | 28 +- .../ecl/{ecl_rsthead.c => ecl_rsthead.cpp} | 26 +- .../lib/ecl/{ecl_smspec.c => ecl_smspec.cpp} | 106 +- .../{ecl_subsidence.c => ecl_subsidence.cpp} | 38 +- .../Ert/lib/ecl/{ecl_sum.c => ecl_sum.cpp} | 112 +- .../ecl/{ecl_sum_data.c => ecl_sum_data.cpp} | 185 +- .../{ecl_sum_index.c => ecl_sum_index.cpp} | 2 +- .../{ecl_sum_tstep.c => ecl_sum_tstep.cpp} | 28 +- .../{ecl_sum_vector.c => ecl_sum_vector.cpp} | 18 +- .../Ert/lib/ecl/{ecl_type.c => ecl_type.cpp} | 32 +- ...{ecl_type_python.c => ecl_type_python.cpp} | 22 +- .../Ert/lib/ecl/{ecl_util.c => ecl_util.cpp} | 34 +- .../ecl/{fault_block.c => fault_block.cpp} | 12 +- ...lt_block_layer.c => fault_block_layer.cpp} | 8 +- ThirdParty/Ert/lib/ecl/fortio.c | 2 +- .../lib/ecl/{grid_dims.c => grid_dims.cpp} | 6 +- ThirdParty/Ert/lib/ecl/{layer.c => layer.cpp} | 12 +- .../Ert/lib/ecl/{nnc_info.c => nnc_info.cpp} | 22 +- .../lib/ecl/{nnc_vector.c => nnc_vector.cpp} | 14 +- .../ecl/{smspec_node.c => smspec_node.cpp} | 38 +- ThirdParty/Ert/lib/ecl/tests/ecl_kw_init.c | 21 + ThirdParty/Ert/lib/ecl/tests/eclxx_kw.cpp | 131 +- ...ollection.c => well_branch_collection.cpp} | 18 +- .../lib/ecl/{well_conn.c => well_conn.cpp} | 143 +- ..._collection.c => well_conn_collection.cpp} | 23 +- .../lib/ecl/{well_info.c => well_info.cpp} | 34 +- ...ell_rseg_loader.c => well_rseg_loader.cpp} | 18 +- .../ecl/{well_segment.c => well_segment.cpp} | 24 +- ...llection.c => well_segment_collection.cpp} | 24 +- .../lib/ecl/{well_state.c => well_state.cpp} | 56 +- .../Ert/lib/ecl/{well_ts.c => well_ts.cpp} | 28 +- ThirdParty/Ert/lib/ert_api_config.h.in | 1 + ThirdParty/Ert/lib/ert_api_config.hpp.in | 1 + .../{geo_pointset.c => geo_pointset.cpp} | 12 +- .../{geo_polygon.c => geo_polygon.cpp} | 16 +- ...ollection.c => geo_polygon_collection.cpp} | 18 +- .../geometry/{geo_region.c => geo_region.cpp} | 20 +- .../{geo_surface.c => geo_surface.cpp} | 12 +- .../lib/geometry/{geo_util.c => geo_util.cpp} | 4 +- ThirdParty/Ert/lib/include/ert/ecl/EclKW.hpp | 123 +- .../Ert/lib/include/ert/ecl/ecl_box.hpp | 19 + .../lib/include/ert/ecl/ecl_coarse_cell.hpp | 19 + .../lib/include/ert/ecl/ecl_endian_flip.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_file.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_file_kw.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_file_view.hpp | 19 + ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.h | 5 +- .../Ert/lib/include/ert/ecl/ecl_grav.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_grav_calc.hpp | 19 + .../lib/include/ert/ecl/ecl_grav_common.hpp | 19 + ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.h | 4 + .../Ert/lib/include/ert/ecl/ecl_grid.hpp | 19 + .../lib/include/ert/ecl/ecl_grid_cache.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_grid_dims.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_init_file.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_io_config.h | 6 + .../Ert/lib/include/ert/ecl/ecl_io_config.hpp | 19 + ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.h | 8 +- ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.hpp | 19 + .../ert/ecl/ecl_kw_grdecl.hpp} | 13 +- .../Ert/lib/include/ert/ecl/ecl_kw_magic.hpp | 20 + .../Ert/lib/include/ert/ecl/ecl_nnc_data.hpp | 19 + .../lib/include/ert/ecl/ecl_nnc_export.hpp | 20 + .../lib/include/ert/ecl/ecl_nnc_geometry.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_region.h | 14 + .../Ert/lib/include/ert/ecl/ecl_region.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_rft_cell.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_rft_file.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_rft_node.h | 2 + .../Ert/lib/include/ert/ecl/ecl_rft_node.hpp | 20 + .../Ert/lib/include/ert/ecl/ecl_rst_file.hpp | 20 + .../Ert/lib/include/ert/ecl/ecl_rsthead.h | 2 + .../Ert/lib/include/ert/ecl/ecl_rsthead.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_smspec.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_subsidence.h | 8 +- .../lib/include/ert/ecl/ecl_subsidence.hpp | 19 + ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.h | 22 +- .../Ert/lib/include/ert/ecl/ecl_sum.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_sum_data.h | 18 +- .../Ert/lib/include/ert/ecl/ecl_sum_data.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_sum_index.hpp | 20 + .../Ert/lib/include/ert/ecl/ecl_sum_tstep.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_sum_vector.h | 2 + .../lib/include/ert/ecl/ecl_sum_vector.hpp | 19 + ThirdParty/Ert/lib/include/ert/ecl/ecl_type.h | 12 +- .../Ert/lib/include/ert/ecl/ecl_type.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_units.hpp | 19 + .../Ert/lib/include/ert/ecl/ecl_util.hpp | 19 + .../Ert/lib/include/ert/ecl/fault_block.hpp | 20 + .../lib/include/ert/ecl/fault_block_layer.hpp | 19 + .../Ert/lib/include/ert/ecl/grid_dims.hpp | 20 + ThirdParty/Ert/lib/include/ert/ecl/layer.h | 3 + ThirdParty/Ert/lib/include/ert/ecl/layer.hpp | 19 + .../Ert/lib/include/ert/ecl/nnc_info.hpp | 19 + .../Ert/lib/include/ert/ecl/nnc_vector.hpp | 19 + .../Ert/lib/include/ert/ecl/smspec_node.hpp | 20 + .../ert/ecl_well/well_branch_collection.hpp | 20 + .../lib/include/ert/ecl_well/well_conn.hpp | 20 + .../ert/ecl_well/well_conn_collection.hpp | 20 + .../lib/include/ert/ecl_well/well_const.hpp | 20 + .../lib/include/ert/ecl_well/well_info.hpp | 20 + .../include/ert/ecl_well/well_rseg_loader.hpp | 20 + .../lib/include/ert/ecl_well/well_segment.hpp | 20 + .../ert/ecl_well/well_segment_collection.hpp | 20 + .../Ert/lib/include/ert/ecl_well/well_state.h | 4 + .../lib/include/ert/ecl_well/well_state.hpp | 20 + .../Ert/lib/include/ert/ecl_well/well_ts.hpp | 20 + .../lib/include/ert/geometry/geo_pointset.hpp | 19 + .../lib/include/ert/geometry/geo_polygon.hpp | 19 + .../ert/geometry/geo_polygon_collection.hpp | 19 + .../lib/include/ert/geometry/geo_region.hpp | 19 + .../lib/include/ert/geometry/geo_surface.h | 10 + .../lib/include/ert/geometry/geo_surface.hpp | 19 + .../Ert/lib/include/ert/geometry/geo_util.hpp | 19 + .../Ert/lib/include/ert/nexus/nexus_plot.hpp | 63 - .../Ert/lib/include/ert/util/arg_pack.hpp | 24 + .../Ert/lib/include/ert/util/buffer.hpp | 24 + .../Ert/lib/include/ert/util/ecl_version.hpp | 24 + ThirdParty/Ert/lib/include/ert/util/hash.hpp | 24 + .../Ert/lib/include/ert/util/hash_node.hpp | 24 + .../Ert/lib/include/ert/util/hash_sll.hpp | 24 + ThirdParty/Ert/lib/include/ert/util/lars.h | 50 - ThirdParty/Ert/lib/include/ert/util/log.h | 62 - .../Ert/lib/include/ert/util/lookup_table.h | 2 +- .../Ert/lib/include/ert/util/lookup_table.hpp | 24 + ThirdParty/Ert/lib/include/ert/util/matrix.h | 194 -- .../Ert/lib/include/ert/util/matrix_blas.h | 45 - .../Ert/lib/include/ert/util/matrix_lapack.h | 93 - .../Ert/lib/include/ert/util/matrix_stat.h | 43 - ThirdParty/Ert/lib/include/ert/util/menu.h | 51 - ThirdParty/Ert/lib/include/ert/util/msg.h | 47 - ThirdParty/Ert/lib/include/ert/util/mzran.hpp | 24 + .../Ert/lib/include/ert/util/node_ctype.hpp | 24 + .../Ert/lib/include/ert/util/node_data.hpp | 24 + .../Ert/lib/include/ert/util/parser.hpp | 24 + .../Ert/lib/include/ert/util/path_fmt.h | 49 - .../Ert/lib/include/ert/util/path_stack.hpp | 24 + .../Ert/lib/include/ert/util/perm_vector.hpp | 24 + .../Ert/lib/include/ert/util/regression.h | 34 - ThirdParty/Ert/lib/include/ert/util/rng.hpp | 24 + ThirdParty/Ert/lib/include/ert/util/set.hpp | 24 + .../Ert/lib/include/ert/util/ssize_t.hpp | 24 + .../Ert/lib/include/ert/util/statistics.hpp | 24 + .../Ert/lib/include/ert/util/stepwise.h | 42 - .../Ert/lib/include/ert/util/string_util.hpp | 24 + .../Ert/lib/include/ert/util/stringlist.hpp | 24 + .../lib/include/ert/util/struct_vector.hpp | 24 + .../Ert/lib/include/ert/util/subst_func.h | 56 - .../Ert/lib/include/ert/util/test_util.h | 2 + .../lib/include/ert/util/test_work_area.hpp | 24 + .../Ert/lib/include/ert/util/thread_pool.h | 43 - .../Ert/lib/include/ert/util/time_interval.h | 53 - .../lib/include/ert/util/time_interval.hpp | 24 + ThirdParty/Ert/lib/include/ert/util/timer.hpp | 24 + .../Ert/lib/include/ert/util/type_macros.hpp | 24 + .../ert/util/type_vector_functions.hpp | 24 + .../Ert/lib/include/ert/util/ui_return.h | 57 - ThirdParty/Ert/lib/include/ert/util/util.h | 1 + ThirdParty/Ert/lib/include/ert/util/util.hpp | 24 + .../Ert/lib/include/ert/util/util_env.h | 37 - .../Ert/lib/include/ert/util/vector.hpp | 24 + ThirdParty/Ert/lib/nexus/nexus_plot.cpp | 170 -- ThirdParty/Ert/lib/nexus/tests/nexus2ecl.cpp | 55 - .../Ert/lib/nexus/tests/nexus_plot_load.cpp | 142 -- ThirdParty/Ert/lib/util/TestArea.cpp | 2 +- .../Ert/lib/util/{arg_pack.c => arg_pack.cpp} | 8 +- .../Ert/lib/util/{buffer.c => buffer.cpp} | 18 +- .../util/{ecl_version.c => ecl_version.cpp} | 4 +- ThirdParty/Ert/lib/util/{hash.c => hash.cpp} | 12 +- .../lib/util/{hash_node.c => hash_node.cpp} | 6 +- .../Ert/lib/util/{hash_sll.c => hash_sll.cpp} | 6 +- ThirdParty/Ert/lib/util/lars.c | 448 ----- ThirdParty/Ert/lib/util/log.c | 253 --- .../util/{lookup_table.c => lookup_table.cpp} | 8 +- ThirdParty/Ert/lib/util/matrix.c | 1751 ----------------- ThirdParty/Ert/lib/util/matrix_blas.c | 286 --- ThirdParty/Ert/lib/util/matrix_lapack.c | 640 ------ ThirdParty/Ert/lib/util/matrix_stat.c | 114 -- ThirdParty/Ert/lib/util/menu.c | 462 ----- ThirdParty/Ert/lib/util/msg.c | 161 -- .../Ert/lib/util/{mzran.c => mzran.cpp} | 6 +- .../lib/util/{node_ctype.c => node_ctype.cpp} | 4 +- .../lib/util/{node_data.c => node_data.cpp} | 6 +- .../Ert/lib/util/{parser.c => parser.cpp} | 10 +- ThirdParty/Ert/lib/util/path_fmt.c | 314 --- .../lib/util/{path_stack.c => path_stack.cpp} | 6 +- .../util/{perm_vector.c => perm_vector.cpp} | 6 +- ThirdParty/Ert/lib/util/regression.c | 143 -- ThirdParty/Ert/lib/util/{rng.c => rng.cpp} | 10 +- ThirdParty/Ert/lib/util/{set.c => set.cpp} | 8 +- .../lib/util/{statistics.c => statistics.cpp} | 6 +- ThirdParty/Ert/lib/util/stepwise.c | 456 ----- .../util/{string_util.c => string_util.cpp} | 14 +- .../lib/util/{stringlist.c => stringlist.cpp} | 10 +- .../{struct_vector.c => struct_vector.cpp} | 4 +- ThirdParty/Ert/lib/util/subst_func.c | 210 -- .../lib/util/{test_util.c => test_util.cpp} | 12 +- .../{test_work_area.c => test_work_area.cpp} | 10 +- .../Ert/lib/util/tests/ert_util_PATH_test.c | 59 - ThirdParty/Ert/lib/util/tests/ert_util_logh.c | 110 -- .../Ert/lib/util/tests/ert_util_matrix.c | 242 --- .../lib/util/tests/ert_util_matrix_lapack.c | 92 - .../Ert/lib/util/tests/ert_util_matrix_stat.c | 169 -- .../lib/util/tests/ert_util_time_interval.c | 245 --- .../Ert/lib/util/tests/ert_util_ui_return.c | 97 - ThirdParty/Ert/lib/util/thread_pool1.c | 90 - ThirdParty/Ert/lib/util/thread_pool_posix.c | 485 ----- ThirdParty/Ert/lib/util/time_interval.c | 174 -- .../Ert/lib/util/{timer.c => timer.cpp} | 4 +- ..._functions.c => type_vector_functions.cpp} | 8 +- ThirdParty/Ert/lib/util/ui_return.c | 116 -- ThirdParty/Ert/lib/util/util.c | 51 +- ThirdParty/Ert/lib/util/util_abort_gnu.c | 4 +- ThirdParty/Ert/lib/util/util_abort_simple.c | 2 +- .../util/{util_endian.c => util_endian.cpp} | 0 ThirdParty/Ert/lib/util/util_env.c | 280 --- .../util/{util_getuid.c => util_getuid.cpp} | 2 +- .../lib/util/{util_lockf.c => util_lockf.cpp} | 2 +- .../util/{util_opendir.c => util_opendir.cpp} | 2 +- .../lib/util/{util_spawn.c => util_spawn.cpp} | 6 +- .../util/{util_symlink.c => util_symlink.cpp} | 8 +- .../util/{util_unlink.c => util_unlink.cpp} | 4 +- .../lib/util/{util_zlib.c => util_zlib.cpp} | 6 +- .../Ert/lib/util/{vector.c => vector.cpp} | 8 +- ...{vector_template.c => vector_template.cpp} | 6 +- .../thread_pool.c => vector_template.hpp.in} | 13 +- ThirdParty/Ert/python/CMakeLists.txt | 6 + ThirdParty/Ert/python/ecl/ecl_type.py | 2 +- ThirdParty/Ert/python/ecl/summary/ecl_sum.py | 166 +- .../ecl/util/test/ecl_mock/ecl_sum_mock.py | 4 +- ThirdParty/Ert/python/python/CMakeLists.txt | 8 - .../Ert/python/python/cwrap/CMakeLists.txt | 12 - .../Ert/python/python/cwrap/__init__.py | 52 - .../Ert/python/python/cwrap/basecclass.py | 156 -- .../Ert/python/python/cwrap/basecenum.py | 169 -- .../Ert/python/python/cwrap/basecvalue.py | 67 - ThirdParty/Ert/python/python/cwrap/cfile.py | 70 - ThirdParty/Ert/python/python/cwrap/clib.py | 90 - .../Ert/python/python/cwrap/metacwrap.py | 67 - .../Ert/python/python/cwrap/prototype.py | 177 -- .../Ert/python/python/ecl/CMakeLists.txt | 14 - ThirdParty/Ert/python/python/ecl/__init__.py | 130 -- .../Ert/python/python/ecl/ecl/CMakeLists.txt | 37 - .../Ert/python/python/ecl/ecl/__init__.py | 115 -- ThirdParty/Ert/python/python/ecl/ecl/cell.py | 127 -- .../Ert/python/python/ecl/ecl/ecl_3d_file.py | 41 - .../Ert/python/python/ecl/ecl/ecl_3dkw.py | 239 --- .../Ert/python/python/ecl/ecl/ecl_cmp.py | 184 -- .../Ert/python/python/ecl/ecl/ecl_file.py | 718 ------- .../python/python/ecl/ecl/ecl_file_view.py | 200 -- .../Ert/python/python/ecl/ecl/ecl_grav.py | 217 -- .../python/python/ecl/ecl/ecl_grav_calc.py | 84 - .../Ert/python/python/ecl/ecl/ecl_grid.py | 1301 ------------ .../python/ecl/ecl/ecl_grid_generator.py | 708 ------- .../python/python/ecl/ecl/ecl_init_file.py | 29 - .../Ert/python/python/ecl/ecl/ecl_kw.py | 1173 ----------- .../Ert/python/python/ecl/ecl/ecl_npv.py | 220 --- .../Ert/python/python/ecl/ecl/ecl_region.py | 1054 ---------- .../python/python/ecl/ecl/ecl_restart_file.py | 157 -- .../Ert/python/python/ecl/ecl/ecl_rft.py | 355 ---- .../Ert/python/python/ecl/ecl/ecl_rft_cell.py | 171 -- .../python/python/ecl/ecl/ecl_smspec_node.py | 196 -- .../python/python/ecl/ecl/ecl_subsidence.py | 143 -- .../Ert/python/python/ecl/ecl/ecl_sum.py | 1300 ------------ .../python/ecl/ecl/ecl_sum_keyword_vector.py | 72 - .../Ert/python/python/ecl/ecl/ecl_sum_node.py | 28 - .../python/python/ecl/ecl/ecl_sum_tstep.py | 83 - .../python/python/ecl/ecl/ecl_sum_var_type.py | 56 - .../python/python/ecl/ecl/ecl_sum_vector.py | 304 --- .../Ert/python/python/ecl/ecl/ecl_type.py | 184 -- .../Ert/python/python/ecl/ecl/ecl_util.py | 166 -- .../python/ecl/ecl/faults/CMakeLists.txt | 12 - .../python/python/ecl/ecl/faults/__init__.py | 7 - .../Ert/python/python/ecl/ecl/faults/fault.py | 654 ------ .../python/ecl/ecl/faults/fault_block.py | 190 -- .../ecl/ecl/faults/fault_block_collection.py | 84 - .../ecl/ecl/faults/fault_block_layer.py | 235 --- .../python/ecl/ecl/faults/fault_collection.py | 135 -- .../python/ecl/ecl/faults/fault_line.py | 253 --- .../python/ecl/ecl/faults/fault_segments.py | 174 -- .../Ert/python/python/ecl/ecl/faults/layer.py | 274 --- .../Ert/python/python/ecl/ecl/fortio.py | 211 -- .../Ert/python/python/ecl/ecl/local.cmake | 13 - .../python/python/ecl/ecl/rft/CMakeLists.txt | 6 - .../Ert/python/python/ecl/ecl/rft/__init__.py | 1 - .../python/ecl/ecl/rft/well_trajectory.py | 84 - .../python/ecl/ecl_lib_info_build.py.in | 3 - .../python/ecl/ecl_lib_info_install.py.in | 3 - .../Ert/python/python/ecl/geo/CMakeLists.txt | 13 - .../Ert/python/python/ecl/geo/__init__.py | 37 - .../Ert/python/python/ecl/geo/cpolyline.py | 210 -- .../python/ecl/geo/cpolyline_collection.py | 120 -- .../Ert/python/python/ecl/geo/geo_pointset.py | 79 - .../Ert/python/python/ecl/geo/geo_region.py | 121 -- .../python/python/ecl/geo/geometry_tools.py | 448 ----- .../Ert/python/python/ecl/geo/polyline.py | 171 -- .../Ert/python/python/ecl/geo/surface.py | 285 --- .../Ert/python/python/ecl/geo/xyz_io.py | 62 - .../Ert/python/python/ecl/test/CMakeLists.txt | 18 - .../Ert/python/python/ecl/test/__init__.py | 11 - .../Ert/python/python/ecl/test/debug_msg.py | 7 - .../python/ecl/test/ecl_mock/CMakeLists.txt | 6 - .../python/ecl/test/ecl_mock/__init__.py | 1 - .../python/ecl/test/ecl_mock/ecl_sum_mock.py | 30 - .../python/ecl/test/ert_test_context.py | 117 -- .../python/python/ecl/test/ert_test_runner.py | 63 - .../python/ecl/test/extended_testcase.py | 181 -- .../python/ecl/test/import_test_case.py | 52 - .../python/python/ecl/test/lint_test_case.py | 61 - .../python/python/ecl/test/path_context.py | 46 - .../python/ecl/test/source_enumerator.py | 39 - .../Ert/python/python/ecl/test/temp_area.py | 81 - .../Ert/python/python/ecl/test/test_area.py | 149 -- .../Ert/python/python/ecl/test/test_run.py | 158 -- .../Ert/python/python/ecl/util/CMakeLists.txt | 33 - .../Ert/python/python/ecl/util/__init__.py | 135 -- .../Ert/python/python/ecl/util/arg_pack.py | 57 - .../Ert/python/python/ecl/util/bool_vector.py | 143 -- .../Ert/python/python/ecl/util/buffer.py | 29 - .../python/python/ecl/util/cthread_pool.py | 85 - .../Ert/python/python/ecl/util/ctime.py | 148 -- .../Ert/python/python/ecl/util/cwd_context.py | 16 - .../python/python/ecl/util/double_vector.py | 70 - .../python/ecl/util/enums/CMakeLists.txt | 11 - .../python/python/ecl/util/enums/__init__.py | 5 - .../python/ecl/util/enums/llsq_result_enum.py | 13 - .../ecl/util/enums/message_level_enum.py | 18 - .../ecl/util/enums/rng_alg_type_enum.py | 8 - .../ecl/util/enums/rng_init_mode_enum.py | 14 - .../ecl/util/enums/ui_return_status_enum.py | 11 - ThirdParty/Ert/python/python/ecl/util/hash.py | 133 -- .../python/ecl/util/install_abort_signals.py | 16 - .../Ert/python/python/ecl/util/int_vector.py | 108 - ThirdParty/Ert/python/python/ecl/util/log.py | 44 - .../python/python/ecl/util/lookup_table.py | 122 -- .../Ert/python/python/ecl/util/matrix.py | 227 --- .../Ert/python/python/ecl/util/path_format.py | 42 - .../python/ecl/util/permutation_vector.py | 38 - .../Ert/python/python/ecl/util/profiler.py | 34 - ThirdParty/Ert/python/python/ecl/util/rng.py | 81 - ThirdParty/Ert/python/python/ecl/util/stat.py | 78 - .../Ert/python/python/ecl/util/stringlist.py | 308 --- .../Ert/python/python/ecl/util/thread_pool.py | 151 -- .../Ert/python/python/ecl/util/time_vector.py | 170 -- .../Ert/python/python/ecl/util/ui_return.py | 116 -- .../Ert/python/python/ecl/util/util_func.py | 54 - .../python/python/ecl/util/vector_template.py | 647 ------ .../Ert/python/python/ecl/util/version.py | 118 -- .../Ert/python/python/ecl/well/CMakeLists.txt | 13 - .../Ert/python/python/ecl/well/__init__.py | 20 - .../python/python/ecl/well/well_connection.py | 108 - .../well/well_connection_direction_enum.py | 15 - .../Ert/python/python/ecl/well/well_info.py | 122 -- .../python/python/ecl/well/well_segment.py | 76 - .../Ert/python/python/ecl/well/well_state.py | 164 -- .../python/python/ecl/well/well_time_line.py | 42 - .../python/python/ecl/well/well_type_enum.py | 16 - .../python/python/legacy/ert/CMakeLists.txt | 11 - .../Ert/python/python/legacy/ert/__init__.py | 0 .../python/python/legacy/ert/ecl/__init__.py | 26 - .../python/legacy/ert/ecl/faults/__init__.py | 7 - .../python/python/legacy/ert/geo/__init__.py | 8 - .../python/python/legacy/ert/test/__init__.py | 10 - .../python/python/legacy/ert/util/__init__.py | 29 - .../python/python/legacy/ert/well/__init__.py | 7 - ThirdParty/Ert/python/python/test_env.py.in | 6 - .../tests/bin_tests/test_summary_resample.py | 2 +- .../Ert/python/tests/cwrap/CMakeLists.txt | 17 - ThirdParty/Ert/python/tests/cwrap/__init__.py | 0 .../Ert/python/tests/cwrap/test_basecclass.py | 19 - .../Ert/python/tests/cwrap/test_basecenum.py | 91 - .../Ert/python/tests/cwrap/test_basecvalue.py | 71 - .../Ert/python/tests/cwrap/test_cfile.py | 31 - .../Ert/python/tests/cwrap/test_metawrap.py | 122 -- .../Ert/python/tests/ecl/CMakeLists.txt | 97 - ThirdParty/Ert/python/tests/ecl/__init__.py | 0 ThirdParty/Ert/python/tests/ecl/test_cell.py | 98 - ThirdParty/Ert/python/tests/ecl/test_debug.py | 24 - .../Ert/python/tests/ecl/test_deprecation.py | 50 - .../Ert/python/tests/ecl/test_ecl_3dkw.py | 202 -- .../Ert/python/tests/ecl/test_ecl_cmp.py | 68 - .../Ert/python/tests/ecl/test_ecl_file.py | 256 --- .../python/tests/ecl/test_ecl_file_statoil.py | 277 --- .../python/tests/ecl/test_ecl_init_file.py | 47 - .../Ert/python/tests/ecl/test_ecl_kw.py | 475 ----- .../python/tests/ecl/test_ecl_kw_statoil.py | 112 -- .../python/tests/ecl/test_ecl_restart_file.py | 67 - .../Ert/python/tests/ecl/test_ecl_sum.py | 144 -- .../python/tests/ecl/test_ecl_sum_tstep.py | 41 - .../python/tests/ecl/test_ecl_sum_vector.py | 54 - .../Ert/python/tests/ecl/test_ecl_type.py | 139 -- .../Ert/python/tests/ecl/test_ecl_util.py | 42 - .../Ert/python/tests/ecl/test_fault_blocks.py | 468 ----- .../tests/ecl/test_fault_blocks_statoil.py | 40 - .../Ert/python/tests/ecl/test_faults.py | 796 -------- .../Ert/python/tests/ecl/test_fk_user_data.py | 48 - .../Ert/python/tests/ecl/test_fortio.py | 139 -- .../Ert/python/tests/ecl/test_geertsma.py | 144 -- ThirdParty/Ert/python/tests/ecl/test_grav.py | 25 - .../Ert/python/tests/ecl/test_grdecl.py | 124 -- ThirdParty/Ert/python/tests/ecl/test_grid.py | 587 ------ .../python/tests/ecl/test_grid_generator.py | 272 --- .../Ert/python/tests/ecl/test_grid_statoil.py | 408 ---- .../Ert/python/tests/ecl/test_indexed_read.py | 116 -- .../Ert/python/tests/ecl/test_kw_function.py | 57 - ThirdParty/Ert/python/tests/ecl/test_layer.py | 306 --- ThirdParty/Ert/python/tests/ecl/test_npv.py | 194 -- .../Ert/python/tests/ecl/test_region.py | 89 - .../python/tests/ecl/test_region_statoil.py | 205 -- .../Ert/python/tests/ecl/test_removed.py | 34 - .../Ert/python/tests/ecl/test_restart.py | 129 -- .../Ert/python/tests/ecl/test_restart_head.py | 41 - ThirdParty/Ert/python/tests/ecl/test_rft.py | 38 - .../Ert/python/tests/ecl/test_rft_cell.py | 95 - .../Ert/python/tests/ecl/test_rft_statoil.py | 142 -- .../python/tests/ecl/test_statoil_faults.py | 128 -- ThirdParty/Ert/python/tests/ecl/test_sum.py | 315 --- .../Ert/python/tests/ecl/test_sum_statoil.py | 500 ----- .../Ert/python/tests/ecl_tests/test_ecl_kw.py | 4 +- .../Ert/python/tests/ecl_tests/test_sum.py | 94 +- .../Ert/python/tests/geometry/CMakeLists.txt | 28 - .../Ert/python/tests/geometry/__init__.py | 0 .../python/tests/geometry/test_convex_hull.py | 27 - .../python/tests/geometry/test_cpolyline.py | 171 -- .../geometry/test_cpolyline_collection.py | 133 -- .../tests/geometry/test_geo_pointset.py | 27 - .../python/tests/geometry/test_geo_region.py | 88 - .../tests/geometry/test_geometry_tools.py | 80 - .../tests/geometry/test_intersection.py | 47 - .../tests/geometry/test_point_in_polygon.py | 60 - .../tests/geometry/test_polygon_slicing.py | 139 -- .../python/tests/geometry/test_polyline.py | 193 -- .../Ert/python/tests/geometry/test_surface.py | 210 -- .../Ert/python/tests/global/CMakeLists.txt | 12 - .../Ert/python/tests/global/__init__.py | 0 .../Ert/python/tests/global/test_import.py | 26 - .../Ert/python/tests/global/test_pylint.py | 34 - .../Ert/python/tests/install/test_install.py | 13 - .../Ert/python/tests/legacy/CMakeLists.txt | 16 - .../Ert/python/tests/legacy/__init__.py | 0 .../Ert/python/tests/legacy/test_ecl.py | 41 - .../Ert/python/tests/legacy/test_geo.py | 14 - .../Ert/python/tests/legacy/test_test.py | 16 - .../Ert/python/tests/legacy/test_util.py | 34 - .../Ert/python/tests/legacy/test_well.py | 13 - .../Ert/python/tests/share/CMakeLists.txt | 8 - ThirdParty/Ert/python/tests/share/__init__.py | 0 .../python/tests/share/test_synthesizer.py | 50 - ThirdParty/Ert/python/tests/test_pylint.py | 34 - .../Ert/python/tests/util/CMakeLists.txt | 46 - ThirdParty/Ert/python/tests/util/__init__.py | 0 .../Ert/python/tests/util/test_arg_pack.py | 35 - .../Ert/python/tests/util/test_cstring.py | 24 - .../python/tests/util/test_cthread_pool.py | 47 - .../Ert/python/tests/util/test_ctime.py | 131 -- ThirdParty/Ert/python/tests/util/test_hash.py | 68 - ThirdParty/Ert/python/tests/util/test_log.py | 8 - .../python/tests/util/test_lookup_table.py | 88 - .../Ert/python/tests/util/test_matrix.py | 247 --- .../python/tests/util/test_path_context.py | 49 - .../Ert/python/tests/util/test_path_fmt.py | 10 - ThirdParty/Ert/python/tests/util/test_rng.py | 45 - .../Ert/python/tests/util/test_spawn.py | 63 - ThirdParty/Ert/python/tests/util/test_stat.py | 43 - .../Ert/python/tests/util/test_string_list.py | 159 -- .../Ert/python/tests/util/test_thread_pool.py | 101 - .../Ert/python/tests/util/test_ui_return.py | 69 - .../Ert/python/tests/util/test_vectors.py | 552 ------ .../Ert/python/tests/util/test_version.py | 110 -- .../Ert/python/tests/util/test_work_area.py | 95 - .../Ert/python/tests/well/CMakeLists.txt | 14 - ThirdParty/Ert/python/tests/well/__init__.py | 0 .../Ert/python/tests/well/test_ecl_well.py | 446 ----- .../Ert/python/tests/well/test_ecl_well2.py | 43 - .../Ert/python/tests/well/test_ecl_well3.py | 48 - .../python/tests/well_tests/test_ecl_well.py | 7 + ThirdParty/Ert/redhat/ert.ecl.spec | 108 - ThirdParty/Ert/requirements.txt | 1 + patches/fix-synthetic-odb-cases.patch | 8 +- 511 files changed, 3901 insertions(+), 42023 deletions(-) delete mode 100644 ThirdParty/Ert/applications/ecl/esummary.c create mode 100644 ThirdParty/Ert/cmake/Tests/test_have_readlinkat_decl.c create mode 100644 ThirdParty/Ert/lib/build_config.hpp.in rename ThirdParty/Ert/lib/ecl/{ecl_box.c => ecl_box.cpp} (91%) rename ThirdParty/Ert/lib/ecl/{ecl_coarse_cell.c => ecl_coarse_cell.cpp} (97%) rename ThirdParty/Ert/lib/ecl/{ecl_file.c => ecl_file.cpp} (98%) rename ThirdParty/Ert/lib/ecl/{ecl_file_kw.c => ecl_file_kw.cpp} (95%) rename ThirdParty/Ert/lib/ecl/{ecl_file_view.c => ecl_file_view.cpp} (93%) rename ThirdParty/Ert/lib/ecl/{ecl_grav.c => ecl_grav.cpp} (94%) rename ThirdParty/Ert/lib/ecl/{ecl_grav_calc.c => ecl_grav_calc.cpp} (97%) rename ThirdParty/Ert/lib/ecl/{ecl_grav_common.c => ecl_grav_common.cpp} (94%) rename ThirdParty/Ert/lib/ecl/{ecl_grid.c => ecl_grid.cpp} (97%) rename ThirdParty/Ert/lib/ecl/{ecl_grid_cache.c => ecl_grid_cache.cpp} (82%) rename ThirdParty/Ert/lib/ecl/{ecl_grid_dims.c => ecl_grid_dims.cpp} (91%) rename ThirdParty/Ert/lib/ecl/{ecl_init_file.c => ecl_init_file.cpp} (97%) rename ThirdParty/Ert/lib/ecl/{ecl_io_config.c => ecl_io_config.cpp} (95%) rename ThirdParty/Ert/lib/ecl/{ecl_kw.c => ecl_kw.cpp} (88%) rename ThirdParty/Ert/lib/ecl/{ecl_kw_functions.c => ecl_kw_functions.cpp} (98%) rename ThirdParty/Ert/lib/ecl/{ecl_kw_grdecl.c => ecl_kw_grdecl.cpp} (97%) rename ThirdParty/Ert/lib/ecl/{ecl_nnc_data.c => ecl_nnc_data.cpp} (95%) rename ThirdParty/Ert/lib/ecl/{ecl_nnc_export.c => ecl_nnc_export.cpp} (96%) rename ThirdParty/Ert/lib/ecl/{ecl_nnc_geometry.c => ecl_nnc_geometry.cpp} (88%) rename ThirdParty/Ert/lib/ecl/{ecl_region.c => ecl_region.cpp} (99%) rename ThirdParty/Ert/lib/ecl/{ecl_rft_cell.c => ecl_rft_cell.cpp} (94%) rename ThirdParty/Ert/lib/ecl/{ecl_rft_file.c => ecl_rft_file.cpp} (91%) rename ThirdParty/Ert/lib/ecl/{ecl_rft_node.c => ecl_rft_node.cpp} (92%) rename ThirdParty/Ert/lib/ecl/{ecl_rst_file.c => ecl_rst_file.cpp} (94%) rename ThirdParty/Ert/lib/ecl/{ecl_rsthead.c => ecl_rsthead.cpp} (93%) rename ThirdParty/Ert/lib/ecl/{ecl_smspec.c => ecl_smspec.cpp} (94%) rename ThirdParty/Ert/lib/ecl/{ecl_subsidence.c => ecl_subsidence.cpp} (90%) rename ThirdParty/Ert/lib/ecl/{ecl_sum.c => ecl_sum.cpp} (92%) rename ThirdParty/Ert/lib/ecl/{ecl_sum_data.c => ecl_sum_data.cpp} (88%) rename ThirdParty/Ert/lib/ecl/{ecl_sum_index.c => ecl_sum_index.cpp} (98%) rename ThirdParty/Ert/lib/ecl/{ecl_sum_tstep.c => ecl_sum_tstep.cpp} (93%) rename ThirdParty/Ert/lib/ecl/{ecl_sum_vector.c => ecl_sum_vector.cpp} (93%) rename ThirdParty/Ert/lib/ecl/{ecl_type.c => ecl_type.cpp} (91%) rename ThirdParty/Ert/lib/ecl/{ecl_type_python.c => ecl_type_python.cpp} (90%) rename ThirdParty/Ert/lib/ecl/{ecl_util.c => ecl_util.cpp} (97%) rename ThirdParty/Ert/lib/ecl/{fault_block.c => fault_block.cpp} (97%) rename ThirdParty/Ert/lib/ecl/{fault_block_layer.c => fault_block_layer.cpp} (96%) rename ThirdParty/Ert/lib/ecl/{grid_dims.c => grid_dims.cpp} (89%) rename ThirdParty/Ert/lib/ecl/{layer.c => layer.cpp} (98%) rename ThirdParty/Ert/lib/ecl/{nnc_info.c => nnc_info.cpp} (90%) rename ThirdParty/Ert/lib/ecl/{nnc_vector.c => nnc_vector.cpp} (91%) rename ThirdParty/Ert/lib/ecl/{smspec_node.c => smspec_node.cpp} (97%) rename ThirdParty/Ert/lib/ecl/{well_branch_collection.c => well_branch_collection.cpp} (87%) rename ThirdParty/Ert/lib/ecl/{well_conn.c => well_conn.cpp} (77%) rename ThirdParty/Ert/lib/ecl/{well_conn_collection.c => well_conn_collection.cpp} (86%) rename ThirdParty/Ert/lib/ecl/{well_info.c => well_info.cpp} (95%) rename ThirdParty/Ert/lib/ecl/{well_rseg_loader.c => well_rseg_loader.cpp} (85%) rename ThirdParty/Ert/lib/ecl/{well_segment.c => well_segment.cpp} (92%) rename ThirdParty/Ert/lib/ecl/{well_segment_collection.c => well_segment_collection.cpp} (90%) rename ThirdParty/Ert/lib/ecl/{well_state.c => well_state.cpp} (93%) rename ThirdParty/Ert/lib/ecl/{well_ts.c => well_ts.cpp} (90%) create mode 100644 ThirdParty/Ert/lib/ert_api_config.hpp.in rename ThirdParty/Ert/lib/geometry/{geo_pointset.c => geo_pointset.cpp} (92%) rename ThirdParty/Ert/lib/geometry/{geo_polygon.c => geo_polygon.cpp} (95%) rename ThirdParty/Ert/lib/geometry/{geo_polygon_collection.c => geo_polygon_collection.cpp} (86%) rename ThirdParty/Ert/lib/geometry/{geo_region.c => geo_region.cpp} (92%) rename ThirdParty/Ert/lib/geometry/{geo_surface.c => geo_surface.cpp} (97%) rename ThirdParty/Ert/lib/geometry/{geo_util.c => geo_util.cpp} (98%) create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_box.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_coarse_cell.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_endian_flip.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_file.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_file_kw.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_file_view.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_grav_calc.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_grav_common.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_grid_cache.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_grid_dims.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_init_file.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_io_config.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.hpp rename ThirdParty/Ert/lib/{ecl/ecl_sum_file.c => include/ert/ecl/ecl_kw_grdecl.hpp} (69%) create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_kw_magic.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_data.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_export.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_geometry.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_region.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_cell.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_file.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_node.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_rst_file.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_smspec.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_subsidence.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_data.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_index.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_tstep.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_vector.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_type.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_units.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/ecl_util.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/fault_block.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/fault_block_layer.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/grid_dims.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/layer.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/nnc_info.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/nnc_vector.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl/smspec_node.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_branch_collection.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_conn.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_conn_collection.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_const.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_info.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_rseg_loader.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_segment.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_segment_collection.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_state.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/ecl_well/well_ts.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/geometry/geo_pointset.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/geometry/geo_polygon.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/geometry/geo_polygon_collection.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/geometry/geo_region.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/geometry/geo_surface.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/geometry/geo_util.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/nexus/nexus_plot.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/arg_pack.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/buffer.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/ecl_version.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/hash.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/hash_node.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/hash_sll.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/lars.h delete mode 100644 ThirdParty/Ert/lib/include/ert/util/log.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/lookup_table.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/matrix.h delete mode 100644 ThirdParty/Ert/lib/include/ert/util/matrix_blas.h delete mode 100644 ThirdParty/Ert/lib/include/ert/util/matrix_lapack.h delete mode 100644 ThirdParty/Ert/lib/include/ert/util/matrix_stat.h delete mode 100644 ThirdParty/Ert/lib/include/ert/util/menu.h delete mode 100644 ThirdParty/Ert/lib/include/ert/util/msg.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/mzran.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/node_ctype.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/node_data.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/parser.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/path_fmt.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/path_stack.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/perm_vector.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/regression.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/rng.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/set.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/ssize_t.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/statistics.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/stepwise.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/string_util.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/stringlist.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/struct_vector.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/subst_func.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/test_work_area.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/thread_pool.h delete mode 100644 ThirdParty/Ert/lib/include/ert/util/time_interval.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/time_interval.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/timer.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/type_macros.hpp create mode 100644 ThirdParty/Ert/lib/include/ert/util/type_vector_functions.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/ui_return.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/util.hpp delete mode 100644 ThirdParty/Ert/lib/include/ert/util/util_env.h create mode 100644 ThirdParty/Ert/lib/include/ert/util/vector.hpp delete mode 100644 ThirdParty/Ert/lib/nexus/nexus_plot.cpp delete mode 100644 ThirdParty/Ert/lib/nexus/tests/nexus2ecl.cpp delete mode 100644 ThirdParty/Ert/lib/nexus/tests/nexus_plot_load.cpp rename ThirdParty/Ert/lib/util/{arg_pack.c => arg_pack.cpp} (99%) rename ThirdParty/Ert/lib/util/{buffer.c => buffer.cpp} (98%) rename ThirdParty/Ert/lib/util/{ecl_version.c => ecl_version.cpp} (93%) rename ThirdParty/Ert/lib/util/{hash.c => hash.cpp} (99%) rename ThirdParty/Ert/lib/util/{hash_node.c => hash_node.cpp} (96%) rename ThirdParty/Ert/lib/util/{hash_sll.c => hash_sll.cpp} (97%) delete mode 100644 ThirdParty/Ert/lib/util/lars.c delete mode 100644 ThirdParty/Ert/lib/util/log.c rename ThirdParty/Ert/lib/util/{lookup_table.c => lookup_table.cpp} (97%) delete mode 100644 ThirdParty/Ert/lib/util/matrix.c delete mode 100644 ThirdParty/Ert/lib/util/matrix_blas.c delete mode 100644 ThirdParty/Ert/lib/util/matrix_lapack.c delete mode 100644 ThirdParty/Ert/lib/util/matrix_stat.c delete mode 100644 ThirdParty/Ert/lib/util/menu.c delete mode 100644 ThirdParty/Ert/lib/util/msg.c rename ThirdParty/Ert/lib/util/{mzran.c => mzran.cpp} (98%) rename ThirdParty/Ert/lib/util/{node_ctype.c => node_ctype.cpp} (95%) rename ThirdParty/Ert/lib/util/{node_data.c => node_data.cpp} (98%) rename ThirdParty/Ert/lib/util/{parser.c => parser.cpp} (99%) delete mode 100644 ThirdParty/Ert/lib/util/path_fmt.c rename ThirdParty/Ert/lib/util/{path_stack.c => path_stack.cpp} (97%) rename ThirdParty/Ert/lib/util/{perm_vector.c => perm_vector.cpp} (94%) delete mode 100644 ThirdParty/Ert/lib/util/regression.c rename ThirdParty/Ert/lib/util/{rng.c => rng.cpp} (98%) rename ThirdParty/Ert/lib/util/{set.c => set.cpp} (97%) rename ThirdParty/Ert/lib/util/{statistics.c => statistics.cpp} (97%) delete mode 100644 ThirdParty/Ert/lib/util/stepwise.c rename ThirdParty/Ert/lib/util/{string_util.c => string_util.cpp} (96%) rename ThirdParty/Ert/lib/util/{stringlist.c => stringlist.cpp} (99%) rename ThirdParty/Ert/lib/util/{struct_vector.c => struct_vector.cpp} (98%) delete mode 100644 ThirdParty/Ert/lib/util/subst_func.c rename ThirdParty/Ert/lib/util/{test_util.c => test_util.cpp} (98%) rename ThirdParty/Ert/lib/util/{test_work_area.c => test_work_area.cpp} (98%) delete mode 100644 ThirdParty/Ert/lib/util/tests/ert_util_PATH_test.c delete mode 100644 ThirdParty/Ert/lib/util/tests/ert_util_logh.c delete mode 100644 ThirdParty/Ert/lib/util/tests/ert_util_matrix.c delete mode 100644 ThirdParty/Ert/lib/util/tests/ert_util_matrix_lapack.c delete mode 100644 ThirdParty/Ert/lib/util/tests/ert_util_matrix_stat.c delete mode 100644 ThirdParty/Ert/lib/util/tests/ert_util_time_interval.c delete mode 100644 ThirdParty/Ert/lib/util/tests/ert_util_ui_return.c delete mode 100644 ThirdParty/Ert/lib/util/thread_pool1.c delete mode 100644 ThirdParty/Ert/lib/util/thread_pool_posix.c delete mode 100644 ThirdParty/Ert/lib/util/time_interval.c rename ThirdParty/Ert/lib/util/{timer.c => timer.cpp} (98%) rename ThirdParty/Ert/lib/util/{type_vector_functions.c => type_vector_functions.cpp} (93%) delete mode 100644 ThirdParty/Ert/lib/util/ui_return.c rename ThirdParty/Ert/lib/util/{util_endian.c => util_endian.cpp} (100%) delete mode 100644 ThirdParty/Ert/lib/util/util_env.c rename ThirdParty/Ert/lib/util/{util_getuid.c => util_getuid.cpp} (99%) rename ThirdParty/Ert/lib/util/{util_lockf.c => util_lockf.cpp} (99%) rename ThirdParty/Ert/lib/util/{util_opendir.c => util_opendir.cpp} (99%) rename ThirdParty/Ert/lib/util/{util_spawn.c => util_spawn.cpp} (97%) rename ThirdParty/Ert/lib/util/{util_symlink.c => util_symlink.cpp} (94%) rename ThirdParty/Ert/lib/util/{util_unlink.c => util_unlink.cpp} (93%) rename ThirdParty/Ert/lib/util/{util_zlib.c => util_zlib.cpp} (97%) rename ThirdParty/Ert/lib/util/{vector.c => vector.cpp} (99%) rename ThirdParty/Ert/lib/util/{vector_template.c => vector_template.cpp} (99%) rename ThirdParty/Ert/lib/{util/thread_pool.c => vector_template.hpp.in} (71%) delete mode 100644 ThirdParty/Ert/python/python/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/cwrap/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/cwrap/__init__.py delete mode 100644 ThirdParty/Ert/python/python/cwrap/basecclass.py delete mode 100644 ThirdParty/Ert/python/python/cwrap/basecenum.py delete mode 100644 ThirdParty/Ert/python/python/cwrap/basecvalue.py delete mode 100644 ThirdParty/Ert/python/python/cwrap/cfile.py delete mode 100644 ThirdParty/Ert/python/python/cwrap/clib.py delete mode 100644 ThirdParty/Ert/python/python/cwrap/metacwrap.py delete mode 100644 ThirdParty/Ert/python/python/cwrap/prototype.py delete mode 100644 ThirdParty/Ert/python/python/ecl/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/cell.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_3d_file.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_3dkw.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_cmp.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_file.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_file_view.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_grav.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_grav_calc.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_grid.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_grid_generator.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_init_file.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_kw.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_npv.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_region.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_restart_file.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_rft.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_rft_cell.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_smspec_node.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_subsidence.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_sum.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_keyword_vector.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_node.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_tstep.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_var_type.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_vector.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_type.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/ecl_util.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/fault.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block_collection.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block_layer.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/fault_collection.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/fault_line.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/fault_segments.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/faults/layer.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/fortio.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/local.cmake delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/rft/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/rft/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl/rft/well_trajectory.py delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl_lib_info_build.py.in delete mode 100644 ThirdParty/Ert/python/python/ecl/ecl_lib_info_install.py.in delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/cpolyline.py delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/cpolyline_collection.py delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/geo_pointset.py delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/geo_region.py delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/geometry_tools.py delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/polyline.py delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/surface.py delete mode 100644 ThirdParty/Ert/python/python/ecl/geo/xyz_io.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/test/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/debug_msg.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/ecl_mock/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/test/ecl_mock/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/ecl_mock/ecl_sum_mock.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/ert_test_context.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/ert_test_runner.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/extended_testcase.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/import_test_case.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/lint_test_case.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/path_context.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/source_enumerator.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/temp_area.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/test_area.py delete mode 100644 ThirdParty/Ert/python/python/ecl/test/test_run.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/util/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/arg_pack.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/bool_vector.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/buffer.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/cthread_pool.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/ctime.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/cwd_context.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/double_vector.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/enums/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/util/enums/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/enums/llsq_result_enum.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/enums/message_level_enum.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/enums/rng_alg_type_enum.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/enums/rng_init_mode_enum.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/enums/ui_return_status_enum.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/hash.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/install_abort_signals.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/int_vector.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/log.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/lookup_table.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/matrix.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/path_format.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/permutation_vector.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/profiler.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/rng.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/stat.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/stringlist.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/thread_pool.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/time_vector.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/ui_return.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/util_func.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/vector_template.py delete mode 100644 ThirdParty/Ert/python/python/ecl/util/version.py delete mode 100644 ThirdParty/Ert/python/python/ecl/well/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/ecl/well/__init__.py delete mode 100644 ThirdParty/Ert/python/python/ecl/well/well_connection.py delete mode 100644 ThirdParty/Ert/python/python/ecl/well/well_connection_direction_enum.py delete mode 100644 ThirdParty/Ert/python/python/ecl/well/well_info.py delete mode 100644 ThirdParty/Ert/python/python/ecl/well/well_segment.py delete mode 100644 ThirdParty/Ert/python/python/ecl/well/well_state.py delete mode 100644 ThirdParty/Ert/python/python/ecl/well/well_time_line.py delete mode 100644 ThirdParty/Ert/python/python/ecl/well/well_type_enum.py delete mode 100644 ThirdParty/Ert/python/python/legacy/ert/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/python/legacy/ert/__init__.py delete mode 100644 ThirdParty/Ert/python/python/legacy/ert/ecl/__init__.py delete mode 100644 ThirdParty/Ert/python/python/legacy/ert/ecl/faults/__init__.py delete mode 100644 ThirdParty/Ert/python/python/legacy/ert/geo/__init__.py delete mode 100644 ThirdParty/Ert/python/python/legacy/ert/test/__init__.py delete mode 100644 ThirdParty/Ert/python/python/legacy/ert/util/__init__.py delete mode 100644 ThirdParty/Ert/python/python/legacy/ert/well/__init__.py delete mode 100644 ThirdParty/Ert/python/python/test_env.py.in delete mode 100644 ThirdParty/Ert/python/tests/cwrap/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/tests/cwrap/__init__.py delete mode 100644 ThirdParty/Ert/python/tests/cwrap/test_basecclass.py delete mode 100644 ThirdParty/Ert/python/tests/cwrap/test_basecenum.py delete mode 100644 ThirdParty/Ert/python/tests/cwrap/test_basecvalue.py delete mode 100644 ThirdParty/Ert/python/tests/cwrap/test_cfile.py delete mode 100644 ThirdParty/Ert/python/tests/cwrap/test_metawrap.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/tests/ecl/__init__.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_cell.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_debug.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_deprecation.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_3dkw.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_cmp.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_file.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_file_statoil.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_init_file.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_kw.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_kw_statoil.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_restart_file.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_sum.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_sum_tstep.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_sum_vector.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_type.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_ecl_util.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_fault_blocks.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_fault_blocks_statoil.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_faults.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_fk_user_data.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_fortio.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_geertsma.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_grav.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_grdecl.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_grid.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_grid_generator.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_grid_statoil.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_indexed_read.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_kw_function.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_layer.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_npv.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_region.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_region_statoil.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_removed.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_restart.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_restart_head.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_rft.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_rft_cell.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_rft_statoil.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_statoil_faults.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_sum.py delete mode 100644 ThirdParty/Ert/python/tests/ecl/test_sum_statoil.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/tests/geometry/__init__.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_convex_hull.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_cpolyline.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_cpolyline_collection.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_geo_pointset.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_geo_region.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_geometry_tools.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_intersection.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_point_in_polygon.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_polygon_slicing.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_polyline.py delete mode 100644 ThirdParty/Ert/python/tests/geometry/test_surface.py delete mode 100644 ThirdParty/Ert/python/tests/global/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/tests/global/__init__.py delete mode 100644 ThirdParty/Ert/python/tests/global/test_import.py delete mode 100644 ThirdParty/Ert/python/tests/global/test_pylint.py delete mode 100644 ThirdParty/Ert/python/tests/install/test_install.py delete mode 100644 ThirdParty/Ert/python/tests/legacy/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/tests/legacy/__init__.py delete mode 100644 ThirdParty/Ert/python/tests/legacy/test_ecl.py delete mode 100644 ThirdParty/Ert/python/tests/legacy/test_geo.py delete mode 100644 ThirdParty/Ert/python/tests/legacy/test_test.py delete mode 100644 ThirdParty/Ert/python/tests/legacy/test_util.py delete mode 100644 ThirdParty/Ert/python/tests/legacy/test_well.py delete mode 100644 ThirdParty/Ert/python/tests/share/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/tests/share/__init__.py delete mode 100644 ThirdParty/Ert/python/tests/share/test_synthesizer.py delete mode 100644 ThirdParty/Ert/python/tests/test_pylint.py delete mode 100644 ThirdParty/Ert/python/tests/util/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/tests/util/__init__.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_arg_pack.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_cstring.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_cthread_pool.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_ctime.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_hash.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_log.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_lookup_table.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_matrix.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_path_context.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_path_fmt.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_rng.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_spawn.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_stat.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_string_list.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_thread_pool.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_ui_return.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_vectors.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_version.py delete mode 100644 ThirdParty/Ert/python/tests/util/test_work_area.py delete mode 100644 ThirdParty/Ert/python/tests/well/CMakeLists.txt delete mode 100644 ThirdParty/Ert/python/tests/well/__init__.py delete mode 100644 ThirdParty/Ert/python/tests/well/test_ecl_well.py delete mode 100644 ThirdParty/Ert/python/tests/well/test_ecl_well2.py delete mode 100644 ThirdParty/Ert/python/tests/well/test_ecl_well3.py delete mode 100644 ThirdParty/Ert/redhat/ert.ecl.spec diff --git a/ResInsightVersion.cmake b/ResInsightVersion.cmake index 32abe5535f..b107893293 100644 --- a/ResInsightVersion.cmake +++ b/ResInsightVersion.cmake @@ -16,7 +16,7 @@ set(RESINSIGHT_DEV_VERSION ".109") set(NRLIB_GITHUB_SHA "ba35d4359882f1c6f5e9dc30eb95fe52af50fd6f") # https://github.com/Statoil/libecl -set(ECL_GITHUB_SHA "b31b055af2d6b887f47aec84c65ec497a5d12973") +set(ECL_GITHUB_SHA "0188b08081eb1ac4ade89ac224b8128b4c9b0481") # https://github.com/OPM/opm-flowdiagnostics set(OPM_FLOWDIAGNOSTICS_SHA "7e2be931d430796ed42efcfb5c6b67a8d5962f7f") diff --git a/ThirdParty/Ert/.travis.yml b/ThirdParty/Ert/.travis.yml index 78fa0c189b..5d137e94ad 100644 --- a/ThirdParty/Ert/.travis.yml +++ b/ThirdParty/Ert/.travis.yml @@ -24,8 +24,6 @@ env: matrix: fast_finish: true - allow_failures: - - env: PYTHON_VERSION=3.6 exclude: - os: osx compiler: gcc diff --git a/ThirdParty/Ert/CMakeLists.txt b/ThirdParty/Ert/CMakeLists.txt index 070dc78d7e..6f1ab299fd 100644 --- a/ThirdParty/Ert/CMakeLists.txt +++ b/ThirdParty/Ert/CMakeLists.txt @@ -268,6 +268,13 @@ try_compile( HAVE_PID_T ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/ try_compile( HAVE_MODE_T ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_mode_t.c ) try_compile( ERT_HAVE_ISFINITE ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_isfinite.c) +if (ERT_HAVE_READLINKAT) + try_compile( ERT_HAVE_READLINKAT_DECLARATION + ${CMAKE_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/cmake/Tests/test_have_readlinkat_decl.c + ) +endif() + set( BUILD_CXX ON ) try_compile( HAVE_CXX_SHARED_PTR ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_shared_ptr.cpp ) if (NOT HAVE_CXX_SHARED_PTR) @@ -357,9 +364,6 @@ if (ENABLE_PYTHON) endif() endif() -if (INSTALL_ERT) - install(EXPORT ecl-config DESTINATION share/cmake/ecl) -endif() - +install(EXPORT ecl-config DESTINATION share/cmake/ecl) export(TARGETS ecl FILE eclConfig.cmake) export(PACKAGE ecl) diff --git a/ThirdParty/Ert/applications/ecl/esummary.c b/ThirdParty/Ert/applications/ecl/esummary.c deleted file mode 100644 index b7a7b4c75f..0000000000 --- a/ThirdParty/Ert/applications/ecl/esummary.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'esummary.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include - -#include -#include -#include - -#include -#include - - -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 enkf program with SIGTERM (the default kill signal) you will get a backtrace. Killing with SIGKILL (-9) will not give a backtrace.*/ -} - -void usage() { - fprintf(stderr," The esummary.x program can be used to extract summary vectors from \n"); - fprintf(stderr," an ensemble of summary files: \n\n"); - fprintf(stderr," bash%% esummary.x ECLIPSE1.DATA ECLIPSE2.DATA KEY1 KEY2 ... \n\n"); - exit(1); -} - - -#define MISSING_STRING " 0.000" - - - -int main(int argc , char ** argv) { - install_SIGNALS(); - { - if (argc < 3) usage(); - - { - ecl_sum_type * first_ecl_sum = NULL; /* This governs the timing */ - vector_type * ecl_sum_list = vector_alloc_new(); - time_interval_type * time_union = NULL; - time_interval_type * time_intersect = NULL; - time_interval_type * time = NULL; - bool use_time_union = true; - - int load_count = 0; - int nvars; - char ** var_list; - bool * has_var; - - /** Loading the data */ - { - int iarg = 1; - /* Some sorting here??? */ - while (iarg < argc && util_file_exists( argv[iarg] )) { - char * path , * basename; - ecl_sum_type * ecl_sum; - util_alloc_file_components( argv[iarg] , &path , &basename , NULL); - fprintf(stderr,"Loading case: %s/%s" , path , basename); fflush(stderr); - ecl_sum = ecl_sum_fread_alloc_case( argv[iarg] , ":"); - if (ecl_sum) { - if (first_ecl_sum == NULL) { - first_ecl_sum = ecl_sum; /* Keep track of this - might sort the vector */ - time_union = time_interval_alloc_copy( ecl_sum_get_sim_time( ecl_sum )); - time_intersect = time_interval_alloc_copy( ecl_sum_get_sim_time( ecl_sum )); - - if (use_time_union) - time = time_union; - else - time = time_intersect; - - vector_append_owned_ref( ecl_sum_list , ecl_sum , ecl_sum_free__ ); - load_count++; - } else { - const time_interval_type * ti = ecl_sum_get_sim_time( ecl_sum ); - if (time_interval_has_overlap(time , ti)) { - time_interval_intersect( time_intersect , ti ); - time_interval_extend( time_union , ti ); - - vector_append_owned_ref( ecl_sum_list , ecl_sum , ecl_sum_free__ ); - load_count++; - } else { - fprintf(stderr,"** Warning case:%s has no time overlap - discarded \n",ecl_sum_get_case( ecl_sum )); - ecl_sum_free( ecl_sum ); - } - } - } else - fprintf(stderr," --- no data found?!"); - - iarg++; - fprintf(stderr,"\n"); - util_safe_free( path ); - free( basename ); - } - } - if (load_count == 0) - usage(); - - nvars = argc - load_count - 1; - if (nvars == 0) util_exit(" --- No variables \n"); - var_list = &argv[load_count + 1]; - has_var = util_calloc( nvars , sizeof * has_var ); - - /* - Checking that the summary files have the various variables - - if a variable is missing from one of the cases it is - completely discarded. - */ - { - int iens,ivar; - - /* Checking the variables */ - for (ivar = 0; ivar < nvars; ivar++) - has_var[ivar] = true; - - for (iens = 0; iens < vector_get_size( ecl_sum_list ); iens++) { - const ecl_sum_type * ecl_sum = vector_iget_const( ecl_sum_list , iens ); - for (ivar = 0; ivar < nvars; ivar++) { - if (has_var[ivar]) { - if (!ecl_sum_has_general_var( ecl_sum , var_list[ivar] )) { - fprintf(stderr,"** Warning: could not find variable: \'%s\' in case:%s - completely discarded.\n", var_list[ivar] , ecl_sum_get_case(ecl_sum)); - has_var[ivar] = false; - } - } - } - } - } - - if (!time_interval_equal(time_union , time_intersect )) { - fprintf(stderr,"** Warning: not all simulations have the same length. "); - if (use_time_union) - fprintf(stderr,"Using %s for missing values.\n" , MISSING_STRING); - else - fprintf(stderr,"Only showing common time period.\n"); - } - - /** The actual summary lookup. */ - { - time_t_vector_type * date_list = time_t_vector_alloc(0,0); - time_t start_time = time_interval_get_start( time ); - FILE * stream = stdout; - int iens,ivar,itime; - - ecl_util_init_month_range( date_list , time_interval_get_start( time ) , time_interval_get_end( time )); - for (itime = 0; itime < time_t_vector_size( date_list ); itime++) { - time_t current_time = time_t_vector_iget( date_list , itime ); - for (ivar = 0; ivar < nvars; ivar++) { /* Iterating over the variables */ - if (has_var[ivar]) { - for (iens = 0; iens < vector_get_size( ecl_sum_list ); iens++) { /* Iterating over the ensemble members */ - const ecl_sum_type * ecl_sum = vector_iget_const( ecl_sum_list , iens ); - - if (ivar == 0 && iens == 0) { /* Display time info in the first columns */ - int day,month,year; - util_set_date_values_utc( current_time , &day , &month, &year); - fprintf(stream , "%7.2f %02d/%02d/%04d " , util_difftime_days( start_time , current_time ) , day , month , year); - } - - { - const time_interval_type * sim_time = ecl_sum_get_sim_time( ecl_sum ); - - if (time_interval_arg_before( sim_time , current_time)) - fprintf(stream , " %s " , MISSING_STRING); // We are before this case has data. - else if (time_interval_arg_after( sim_time , current_time)) - fprintf(stream , " %s " , MISSING_STRING); // We are after this case has data. - else { - double value = ecl_sum_get_general_var_from_sim_time(ecl_sum , current_time , var_list[ivar]); - fprintf(stream , " %12.3f " , value); - } - - } - } - } - } - fprintf(stream , "\n"); - } - time_t_vector_free( date_list ); - } - vector_free( ecl_sum_list ); - free( has_var ); - } - } -} diff --git a/ThirdParty/Ert/cmake/Tests/test_have_readlinkat_decl.c b/ThirdParty/Ert/cmake/Tests/test_have_readlinkat_decl.c new file mode 100644 index 0000000000..3d77e99904 --- /dev/null +++ b/ThirdParty/Ert/cmake/Tests/test_have_readlinkat_decl.c @@ -0,0 +1,17 @@ +#include +#include + +#include + +#define NCHAR 63 + +int main(int argc, char *argv[]) +{ + char linkname[NCHAR + 1] = { 0 }; + ssize_t r; + + r = (argc < 2) ? -1 + : readlinkat(1, argv[1], linkname, NCHAR); + + return (r > 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/ThirdParty/Ert/lib/CMakeLists.txt b/ThirdParty/Ert/lib/CMakeLists.txt index f1bcff4fdb..5852d41847 100644 --- a/ThirdParty/Ert/lib/CMakeLists.txt +++ b/ThirdParty/Ert/lib/CMakeLists.txt @@ -9,23 +9,23 @@ else() endif() if (ERT_HAVE_GETUID AND ERT_HAVE_OPENDIR) - list(APPEND opt_srcs util/test_work_area.c util/util_getuid.c) + list(APPEND opt_srcs util/test_work_area.cpp util/util_getuid.cpp) endif() if (ERT_HAVE_OPENDIR) - list(APPEND opt_srcs util/util_opendir.c) + list(APPEND opt_srcs util/util_opendir.cpp) endif() if (ERT_HAVE_SPAWN) - list(APPEND opt_srcs util/util_spawn.c) + list(APPEND opt_srcs util/util_spawn.cpp) endif() if (ERT_HAVE_LOCKF) - list(APPEND opt_srcs util/util_lockf.c) + list(APPEND opt_srcs util/util_lockf.cpp) endif () if (ERT_HAVE_UNISTD) - list(APPEND opt_srcs util/path_stack.c) + list(APPEND opt_srcs util/path_stack.cpp) endif () if (MSVC) @@ -36,20 +36,22 @@ foreach (type int double long time_t float) set(TYPE ${type}) set(SIGNED_TYPE true) configure_file(vector_template.h.in include/ert/util/${type}_vector.h) - configure_file(util/vector_template.c ${type}_vector.c) - list(APPEND opt_srcs ${CMAKE_CURRENT_BINARY_DIR}/${type}_vector.c) + configure_file(vector_template.hpp.in include/ert/util/${type}_vector.hpp) + configure_file(util/vector_template.cpp ${type}_vector.cpp) + list(APPEND opt_srcs ${CMAKE_CURRENT_BINARY_DIR}/${type}_vector.cpp) endforeach () foreach (type bool size_t) set(TYPE ${type}) set(SIGNED_TYPE false) configure_file(vector_template.h.in include/ert/util/${type}_vector.h) - configure_file(util/vector_template.c ${type}_vector.c) - list(APPEND opt_srcs ${CMAKE_CURRENT_BINARY_DIR}/${type}_vector.c) + configure_file(vector_template.hpp.in include/ert/util/${type}_vector.hpp) + configure_file(util/vector_template.cpp ${type}_vector.cpp) + list(APPEND opt_srcs ${CMAKE_CURRENT_BINARY_DIR}/${type}_vector.cpp) endforeach () if (ZLIB_FOUND) - list(APPEND opt_srcs util/util_zlib.c) + list(APPEND opt_srcs util/util_zlib.cpp) endif () if (ERT_BUILD_CXX) @@ -60,95 +62,96 @@ if (ERT_BUILD_CXX) ) endif () - configure_file(build_config.h.in include/ert/util/build_config.h) configure_file(ert_api_config.h.in include/ert/util/ert_api_config.h) +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 util/rng.c - util/lookup_table.c - util/statistics.c - util/mzran.c - util/set.c - util/hash_node.c - util/hash_sll.c - util/hash.c - util/node_data.c - util/node_ctype.c +add_library(ecl util/rng.cpp + util/lookup_table.cpp + util/statistics.cpp + util/mzran.cpp + util/set.cpp + util/hash_node.cpp + util/hash_sll.cpp + util/hash.cpp + util/node_data.cpp + util/node_ctype.cpp util/util.c - util/util_symlink.c + util/util_symlink.cpp util/util_lfs.c - util/util_unlink.c - util/arg_pack.c - util/vector.c - util/parser.c - util/stringlist.c - util/buffer.c - util/timer.c - util/string_util.c - util/type_vector_functions.c - util/ecl_version.c - util/struct_vector.c - util/perm_vector.c - util/test_util.c + util/util_unlink.cpp + util/arg_pack.cpp + util/vector.cpp + util/parser.cpp + util/stringlist.cpp + util/buffer.cpp + util/timer.cpp + util/string_util.cpp + util/type_vector_functions.cpp + util/ecl_version.cpp + util/struct_vector.cpp + util/perm_vector.cpp + util/test_util.cpp ${opt_srcs} - ecl/ecl_rsthead.c - ecl/ecl_sum_tstep.c - ecl/ecl_rst_file.c - ecl/ecl_init_file.c - ecl/ecl_grid_cache.c - ecl/smspec_node.c - ecl/ecl_kw_grdecl.c - ecl/ecl_file_kw.c - ecl/ecl_file_view.c - ecl/ecl_grav.c - ecl/ecl_grav_calc.c - ecl/ecl_smspec.c - ecl/ecl_sum_data.c - ecl/ecl_util.c - ecl/ecl_kw.c - ecl/ecl_sum.c - ecl/ecl_sum_vector.c + 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_grav_calc.cpp + ecl/ecl_smspec.cpp + ecl/ecl_sum_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.c - ecl/ecl_rft_node.c - ecl/ecl_rft_cell.c - ecl/ecl_grid.c - ecl/ecl_coarse_cell.c - ecl/ecl_box.c - ecl/ecl_io_config.c - ecl/ecl_file.c - ecl/ecl_region.c - ecl/ecl_subsidence.c - ecl/ecl_grid_dims.c - ecl/grid_dims.c - ecl/nnc_info.c - ecl/ecl_grav_common.c - ecl/nnc_vector.c - ecl/ecl_nnc_export.c - ecl/ecl_nnc_data.c - ecl/ecl_nnc_geometry.c - ecl/layer.c - ecl/fault_block.c - ecl/fault_block_layer.c - ecl/ecl_type.c - ecl/ecl_type_python.c - ecl/well_state.c - ecl/well_conn.c - ecl/well_info.c - ecl/well_ts.c - ecl/well_conn_collection.c - ecl/well_segment.c - ecl/well_segment_collection.c - ecl/well_branch_collection.c - ecl/well_rseg_loader.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 - geometry/geo_surface.c - geometry/geo_util.c - geometry/geo_pointset.c - geometry/geo_region.c - geometry/geo_polygon.c - geometry/geo_polygon_collection.c + geometry/geo_surface.cpp + geometry/geo_util.cpp + geometry/geo_pointset.cpp + geometry/geo_region.cpp + geometry/geo_polygon.cpp + geometry/geo_polygon_collection.cpp ) target_link_libraries(ecl PUBLIC ${m} @@ -190,7 +193,7 @@ endif () set_target_properties(ecl PROPERTIES VERSION ${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR} SOVERSION ${ECL_VERSION_MAJOR}) -if (INSTALL_ERT) + install(TARGETS ecl EXPORT ecl-config ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -215,7 +218,6 @@ if (ERT_BUILD_CXX) PATTERN *.hpp ) endif () -endif() if (NOT BUILD_TESTS) return () diff --git a/ThirdParty/Ert/lib/build_config.hpp.in b/ThirdParty/Ert/lib/build_config.hpp.in new file mode 100644 index 0000000000..3c81293d5b --- /dev/null +++ b/ThirdParty/Ert/lib/build_config.hpp.in @@ -0,0 +1 @@ +#include diff --git a/ThirdParty/Ert/lib/ecl/FortIO.cpp b/ThirdParty/Ert/lib/ecl/FortIO.cpp index 7732390422..803640ad6e 100644 --- a/ThirdParty/Ert/lib/ecl/FortIO.cpp +++ b/ThirdParty/Ert/lib/ecl/FortIO.cpp @@ -19,8 +19,7 @@ #include -#include -#include +#include #include diff --git a/ThirdParty/Ert/lib/ecl/Smspec.cpp b/ThirdParty/Ert/lib/ecl/Smspec.cpp index 558c652bf8..ba81341bef 100644 --- a/ThirdParty/Ert/lib/ecl/Smspec.cpp +++ b/ThirdParty/Ert/lib/ecl/Smspec.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace ERT { diff --git a/ThirdParty/Ert/lib/ecl/ecl_box.c b/ThirdParty/Ert/lib/ecl/ecl_box.cpp similarity index 91% rename from ThirdParty/Ert/lib/ecl/ecl_box.c rename to ThirdParty/Ert/lib/ecl/ecl_box.cpp index 9c5b0350c1..f5fc900fab 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_box.c +++ b/ThirdParty/Ert/lib/ecl/ecl_box.cpp @@ -21,10 +21,10 @@ #include #include -#include +#include -#include -#include +#include +#include #define ECL_BOX_TYPE_ID 6610643 @@ -60,7 +60,7 @@ UTIL_SAFE_CAST_FUNCTION( ecl_box , ECL_BOX_TYPE_ID) */ ecl_box_type * ecl_box_alloc(const ecl_grid_type * ecl_grid , int __i1,int __i2 , int __j1 , int __j2 , int __k1, int __k2) { - ecl_box_type * ecl_box = util_malloc(sizeof * ecl_box ); + ecl_box_type * ecl_box = (ecl_box_type *)util_malloc(sizeof * ecl_box ); UTIL_TYPE_ID_INIT( ecl_box , ECL_BOX_TYPE_ID); ecl_box->parent_grid = ecl_grid; /* Properties of the parent grid. */ @@ -102,8 +102,8 @@ ecl_box_type * ecl_box_alloc(const ecl_grid_type * ecl_grid , int __i1,int __i2 int global_counter = 0; int i,j,k; ecl_box->active_size = 0; - ecl_box->active_list = util_calloc( ecl_box->box_nx * ecl_box->box_ny * ecl_box->box_nz , sizeof * ecl_box->active_list ); - ecl_box->global_list = util_calloc( ecl_box->box_nx * ecl_box->box_ny * ecl_box->box_nz , sizeof * ecl_box->global_list ); + ecl_box->active_list = (int*)util_calloc( ecl_box->box_nx * ecl_box->box_ny * ecl_box->box_nz , sizeof * ecl_box->active_list ); + ecl_box->global_list = (int*)util_calloc( ecl_box->box_nx * ecl_box->box_ny * ecl_box->box_nz , sizeof * ecl_box->global_list ); for (k=k1; k <= k2; k++) for (j=j1; j <= j2; j++) for (i=i1; i <= i2; i++) { @@ -121,7 +121,7 @@ ecl_box_type * ecl_box_alloc(const ecl_grid_type * ecl_grid , int __i1,int __i2 } } - ecl_box->active_list = util_realloc( ecl_box->active_list , ecl_box->active_size * sizeof * ecl_box->active_list ); + ecl_box->active_list = (int*)util_realloc( ecl_box->active_list , ecl_box->active_size * sizeof * ecl_box->active_list ); } } return ecl_box; diff --git a/ThirdParty/Ert/lib/ecl/ecl_coarse_cell.c b/ThirdParty/Ert/lib/ecl/ecl_coarse_cell.cpp similarity index 97% rename from ThirdParty/Ert/lib/ecl/ecl_coarse_cell.c rename to ThirdParty/Ert/lib/ecl/ecl_coarse_cell.cpp index 3716b9fa0a..48e688d011 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_coarse_cell.c +++ b/ThirdParty/Ert/lib/ecl/ecl_coarse_cell.cpp @@ -20,12 +20,12 @@ #include #include -#include -#include -#include +#include +#include +#include -#include -#include +#include +#include /******************************************************************/ /* @@ -140,7 +140,7 @@ void ecl_coarse_cell_assert( ecl_coarse_cell_type * coarse_cell ) { ecl_coarse_cell_type * ecl_coarse_cell_alloc() { const int LARGE = 1 << 30; - ecl_coarse_cell_type * coarse_cell = util_malloc( sizeof * coarse_cell ); + 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 ); coarse_cell->ijk[0] = LARGE; diff --git a/ThirdParty/Ert/lib/ecl/ecl_file.c b/ThirdParty/Ert/lib/ecl/ecl_file.cpp similarity index 98% rename from ThirdParty/Ert/lib/ecl/ecl_file.c rename to ThirdParty/Ert/lib/ecl/ecl_file.cpp index 7c9d3f652c..510c87f2cf 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_file.c +++ b/ThirdParty/Ert/lib/ecl/ecl_file.cpp @@ -22,21 +22,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 /** This file implements functionality to load an ECLIPSE file in @@ -178,7 +178,7 @@ UTIL_IS_INSTANCE_FUNCTION( ecl_file , ECL_FILE_ID) ecl_file_type * ecl_file_alloc_empty( int flags ) { - ecl_file_type * ecl_file = util_malloc( sizeof * ecl_file ); + 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( ); @@ -800,7 +800,6 @@ ecl_version_enum ecl_file_get_ecl_version( const ecl_file_type * file ) { return FRONTSIM; util_abort("%s: Simulator version value:%d not recognized \n",__func__ , int_value ); - return -1; } /* @@ -887,7 +886,7 @@ void ecl_file_push_block( ecl_file_type * ecl_file ) { } void ecl_file_pop_block( ecl_file_type * ecl_file ) { - ecl_file->active_view = vector_pop_back( ecl_file->map_stack ); + ecl_file->active_view = (ecl_file_view_type *)vector_pop_back( ecl_file->map_stack ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_file_kw.c b/ThirdParty/Ert/lib/ecl/ecl_file_kw.cpp similarity index 95% rename from ThirdParty/Ert/lib/ecl/ecl_file_kw.c rename to ThirdParty/Ert/lib/ecl/ecl_file_kw.cpp index d8fe735202..e07c9884d6 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_file_kw.c +++ b/ThirdParty/Ert/lib/ecl/ecl_file_kw.cpp @@ -21,12 +21,12 @@ #include #include -#include -#include +#include +#include -#include -#include -#include +#include +#include +#include #include /* @@ -69,7 +69,7 @@ struct ecl_file_kw_struct { /*****************************************************************/ inv_map_type * inv_map_alloc() { - inv_map_type * map = util_malloc( sizeof * map ); + 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; @@ -137,7 +137,7 @@ 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 = util_malloc( sizeof * file_kw ); + 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 ); @@ -363,14 +363,14 @@ void ecl_file_kw_fwrite( const ecl_file_kw_type * file_kw , FILE * 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_ctype_fortio( 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 = util_malloc( buffer_size * sizeof * buffer ); + char * buffer = (char*)util_malloc( buffer_size * sizeof * buffer ); size_t num_read = fread( buffer, 1 , buffer_size , stream); if (num_read != buffer_size) { @@ -379,7 +379,7 @@ ecl_file_kw_type ** ecl_file_kw_fread_alloc_multiple( FILE * stream , int num) { } { - ecl_file_kw_type ** kw_list = util_malloc( num * sizeof * kw_list ); + 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]; diff --git a/ThirdParty/Ert/lib/ecl/ecl_file_view.c b/ThirdParty/Ert/lib/ecl/ecl_file_view.cpp similarity index 93% rename from ThirdParty/Ert/lib/ecl/ecl_file_view.c rename to ThirdParty/Ert/lib/ecl/ecl_file_view.cpp index 0d42d7fd7a..ed3e549ebd 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_file_view.c +++ b/ThirdParty/Ert/lib/ecl/ecl_file_view.cpp @@ -17,17 +17,17 @@ */ -#include -#include -#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include struct ecl_file_view_struct { @@ -71,7 +71,7 @@ const char * ecl_file_view_get_src_file( const ecl_file_view_type * file_view ) 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 = util_malloc( sizeof * ecl_file_view ); + ecl_file_view_type * ecl_file_view = (ecl_file_view_type*)util_malloc( sizeof * ecl_file_view ); ecl_file_view->kw_list = vector_alloc_new(); ecl_file_view->kw_index = hash_alloc(); ecl_file_view->distinct_kw = stringlist_alloc_new(); @@ -84,7 +84,7 @@ ecl_file_view_type * ecl_file_view_alloc( fortio_type * fortio , int * flags , i } int ecl_file_view_get_global_index( const ecl_file_view_type * ecl_file_view , const char * kw , int ith) { - const int_vector_type * index_vector = hash_get(ecl_file_view->kw_index , kw); + const int_vector_type * index_vector = (const int_vector_type*)hash_get(ecl_file_view->kw_index , kw); int global_index = int_vector_iget( index_vector , ith); return global_index; } @@ -106,7 +106,7 @@ void ecl_file_view_make_index( ecl_file_view_type * ecl_file_view ) { { int i; for (i=0; i < vector_get_size( ecl_file_view->kw_list ); i++) { - const ecl_file_kw_type * file_kw = vector_iget_const( ecl_file_view->kw_list , i); + const ecl_file_kw_type * file_kw = (const ecl_file_kw_type*)vector_iget_const( ecl_file_view->kw_list , i); const char * header = ecl_file_kw_get_header( file_kw ); if ( !hash_has_key( ecl_file_view->kw_index , header )) { int_vector_type * index_vector = int_vector_alloc( 0 , -1 ); @@ -115,7 +115,7 @@ void ecl_file_view_make_index( ecl_file_view_type * ecl_file_view ) { } { - int_vector_type * index_vector = hash_get( ecl_file_view->kw_index , header); + int_vector_type * index_vector = (int_vector_type*)hash_get( ecl_file_view->kw_index , header); int_vector_append( index_vector , i); } } @@ -128,7 +128,7 @@ bool ecl_file_view_has_kw( const ecl_file_view_type * ecl_file_view, const char 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 * file_kw = vector_iget( ecl_file_view->kw_list , global_index); + ecl_file_kw_type * file_kw = (ecl_file_kw_type*)vector_iget( ecl_file_view->kw_list , global_index); return file_kw; } @@ -169,7 +169,7 @@ ecl_kw_type * ecl_file_view_iget_kw( const ecl_file_view_type * ecl_file_view , 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* buffer) { +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 )) { @@ -177,7 +177,7 @@ void ecl_file_view_index_fload_kw(const ecl_file_view_type * ecl_file_view, cons 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, buffer); + ecl_kw_fread_indexed_data(ecl_file_view->fortio, offset + ECL_KW_HEADER_FORTIO_SIZE, data_type, element_count, index_map, io_buffer); } } @@ -185,7 +185,7 @@ void ecl_file_view_index_fload_kw(const ecl_file_view_type * ecl_file_view, cons 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 int_vector_type * index_list = hash_get( ecl_file_view->kw_index , kw ); + const int_vector_type * index_list = (const int_vector_type*)hash_get( ecl_file_view->kw_index , kw ); int index = 0; while (index < int_vector_size( index_list )) { const ecl_kw_type * ecl_kw = ecl_file_view_iget_kw( ecl_file_view , int_vector_iget( index_list , index )); @@ -247,7 +247,7 @@ int ecl_file_view_iget_named_size( const ecl_file_view_type * ecl_file_view , co 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) { int index = 0; while (index < vector_get_size( ecl_file_view->kw_list )) { - ecl_file_kw_type * ikw = vector_iget( ecl_file_view->kw_list , index ); + ecl_file_kw_type * ikw = (ecl_file_kw_type*)vector_iget( ecl_file_view->kw_list , index ); if (ecl_file_kw_ptr_eq( ikw , old_kw)) { /* Found it; observe that the vector_iset() function will @@ -274,7 +274,7 @@ bool ecl_file_view_load_all( ecl_file_view_type * ecl_file_view ) { if (fortio_assert_stream_open( ecl_file_view->fortio )) { int index; for (index = 0; index < vector_get_size( ecl_file_view->kw_list); index++) { - ecl_file_kw_type * ikw = vector_iget( ecl_file_view->kw_list , index ); + ecl_file_kw_type * ikw = (ecl_file_kw_type*)vector_iget( ecl_file_view->kw_list , index ); ecl_file_kw_get_kw( ikw , ecl_file_view->fortio , ecl_file_view->inv_map); } loadOK = true; @@ -314,7 +314,7 @@ 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) { if (hash_has_key(ecl_file_view->kw_index , kw)) { - const int_vector_type * index_vector = hash_get(ecl_file_view->kw_index , kw); + const int_vector_type * index_vector = (const int_vector_type*)hash_get(ecl_file_view->kw_index , kw); return int_vector_size( index_vector ); } else return 0; @@ -332,9 +332,9 @@ void ecl_file_view_fwrite( const ecl_file_view_type * ecl_file_view , fortio_typ int ecl_file_view_iget_occurence( const ecl_file_view_type * ecl_file_view , int global_index) { - const ecl_file_kw_type * file_kw = vector_iget_const( ecl_file_view->kw_list , global_index); + const ecl_file_kw_type * file_kw = (const ecl_file_kw_type*)vector_iget_const( ecl_file_view->kw_list , global_index); const char * header = ecl_file_kw_get_header( file_kw ); - const int_vector_type * index_vector = hash_get( ecl_file_view->kw_index , header ); + const int_vector_type * index_vector = (const int_vector_type*)hash_get( ecl_file_view->kw_index , header ); const int * index_data = int_vector_get_const_ptr( index_vector ); int occurence = -1; @@ -354,7 +354,7 @@ int ecl_file_view_iget_occurence( const ecl_file_view_type * ecl_file_view , int void ecl_file_view_fprintf_kw_list(const ecl_file_view_type * ecl_file_view , FILE * stream) { int i; for (i=0; i < vector_get_size( ecl_file_view->kw_list ); i++) { - const ecl_file_kw_type * file_kw = vector_iget_const( ecl_file_view->kw_list , i ); + const ecl_file_kw_type * file_kw = (const ecl_file_kw_type*)vector_iget_const( ecl_file_view->kw_list , i ); 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 ) , @@ -376,7 +376,7 @@ ecl_file_view_type * ecl_file_view_alloc_blockview2(const ecl_file_view_type * e kw_index = ecl_file_view_get_global_index( ecl_file_view , start_kw , occurence ); { - ecl_file_kw_type * file_kw = vector_iget( ecl_file_view->kw_list , kw_index ); + ecl_file_kw_type * file_kw = (ecl_file_kw_type*)vector_iget( ecl_file_view->kw_list , kw_index ); while (true) { ecl_file_view_add_kw( block_map , file_kw ); @@ -385,7 +385,7 @@ ecl_file_view_type * ecl_file_view_alloc_blockview2(const ecl_file_view_type * e break; else { if (end_kw) { - file_kw = vector_iget(ecl_file_view->kw_list , kw_index); + file_kw = (ecl_file_kw_type*)vector_iget(ecl_file_view->kw_list , kw_index); if (strcmp( end_kw , ecl_file_kw_get_header( file_kw )) == 0) break; } @@ -589,7 +589,7 @@ double ecl_file_view_iget_restart_sim_days(const ecl_file_view_type * ecl_file_v 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 int_vector_type * intehead_index_list = hash_get( ecl_file_view->kw_index , INTEHEAD_KW ); + const int_vector_type * intehead_index_list = (const int_vector_type *)hash_get( ecl_file_view->kw_index , INTEHEAD_KW ); int index = 0; while (index < int_vector_size( intehead_index_list )) { const ecl_kw_type * intehead_kw = ecl_file_view_iget_kw( ecl_file_view , int_vector_iget( intehead_index_list , index )); @@ -807,10 +807,10 @@ ecl_file_view_type * ecl_file_view_fread_alloc( fortio_type * fortio , int * fla ecl_file_transaction_type * ecl_file_view_start_transaction(ecl_file_view_type * file_view) { - ecl_file_transaction_type * t = util_malloc(sizeof * t); + 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 = util_malloc( size * sizeof * t->ref_count ); + 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]); diff --git a/ThirdParty/Ert/lib/ecl/ecl_grav.c b/ThirdParty/Ert/lib/ecl/ecl_grav.cpp similarity index 94% rename from ThirdParty/Ert/lib/ecl/ecl_grav.c rename to ThirdParty/Ert/lib/ecl/ecl_grav.cpp index a763f111f0..5d25b9b966 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_grav.c +++ b/ThirdParty/Ert/lib/ecl/ecl_grav.cpp @@ -20,19 +20,19 @@ #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 /** @@ -157,7 +157,7 @@ static const char * get_den_kw( ecl_phase_enum phase , ecl_version_enum ecl_vers static void ecl_grav_phase_ensure_work( ecl_grav_phase_type * grav_phase) { if (grav_phase->work == NULL) - grav_phase->work = util_calloc( ecl_grid_cache_get_size( grav_phase->grid_cache ) , sizeof * grav_phase->work ); + grav_phase->work = (double*)util_calloc( ecl_grid_cache_get_size( grav_phase->grid_cache ) , sizeof * grav_phase->work ); } @@ -213,19 +213,19 @@ static ecl_grav_phase_type * ecl_grav_phase_alloc( ecl_grav_type * ecl_grav , const ecl_grid_cache_type * grid_cache = ecl_grav->grid_cache; const char * sat_kw_name = ecl_util_get_phase_name( phase ); { - ecl_grav_phase_type * grav_phase = util_malloc( sizeof * grav_phase ); + ecl_grav_phase_type * grav_phase = (ecl_grav_phase_type*)util_malloc( sizeof * grav_phase ); const int size = ecl_grid_cache_get_size( grid_cache ); 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 = util_calloc( size , sizeof * grav_phase->fluid_mass ); + 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 ); - double_vector_type * std_density = hash_get( ecl_grav->std_density , ecl_util_get_phase_name( phase )); + double_vector_type * std_density = (double_vector_type*)hash_get( ecl_grav->std_density , ecl_util_get_phase_name( phase )); ecl_kw_type * fip_kw; if ( phase == ECL_OIL_PHASE) @@ -349,7 +349,7 @@ static void ecl_grav_survey_add_phases( ecl_grav_type * ecl_grav , ecl_grav_surv 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 = util_malloc( sizeof * survey ); + ecl_grav_survey_type * survey = (ecl_grav_survey_type*)util_malloc( sizeof * survey ); UTIL_TYPE_ID_INIT( survey , ECL_GRAV_SURVEY_ID ); survey->grid_cache = ecl_grav->grid_cache; survey->aquifer_cell = ecl_grav->aquifer_cell; @@ -358,7 +358,7 @@ static ecl_grav_survey_type * ecl_grav_survey_alloc_empty(const ecl_grav_type * survey->phase_map = hash_alloc(); if (calc_type & GRAV_CALC_USE_PORV) - survey->porv = util_calloc( ecl_grid_cache_get_size( ecl_grav->grid_cache ) , sizeof * survey->porv ); + survey->porv = (double*)util_calloc( ecl_grid_cache_get_size( ecl_grav->grid_cache ) , sizeof * survey->porv ); else survey->porv = NULL; @@ -549,10 +549,10 @@ static double ecl_grav_survey_eval( const ecl_grav_survey_type * base_survey, int phase_nr; double deltag = 0; for (phase_nr = 0; phase_nr < vector_get_size( base_survey->phase_list ); phase_nr++) { - ecl_grav_phase_type * base_phase = vector_iget( base_survey->phase_list , phase_nr ); + ecl_grav_phase_type * base_phase = (ecl_grav_phase_type*)vector_iget( base_survey->phase_list , phase_nr ); if (base_phase->phase & phase_mask) { if (monitor_survey != NULL) { - const ecl_grav_phase_type * monitor_phase = vector_iget_const( monitor_survey->phase_list , phase_nr ); + const ecl_grav_phase_type * monitor_phase = (const ecl_grav_phase_type*)vector_iget_const( 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 ); @@ -570,7 +570,7 @@ static double ecl_grav_survey_eval( const ecl_grav_survey_type * base_survey, */ ecl_grav_type * ecl_grav_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file) { - ecl_grav_type * ecl_grav = util_malloc( sizeof * ecl_grav ); + ecl_grav_type * ecl_grav = (ecl_grav_type*)util_malloc( sizeof * ecl_grav ); ecl_grav->init_file = init_file; ecl_grav->grid_cache = ecl_grid_cache_alloc( ecl_grid ); ecl_grav->aquifer_cell = ecl_grav_common_alloc_aquifer_cell( ecl_grav->grid_cache , ecl_grav->init_file ); @@ -619,7 +619,7 @@ static ecl_grav_survey_type * ecl_grav_get_survey( const ecl_grav_type * grav , return NULL; // Calling scope must determine if this is OK? else { if (hash_has_key( grav->surveys , name)) - return hash_get( grav->surveys , name ); + return (ecl_grav_survey_type*)hash_get( grav->surveys , name ); else { hash_iter_type * survey_iter = hash_iter_alloc( grav->surveys ); fprintf(stderr,"Survey name:%s not registered. Available surveys are: \n\n " , name); @@ -680,7 +680,7 @@ void ecl_grav_new_std_density( ecl_grav_type * grav , ecl_phase_enum phase , dou void ecl_grav_add_std_density( ecl_grav_type * grav , ecl_phase_enum phase , int pvtnum , double density) { - double_vector_type * std_density = hash_get( grav->std_density , ecl_util_get_phase_name( phase )); + double_vector_type * std_density = (double_vector_type*)hash_get( grav->std_density , ecl_util_get_phase_name( phase )); double_vector_iset( std_density , pvtnum , density ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_grav_calc.c b/ThirdParty/Ert/lib/ecl/ecl_grav_calc.cpp similarity index 97% rename from ThirdParty/Ert/lib/ecl/ecl_grav_calc.c rename to ThirdParty/Ert/lib/ecl/ecl_grav_calc.cpp index 66618bbbe6..ae41b98c69 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_grav_calc.c +++ b/ThirdParty/Ert/lib/ecl/ecl_grav_calc.cpp @@ -20,12 +20,12 @@ #include #include -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include diff --git a/ThirdParty/Ert/lib/ecl/ecl_grav_common.c b/ThirdParty/Ert/lib/ecl/ecl_grav_common.cpp similarity index 94% rename from ThirdParty/Ert/lib/ecl/ecl_grav_common.c rename to ThirdParty/Ert/lib/ecl/ecl_grav_common.cpp index 024a44c09f..37da5a000c 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_grav_common.c +++ b/ThirdParty/Ert/lib/ecl/ecl_grav_common.cpp @@ -21,13 +21,14 @@ #include #include -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include /* This file contains code which is common to both the ecl_grav @@ -36,7 +37,7 @@ */ bool * ecl_grav_common_alloc_aquifer_cell( const ecl_grid_cache_type * grid_cache , const ecl_file_type * init_file) { - bool * aquifer_cell = util_calloc( ecl_grid_cache_get_size( grid_cache ) , sizeof * aquifer_cell ); + bool * aquifer_cell = (bool*)util_calloc( ecl_grid_cache_get_size( grid_cache ) , sizeof * aquifer_cell ); for (int active_index = 0; active_index < ecl_grid_cache_get_size( grid_cache ); active_index++) aquifer_cell[ active_index ] = false; diff --git a/ThirdParty/Ert/lib/ecl/ecl_grid.c b/ThirdParty/Ert/lib/ecl/ecl_grid.cpp similarity index 97% rename from ThirdParty/Ert/lib/ecl/ecl_grid.c rename to ThirdParty/Ert/lib/ecl/ecl_grid.cpp index d04f6715d5..4f494d0ffc 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_grid.c +++ b/ThirdParty/Ert/lib/ecl/ecl_grid.cpp @@ -22,26 +22,26 @@ #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 +#include +#include +#include +#include +#include +#include /** @@ -861,7 +861,7 @@ static void ecl_cell_fwrite_GRID(const ecl_grid_type * grid, ecl_kw_fwrite( coords_kw , fortio ); { - float * corners = ecl_kw_get_void_ptr( corners_kw ); + float * corners = (float*)ecl_kw_get_void_ptr( corners_kw ); point_type point; int c; @@ -1288,7 +1288,8 @@ static double ecl_cell_get_signed_volume( ecl_cell_type * cell) { point_type corners[ 8 ]; memcpy( corners, cell->corner_list, sizeof( point_type ) * 8 ); - tetrahedron_type tet = { .p0 = center }; + tetrahedron_type tet; + tet.p0 = center; double volume = 0; /* using both tetrahedron decompositions - gives good agreement @@ -1567,7 +1568,7 @@ static void ecl_grid_free_cells( ecl_grid_type * grid ) { } static bool ecl_grid_alloc_cells( ecl_grid_type * grid , bool init_valid) { - grid->cells = malloc(grid->size * sizeof * grid->cells ); + grid->cells = (ecl_cell_type*)malloc(grid->size * sizeof * grid->cells ); if (!grid->cells) return false; @@ -1600,7 +1601,7 @@ static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid, int nz, int lgr_nr, bool init_valid) { - ecl_grid_type * grid = util_malloc(sizeof * grid ); + ecl_grid_type * grid = (ecl_grid_type*)util_malloc(sizeof * grid ); UTIL_TYPE_ID_INIT(grid , ECL_GRID_ID); grid->total_active = 0; grid->total_active_fracture = 0; @@ -1845,9 +1846,9 @@ static void ecl_grid_init_index_map__(ecl_grid_type * ecl_grid, static void ecl_grid_realloc_index_map(ecl_grid_type * ecl_grid) { /* Creating the inverse mapping for the matrix cells. */ - ecl_grid->index_map = util_realloc(ecl_grid->index_map, + ecl_grid->index_map = (int*)util_realloc(ecl_grid->index_map, ecl_grid->size * sizeof * ecl_grid->index_map); - ecl_grid->inv_index_map = util_realloc(ecl_grid->inv_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, @@ -1858,9 +1859,9 @@ static void ecl_grid_realloc_index_map(ecl_grid_type * ecl_grid) { /* Create the inverse mapping for the fractures. */ if (ecl_grid->dualp_flag != FILEHEAD_SINGLE_POROSITY) { - ecl_grid->fracture_index_map = util_realloc(ecl_grid->fracture_index_map, + 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 = util_realloc(ecl_grid->inv_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, @@ -2023,7 +2024,7 @@ static ecl_coarse_cell_type * ecl_grid_get_or_create_coarse_cell( ecl_grid_type 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__); - return vector_iget( ecl_grid->coarse_cells , coarse_nr ); + return (ecl_coarse_cell_type*)vector_iget( ecl_grid->coarse_cells , coarse_nr ); } @@ -2044,7 +2045,7 @@ static void ecl_grid_init_coarse_cells( ecl_grid_type * ecl_grid ) { ecl_coarse_cell_type * ecl_grid_iget_coarse_group( const ecl_grid_type * ecl_grid , int coarse_nr ) { - return vector_iget( ecl_grid->coarse_cells , coarse_nr ); + return (ecl_coarse_cell_type*)vector_iget( ecl_grid->coarse_cells , coarse_nr ); } @@ -2123,7 +2124,7 @@ static void ecl_grid_init_mapaxes( ecl_grid_type * ecl_grid , bool apply_mapaxes } ecl_grid->origo[0] = mapaxes[2]; ecl_grid->origo[1] = mapaxes[3]; - ecl_grid->mapaxes = util_malloc( 6 * sizeof * ecl_grid->mapaxes ); + ecl_grid->mapaxes = (float*)util_malloc( 6 * sizeof * ecl_grid->mapaxes ); memcpy( ecl_grid->mapaxes , mapaxes , 6 * sizeof( float )); /* @@ -2230,10 +2231,10 @@ static void ecl_grid_install_lgr_GRID(ecl_grid_type * host_grid , ecl_grid_type 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 = util_alloc_strip_copy( ecl_kw_iget_ptr( lgrname_kw , 0) ); /* trailing zeros are stripped away. */ + 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); - char * parent = util_alloc_strip_copy( ecl_kw_iget_ptr( parent_kw , 0)); + char * parent = (char*)util_alloc_strip_copy( (const char*)ecl_kw_iget_ptr( parent_kw , 0)); if (strlen( parent ) > 0) lgr_grid->parent_name = parent; @@ -2251,7 +2252,7 @@ static void ecl_grid_set_lgr_name_EGRID(ecl_grid_type * lgr_grid , const ecl_fil 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 = util_alloc_strip_copy( ecl_kw_iget_ptr( lgr_kw , 0) ); /* trailing zeros are stripped away. */ + lgr_grid->name = (char*)util_alloc_strip_copy( (const char*)ecl_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 @@ -2259,7 +2260,7 @@ static void ecl_grid_set_lgr_name_GRID(ecl_grid_type * lgr_grid , const ecl_file only one element the current lgr is assumed to descend from the main grid */ if (ecl_kw_get_size( lgr_kw ) == 2) { - char * parent = util_alloc_strip_copy( ecl_kw_iget_ptr( lgr_kw , 1)); + char * parent = (char*)util_alloc_strip_copy( (const char*)ecl_kw_iget_ptr( lgr_kw , 1)); if ((strlen(parent) == 0) || (strcmp(parent , GLOBAL_STRING ) == 0)) free( parent ); @@ -2430,9 +2431,9 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_data__(ecl_grid_type * global_grid, static void ecl_grid_copy_mapaxes( ecl_grid_type * target_grid , const ecl_grid_type * src_grid ) { target_grid->use_mapaxes = src_grid->use_mapaxes; if (src_grid->mapaxes) - target_grid->mapaxes = util_realloc_copy(target_grid->mapaxes , src_grid->mapaxes , 6 * sizeof * src_grid->mapaxes ); + target_grid->mapaxes = (float*)util_realloc_copy(target_grid->mapaxes , src_grid->mapaxes , 6 * sizeof * src_grid->mapaxes ); else - target_grid->mapaxes = util_realloc_copy(target_grid->mapaxes , NULL , 0 ); + target_grid->mapaxes = (float*)util_realloc_copy(target_grid->mapaxes , NULL , 0 ); for (int i=0; i < 2; i++) { target_grid->unit_x[i] = src_grid->unit_x[i]; @@ -2485,7 +2486,7 @@ ecl_grid_type * ecl_grid_alloc_copy( const ecl_grid_type * src_grid ) { { int grid_nr; for (grid_nr = 0; grid_nr < vector_get_size( src_grid->LGR_list ); grid_nr++) { - const ecl_grid_type * src_lgr = vector_iget_const( 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; @@ -2528,12 +2529,12 @@ ecl_grid_type * ecl_grid_alloc_processed_copy( const ecl_grid_type * src_grid , } else { int nx,ny,nz,na; int zcorn_size = ecl_grid_get_zcorn_size( src_grid ); - float * zcorn_float = util_malloc( zcorn_size * sizeof * zcorn_float ); + float * zcorn_float = (float*)util_malloc( zcorn_size * sizeof * zcorn_float ); float * coord = ecl_grid_alloc_coord_data( src_grid ); float * mapaxes = NULL; if (ecl_grid_get_mapaxes( src_grid )) { - mapaxes = util_malloc( 6 * sizeof * mapaxes ); + mapaxes = (float*)util_malloc( 6 * sizeof * mapaxes ); ecl_grid_init_mapaxes_data_float(src_grid, mapaxes); } ecl_grid_get_dims( src_grid , &nx, &ny , &nz , &na); @@ -3160,8 +3161,8 @@ static ecl_grid_type * ecl_grid_alloc_GRID__(ecl_grid_type * global_grid , const int coords_size = -1; int index; - int ** coords = util_calloc( num_coords , sizeof * coords ); - float ** corners = util_calloc( num_coords , sizeof * corners ); + int ** coords = (int **)util_calloc( num_coords , sizeof * coords ); + float ** corners = (float**)util_calloc( num_coords , sizeof * corners ); for (index = 0; index < num_coords; index++) { const ecl_kw_type * coords_kw = ecl_file_iget_named_kw(ecl_file , COORDS_KW , index + cell_offset); @@ -3449,7 +3450,7 @@ ecl_grid_type * ecl_grid_alloc_dx_dy_dz_tops( int nx, int ny , int nz , const do 0, true); if (grid) { int i, j, k; - double * y0 = util_calloc( nx, sizeof * y0 ); + double * y0 = (double*)util_calloc( nx, sizeof * y0 ); for (k=0; k < nz; k++) { for (i=0; i < nx; i++) { @@ -3744,8 +3745,8 @@ static bool ecl_grid_compare_coarse_cells(const ecl_grid_type * g1 , const ecl_g int c; for (c = 0; c < vector_get_size( g1->coarse_cells ); c++) { - const ecl_coarse_cell_type * coarse_cell1 = vector_iget_const( g1->coarse_cells , c); - const ecl_coarse_cell_type * coarse_cell2 = vector_iget_const( g2->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 ); if (!equal) @@ -3909,8 +3910,8 @@ bool ecl_grid_compare(const ecl_grid_type * g1 , const ecl_grid_type * g2 , bool 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 = vector_iget_const( g1->LGR_list , grid_nr); - const ecl_grid_type * lgr2 = vector_iget_const( g2->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); printf("Comparing lgr grid:%d \n",grid_nr); equal = ecl_grid_compare__(lgr1 , lgr2 , include_nnc , verbose); @@ -4185,7 +4186,7 @@ int ecl_grid_get_global_index_from_xy_bottom( const ecl_grid_type * ecl_grid , d static void ecl_grid_clear_visited( ecl_grid_type * grid ) { if (grid->visited == NULL) - grid->visited = util_calloc( grid->size , sizeof * grid->visited ); + grid->visited = (bool*)util_calloc( grid->size , sizeof * grid->visited ); { int i; @@ -4407,7 +4408,7 @@ void ecl_grid_alloc_blocking_variables(ecl_grid_type * grid, int block_dim) { else util_abort("%: valid values are two and three. Value:%d invaid \n",__func__ , block_dim); - grid->values = util_calloc( grid->block_size , sizeof * grid->values ); + grid->values = (double_vector_type**)util_calloc( grid->block_size , sizeof * grid->values ); for (index = 0; index < grid->block_size; index++) grid->values[index] = double_vector_alloc( 0 , 0.0 ); } @@ -5128,7 +5129,7 @@ ecl_grid_type * ecl_grid_get_lgr(const ecl_grid_type * main_grid, const char * _ __assert_main_grid( main_grid ); { char * lgr_name = util_alloc_strip_copy( __lgr_name ); - ecl_grid_type * lgr_grid = hash_get(main_grid->LGR_hash , lgr_name); + ecl_grid_type * lgr_grid = (ecl_grid_type*)hash_get(main_grid->LGR_hash , lgr_name); free(lgr_name); return lgr_grid; } @@ -5195,7 +5196,7 @@ int ecl_grid_get_num_lgr(const ecl_grid_type * main_grid ) { ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid, int lgr_index) { __assert_main_grid( main_grid ); - return vector_iget( main_grid->LGR_list , lgr_index); + return (ecl_grid_type*)vector_iget( main_grid->LGR_list , lgr_index); } /* @@ -5212,7 +5213,7 @@ ecl_grid_type * ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type * main_grid, in __assert_main_grid( main_grid ); { int lgr_index = int_vector_iget( main_grid->lgr_index_map , lgr_nr ); - return vector_iget( main_grid->LGR_list , lgr_index); + return (ecl_grid_type*)vector_iget( main_grid->LGR_list , lgr_index); } } @@ -5276,7 +5277,7 @@ stringlist_type * ecl_grid_alloc_lgr_name_list(const ecl_grid_type * ecl_grid) { 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 = vector_iget( ecl_grid->LGR_list , lgr_index); + const ecl_grid_type * lgr = (const ecl_grid_type*)vector_iget( ecl_grid->LGR_list , lgr_index); return lgr->name; } else return NULL; @@ -5421,7 +5422,7 @@ void ecl_grid_summarize(const ecl_grid_type * ecl_grid) { int grid_nr; for (grid_nr=1; grid_nr < vector_get_size( ecl_grid->LGR_list ); grid_nr++) { printf("\n"); - ecl_grid_summarize( vector_iget_const( ecl_grid->LGR_list , grid_nr )); + ecl_grid_summarize( (const ecl_grid_type*)vector_iget_const( ecl_grid->LGR_list , grid_nr )); } } ecl_grid_test_lgr_consistency( ecl_grid ); @@ -5643,7 +5644,7 @@ int ecl_grid_get_region_cells(const ecl_grid_type * ecl_grid , const ecl_kw_type 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 = ecl_kw_iget_ptr( region_kw , 0); + const int * region_ptr = (const int*)ecl_kw_iget_ptr( region_kw , 0); int_vector_reset( index_list ); @@ -5748,7 +5749,7 @@ bool ecl_grid_test_lgr_consistency( const ecl_grid_type * ecl_grid ) { hash_iter_type * lgr_iter = hash_iter_alloc( ecl_grid->children ); bool consistent = true; while (!hash_iter_is_complete( lgr_iter )) { - const ecl_grid_type * lgr = hash_iter_get_next_value( lgr_iter ); + const ecl_grid_type * lgr = (const ecl_grid_type*)hash_iter_get_next_value( lgr_iter ); consistent &= ecl_grid_test_lgr_consistency2( ecl_grid , lgr ); consistent &= ecl_grid_test_lgr_consistency( lgr ); } @@ -5815,7 +5816,7 @@ void ecl_grid_dump(const ecl_grid_type * grid , FILE * stream) { { int i; for (i = 0; i < vector_get_size( grid->LGR_list ); i++) - ecl_grid_dump__( vector_iget_const( grid->LGR_list , i) , stream ); + ecl_grid_dump__( (const ecl_grid_type*)vector_iget_const( grid->LGR_list , i) , stream ); } } @@ -5824,7 +5825,7 @@ void ecl_grid_dump_ascii(ecl_grid_type * grid , bool active_only , FILE * stream { int i; for (i = 0; i < vector_get_size( grid->LGR_list ); i++) - ecl_grid_dump_ascii__( vector_iget( grid->LGR_list , i) , active_only , stream ); + ecl_grid_dump_ascii__( (ecl_grid_type*)vector_iget( grid->LGR_list , i) , active_only , stream ); } } @@ -6068,7 +6069,7 @@ void ecl_grid_fwrite_GRID2( const ecl_grid_type * grid , const char * filename, { int grid_nr; for (grid_nr = 0; grid_nr < vector_get_size( grid->LGR_list ); grid_nr++) { - const ecl_grid_type * igrid = vector_iget_const( 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 ); } } @@ -6296,7 +6297,7 @@ void ecl_grid_init_coord_data_double( const ecl_grid_type * grid , double * coor float * ecl_grid_alloc_coord_data( const ecl_grid_type * grid ) { - float * coord = util_calloc( ecl_grid_get_coord_size(grid) , sizeof * coord ); + float * coord = (float*)util_calloc( ecl_grid_get_coord_size(grid) , sizeof * coord ); ecl_grid_init_coord_data( grid , coord ); return coord; } @@ -6304,7 +6305,7 @@ float * ecl_grid_alloc_coord_data( const ecl_grid_type * grid ) { void ecl_grid_assert_coord_kw( ecl_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 , ecl_kw_get_void_ptr( grid->coord_kw )); + ecl_grid_init_coord_data( grid , (float*)ecl_kw_get_void_ptr( grid->coord_kw )); } } @@ -6366,7 +6367,7 @@ void ecl_grid_init_zcorn_data_double( const ecl_grid_type * grid , double * zcor float * ecl_grid_alloc_zcorn_data( const ecl_grid_type * grid ) { - float * zcorn = util_calloc( 8 * grid->size , sizeof * zcorn ); + float * zcorn = (float*)util_calloc( 8 * grid->size , sizeof * zcorn ); ecl_grid_init_zcorn_data( grid , zcorn ); return zcorn; } @@ -6375,7 +6376,7 @@ float * ecl_grid_alloc_zcorn_data( const ecl_grid_type * grid ) { 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 , ecl_kw_get_void_ptr(zcorn_kw)); + ecl_grid_init_zcorn_data(grid , (float*)ecl_kw_get_void_ptr(zcorn_kw)); return zcorn_kw; } @@ -6444,7 +6445,7 @@ 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 * actnum = util_calloc( grid->size , sizeof * actnum); + int * actnum = (int*)util_calloc( grid->size , sizeof * actnum); ecl_grid_init_actnum_data( grid , actnum ); return actnum; } @@ -6453,7 +6454,7 @@ 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 * actnum_kw = ecl_kw_alloc( ACTNUM_KW , grid->size , ECL_INT); - ecl_grid_init_actnum_data( grid , ecl_kw_get_void_ptr( actnum_kw )); + ecl_grid_init_actnum_data( grid , (int*)ecl_kw_get_void_ptr( actnum_kw )); return actnum_kw; } @@ -6499,7 +6500,7 @@ static void ecl_grid_init_hostnum_data( const ecl_grid_type * grid , int * hostn } int * ecl_grid_alloc_hostnum_data( const ecl_grid_type * grid ) { - int * hostnum = util_calloc( grid->size , sizeof * hostnum ); + int * hostnum = (int*)util_calloc( grid->size , sizeof * hostnum ); ecl_grid_init_hostnum_data( grid , hostnum ); return hostnum; } @@ -6507,7 +6508,7 @@ int * ecl_grid_alloc_hostnum_data( const ecl_grid_type * grid ) { 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 , ecl_kw_get_void_ptr( hostnum_kw )); + ecl_grid_init_hostnum_data( grid , (int*)ecl_kw_get_void_ptr( hostnum_kw )); return hostnum_kw; } @@ -6522,7 +6523,7 @@ static void ecl_grid_init_corsnum_data( const ecl_grid_type * grid , int * corsn } int * ecl_grid_alloc_corsnum_data( const ecl_grid_type * grid ) { - int * corsnum = util_calloc( grid->size , sizeof * corsnum ); + int * corsnum = (int*)util_calloc( grid->size , sizeof * corsnum ); ecl_grid_init_corsnum_data( grid , corsnum ); return corsnum; } @@ -6530,7 +6531,7 @@ int * ecl_grid_alloc_corsnum_data( const ecl_grid_type * grid ) { 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 , ecl_kw_get_void_ptr( corsnum_kw )); + ecl_grid_init_corsnum_data( grid , (int*)ecl_kw_get_void_ptr( corsnum_kw )); return corsnum_kw; } @@ -6698,7 +6699,7 @@ void ecl_grid_fwrite_EGRID2( ecl_grid_type * grid , const char * filename, ert_e { int grid_nr; for (grid_nr = 0; grid_nr < vector_get_size( grid->LGR_list ); grid_nr++) { - ecl_grid_type * igrid = vector_iget( 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 ); } } @@ -6726,7 +6727,7 @@ void ecl_grid_fwrite_EGRID( ecl_grid_type * grid , const char * filename, bool o 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); { - float * depth_ptr = ecl_kw_get_ptr(depth_kw); + 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 ); } @@ -6742,9 +6743,9 @@ void ecl_grid_fwrite_dims( const ecl_grid_type * grid , fortio_type * init_file, ecl_kw_type * dz = ecl_kw_alloc("DZ" , ecl_grid_get_nactive(grid) , ECL_FLOAT); { { - float * dx_ptr = ecl_kw_get_ptr(dx); - float * dy_ptr = ecl_kw_get_ptr(dy); - float * dz_ptr = ecl_kw_get_ptr(dz); + 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 ); @@ -6883,7 +6884,7 @@ int ecl_grid_get_num_nnc( const ecl_grid_type * grid ) { { int grid_nr; for (grid_nr = 0; grid_nr < vector_get_size( grid->LGR_list ); grid_nr++) { - ecl_grid_type * igrid = vector_iget( 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 ); } } @@ -6894,7 +6895,7 @@ int ecl_grid_get_num_nnc( const ecl_grid_type * grid ) { 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); { - double * volume_data = ecl_kw_get_ptr( volume_kw ); + double * volume_data = (double*)ecl_kw_get_ptr( volume_kw ); int active_index; for (active_index = 0; active_index < ecl_grid_get_active_size(grid); active_index++) { double cell_volume = ecl_grid_get_cell_volume1A(grid , active_index); @@ -6908,7 +6909,7 @@ static ecl_kw_type * ecl_grid_alloc_volume_kw_active( const ecl_grid_type * grid 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); { - double * volume_data = ecl_kw_get_ptr( volume_kw ); + double * volume_data = (double*)ecl_kw_get_ptr( volume_kw ); int global_index; for (global_index = 0; global_index < ecl_grid_get_global_size(grid); global_index++) { double cell_volume = ecl_grid_get_cell_volume1(grid , global_index); diff --git a/ThirdParty/Ert/lib/ecl/ecl_grid_cache.c b/ThirdParty/Ert/lib/ecl/ecl_grid_cache.cpp similarity index 82% rename from ThirdParty/Ert/lib/ecl/ecl_grid_cache.c rename to ThirdParty/Ert/lib/ecl/ecl_grid_cache.cpp index 3c11f46231..f856b9cc41 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_grid_cache.c +++ b/ThirdParty/Ert/lib/ecl/ecl_grid_cache.cpp @@ -21,13 +21,13 @@ #include #include -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include @@ -54,15 +54,15 @@ struct ecl_grid_cache_struct { ecl_grid_cache_type * ecl_grid_cache_alloc( const ecl_grid_type * grid ) { - ecl_grid_cache_type * grid_cache = util_malloc( sizeof * grid_cache ); + ecl_grid_cache_type * grid_cache = (ecl_grid_cache_type*)util_malloc( sizeof * grid_cache ); grid_cache->grid = grid; grid_cache->volume = NULL; grid_cache->size = ecl_grid_get_active_size( grid ); - grid_cache->xpos = util_calloc( grid_cache->size , sizeof * grid_cache->xpos ); - grid_cache->ypos = util_calloc( grid_cache->size , sizeof * grid_cache->ypos ); - grid_cache->zpos = util_calloc( grid_cache->size , sizeof * grid_cache->zpos ); - grid_cache->global_index = util_calloc( grid_cache->size , sizeof * grid_cache->global_index ); + grid_cache->xpos = (double*)util_calloc( grid_cache->size , sizeof * grid_cache->xpos ); + grid_cache->ypos = (double*)util_calloc( grid_cache->size , sizeof * grid_cache->ypos ); + grid_cache->zpos = (double*)util_calloc( grid_cache->size , sizeof * grid_cache->zpos ); + grid_cache->global_index = (int*)util_calloc( grid_cache->size , sizeof * grid_cache->global_index ); { int active_index; @@ -113,7 +113,7 @@ const double * ecl_grid_cache_get_volume( const ecl_grid_cache_type * grid_cache if (!grid_cache->volume) { // C++ style const cast. ecl_grid_cache_type * gc = (ecl_grid_cache_type *) grid_cache; - gc->volume = util_calloc( gc->size , sizeof * gc->volume ); + gc->volume = (double*)util_calloc( gc->size , sizeof * gc->volume ); for (int active_index = 0; active_index < grid_cache->size; active_index++) gc->volume[active_index] = ecl_grid_get_cell_volume1A( gc->grid , active_index ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_grid_dims.c b/ThirdParty/Ert/lib/ecl/ecl_grid_dims.cpp similarity index 91% rename from ThirdParty/Ert/lib/ecl/ecl_grid_dims.c rename to ThirdParty/Ert/lib/ecl/ecl_grid_dims.cpp index 23d4b40838..24e6b671c3 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_grid_dims.c +++ b/ThirdParty/Ert/lib/ecl/ecl_grid_dims.cpp @@ -18,15 +18,15 @@ #include #include -#include -#include +#include +#include -#include -#include +#include +#include #include -#include -#include -#include +#include +#include +#include struct ecl_grid_dims_struct { @@ -101,7 +101,7 @@ ecl_grid_dims_type * ecl_grid_dims_alloc( const char * grid_file , const char * 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 = util_malloc( sizeof * grid_dims ); + grid_dims = (ecl_grid_dims_type*)util_malloc( sizeof * grid_dims ); grid_dims->dims_list = vector_alloc_new( ); { @@ -144,6 +144,6 @@ 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 ) { - return vector_iget_const( grid_dims->dims_list , grid_nr ); + return (const grid_dims_type*)vector_iget_const( grid_dims->dims_list , grid_nr ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_init_file.c b/ThirdParty/Ert/lib/ecl/ecl_init_file.cpp similarity index 97% rename from ThirdParty/Ert/lib/ecl/ecl_init_file.c rename to ThirdParty/Ert/lib/ecl/ecl_init_file.cpp index eb20dc8674..98b1ce5ba9 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_init_file.c +++ b/ThirdParty/Ert/lib/ecl/ecl_init_file.cpp @@ -31,14 +31,15 @@ */ -#include +#include #include -#include -#include -#include -#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 ); diff --git a/ThirdParty/Ert/lib/ecl/ecl_io_config.c b/ThirdParty/Ert/lib/ecl/ecl_io_config.cpp similarity index 95% rename from ThirdParty/Ert/lib/ecl/ecl_io_config.c rename to ThirdParty/Ert/lib/ecl/ecl_io_config.cpp index 924bc15c6b..5c5ee3a4d8 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_io_config.c +++ b/ThirdParty/Ert/lib/ecl/ecl_io_config.cpp @@ -20,10 +20,10 @@ #include #include -#include +#include -#include -#include +#include +#include /** @@ -61,7 +61,7 @@ struct ecl_io_config_struct { /*****************************************************************/ static ecl_io_config_type * ecl_io_config_alloc__() { - ecl_io_config_type * ecl_io_config = util_malloc(sizeof * ecl_io_config ); + ecl_io_config_type * ecl_io_config = (ecl_io_config_type*)util_malloc(sizeof * ecl_io_config ); ecl_io_config->formatted = FMT_UNDEFINED; ecl_io_config->unified_restart = UNIF_UNDEFINED; diff --git a/ThirdParty/Ert/lib/ecl/ecl_kw.c b/ThirdParty/Ert/lib/ecl/ecl_kw.cpp similarity index 88% rename from ThirdParty/Ert/lib/ecl/ecl_kw.c rename to ThirdParty/Ert/lib/ecl/ecl_kw.cpp index 82dd68a1d2..8fed785eed 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_kw.c +++ b/ThirdParty/Ert/lib/ecl/ecl_kw.cpp @@ -22,15 +22,15 @@ #include #include -#include -#include -#include +#include +#include +#include -#include -#include +#include +#include #include -#include -#include +#include +#include #define ECL_KW_TYPE_ID 6111098 @@ -162,7 +162,7 @@ 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_ctype_fortio(ecl_type) + ecl_type_get_sizeof_iotype(ecl_type) ); } @@ -191,7 +191,7 @@ static char * alloc_read_fmt(const ecl_data_type data_type ) { static char * alloc_write_fmt_string(const ecl_data_type ecl_type) { return util_alloc_sprintf( " '%%-%ds'", - ecl_type_get_sizeof_ctype_fortio(ecl_type) + ecl_type_get_sizeof_iotype(ecl_type) ); } @@ -258,12 +258,105 @@ static void ecl_kw_assert_index(const ecl_kw_type *ecl_kw , int index, const cha -static void ecl_kw_endian_convert_data(ecl_kw_type *ecl_kw) { - if (ecl_type_is_numeric(ecl_kw->data_type) || ecl_type_is_bool(ecl_kw->data_type)) - util_endian_flip_vector(ecl_kw->data , ecl_kw_get_sizeof_ctype(ecl_kw) , 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; + memcpy(&buffer[buffer_offset], &ecl_kw->data[data_offset], sizeof_iotype); + } + + return buffer; + } + + if (ecl_type_is_mess(ecl_kw->data_type)) + return buffer; + + 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. + */ + 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; } @@ -282,7 +375,7 @@ bool ecl_kw_name_equal( const ecl_kw_type * ecl_kw , const char * name) { void ecl_kw_get_memcpy_data(const ecl_kw_type *ecl_kw , void *target) { - memcpy(target , ecl_kw->data , ecl_kw->size * ecl_kw_get_sizeof_ctype(ecl_kw)); + 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) { @@ -303,14 +396,14 @@ if (ecl_type_is_double(ecl_kw->data_type)) /** 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_kw_get_sizeof_ctype(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_kw_get_sizeof_ctype(ecl_kw)); + memcpy(ecl_kw->data , src , ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); } @@ -363,7 +456,7 @@ bool ecl_kw_header_eq(const ecl_kw_type *ecl_kw1 , const ecl_kw_type * ecl_kw2) } 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_kw_get_sizeof_ctype(ecl_kw)); + int cmp = memcmp( ecl_kw->data , data , cmp_elements * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); if (cmp == 0) return true; else @@ -468,7 +561,7 @@ static void ecl_kw_set_shared_ref(ecl_kw_type * ecl_kw , void *data_ptr) { util_abort("%s: can not change to shared for keyword with allocated storage - aborting \n",__func__); } ecl_kw->shared_data = true; - ecl_kw->data = data_ptr; + ecl_kw->data = (char*)data_ptr; } @@ -484,7 +577,7 @@ static size_t ecl_kw_fortio_data_size( const ecl_kw_type * ecl_kw) { 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_ctype_fortio( ecl_kw->data_type ); // Actual data + ecl_kw->size * ecl_type_get_sizeof_iotype( ecl_kw->data_type ); // Actual data } @@ -543,7 +636,7 @@ ecl_kw_type * ecl_kw_alloc_new_shared(const char * header , int size, ecl_data_ ecl_kw_type * ecl_kw_alloc_empty() { ecl_kw_type *ecl_kw; - ecl_kw = util_malloc(sizeof *ecl_kw ); + ecl_kw = (ecl_kw_type*)util_malloc(sizeof *ecl_kw ); ecl_kw->header = NULL; ecl_kw->header8 = NULL; ecl_kw->data = NULL; @@ -573,7 +666,7 @@ 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_kw_get_sizeof_ctype(target)); + memcpy(target->data , src->data , target->size * ecl_type_get_sizeof_ctype(target->data_type)); } @@ -589,10 +682,10 @@ void ecl_kw_memcpy(ecl_kw_type *target, const ecl_kw_type *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; + ecl_kw_type *new_; + new_ = ecl_kw_alloc_empty(); + ecl_kw_memcpy(new_ , src); + return new_; } /** @@ -637,7 +730,7 @@ ecl_kw_type * ecl_kw_alloc_slice_copy( const ecl_kw_type * src, int index1, int int target_index = 0; const char * src_ptr = src->data; char * new_ptr = new_kw->data; - int sizeof_ctype = ecl_kw_get_sizeof_ctype(new_kw); + 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 ); @@ -658,10 +751,10 @@ void ecl_kw_resize( ecl_kw_type * ecl_kw, int new_size) { 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_kw_get_sizeof_ctype(ecl_kw); - size_t new_byte_size = new_size * ecl_kw_get_sizeof_ctype(ecl_kw); + 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 = util_realloc(ecl_kw->data , new_byte_size ); + 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); @@ -703,18 +796,19 @@ const void * ecl_kw_copyc__(const void * 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_kw_get_sizeof_ctype(ecl_kw)]; + 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_kw_get_sizeof_ctype(ecl_kw)); + 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 * ecl_kw_get_sizeof_ctype(ecl_kw)] , iptr, ecl_kw_get_sizeof_ctype(ecl_kw)); + memcpy(&ecl_kw->data[i * sizeof_ctype] , iptr, sizeof_ctype); } @@ -768,34 +862,20 @@ ctype ecl_kw_iget_ ## ctype(const ecl_kw_type * ecl_kw, int i) { 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 -bool ecl_kw_iget_bool( const ecl_kw_type * ecl_kw , int i) { - int int_value; - if (ecl_kw_get_type(ecl_kw) != ECL_BOOL_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 , &int_value); - if (int_value == ECL_BOOL_TRUE_INT) - return true; - else if (int_value == ECL_BOOL_FALSE_INT) - return false; - else { - util_abort("%s: fuckup - wrong integer in BOOL type \n",__func__); - return false; - } -} - 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 ecl_kw_iget_ptr( ecl_kw , i ); + 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 ecl_kw_iget_ptr( ecl_kw , i ); + return (const char *)ecl_kw_iget_ptr( ecl_kw , i ); } @@ -864,7 +944,7 @@ void ecl_kw_iset_string_ptr( ecl_kw_type * ecl_kw, int index, const char * s) { } size_t input_len = strlen(s); - size_t type_len = ecl_type_get_sizeof_ctype_fortio(ecl_kw_get_data_type(ecl_kw)); + 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); @@ -892,9 +972,9 @@ void ecl_kw_iset_string_ptr( ecl_kw_type * ecl_kw, int index, const char * s) { */ bool ecl_kw_icmp_string( const ecl_kw_type * ecl_kw , int index, const char * other_string) { - const char * kw_string = ecl_kw_iget_char_ptr( ecl_kw , index ); + const char * kw_string = (const char *)ecl_kw_iget_char_ptr( ecl_kw , index ); if (strlen(other_string)) { - char * match = strstr( kw_string , other_string); + const char * match = strstr( kw_string , other_string); if (match == kw_string) return true; } @@ -914,6 +994,7 @@ void ecl_kw_iset_ ## ctype(ecl_kw_type * ecl_kw, int i, ctype 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 @@ -978,20 +1059,6 @@ ECL_KW_SCALE_INDEXED( int , ECL_INT_TYPE); #undef ECL_KW_SCALE_INDEXED -void ecl_kw_iset_bool( ecl_kw_type * ecl_kw , int i , bool bool_value) { - int int_value; - if (ecl_kw_get_type(ecl_kw) != ECL_BOOL_TYPE) - util_abort("%s: Keyword: %s is wrong type - aborting \n",__func__ , ecl_kw_get_header8(ecl_kw)); - - if (bool_value) - int_value = ECL_BOOL_TRUE_INT; - else - int_value = ECL_BOOL_FALSE_INT; - - ecl_kw_iset_static(ecl_kw , i , &int_value); -} - - /*****************************************************************/ /* Various ways to get pointers to the underlying data. */ @@ -1006,6 +1073,7 @@ ctype * ecl_kw_get_ ## ctype ## _ptr(const ecl_kw_type * ecl_kw) { 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) { @@ -1091,7 +1159,6 @@ static double __fscanf_ECL_double( FILE * stream , const char * fmt) { } bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { - const char null_char = '\0'; bool fmt_file = fortio_fmt_file( fortio ); if (ecl_kw->size > 0) { const int blocksize = get_blocksize( ecl_kw->data_type ); @@ -1113,7 +1180,7 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { ecl_kw_fscanf_qstring( &ecl_kw->data[offset], read_fmt, - ecl_type_get_sizeof_ctype_fortio(ecl_kw_get_data_type(ecl_kw)), + ecl_type_get_sizeof_iotype(ecl_kw_get_data_type(ecl_kw)), stream ); break; @@ -1121,16 +1188,19 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { { 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_kw_get_sizeof_ctype(ecl_kw) , ecl_kw->header8 , fortio_filename_ref(fortio)); + 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_kw_get_sizeof_ctype(ecl_kw) , - ecl_kw->header8 , + 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)); } } @@ -1161,7 +1231,7 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { default: util_abort("%s: Internal error: internal eclipse_type: %d not recognized - aborting \n",__func__ , ecl_kw_get_type(ecl_kw)); } - offset += ecl_kw_get_sizeof_ctype(ecl_kw); + offset += ecl_type_get_sizeof_ctype(ecl_kw->data_type); index++; } } @@ -1171,46 +1241,14 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { free(read_fmt); return true; } else { - bool read_ok = true; - if (ecl_type_is_char(ecl_kw->data_type) || ecl_type_is_mess(ecl_kw->data_type) || ecl_type_is_string(ecl_kw->data_type)) { - const int blocks = ecl_kw->size / blocksize + (ecl_kw->size % blocksize == 0 ? 0 : 1); - int ib = 0; - while (true) { - /* - Due to the necessary terminating \0 characters there is - not a continous file/memory mapping. - */ - int read_elm = util_int_min((ib + 1) * blocksize , ecl_kw->size) - ib * blocksize; - FILE * stream = fortio_get_FILE(fortio); - int record_size = fortio_init_read(fortio); - if (record_size >= 0) { - int ir; - const int sizeof_ctype = ecl_type_get_sizeof_ctype(ecl_kw->data_type); - const int sizeof_ctype_fortio = ecl_type_get_sizeof_ctype_fortio(ecl_kw->data_type); - for (ir = 0; ir < read_elm; ir++) { - util_fread( &ecl_kw->data[(ib * blocksize + ir) * sizeof_ctype] , 1 , sizeof_ctype_fortio , stream , __func__); - ecl_kw->data[(ib * blocksize + ir) * sizeof_ctype + sizeof_ctype_fortio] = null_char; - } - read_ok = fortio_complete_read(fortio , record_size); - } else - read_ok = false; + 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) - break; + if (read_ok) + ecl_kw_load_from_input_buffer(ecl_kw, buffer); - ib++; - if (ib == blocks) - break; - } - } else { - /** - This function handles the fuc***g blocks transparently at a - low level. - */ - read_ok = fortio_fread_buffer(fortio , ecl_kw->data , ecl_kw->size * ecl_kw_get_sizeof_ctype(ecl_kw)); - if (read_ok && ECL_ENDIAN_FLIP) - ecl_kw_endian_convert_data(ecl_kw); - } + free(buffer); return read_ok; } } else @@ -1219,30 +1257,24 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { } -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* buffer) { +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 element_size = ecl_type_get_sizeof_ctype(data_type); - - if(ecl_type_is_char(data_type) || ecl_type_is_mess(data_type)) { - element_size = ECL_STRING8_LENGTH; - } - + 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) { + 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, element_size, element_count, block_size); - util_fread(&buffer[index * element_size], element_size, 1, stream, __func__); + + 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(buffer, element_size, int_vector_size(index_map)); - } + if (ECL_ENDIAN_FLIP) + util_endian_flip_vector(io_buffer, sizeof_iotype, int_vector_size(index_map)); } /** @@ -1272,7 +1304,7 @@ bool ecl_kw_fskip_data__( ecl_data_type data_type , const int element_count , fo } 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_ctype_fortio(data_type); + int element_size = ecl_type_get_sizeof_iotype(data_type); if(!fortio_data_fskip(fortio, element_size, element_count, block_count)) return false; @@ -1452,7 +1484,7 @@ bool ecl_kw_fseek_last_kw(const char * kw , bool abort_on_error , fortio_type *f void ecl_kw_set_data_ptr(ecl_kw_type * ecl_kw , void * data) { if (!ecl_kw->shared_data) util_safe_free( ecl_kw->data ); - ecl_kw->data = data; + ecl_kw->data = (char*)data; } @@ -1464,8 +1496,8 @@ void ecl_kw_alloc_data(ecl_kw_type *ecl_kw) { 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_kw_get_sizeof_ctype(ecl_kw); - ecl_kw->data = util_realloc(ecl_kw->data , byte_size ); + 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 ); memset(ecl_kw->data , 0 , byte_size); } } @@ -1482,7 +1514,7 @@ void ecl_kw_free_data(ecl_kw_type *ecl_kw) { void ecl_kw_set_header_name(ecl_kw_type * ecl_kw , const char * header) { - ecl_kw->header8 = realloc(ecl_kw->header8 , ECL_STRING8_LENGTH + 1); + ecl_kw->header8 = (char*)realloc(ecl_kw->header8 , ECL_STRING8_LENGTH + 1); if (strlen(header) <= 8) { sprintf(ecl_kw->header8 , "%-8s" , header); @@ -1491,7 +1523,7 @@ void ecl_kw_set_header_name(ecl_kw_type * ecl_kw , const char * header) { ecl_kw->header = util_alloc_strip_copy( ecl_kw->header8 ); } else { - ecl_kw->header = util_alloc_copy(header, strlen( header ) + 1); + ecl_kw->header = (char*)util_alloc_copy(header, strlen( header ) + 1); } } @@ -1545,10 +1577,9 @@ void ecl_kw_fskip(fortio_type *fortio) { -static void ecl_kw_fwrite_data_unformatted( ecl_kw_type * ecl_kw , fortio_type * fortio ) { - if (ECL_ENDIAN_FLIP) - ecl_kw_endian_convert_data(ecl_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); @@ -1556,29 +1587,11 @@ static void ecl_kw_fwrite_data_unformatted( ecl_kw_type * ecl_kw , fortio_type * 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; - if (ecl_type_is_char(ecl_kw->data_type) || ecl_type_is_mess(ecl_kw->data_type) || ecl_type_is_string(ecl_kw->data_type)) { - /* - Due to the terminating \0 characters there is not a - continous file/memory mapping - the \0 characters arel - skipped. - */ - FILE *stream = fortio_get_FILE(fortio); - int word_size = ecl_type_get_sizeof_ctype_fortio(ecl_kw->data_type); - int record_size = this_blocksize * word_size; /* The total size in bytes of the record written by the fortio layer. */ - int i; - fortio_init_write(fortio , record_size ); - for (i = 0; i < this_blocksize; i++) - fwrite(&ecl_kw->data[(block_nr * blocksize + i) * ecl_kw_get_sizeof_ctype(ecl_kw)] , 1 , word_size , stream); - fortio_complete_write(fortio , record_size); - } else { - int record_size = this_blocksize * ecl_kw_get_sizeof_ctype(ecl_kw); /* The total size in bytes of the record written by the fortio layer. */ - fortio_fwrite_record(fortio , &ecl_kw->data[block_nr * blocksize * ecl_kw_get_sizeof_ctype(ecl_kw)] , record_size); - } + 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); } } - - if (ECL_ENDIAN_FLIP) - ecl_kw_endian_convert_data(ecl_kw); + free(iobuffer); } @@ -1761,10 +1774,6 @@ ecl_data_type ecl_kw_get_data_type(const ecl_kw_type * ecl_kw) { return ecl_kw->data_type; } -size_t ecl_kw_get_sizeof_ctype(const ecl_kw_type * ecl_kw) { - return ecl_type_get_sizeof_ctype(ecl_kw->data_type); -} - /******************************************************************/ @@ -1772,14 +1781,14 @@ size_t ecl_kw_get_sizeof_ctype(const ecl_kw_type * ecl_kw) { 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 = 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_kw_get_sizeof_ctype(ecl_kw) , ecl_kw->size); + buffer_fread(buffer , ecl_kw->data , ecl_type_get_sizeof_ctype(ecl_kw->data_type) , ecl_kw->size); return ecl_kw; } @@ -1789,7 +1798,7 @@ void ecl_kw_buffer_store(const ecl_kw_type * ecl_kw , buffer_type * buffer) { 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_kw_get_sizeof_ctype(ecl_kw) , ecl_kw->size); + buffer_fwrite( buffer , ecl_kw->data , ecl_type_get_sizeof_ctype(ecl_kw->data_type) , ecl_kw->size); } @@ -1877,7 +1886,7 @@ ecl_kw_type * ecl_kw_alloc_scatter_copy( const ecl_kw_type * src_kw , int target int default_int = 0; double default_double = 0; float default_float = 0; - int default_bool = ECL_BOOL_FALSE_INT; + 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 ); @@ -1982,7 +1991,7 @@ void ecl_kw_summarize(const ecl_kw_type * ecl_kw) { #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 = ecl_kw_get_data_ref(ecl_kw); \ + ctype * data = (ctype *)ecl_kw_get_data_ref(ecl_kw); \ int i; \ for (i=0;i < ecl_kw->size; i++) \ data[i] = value; \ @@ -1992,26 +2001,9 @@ void ecl_kw_scalar_set_ ## ctype( ecl_kw_type * ecl_kw , ctype value){ \ 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_bool( ecl_kw_type * ecl_kw , bool bool_value) { - if (ecl_kw_get_type(ecl_kw) != ECL_BOOL_TYPE) - util_abort("%s: Keyword: %s is wrong type - aborting \n",__func__ , ecl_kw_get_header8(ecl_kw)); - { - int * data = ecl_kw_get_data_ref(ecl_kw); - int int_value; - if (bool_value) - int_value = ECL_BOOL_TRUE_INT; - else - int_value = ECL_BOOL_FALSE_INT; - { - int i; - for ( i=0; i < ecl_kw->size; i++) - data[i] = int_value; - } - } -} - 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); @@ -2040,12 +2032,12 @@ void ecl_kw_scalar_set__(ecl_kw_type * ecl_kw , const void * value) { 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_kw_get_sizeof_ctype(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_kw_get_sizeof_ctype(ecl_kw)); + memcpy(ecl_kw->data , values , ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); } /*****************************************************************/ @@ -2056,7 +2048,7 @@ 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 = ecl_kw_get_data_ref(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++) \ @@ -2085,7 +2077,7 @@ 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 = ecl_kw_get_data_ref(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++) \ @@ -2134,8 +2126,8 @@ void ecl_kw_copy_indexed( ecl_kw_type * target_kw , const int_vector_type * inde if (!ecl_kw_size_and_type_equal( target_kw , src_kw )) util_abort("%s: type/size mismatch\n",__func__); { - char * target_data = ecl_kw_get_data_ref( target_kw ); - const char * src_data = ecl_kw_get_data_ref( src_kw ); + 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 ); @@ -2154,8 +2146,8 @@ static void ecl_kw_inplace_add_indexed_ ## ctype( ecl_kw_type * target_kw , cons if (!ecl_kw_assert_binary_ ## ctype( target_kw , add_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * add_data = ecl_kw_get_data_ref( add_kw ); \ + 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; \ @@ -2197,8 +2189,8 @@ static void ecl_kw_inplace_add_ ## ctype( ecl_kw_type * target_kw , const ecl_kw if (!ecl_kw_assert_binary_ ## ctype( target_kw , add_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * add_data = ecl_kw_get_data_ref( add_kw ); \ + 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]; \ @@ -2232,8 +2224,8 @@ static void ecl_kw_inplace_add_squared_ ## ctype( ecl_kw_type * target_kw , cons if (!ecl_kw_assert_binary_ ## ctype( target_kw , add_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * add_data = ecl_kw_get_data_ref( add_kw ); \ + 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]; \ @@ -2272,8 +2264,8 @@ void ecl_kw_inplace_sub_ ## ctype( ecl_kw_type * target_kw , const ecl_kw_type * if (!ecl_kw_assert_binary_ ## ctype( target_kw , sub_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * sub_data = ecl_kw_get_data_ref( sub_kw ); \ + 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]; \ @@ -2306,8 +2298,8 @@ static void ecl_kw_inplace_sub_indexed_ ## ctype( ecl_kw_type * target_kw , cons if (!ecl_kw_assert_binary_ ## ctype( target_kw , sub_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * sub_data = ecl_kw_get_data_ref( sub_kw ); \ + 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; \ @@ -2346,7 +2338,7 @@ void ecl_kw_inplace_sub_indexed( ecl_kw_type * target_kw , const int_vector_type #define ECL_KW_TYPED_INPLACE_ABS( ctype , abs_func) \ void ecl_kw_inplace_abs_ ## ctype( ecl_kw_type * kw ) { \ - ctype * data = ecl_kw_get_data_ref( 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]); \ @@ -2384,7 +2376,7 @@ static int sqrti(int x) { #define ECL_KW_TYPED_INPLACE_SQRT( ctype, sqrt_func ) \ void ecl_kw_inplace_sqrt_ ## ctype( ecl_kw_type * kw ) { \ - ctype * data = ecl_kw_get_data_ref( 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]); \ @@ -2423,8 +2415,8 @@ void ecl_kw_inplace_mul_ ## ctype( ecl_kw_type * target_kw , const ecl_kw_type * if (!ecl_kw_assert_binary_ ## ctype( target_kw , mul_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * mul_data = ecl_kw_get_data_ref( mul_kw ); \ + 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]; \ @@ -2457,8 +2449,8 @@ static void ecl_kw_inplace_mul_indexed_ ## ctype( ecl_kw_type * target_kw , cons if (!ecl_kw_assert_binary_ ## ctype( target_kw , mul_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * mul_data = ecl_kw_get_data_ref( mul_kw ); \ + 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; \ @@ -2501,8 +2493,8 @@ void ecl_kw_inplace_div_ ## ctype( ecl_kw_type * target_kw , const ecl_kw_type * if (!ecl_kw_assert_binary_ ## ctype( target_kw , div_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * div_data = ecl_kw_get_data_ref( div_kw ); \ + 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]; \ @@ -2536,8 +2528,8 @@ static void ecl_kw_inplace_div_indexed_ ## ctype( ecl_kw_type * target_kw , cons if (!ecl_kw_assert_binary_ ## ctype( target_kw , div_kw )) \ util_abort("%s: type/size mismatch\n",__func__); \ { \ - ctype * target_data = ecl_kw_get_data_ref( target_kw ); \ - const ctype * div_data = ecl_kw_get_data_ref( div_kw ); \ + 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; \ @@ -2582,8 +2574,8 @@ bool ecl_kw_inplace_safe_div(ecl_kw_type * target_kw, const ecl_kw_type * diviso if (ecl_kw_get_type(divisor) != ECL_INT_TYPE) return false; - float * target_data = ecl_kw_get_data_ref( target_kw ); - const int* div_data = ecl_kw_get_data_ref( divisor ); + 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]; @@ -2685,14 +2677,14 @@ bool ecl_kw_is_kw_file(fortio_type * fortio) { #define KW_MAX_MIN(type) \ { \ - type * data = ecl_kw_get_data_ref(ecl_kw); \ + 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_kw_get_sizeof_ctype(ecl_kw)); \ - memcpy(_min , &min , ecl_kw_get_sizeof_ctype(ecl_kw)); \ + memcpy(_max , &max , ecl_type_get_sizeof_ctype(ecl_kw->data_type)); \ + memcpy(_min , &min , ecl_type_get_sizeof_ctype(ecl_kw->data_type)); \ } @@ -2753,13 +2745,13 @@ ECL_KW_MIN( double ) #define KW_SUM_INDEXED(type) \ { \ - const type * data = ecl_kw_get_data_ref(ecl_kw); \ + 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_kw_get_sizeof_ctype(ecl_kw)); \ + memcpy(_sum , &sum , ecl_type_get_sizeof_ctype(ecl_kw->data_type)); \ } @@ -2776,12 +2768,12 @@ void ecl_kw_element_sum_indexed(const ecl_kw_type * ecl_kw , const int_vector_ty break; case(ECL_BOOL_TYPE): { - const int * data = ecl_kw_get_data_ref(ecl_kw); + 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]] == ECL_BOOL_TRUE_INT); + sum += (data[index_ptr[i]]); memcpy(_sum , &sum , sizeof sum); } @@ -2801,11 +2793,11 @@ void ecl_kw_element_sum_indexed(const ecl_kw_type * ecl_kw , const int_vector_ty #define KW_SUM(type) \ { \ - const type * data = ecl_kw_get_data_ref(ecl_kw); \ + 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_kw_get_sizeof_ctype(ecl_kw)); \ + memcpy(_sum , &sum , ecl_type_get_sizeof_ctype(ecl_kw->data_type)); \ } @@ -2872,24 +2864,13 @@ static void ecl_kw_fprintf_data_ ## ctype(const ecl_kw_type * ecl_kw , const cha 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_bool( const ecl_kw_type * ecl_kw , const char * fmt , FILE * stream) { - const int * data = (const int *) ecl_kw->data; - int i; - for (i=0; i < ecl_kw->size; i++) { - if (data[i] == ECL_BOOL_TRUE_INT) - fprintf(stream , fmt , 1); - else - fprintf(stream , fmt , 0); - } -} - - 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_kw_get_sizeof_ctype(ecl_kw)]); + fprintf(stream , fmt , &ecl_kw->data[ i * ecl_type_get_sizeof_ctype(ecl_kw->data_type)]); } @@ -2916,8 +2897,8 @@ static bool ecl_kw_elm_equal_numeric__( const ecl_kw_type * ecl_kw1 , const ecl_ 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_kw_get_sizeof_ctype(ecl_kw1) * offset; - int cmp = memcmp( &ecl_kw1->data[ data_offset ] , &ecl_kw2->data[ data_offset ] , ecl_kw_get_sizeof_ctype(ecl_kw1)); + 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 @@ -2956,4 +2937,4 @@ int ecl_kw_first_different( const ecl_kw_type * ecl_kw1 , const ecl_kw_type * ec } } -#include "ecl_kw_functions.c" +#include "ecl_kw_functions.cpp" diff --git a/ThirdParty/Ert/lib/ecl/ecl_kw_functions.c b/ThirdParty/Ert/lib/ecl/ecl_kw_functions.cpp similarity index 98% rename from ThirdParty/Ert/lib/ecl/ecl_kw_functions.c rename to ThirdParty/Ert/lib/ecl/ecl_kw_functions.cpp index edc577d0cc..d10646fd33 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_kw_functions.c +++ b/ThirdParty/Ert/lib/ecl/ecl_kw_functions.cpp @@ -23,7 +23,7 @@ void ecl_kw_fix_uninitialized(ecl_kw_type * ecl_kw , int nx , int ny , int nz, const int * actnum) { int i,j,k; - int * data = ecl_kw_get_ptr( ecl_kw ); + int * data = (int*)ecl_kw_get_ptr( ecl_kw ); int_vector_type * undetermined1 = int_vector_alloc(0,0); int_vector_type * undetermined2 = int_vector_alloc(0,0); diff --git a/ThirdParty/Ert/lib/ecl/ecl_kw_grdecl.c b/ThirdParty/Ert/lib/ecl/ecl_kw_grdecl.cpp similarity index 97% rename from ThirdParty/Ert/lib/ecl/ecl_kw_grdecl.c rename to ThirdParty/Ert/lib/ecl/ecl_kw_grdecl.cpp index f71b75ad6c..fc51a42e8d 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_kw_grdecl.c +++ b/ThirdParty/Ert/lib/ecl/ecl_kw_grdecl.cpp @@ -19,11 +19,11 @@ #include #include -#include +#include -#include -#include -#include +#include +#include +#include #define MAX_GRDECL_HEADER_SIZE 512 @@ -260,8 +260,8 @@ static char * fscanf_alloc_grdecl_data( const char * header , bool strict , ecl_ int data_index = 0; int sizeof_ctype = ecl_type_get_sizeof_ctype( data_type ); int data_size = init_size; - char * buffer = util_calloc( (buffer_size + 1) , sizeof * buffer ); - char * data = util_calloc( sizeof_ctype * data_size , sizeof * data ); + 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) { @@ -347,7 +347,7 @@ static char * fscanf_alloc_grdecl_data( const char * header , bool strict , ecl_ data_size = util_size_t_min( ECL_KW_MAX_SIZE , 2*(data_index + multiplier)); byte_size *= data_size; - data = util_realloc( data , byte_size ); + data = (char*)util_realloc( data , byte_size ); } else { /* We are asking for more elements than can possible be adressed in @@ -371,7 +371,7 @@ static char * fscanf_alloc_grdecl_data( const char * header , bool strict , ecl_ } free( buffer ); *kw_size = data_index; - data = util_realloc( data , sizeof_ctype * data_index * sizeof * data ); + data = (char*)util_realloc( data , sizeof_ctype * data_index * sizeof * data ); return data; } diff --git a/ThirdParty/Ert/lib/ecl/ecl_nnc_data.c b/ThirdParty/Ert/lib/ecl/ecl_nnc_data.cpp similarity index 95% rename from ThirdParty/Ert/lib/ecl/ecl_nnc_data.c rename to ThirdParty/Ert/lib/ecl/ecl_nnc_data.cpp index c96f9c202c..ca35f63fb8 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_nnc_data.c +++ b/ThirdParty/Ert/lib/ecl/ecl_nnc_data.cpp @@ -18,12 +18,12 @@ #define ECL_NNC_DATA_TYPE_ID 83756236 -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include enum kw_data_type { TRANS_DATA = 1, @@ -211,12 +211,12 @@ static bool ecl_nnc_data_set_values(ecl_nnc_data_type * data, const ecl_grid_typ } 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 = util_malloc(sizeof * data); + 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 = util_malloc( nnc_size * sizeof(double)); + 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; diff --git a/ThirdParty/Ert/lib/ecl/ecl_nnc_export.c b/ThirdParty/Ert/lib/ecl/ecl_nnc_export.cpp similarity index 96% rename from ThirdParty/Ert/lib/ecl/ecl_nnc_export.c rename to ThirdParty/Ert/lib/ecl/ecl_nnc_export.cpp index ec549de43d..79cec6dabb 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_nnc_export.c +++ b/ThirdParty/Ert/lib/ecl/ecl_nnc_export.cpp @@ -17,13 +17,13 @@ */ #include -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include int ecl_nnc_export_get_size( const ecl_grid_type * grid ) { @@ -147,7 +147,7 @@ bool ecl_nnc_equal( const ecl_nnc_type * nnc1 , const ecl_nnc_type * nnc2) { static int ecl_nnc_sort_cmp__( const void * nnc1 , const void * nnc2) { - return ecl_nnc_sort_cmp( nnc1 , nnc2 ); + return ecl_nnc_sort_cmp( (const ecl_nnc_type*)nnc1 , (const ecl_nnc_type*)nnc2 ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_nnc_geometry.c b/ThirdParty/Ert/lib/ecl/ecl_nnc_geometry.cpp similarity index 88% rename from ThirdParty/Ert/lib/ecl/ecl_nnc_geometry.c rename to ThirdParty/Ert/lib/ecl/ecl_nnc_geometry.cpp index 064862c16a..84251d8f47 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_nnc_geometry.c +++ b/ThirdParty/Ert/lib/ecl/ecl_nnc_geometry.cpp @@ -18,7 +18,7 @@ #include -#include +#include #define ECL_NNC_GEOMETRY_TYPE_ID 6124343 @@ -65,12 +65,12 @@ static void ecl_nnc_geometry_add_pairs( const ecl_nnc_geometry_type * nnc_geo , int lgr_nr2 = nnc_vector_get_lgr_nr( nnc_vector ); for (int index2 = 0; index2 < nnc_vector_get_size( nnc_vector ); index2++) { - ecl_nnc_pair_type pair = {.grid_nr1 = lgr_nr1, - .global_index1 = global_index1, - .grid_nr2 = lgr_nr2, - .global_index2 = int_vector_iget( grid2_index_list , index2 ), - .input_index = int_vector_iget( nnc_index_list, index2 )}; - + ecl_nnc_pair_type pair; + pair.grid_nr1 = lgr_nr1; + pair.global_index1 = global_index1; + pair.grid_nr2 = lgr_nr2; + pair.global_index2 = int_vector_iget( grid2_index_list , index2 ); + pair.input_index = int_vector_iget( nnc_index_list, index2 ); struct_vector_append( nnc_geo->data , &pair); } } @@ -100,7 +100,7 @@ static int ecl_nnc_cmp(const void * _nnc1 , const void * _nnc2) { ecl_nnc_geometry_type * ecl_nnc_geometry_alloc( const ecl_grid_type * grid ) { - ecl_nnc_geometry_type * nnc_geo = util_malloc( sizeof * nnc_geo ); + 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 = struct_vector_alloc( sizeof( struct ecl_nnc_pair_struct )); @@ -121,7 +121,7 @@ void ecl_nnc_geometry_free( ecl_nnc_geometry_type * nnc_geo) { const ecl_nnc_pair_type * ecl_nnc_geometry_iget( const ecl_nnc_geometry_type * nnc_geo , int index) { - return struct_vector_iget_ptr( nnc_geo->data , index ); + return (const ecl_nnc_pair_type*)struct_vector_iget_ptr( nnc_geo->data , index ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_region.c b/ThirdParty/Ert/lib/ecl/ecl_region.cpp similarity index 99% rename from ThirdParty/Ert/lib/ecl/ecl_region.c rename to ThirdParty/Ert/lib/ecl/ecl_region.cpp index 08410ddfc4..f76c7fc5a0 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_region.c +++ b/ThirdParty/Ert/lib/ecl/ecl_region.cpp @@ -20,17 +20,17 @@ #include #include -#include -#include +#include +#include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /** @@ -137,12 +137,12 @@ void ecl_region_unlock( ecl_region_type * region ){ ecl_region_type * ecl_region_alloc( const ecl_grid_type * ecl_grid , bool preselect) { - ecl_region_type * region = util_malloc( sizeof * region ); + 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 = util_calloc(region->grid_vol , sizeof * region->active_mask ); + 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); diff --git a/ThirdParty/Ert/lib/ecl/ecl_rft_cell.c b/ThirdParty/Ert/lib/ecl/ecl_rft_cell.cpp similarity index 94% rename from ThirdParty/Ert/lib/ecl/ecl_rft_cell.c rename to ThirdParty/Ert/lib/ecl/ecl_rft_cell.cpp index 0a2bced36e..ae683086f4 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_rft_cell.c +++ b/ThirdParty/Ert/lib/ecl/ecl_rft_cell.cpp @@ -23,13 +23,13 @@ #include #include -#include -#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include #define ECL_RFT_CELL_TYPE_ID 99164012 @@ -78,7 +78,7 @@ struct plt_data_struct { /*****************************************************************/ static rft_data_type * rft_data_alloc( double swat , double sgas) { - rft_data_type * data = util_malloc( sizeof * data ); + rft_data_type * data = (rft_data_type*)util_malloc( sizeof * data ); UTIL_TYPE_ID_INIT( data , RFT_DATA_TYPE_ID ); data->swat = swat; @@ -98,7 +98,7 @@ static UTIL_IS_INSTANCE_FUNCTION( rft_data , RFT_DATA_TYPE_ID) /*****************************************************************/ static plt_data_type * plt_data_alloc( double orat , double grat , double wrat,double connection_start, double connection_end, double flowrate , double oil_flowrate , double gas_flowrate , double water_flowrate) { - plt_data_type * data = util_malloc( sizeof * data ); + plt_data_type * data = (plt_data_type*)util_malloc( sizeof * data ); UTIL_TYPE_ID_INIT( data , PLT_DATA_TYPE_ID ); data->orat = orat; @@ -133,7 +133,7 @@ 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 = util_malloc( sizeof * cell ); + ecl_rft_cell_type * cell = (ecl_rft_cell_type*)util_malloc( sizeof * cell ); UTIL_TYPE_ID_INIT( cell , ECL_RFT_CELL_TYPE_ID ); cell->i = i; @@ -180,9 +180,9 @@ ecl_rft_cell_type * ecl_rft_cell_alloc_PLT( int i , void ecl_rft_cell_free( ecl_rft_cell_type * cell ) { if (rft_data_is_instance( cell->data )) - rft_data_free( cell->data ); + rft_data_free( (rft_data_type*)cell->data ); else if (plt_data_is_instance( cell->data )) - plt_data_free( cell->data ); + plt_data_free( (plt_data_type*)cell->data ); free( cell ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_rft_file.c b/ThirdParty/Ert/lib/ecl/ecl_rft_file.cpp similarity index 91% rename from ThirdParty/Ert/lib/ecl/ecl_rft_file.c rename to ThirdParty/Ert/lib/ecl/ecl_rft_file.cpp index 17c381087a..0600a94efe 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_rft_file.c +++ b/ThirdParty/Ert/lib/ecl/ecl_rft_file.cpp @@ -25,16 +25,16 @@ #include #endif -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /** @@ -63,7 +63,7 @@ struct ecl_rft_file_struct { static ecl_rft_file_type * ecl_rft_file_alloc_empty(const char * filename) { - ecl_rft_file_type * rft_vector = util_malloc(sizeof * rft_vector ); + ecl_rft_file_type * rft_vector = (ecl_rft_file_type*)util_malloc(sizeof * rft_vector ); UTIL_TYPE_ID_INIT( rft_vector , ECL_RFT_FILE_ID ); rft_vector->data = vector_alloc_new(); rft_vector->filename = util_alloc_string_copy(filename); @@ -106,7 +106,7 @@ ecl_rft_file_type * ecl_rft_file_alloc(const char * filename) { if (!hash_has_key( rft_vector->well_index , well_name)) hash_insert_hash_owned_ref( rft_vector->well_index , well_name , int_vector_alloc( 0 , 0 ) , int_vector_free__); { - int_vector_type * index_list = hash_get( rft_vector->well_index , well_name ); + int_vector_type * index_list = (int_vector_type*)hash_get( rft_vector->well_index , well_name ); int_vector_append(index_list , global_index); } global_index++; @@ -228,7 +228,7 @@ int ecl_rft_file_get_size__( const ecl_rft_file_type * rft_file, const char * we int match_count = 0; int i; for ( i=0; i < vector_get_size( rft_file->data ); i++) { - const ecl_rft_node_type * rft = vector_iget_const( rft_file->data , i); + const ecl_rft_node_type * rft = (const ecl_rft_node_type*)vector_iget_const( rft_file->data , i); if (well_pattern) { if (util_fnmatch( well_pattern , ecl_rft_node_get_well_name( rft )) != 0) @@ -274,7 +274,7 @@ const char * ecl_rft_file_get_filename( const ecl_rft_file_type * rft_file ) { */ ecl_rft_node_type * ecl_rft_file_iget_node( const ecl_rft_file_type * rft_file , int index) { - return vector_iget( rft_file->data , index ); + return (ecl_rft_node_type*)vector_iget( rft_file->data , index ); } @@ -306,7 +306,7 @@ ecl_rft_node_type * ecl_rft_file_iget_node( const ecl_rft_file_type * rft_file , ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * rft_file , const char * well, int index) { - const int_vector_type * index_vector = hash_get(rft_file->well_index , well); + const int_vector_type * index_vector = (const int_vector_type*)hash_get(rft_file->well_index , well); return ecl_rft_file_iget_node( rft_file , int_vector_iget(index_vector , index)); } @@ -314,7 +314,7 @@ ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * rft_fi static int ecl_rft_file_get_node_index_time_rft( const ecl_rft_file_type * rft_file , const char * well , time_t recording_time) { int global_index = -1; if (hash_has_key( rft_file->well_index , well)) { - const int_vector_type * index_vector = hash_get(rft_file->well_index , well); + const int_vector_type * index_vector = (const int_vector_type*)hash_get(rft_file->well_index , well); int well_index = 0; while (true) { if (well_index == int_vector_size( index_vector )) @@ -364,7 +364,7 @@ bool ecl_rft_file_has_well( const ecl_rft_file_type * rft_file , const char * we */ int ecl_rft_file_get_well_occurences( const ecl_rft_file_type * rft_file , const char * well) { - const int_vector_type * index_vector = hash_get(rft_file->well_index , well); + const int_vector_type * index_vector = (const int_vector_type*)hash_get(rft_file->well_index , well); return int_vector_size( index_vector ); } @@ -423,7 +423,7 @@ void ecl_rft_file_update(const char * rft_file_name, ecl_rft_node_type ** nodes, vector_sort(rft_file->data,(vector_cmp_ftype *) ecl_rft_node_cmp); for(node_index=0; node_index < vector_get_size( rft_file->data ); node_index++) { - const ecl_rft_node_type *new_node = vector_iget_const(rft_file->data, node_index); + const ecl_rft_node_type *new_node = (const ecl_rft_node_type*)vector_iget_const(rft_file->data, node_index); ecl_rft_node_fwrite(new_node, fortio, unit_set); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_rft_node.c b/ThirdParty/Ert/lib/ecl/ecl_rft_node.cpp similarity index 92% rename from ThirdParty/Ert/lib/ecl/ecl_rft_node.c rename to ThirdParty/Ert/lib/ecl/ecl_rft_node.cpp index dc19a5ea30..d4681bf3f6 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_rft_node.c +++ b/ThirdParty/Ert/lib/ecl/ecl_rft_node.cpp @@ -23,18 +23,18 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include /** @@ -106,7 +106,7 @@ static ecl_rft_enum translate_from_sting_to_ecl_rft_enum(const char * 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 = util_malloc(sizeof * rft_node ); + ecl_rft_node_type * rft_node = (ecl_rft_node_type*)util_malloc(sizeof * rft_node ); UTIL_TYPE_ID_INIT( rft_node , ECL_RFT_NODE_ID ); rft_node->well_name = util_alloc_string_copy(well_name); rft_node->cells = vector_alloc_new(); @@ -130,7 +130,7 @@ static ecl_rft_node_type * ecl_rft_node_alloc_empty(const char * data_type_strin } { - ecl_rft_node_type * rft_node = util_malloc(sizeof * rft_node ); + ecl_rft_node_type * rft_node = (ecl_rft_node_type*)util_malloc(sizeof * rft_node ); UTIL_TYPE_ID_INIT( rft_node , ECL_RFT_NODE_ID ); rft_node->cells = vector_alloc_new(); @@ -269,11 +269,11 @@ static void ecl_rft_node_init_cells( ecl_rft_node_type * rft_node , const ecl_fi 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(ecl_kw_iget_ptr(welletc , WELLETC_TYPE_INDEX)); + 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); - rft_node->well_name = util_alloc_strip_copy( ecl_kw_iget_ptr(welletc , WELLETC_NAME_INDEX)); + rft_node->well_name = (char*)util_alloc_strip_copy( (const char*)ecl_kw_iget_ptr(welletc , WELLETC_NAME_INDEX)); /* Time information. */ { @@ -325,7 +325,7 @@ ecl_rft_enum ecl_rft_node_get_type(const ecl_rft_node_type * rft_node) { return /* various functions to access properties at the cell level */ const ecl_rft_cell_type * ecl_rft_node_iget_cell( const ecl_rft_node_type * rft_node , int index) { - return vector_iget_const( rft_node->cells , index ); + return (const ecl_rft_cell_type*)vector_iget_const( rft_node->cells , index ); } @@ -349,7 +349,7 @@ const ecl_rft_cell_type * ecl_rft_node_iget_cell_sorted( ecl_rft_node_type * rft if (!rft_node->sort_perm_in_sync) ecl_rft_node_create_sort_perm( rft_node ); - return vector_iget_const( rft_node->cells , int_vector_iget( rft_node->sort_perm , index )); + return (const ecl_rft_cell_type*)vector_iget_const( rft_node->cells , int_vector_iget( rft_node->sort_perm , index )); } } @@ -403,7 +403,7 @@ static void assert_type_and_index( const ecl_rft_node_type * rft_node , ecl_rft_ 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 = vector_iget_const( rft_node->cells , index ); + const ecl_rft_cell_type * cell = (const ecl_rft_cell_type*)vector_iget_const( rft_node->cells , index ); return ecl_rft_cell_get_sgas( cell ); } } @@ -412,7 +412,7 @@ double ecl_rft_node_iget_sgas( const ecl_rft_node_type * rft_node , int index) { 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 = vector_iget_const( rft_node->cells , index ); + const ecl_rft_cell_type * cell = (const ecl_rft_cell_type*)vector_iget_const( rft_node->cells , index ); return ecl_rft_cell_get_swat( cell ); } } @@ -424,7 +424,7 @@ double ecl_rft_node_get_days(const ecl_rft_node_type * rft_node ){ 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 = vector_iget_const( rft_node->cells , index ); + const ecl_rft_cell_type * cell = (const ecl_rft_cell_type*)vector_iget_const( rft_node->cells , index ); return ecl_rft_cell_get_soil( cell ); } } @@ -435,7 +435,7 @@ double ecl_rft_node_iget_soil( const ecl_rft_node_type * rft_node , int index) { 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 = vector_iget_const( rft_node->cells , index ); + const ecl_rft_cell_type * cell = (const ecl_rft_cell_type*)vector_iget_const( rft_node->cells , index ); return ecl_rft_cell_get_orat( cell ); } } @@ -444,7 +444,7 @@ double ecl_rft_node_iget_orat( const ecl_rft_node_type * rft_node , int index) { 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 = vector_iget_const( rft_node->cells , index); + const ecl_rft_cell_type * cell = (const ecl_rft_cell_type*)vector_iget_const( rft_node->cells , index); return ecl_rft_cell_get_wrat( cell ); } } @@ -453,7 +453,7 @@ 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) { assert_type_and_index( rft_node , PLT , index ); { - const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , index); + const ecl_rft_cell_type * cell = (const ecl_rft_cell_type*)vector_iget_const( rft_node->cells , index); return ecl_rft_cell_get_grat( cell ); } } @@ -594,7 +594,7 @@ void ecl_rft_node_fwrite(const ecl_rft_node_type * rft_node, fortio_type * forti int i; for(i =0;icells , i); + const ecl_rft_cell_type * cell = (const ecl_rft_cell_type*)vector_iget_const( 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); diff --git a/ThirdParty/Ert/lib/ecl/ecl_rst_file.c b/ThirdParty/Ert/lib/ecl/ecl_rst_file.cpp similarity index 94% rename from ThirdParty/Ert/lib/ecl/ecl_rst_file.c rename to ThirdParty/Ert/lib/ecl/ecl_rst_file.cpp index 2bc6fd70cd..646f6c6598 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_rst_file.c +++ b/ThirdParty/Ert/lib/ecl/ecl_rst_file.cpp @@ -23,21 +23,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 struct ecl_rst_file_struct { fortio_type * fortio; @@ -50,7 +50,7 @@ struct ecl_rst_file_struct { 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 = util_malloc( sizeof * rst_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; diff --git a/ThirdParty/Ert/lib/ecl/ecl_rsthead.c b/ThirdParty/Ert/lib/ecl/ecl_rsthead.cpp similarity index 93% rename from ThirdParty/Ert/lib/ecl/ecl_rsthead.c rename to ThirdParty/Ert/lib/ecl/ecl_rsthead.cpp index 52d40a9aab..49b797d1cc 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_rsthead.c +++ b/ThirdParty/Ert/lib/ecl/ecl_rsthead.cpp @@ -17,13 +17,13 @@ */ #include -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static time_t rsthead_date( int day , int month , int year) { @@ -55,7 +55,7 @@ int ecl_rsthead_get_report_step( const ecl_rsthead_type * header ) { 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 = util_malloc( sizeof * rsthead ); + ecl_rsthead_type * rsthead = (ecl_rsthead_type*)util_malloc( sizeof * rsthead ); rsthead->report_step = report_step; { const int * data = (const int *) ecl_kw_get_void_ptr( intehead_kw ); @@ -88,10 +88,7 @@ ecl_rsthead_type * ecl_rsthead_alloc_from_kw( int report_step , const ecl_kw_typ // The only derived quantity rsthead->sim_time = rsthead_date( rsthead->day , rsthead->month , rsthead->year ); } - - if (doubhead_kw) - rsthead->sim_days = ecl_kw_iget_double( doubhead_kw , DOUBHEAD_DAYS_INDEX ); - + rsthead->sim_days = ecl_kw_iget_double( doubhead_kw , DOUBHEAD_DAYS_INDEX ); if (logihead_kw) rsthead->dualp = ecl_kw_iget_bool( logihead_kw , LOGIHEAD_DUALP_INDEX); @@ -112,15 +109,12 @@ ecl_rsthead_type * ecl_rsthead_alloc_from_kw( int report_step , const ecl_kw_typ 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 = NULL; + 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, DOUBHEAD_KW)) - doubhead_kw = ecl_file_view_iget_named_kw(rst_view, DOUBHEAD_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); @@ -135,7 +129,7 @@ ecl_rsthead_type * ecl_rsthead_alloc( const ecl_file_view_type * rst_view, int r ecl_rsthead_type * ecl_rsthead_alloc_empty() { - ecl_rsthead_type * rsthead = util_malloc( sizeof * rsthead ); + ecl_rsthead_type * rsthead = (ecl_rsthead_type*)util_malloc( sizeof * rsthead ); rsthead->day = 0; rsthead->month = 0; diff --git a/ThirdParty/Ert/lib/ecl/ecl_smspec.c b/ThirdParty/Ert/lib/ecl/ecl_smspec.cpp similarity index 94% rename from ThirdParty/Ert/lib/ecl/ecl_smspec.c rename to ThirdParty/Ert/lib/ecl/ecl_smspec.cpp index ebdd880dee..2e774554b2 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_smspec.c +++ b/ThirdParty/Ert/lib/ecl/ecl_smspec.cpp @@ -22,21 +22,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 #ifdef HAVE_FNMATCH #include @@ -251,7 +251,7 @@ static const char* smspec_required_keywords[] = { ecl_smspec_type * ecl_smspec_alloc_empty(bool write_mode , const char * key_join_string) { ecl_smspec_type *ecl_smspec; - ecl_smspec = util_malloc(sizeof *ecl_smspec ); + ecl_smspec = (ecl_smspec_type*)util_malloc(sizeof *ecl_smspec ); UTIL_TYPE_ID_INIT(ecl_smspec , ECL_SMSPEC_ID); ecl_smspec->well_var_index = hash_alloc(); @@ -295,7 +295,7 @@ ecl_smspec_type * ecl_smspec_alloc_empty(bool write_mode , const char * key_join 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 = util_malloc( params_size * sizeof * mapping ); + int * mapping = (int*)util_malloc( params_size * sizeof * mapping ); for (int i = 0; i < params_size; i++) mapping[i] = -1; @@ -326,7 +326,7 @@ int * ecl_smspec_alloc_mapping( const ecl_smspec_type * self, const ecl_smspec_t const smspec_node_type * ecl_smspec_iget_node( const ecl_smspec_type * smspec , int index ) { - return vector_iget_const( smspec->smspec_nodes , index ); + return (const smspec_node_type*)vector_iget_const( smspec->smspec_nodes , index ); } int ecl_smspec_num_nodes( const ecl_smspec_type * smspec) { @@ -844,13 +844,13 @@ static void ecl_smspec_install_special_keys( ecl_smspec_type * ecl_smspec , smsp if (!hash_has_key(ecl_smspec->well_completion_var_index , well)) hash_insert_hash_owned_ref(ecl_smspec->well_completion_var_index , well , hash_alloc() , hash_free__); { - hash_type * cell_hash = hash_get(ecl_smspec->well_completion_var_index , well); + hash_type * cell_hash = (hash_type*)hash_get(ecl_smspec->well_completion_var_index , well); char cell_str[16]; sprintf(cell_str , "%d" , num); if (!hash_has_key(cell_hash , cell_str)) hash_insert_hash_owned_ref(cell_hash , cell_str , hash_alloc() , hash_free__); { - hash_type * var_hash = hash_get(cell_hash , cell_str); + hash_type * var_hash = (hash_type*)hash_get(cell_hash , cell_str); hash_insert_ref(var_hash , keyword , smspec_node ); } } @@ -865,7 +865,7 @@ static void ecl_smspec_install_special_keys( ecl_smspec_type * ecl_smspec , smsp if (!hash_has_key(ecl_smspec->group_var_index , group)) hash_insert_hash_owned_ref(ecl_smspec->group_var_index , group, hash_alloc() , hash_free__); { - hash_type * var_hash = hash_get(ecl_smspec->group_var_index , group); + hash_type * var_hash = (hash_type*)hash_get(ecl_smspec->group_var_index , group); hash_insert_ref(var_hash , keyword , smspec_node ); } break; @@ -873,7 +873,7 @@ static void ecl_smspec_install_special_keys( ecl_smspec_type * ecl_smspec , smsp if (!hash_has_key(ecl_smspec->region_var_index , keyword)) hash_insert_hash_owned_ref( ecl_smspec->region_var_index , keyword , hash_alloc() , hash_free__); { - hash_type * var_hash = hash_get(ecl_smspec->region_var_index , keyword); + hash_type * var_hash = (hash_type*)hash_get(ecl_smspec->region_var_index , keyword); char num_str[16]; sprintf( num_str , "%d" , num); hash_insert_ref(var_hash , num_str , smspec_node); @@ -884,7 +884,7 @@ static void ecl_smspec_install_special_keys( ecl_smspec_type * ecl_smspec , smsp if (!hash_has_key(ecl_smspec->well_var_index , well)) hash_insert_hash_owned_ref(ecl_smspec->well_var_index , well , hash_alloc() , hash_free__); { - hash_type * var_hash = hash_get(ecl_smspec->well_var_index , well); + hash_type * var_hash = (hash_type*)hash_get(ecl_smspec->well_var_index , well); hash_insert_ref(var_hash , keyword , smspec_node ); } break; @@ -897,7 +897,7 @@ static void ecl_smspec_install_special_keys( ecl_smspec_type * ecl_smspec , smsp if (!hash_has_key(ecl_smspec->block_var_index , keyword)) hash_insert_hash_owned_ref(ecl_smspec->block_var_index , keyword , hash_alloc() , hash_free__); { - hash_type * block_hash = hash_get(ecl_smspec->block_var_index , keyword); + hash_type * block_hash = (hash_type*)hash_get(ecl_smspec->block_var_index , keyword); char block_nr[16]; sprintf( block_nr , "%d" , num ); hash_insert_ref(block_hash , block_nr , smspec_node); @@ -1018,8 +1018,8 @@ bool ecl_smspec_equal(const ecl_smspec_type * self, return false; for (int i=0; i < vector_get_size( self->smspec_nodes ); i++) { - const smspec_node_type * node1 = vector_iget_const(self->smspec_nodes, i); - const smspec_node_type * node2 = vector_iget_const(other->smspec_nodes, i); + const smspec_node_type * node1 = (const smspec_node_type*)vector_iget_const(self->smspec_nodes, i); + const smspec_node_type * node2 = (const smspec_node_type*)vector_iget_const(other->smspec_nodes, i); if (!smspec_node_equal(node1, node2)) return false; @@ -1039,7 +1039,7 @@ static void ecl_smspec_load_restart( ecl_smspec_type * ecl_smspec , const ecl_fi int i; tmp_base[0] = '\0'; for (i=0; i < ecl_kw_get_size( restart_kw ); i++) - strcat( tmp_base , ecl_kw_iget_ptr( 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. */ @@ -1204,7 +1204,7 @@ static bool ecl_smspec_fread_header(ecl_smspec_type * ecl_smspec, const char * h 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 = ecl_kw_iget_int(intehead, INTEHEAD_SMSPEC_UNIT_INDEX); + 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 @@ -1240,9 +1240,9 @@ static bool ecl_smspec_fread_header(ecl_smspec_type * ecl_smspec, const char * h 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 = util_alloc_strip_copy(ecl_kw_iget_ptr(wells , params_index)); - char * kw = util_alloc_strip_copy(ecl_kw_iget_ptr(keywords , params_index)); - char * unit = util_alloc_strip_copy(ecl_kw_iget_ptr(units , params_index)); + 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)); char * lgr_name = NULL; smspec_node_type * smspec_node; @@ -1252,7 +1252,7 @@ static bool ecl_smspec_fread_header(ecl_smspec_type * ecl_smspec, const char * h 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 ); - lgr_name = util_alloc_strip_copy( ecl_kw_iget_ptr( lgrs , params_index )); + lgr_name = (char*)util_alloc_strip_copy( (const char*)ecl_kw_iget_ptr( lgrs , params_index )); smspec_node = smspec_node_alloc_lgr( var_type , well , kw , unit , lgr_name , ecl_smspec->key_join_string , lgr_i , lgr_j , lgr_k , params_index, default_value); } else smspec_node = smspec_node_alloc( var_type , well , kw , unit , ecl_smspec->key_join_string , ecl_smspec->grid_dims , num , params_index , default_value); @@ -1293,7 +1293,7 @@ ecl_smspec_type * ecl_smspec_fread_alloc(const char *header_file, const char * k if (ecl_smspec_fread_header(ecl_smspec , header_file , include_restart)) { if (hash_has_key( ecl_smspec->misc_var_index , "TIME")) { - const smspec_node_type * time_node = hash_get(ecl_smspec->misc_var_index , "TIME"); + const smspec_node_type * time_node = (const smspec_node_type*)hash_get(ecl_smspec->misc_var_index , "TIME"); const char * time_unit = smspec_node_get_unit( time_node ); ecl_smspec->time_index = smspec_node_get_params_index( time_node ); @@ -1306,9 +1306,9 @@ ecl_smspec_type * ecl_smspec_fread_alloc(const char *header_file, const char * k } if (hash_has_key(ecl_smspec->misc_var_index , "DAY")) { - ecl_smspec->day_index = smspec_node_get_params_index( hash_get(ecl_smspec->misc_var_index , "DAY") ); - ecl_smspec->month_index = smspec_node_get_params_index( hash_get(ecl_smspec->misc_var_index , "MONTH") ); - ecl_smspec->year_index = smspec_node_get_params_index( hash_get(ecl_smspec->misc_var_index , "YEAR") ); + ecl_smspec->day_index = smspec_node_get_params_index( (const smspec_node_type*)hash_get(ecl_smspec->misc_var_index , "DAY") ); + ecl_smspec->month_index = smspec_node_get_params_index( (const smspec_node_type*)hash_get(ecl_smspec->misc_var_index , "MONTH") ); + ecl_smspec->year_index = smspec_node_get_params_index( (const smspec_node_type*)hash_get(ecl_smspec->misc_var_index , "YEAR") ); } if ((ecl_smspec->time_index == -1) && ( ecl_smspec->day_index == -1)) { @@ -1392,9 +1392,9 @@ int ecl_smspec_get_num_regions(const ecl_smspec_type * ecl_smspec) { const smspec_node_type * ecl_smspec_get_well_var_node( const ecl_smspec_type * smspec , const char * well , const char * var) { const smspec_node_type * node = NULL; if (hash_has_key( smspec->well_var_index , well)) { - hash_type * var_hash = hash_get(smspec->well_var_index , well); + hash_type * var_hash = (hash_type*)hash_get(smspec->well_var_index , well); if (hash_has_key(var_hash , var)) - node = hash_get(var_hash , var); + node = (const smspec_node_type*)hash_get(var_hash , var); } return node; } @@ -1419,9 +1419,9 @@ bool ecl_smspec_has_well_var(const ecl_smspec_type * ecl_smspec , const char * w const smspec_node_type * ecl_smspec_get_group_var_node( const ecl_smspec_type * smspec , const char * group , const char * var) { const smspec_node_type * node = NULL; if (hash_has_key(smspec->group_var_index , group)) { - hash_type * var_hash = hash_get(smspec->group_var_index , group); + hash_type * var_hash = (hash_type*)hash_get(smspec->group_var_index , group); if (hash_has_key(var_hash , var)) - node = hash_get(var_hash , var); + node = (const smspec_node_type*)hash_get(var_hash , var); } return node; } @@ -1445,7 +1445,7 @@ bool ecl_smspec_has_group_var(const ecl_smspec_type * ecl_smspec , const char * const smspec_node_type * ecl_smspec_get_field_var_node(const ecl_smspec_type * ecl_smspec , const char *var) { const smspec_node_type * node = NULL; if (hash_has_key(ecl_smspec->field_var_index , var)) - node = hash_get(ecl_smspec->field_var_index , var); + node = (const smspec_node_type*)hash_get(ecl_smspec->field_var_index , var); return node; } @@ -1479,9 +1479,9 @@ static const smspec_node_type * ecl_smspec_get_block_var_node_string(const ecl_s const smspec_node_type * node = NULL; if (hash_has_key(ecl_smspec->block_var_index , block_var)) { - hash_type * block_hash = hash_get(ecl_smspec->block_var_index , block_var); + hash_type * block_hash = (hash_type*)hash_get(ecl_smspec->block_var_index , block_var); if (hash_has_key(block_hash , block_str)) - node = hash_get(block_hash , block_str); + node = (const smspec_node_type*)hash_get(block_hash , block_str); } return node; @@ -1539,9 +1539,9 @@ const smspec_node_type * ecl_smspec_get_region_var_node(const ecl_smspec_type * if (hash_has_key(ecl_smspec->region_var_index , region_var)) { char * nr_str = util_alloc_sprintf( "%d" , region_nr ); - hash_type * nr_hash = hash_get(ecl_smspec->region_var_index , region_var); + hash_type * nr_hash = (hash_type*)hash_get(ecl_smspec->region_var_index , region_var); if (hash_has_key( nr_hash , nr_str)) - node = hash_get( nr_hash , nr_str ); + node = (const smspec_node_type*)hash_get( nr_hash , nr_str ); free( nr_str ); } @@ -1567,7 +1567,7 @@ const smspec_node_type * ecl_smspec_get_misc_var_node(const ecl_smspec_type * ec const smspec_node_type * node = NULL; if (hash_has_key(ecl_smspec->misc_var_index , var)) - node = hash_get(ecl_smspec->misc_var_index , var); + node = (const smspec_node_type*)hash_get(ecl_smspec->misc_var_index , var); return node; } @@ -1593,12 +1593,12 @@ const smspec_node_type * ecl_smspec_get_well_completion_var_node(const ecl_smspe char * cell_str = util_alloc_sprintf("%d" , cell_nr); if (hash_has_key(ecl_smspec->well_completion_var_index , well)) { - hash_type * cell_hash = hash_get(ecl_smspec->well_completion_var_index , well); + hash_type * cell_hash = (hash_type*)hash_get(ecl_smspec->well_completion_var_index , well); if (hash_has_key(cell_hash , cell_str)) { - hash_type * var_hash = hash_get(cell_hash , cell_str); + hash_type * var_hash = (hash_type*)hash_get(cell_hash , cell_str); if (hash_has_key(var_hash , var)) - node = hash_get( var_hash , var); + node = (const smspec_node_type*)hash_get( var_hash , var); } } free(cell_str); @@ -1630,7 +1630,7 @@ int ecl_smspec_get_well_completion_var_params_index(const ecl_smspec_type * ecl const smspec_node_type * ecl_smspec_get_general_var_node( const ecl_smspec_type * smspec , const char * lookup_kw ) { if (hash_has_key( smspec->gen_var_index , lookup_kw )) { - const smspec_node_type * smspec_node = hash_get( smspec->gen_var_index , lookup_kw ); + const smspec_node_type * smspec_node = (const smspec_node_type*)hash_get( smspec->gen_var_index , lookup_kw ); return smspec_node; } else return NULL; @@ -1651,7 +1651,7 @@ bool ecl_smspec_has_general_var(const ecl_smspec_type * ecl_smspec , const char /** 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 smspec_node_type * smspec_node = hash_get( ecl_smspec->gen_var_index , lookup_kw ); + const smspec_node_type * smspec_node = (const smspec_node_type*)hash_get( ecl_smspec->gen_var_index , lookup_kw ); return smspec_node_get_unit( smspec_node ); } @@ -1768,7 +1768,7 @@ int ecl_smspec_get_date_year_index( const ecl_smspec_type * smspec ) { bool ecl_smspec_general_is_total( const ecl_smspec_type * smspec , const char * gen_key) { - const smspec_node_type * smspec_node = hash_get( smspec->gen_var_index , gen_key ); + const smspec_node_type * smspec_node = (const smspec_node_type*)hash_get( smspec->gen_var_index , gen_key ); return smspec_node_is_total( smspec_node ); } @@ -1914,7 +1914,7 @@ stringlist_type * ecl_smspec_alloc_group_list( const ecl_smspec_type * smspec , stringlist_type * ecl_smspec_alloc_well_var_list( const ecl_smspec_type * smspec ) { hash_iter_type * well_iter = hash_iter_alloc( smspec->well_var_index ); - hash_type * var_hash = hash_iter_get_next_value( well_iter ); + hash_type * var_hash = (hash_type*)hash_iter_get_next_value( well_iter ); hash_iter_free( well_iter ); return hash_alloc_stringlist( var_hash ); } @@ -1949,7 +1949,7 @@ void ecl_smspec_sort( ecl_smspec_type * smspec ) { vector_sort( smspec->smspec_nodes , smspec_node_cmp__); for (int i=0; i < vector_get_size( smspec->smspec_nodes ); i++) { - smspec_node_type * node = vector_iget( smspec->smspec_nodes , i ); + smspec_node_type * node = (smspec_node_type*)vector_iget( smspec->smspec_nodes , i ); smspec_node_set_params_index( node , i ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_subsidence.c b/ThirdParty/Ert/lib/ecl/ecl_subsidence.cpp similarity index 90% rename from ThirdParty/Ert/lib/ecl/ecl_subsidence.c rename to ThirdParty/Ert/lib/ecl/ecl_subsidence.cpp index 4fe053f6f9..301e3ce9a9 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_subsidence.c +++ b/ThirdParty/Ert/lib/ecl/ecl_subsidence.cpp @@ -22,19 +22,19 @@ #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 /** @@ -84,14 +84,14 @@ struct ecl_subsidence_survey_struct { static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_empty(const ecl_subsidence_type * sub, const char * name) { - ecl_subsidence_survey_type * survey = util_malloc( sizeof * survey ); + 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 = util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->porv ); - survey->pressure = util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->pressure ); + survey->porv = (double*)util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->porv ); + survey->pressure = (double*)util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->pressure ); return survey; } @@ -144,7 +144,7 @@ static double ecl_subsidence_survey_eval( const ecl_subsidence_survey_type * bas const ecl_grid_cache_type * grid_cache = base_survey->grid_cache; const int size = ecl_grid_cache_get_size( grid_cache ); - double * weight = util_calloc( size , sizeof * weight ); + double * weight = (double*)util_calloc( size , sizeof * weight ); double deltaz; int index; @@ -174,7 +174,7 @@ static double ecl_subsidence_survey_eval_geertsma( const ecl_subsidence_survey_t const double * cell_volume = ecl_grid_cache_get_volume( grid_cache ); const int size = ecl_grid_cache_get_size( grid_cache ); double scale_factor = 1e4 *(1 + poisson_ratio) * ( 1 - 2*poisson_ratio) / ( 4*M_PI*( 1 - poisson_ratio) * youngs_modulus ); - double * weight = util_calloc( size , sizeof * weight ); + double * weight = (double*)util_calloc( size , sizeof * weight ); double deltaz; for (int index = 0; index < size; index++) { @@ -202,7 +202,7 @@ static double ecl_subsidence_survey_eval_geertsma( const ecl_subsidence_survey_t */ ecl_subsidence_type * ecl_subsidence_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file) { - ecl_subsidence_type * ecl_subsidence = util_malloc( sizeof * ecl_subsidence ); + ecl_subsidence_type * ecl_subsidence = (ecl_subsidence_type*)util_malloc( sizeof * ecl_subsidence ); ecl_subsidence->init_file = init_file; ecl_subsidence->grid_cache = ecl_grid_cache_alloc( ecl_grid ); ecl_subsidence->aquifer_cell = ecl_grav_common_alloc_aquifer_cell( ecl_subsidence->grid_cache , init_file ); @@ -232,7 +232,7 @@ static ecl_subsidence_survey_type * ecl_subsidence_get_survey( const ecl_subside if (name == NULL) return NULL; // Calling scope must determine if this is OK? else - return hash_get( subsidence->surveys , name ); + return (ecl_subsidence_survey_type*)hash_get( subsidence->surveys , name ); } diff --git a/ThirdParty/Ert/lib/ecl/ecl_sum.c b/ThirdParty/Ert/lib/ecl/ecl_sum.cpp similarity index 92% rename from ThirdParty/Ert/lib/ecl/ecl_sum.c rename to ThirdParty/Ert/lib/ecl/ecl_sum.cpp index 3d5d0ed627..070a70d00b 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_sum.c +++ b/ThirdParty/Ert/lib/ecl/ecl_sum.cpp @@ -22,23 +22,23 @@ #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 +#include +#include /** @@ -123,7 +123,7 @@ UTIL_IS_INSTANCE_FUNCTION( ecl_sum , ECL_SUM_ID ); The actual loading is implemented in the ecl_sum_data.c file. */ -void ecl_sum_set_case( ecl_sum_type * ecl_sum , const char * ecl_case) { +void ecl_sum_set_case( ecl_sum_type * ecl_sum , const char * input_arg) { util_safe_free( ecl_sum->ecl_case ); util_safe_free( ecl_sum->path ); util_safe_free( ecl_sum->abs_path ); @@ -132,9 +132,9 @@ void ecl_sum_set_case( ecl_sum_type * ecl_sum , const char * ecl_case) { { char *path , *base, *ext; - util_alloc_file_components( ecl_case , &path , &base , &ext); + util_alloc_file_components( input_arg, &path , &base , &ext); - ecl_sum->ecl_case = util_alloc_string_copy( ecl_case ); + ecl_sum->ecl_case = util_alloc_filename( path, base, NULL ); ecl_sum->path = util_alloc_string_copy( path ); ecl_sum->base = util_alloc_string_copy( base ); ecl_sum->ext = util_alloc_string_copy( ext ); @@ -154,7 +154,7 @@ static ecl_sum_type * ecl_sum_alloc__( const char * input_arg , const char * key if (!ecl_util_path_access(input_arg)) return NULL; - ecl_sum_type * ecl_sum = util_malloc( sizeof * ecl_sum ); + 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; @@ -183,11 +183,17 @@ static bool ecl_sum_fread_data( ecl_sum_type * ecl_sum , const stringlist_type * static void ecl_sum_fread_history( ecl_sum_type * ecl_sum ) { - ecl_sum_type * restart_case = ecl_sum_fread_alloc_case__( ecl_smspec_get_restart_case( ecl_sum->smspec ) , ":" , true); + 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_case__(restart_header, ":" , true); if (restart_case) { ecl_sum->restart_case = restart_case; ecl_sum_data_add_case(ecl_sum->data , restart_case->data ); } + free(restart_header); } @@ -711,6 +717,9 @@ double ecl_sum_get_general_var(const ecl_sum_type * ecl_sum , int time_index , c 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); } @@ -719,6 +728,9 @@ void ecl_sum_fwrite_interp_csv_line(const ecl_sum_type * ecl_sum, time_t sim_tim 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) { @@ -901,6 +913,38 @@ void ecl_sum_init_data_vector( const ecl_sum_type * ecl_sum , double_vector_type } +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 smspec_node_type * 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 ); } @@ -1082,7 +1126,7 @@ static void ecl_sum_fprintf_header( const ecl_sum_type * ecl_sum , const stringl 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 = util_malloc( DATE_STRING_LENGTH * sizeof * date_string); + char * date_string = (char*)util_malloc( DATE_STRING_LENGTH * sizeof * date_string); char * current_locale = NULL; if (fmt->locale != NULL) @@ -1420,3 +1464,29 @@ time_t_vector_type * ecl_sum_alloc_time_solution( const ecl_sum_type * ecl_sum , 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 smspec_node_type * 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 smspec_node_type *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 smspec_node_type * 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 smspec_node_type *node) { + return ecl_sum_iget_first_value(ecl_sum, smspec_node_get_params_index(node)); +} diff --git a/ThirdParty/Ert/lib/ecl/ecl_sum_data.c b/ThirdParty/Ert/lib/ecl/ecl_sum_data.cpp similarity index 88% rename from ThirdParty/Ert/lib/ecl/ecl_sum_data.c rename to ThirdParty/Ert/lib/ecl/ecl_sum_data.cpp index 6f38d91f21..a1d3e0f3f1 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_sum_data.c +++ b/ThirdParty/Ert/lib/ecl/ecl_sum_data.cpp @@ -19,22 +19,22 @@ #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 +#include +#include @@ -258,7 +258,7 @@ static void ecl_sum_data_clear_index( ecl_sum_data_type * data ) { ecl_sum_data_type * ecl_sum_data_alloc(ecl_smspec_type * smspec) { - ecl_sum_data_type * data = util_malloc( sizeof * data ); + ecl_sum_data_type * data = (ecl_sum_data_type*)util_malloc( sizeof * data ); data->data = vector_alloc_new(); data->smspec = smspec; @@ -293,7 +293,7 @@ ecl_sum_data_type * ecl_sum_data_alloc(ecl_smspec_type * smspec) { static ecl_sum_tstep_type * ecl_sum_data_iget_ministep( const ecl_sum_data_type * data , int internal_index ) { - return vector_iget( data->data , internal_index ); + return (ecl_sum_tstep_type*)vector_iget( data->data , internal_index ); } @@ -709,8 +709,8 @@ static void ecl_sum_data_build_index( ecl_sum_data_type * sum_data ) { /* Identify various global first and last values. */ { - const ecl_sum_tstep_type * first_ministep = vector_iget_const( sum_data->data, 0 ); - const ecl_sum_tstep_type * last_ministep = vector_get_last_const( sum_data->data ); + const ecl_sum_tstep_type * first_ministep = (const ecl_sum_tstep_type*)vector_iget_const( sum_data->data, 0 ); + const ecl_sum_tstep_type * last_ministep = (const ecl_sum_tstep_type*)vector_get_last_const( sum_data->data ); /* In most cases the days_start and data_start_time will agree with the global simulation start; however in the case where we @@ -772,7 +772,7 @@ ecl_sum_tstep_type * ecl_sum_data_add_new_tstep( ecl_sum_data_type * data , int ecl_sum_tstep_type * prev_tstep = NULL; if (vector_get_size( data->data ) > 0) - prev_tstep = vector_get_last( data->data ); + prev_tstep = (ecl_sum_tstep_type*)vector_get_last( data->data ); ecl_sum_data_append_tstep__( data , tstep ); { @@ -1234,7 +1234,7 @@ int ecl_sum_data_get_report_step_from_days(const ecl_sum_data_type * data , doub for (i=1; i < int_vector_size( data->report_last_index ); i++) { int ministep_index = int_vector_iget( data->report_last_index , i ); - const ecl_sum_tstep_type * ministep = vector_iget_const( data->data , ministep_index ); + const ecl_sum_tstep_type * ministep = (const ecl_sum_tstep_type*)vector_iget_const( data->data , ministep_index ); double_vector_iset( days_map , i , ecl_sum_tstep_get_sim_days( ministep )); int_vector_iset( report_map , i , ecl_sum_tstep_get_report( ministep )); @@ -1288,7 +1288,7 @@ int ecl_sum_data_get_report_step_from_time(const ecl_sum_data_type * data , time for (i=1; i < int_vector_size( data->report_last_index ); i++) { int ministep_index = int_vector_iget( data->report_last_index , i ); - const ecl_sum_tstep_type * ministep = vector_iget_const( data->data , ministep_index ); + const ecl_sum_tstep_type * ministep = (const ecl_sum_tstep_type*)vector_iget_const( data->data , ministep_index ); time_t_vector_iset( time_map , i , ecl_sum_tstep_get_sim_time( ministep )); int_vector_iset( report_map , i , ecl_sum_tstep_get_report( ministep )); @@ -1412,6 +1412,132 @@ double_vector_type * ecl_sum_data_alloc_data_vector( const ecl_sum_data_type * d } +void ecl_sum_data_init_double_vector(const ecl_sum_data_type * data, int params_index, double * output_data) { + int i; + for (i = 0; i < vector_get_size(data->data); i++) { + const ecl_sum_tstep_type * ministep = ecl_sum_data_iget_ministep( data , i ); + output_data[i] = ecl_sum_tstep_iget(ministep, params_index); + } +} + +void ecl_sum_data_init_datetime64_vector(const ecl_sum_data_type * data, int64_t * output_data, int multiplier) { + int i; + for (i = 0; i < vector_get_size(data->data); i++) { + const ecl_sum_tstep_type * ministep = ecl_sum_data_iget_ministep( data , i ); + output_data[i] = ecl_sum_tstep_get_sim_time(ministep) * multiplier; + } +} + +void ecl_sum_data_init_double_vector_interp(const ecl_sum_data_type * data, + const smspec_node_type * 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); + 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); + } + + for (int time_index=0; time_index < time_t_vector_size(time_points); time_index++) { + time_t sim_time = time_t_vector_iget( time_points, time_index); + double value; + if (sim_time < start_time) + value = start_value; + + else if (sim_time > end_time) + value = end_value; + + else { + int time_index1, time_index2; + double weight1, weight2; + ecl_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); + } + + 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); + int key_stride = 1; + for (int time_index=0; time_index < vector_get_size(data->data); time_index++) { + const ecl_sum_tstep_type * ministep = ecl_sum_data_iget_ministep(data , time_index); + for (int key_index = 0; key_index < ecl_sum_vector_get_size(keywords); key_index++) { + int param_index = ecl_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_tstep_iget(ministep, 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); + 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); + + + for (int time_index=0; time_index < time_t_vector_size(time_points); time_index++) { + time_t sim_time = time_t_vector_iget( time_points, time_index); + 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); + int data_index = key_index*key_stride + time_index*time_stride; + bool is_rate = ecl_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); + } + } 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); + int data_index = key_index*key_stride + time_index*time_stride; + bool is_rate = ecl_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); + } + } else { + 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); + + for (int key_index = 0; key_index < num_keywords; key_index++) { + int param_index = ecl_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( data, sim_time, param_index , is_rate, time_index1, time_index2, weight1, weight2); + output_data[data_index] = value; + } + } + } +} /** This function will return the total number of ministeps in the @@ -1487,3 +1613,18 @@ bool ecl_sum_data_report_step_compatible( const ecl_sum_data_type * data1 , cons } return compatible; } + + +double ecl_sum_data_iget_last_value(const ecl_sum_data_type * data, int param_index) { + const ecl_sum_tstep_type * tstep = (const ecl_sum_tstep_type*)vector_get_last_const(data->data); + return ecl_sum_tstep_iget( tstep, 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 ecl_sum_data_iget_first_value(const ecl_sum_data_type * data, int param_index) { + const ecl_sum_tstep_type * tstep = (const ecl_sum_tstep_type*) vector_iget_const(data->data, 0); + return ecl_sum_tstep_iget(tstep, param_index); +} diff --git a/ThirdParty/Ert/lib/ecl/ecl_sum_index.c b/ThirdParty/Ert/lib/ecl/ecl_sum_index.cpp similarity index 98% rename from ThirdParty/Ert/lib/ecl/ecl_sum_index.c rename to ThirdParty/Ert/lib/ecl/ecl_sum_index.cpp index 92f8d73bc5..051aca0b97 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_sum_index.c +++ b/ThirdParty/Ert/lib/ecl/ecl_sum_index.cpp @@ -16,7 +16,7 @@ for more details. */ -#include +#include /* This file contains all the internalized information from parsing a diff --git a/ThirdParty/Ert/lib/ecl/ecl_sum_tstep.c b/ThirdParty/Ert/lib/ecl/ecl_sum_tstep.cpp similarity index 93% rename from ThirdParty/Ert/lib/ecl/ecl_sum_tstep.c rename to ThirdParty/Ert/lib/ecl/ecl_sum_tstep.cpp index 8228400d02..86eeaf7ecc 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_sum_tstep.c +++ b/ThirdParty/Ert/lib/ecl/ecl_sum_tstep.cpp @@ -19,14 +19,14 @@ #include #include -#include -#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define ECL_SUM_TSTEP_ID 88631 @@ -72,10 +72,10 @@ struct ecl_sum_tstep_struct { 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 = util_alloc_copy(src , sizeof * src ); + ecl_sum_tstep_type * target = (ecl_sum_tstep_type*)util_alloc_copy(src , sizeof * src ); target->smspec = new_smspec; - target->data = util_malloc( params_size * sizeof * target->data ); + target->data = (float*)util_malloc( params_size * sizeof * target->data ); target->data_size = params_size; for (int i=0; i < params_size; i++) { @@ -89,20 +89,20 @@ ecl_sum_tstep_type * ecl_sum_tstep_alloc_remap_copy( const ecl_sum_tstep_type * } ecl_sum_tstep_type * ecl_sum_tstep_alloc_copy( const ecl_sum_tstep_type * src ) { - ecl_sum_tstep_type * target = util_alloc_copy(src , sizeof * src ); - target->data = util_alloc_copy( src->data , src->data_size * sizeof * src->data ); + ecl_sum_tstep_type * target = (ecl_sum_tstep_type*)util_alloc_copy(src , sizeof * src ); + target->data = (float*)util_alloc_copy( src->data , src->data_size * sizeof * 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 = util_malloc( sizeof * tstep ); + ecl_sum_tstep_type * tstep = (ecl_sum_tstep_type*)util_malloc( sizeof * tstep ); UTIL_TYPE_ID_INIT( tstep , ECL_SUM_TSTEP_ID); tstep->smspec = smspec; tstep->report_step = report_step; tstep->ministep = ministep_nr; tstep->data_size = ecl_smspec_get_params_size( smspec ); - tstep->data = util_calloc( tstep->data_size , sizeof * tstep->data ); + tstep->data = (float*)util_calloc( tstep->data_size , sizeof * tstep->data ); return tstep; } @@ -282,7 +282,7 @@ void ecl_sum_tstep_fwrite( const ecl_sum_tstep_type * ministep , const int_vecto ecl_kw_type * params_kw = ecl_kw_alloc( PARAMS_KW , compact_size , ECL_FLOAT ); const int * index = int_vector_get_ptr( index_map ); - float * data = ecl_kw_get_ptr( params_kw ); + float * data = (float*)ecl_kw_get_ptr( params_kw ); { int i; diff --git a/ThirdParty/Ert/lib/ecl/ecl_sum_vector.c b/ThirdParty/Ert/lib/ecl/ecl_sum_vector.cpp similarity index 93% rename from ThirdParty/Ert/lib/ecl/ecl_sum_vector.c rename to ThirdParty/Ert/lib/ecl/ecl_sum_vector.cpp index bc735e7b99..731d7a5cf5 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_sum_vector.c +++ b/ThirdParty/Ert/lib/ecl/ecl_sum_vector.cpp @@ -16,15 +16,15 @@ for more details. */ #include -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define ECL_SUM_VECTOR_TYPE_ID 8768778 @@ -59,7 +59,7 @@ static void ecl_sum_vector_add_node(ecl_sum_vector_type * vector, const smspec_n ecl_sum_vector_type * ecl_sum_vector_alloc(const ecl_sum_type * ecl_sum, bool add_keywords) { - ecl_sum_vector_type * ecl_sum_vector = util_malloc( sizeof * ecl_sum_vector ); + ecl_sum_vector_type * ecl_sum_vector = (ecl_sum_vector_type*)util_malloc( sizeof * ecl_sum_vector ); UTIL_TYPE_ID_INIT( ecl_sum_vector , ECL_SUM_VECTOR_TYPE_ID); ecl_sum_vector->ecl_sum = ecl_sum; ecl_sum_vector->node_index_list = int_vector_alloc(0,0); diff --git a/ThirdParty/Ert/lib/ecl/ecl_type.c b/ThirdParty/Ert/lib/ecl/ecl_type.cpp similarity index 91% rename from ThirdParty/Ert/lib/ecl/ecl_type.c rename to ThirdParty/Ert/lib/ecl/ecl_type.cpp index a259bb5428..acf8bf4043 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_type.c +++ b/ThirdParty/Ert/lib/ecl/ecl_type.cpp @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include /*****************************************************************/ /* The string names for the different ECLIPSE low-level @@ -37,7 +37,7 @@ static char * alloc_string_name(const ecl_data_type ecl_type) { return util_alloc_sprintf( "C%03d", - ecl_type_get_sizeof_ctype_fortio(ecl_type) + ecl_type_get_sizeof_iotype(ecl_type) ); } @@ -64,11 +64,11 @@ ecl_data_type ecl_type_create(const ecl_type_enum type, const size_t element_siz ecl_type_create_from_type(type) ); - if(ecl_type_get_sizeof_ctype_fortio(ecl_type) != element_size) + if(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_ctype_fortio(ecl_type) + element_size, ecl_type_get_sizeof_iotype(ecl_type) ); return ecl_type; @@ -146,17 +146,25 @@ ecl_data_type ecl_type_create_from_name( const char * type_name ) { } -int ecl_type_get_sizeof_ctype_fortio(const ecl_data_type ecl_type) { - if(ecl_type_is_char(ecl_type) || ecl_type_is_string(ecl_type)) - return ecl_type.element_size - 1; - else - return ecl_type_get_sizeof_ctype(ecl_type); -} - 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) || diff --git a/ThirdParty/Ert/lib/ecl/ecl_type_python.c b/ThirdParty/Ert/lib/ecl/ecl_type_python.cpp similarity index 90% rename from ThirdParty/Ert/lib/ecl/ecl_type_python.c rename to ThirdParty/Ert/lib/ecl/ecl_type_python.cpp index 8e5f843dd9..98bd5f8673 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_type_python.c +++ b/ThirdParty/Ert/lib/ecl/ecl_type_python.cpp @@ -1,14 +1,18 @@ -#include -#include -#include +#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 = util_malloc(sizeof * 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; } @@ -40,10 +44,12 @@ 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_ctype_fortio_python(const ecl_data_type * ecl_type) { - return ecl_type_get_sizeof_ctype_fortio(*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); } @@ -106,3 +112,7 @@ ecl_data_type * ecl_kw_get_data_type_python( const ecl_kw_type * ecl_kw ) { 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/ThirdParty/Ert/lib/ecl/ecl_util.c b/ThirdParty/Ert/lib/ecl/ecl_util.cpp similarity index 97% rename from ThirdParty/Ert/lib/ecl/ecl_util.c rename to ThirdParty/Ert/lib/ecl/ecl_util.cpp index 3aac4927b5..f94bcb8f6c 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_util.c +++ b/ThirdParty/Ert/lib/ecl/ecl_util.cpp @@ -24,13 +24,13 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include +#include +#include #define ECL_PHASE_NAME_OIL "SOIL" // SHould match the keywords found in restart file @@ -218,7 +218,7 @@ ecl_file_enum ecl_util_inspect_extension(const char * ext , bool *_fmt_file, int ecl_file_enum ecl_util_get_file_type(const char * filename, bool *fmt_file, int * report_nr) { - char *ext = strrchr(filename , '.'); + char *ext = (char*)strrchr(filename , '.'); if (ext == NULL) return ECL_OTHER_FILE; @@ -568,35 +568,35 @@ static bool numeric_extension_predicate(const char * filename, const char * base static bool summary_UPPERCASE_ASCII(const char * filename, const void * base) { - return numeric_extension_predicate(filename, base, 'A'); + return numeric_extension_predicate(filename, (const char*)base, 'A'); } static bool summary_UPPERCASE_BINARY(const char * filename, const void * base) { - return numeric_extension_predicate(filename, base, 'S'); + return numeric_extension_predicate(filename, (const char*)base, 'S'); } static bool summary_lowercase_ASCII(const char * filename, const void * base) { - return numeric_extension_predicate(filename, base, 'a'); + return numeric_extension_predicate(filename, (const char*)base, 'a'); } static bool summary_lowercase_BINARY(const char * filename, const void * base) { - return numeric_extension_predicate(filename, base, 's'); + return numeric_extension_predicate(filename, (const char*)base, 's'); } static bool restart_UPPERCASE_ASCII(const char * filename, const void * base) { - return numeric_extension_predicate(filename, base, 'F'); + return numeric_extension_predicate(filename, (const char*)base, 'F'); } static bool restart_UPPERCASE_BINARY(const char * filename, const void * base) { - return numeric_extension_predicate(filename, base, 'X'); + return numeric_extension_predicate(filename, (const char*)base, 'X'); } static bool restart_lowercase_ASCII(const char * filename, const void * base) { - return numeric_extension_predicate(filename, base, 'f'); + return numeric_extension_predicate(filename, (const char*)base, 'f'); } static bool restart_lowercase_BINARY(const char * filename, const void * base) { - return numeric_extension_predicate(filename, base, 'x'); + 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) { @@ -1211,7 +1211,7 @@ time_t ecl_util_get_start_date(const char * data_file) { util_abort("%s: sorry - could not find \"/\" termination of START keyword in data_file: \n",__func__ , data_file); buffer_size = (util_ftell(stream) - start_pos) ; - buffer = util_calloc( buffer_size + 1 , sizeof * buffer ); + buffer = (char*)util_calloc( buffer_size + 1 , sizeof * buffer ); util_fseek( stream , start_pos , SEEK_SET); util_fread( buffer , sizeof * buffer , buffer_size ,stream , __func__); buffer[buffer_size] = '\0'; @@ -1248,7 +1248,7 @@ static int ecl_util_get_num_parallel_cpu__(basic_parser_type* parser, FILE* stre util_abort("%s: sorry - could not find \"/\" termination of PARALLEL keyword in data_file: \n",__func__ , data_file); buffer_size = (util_ftell(stream) - start_pos) ; - buffer = util_calloc( buffer_size + 1 , sizeof * buffer ); + buffer = (char*)util_calloc( buffer_size + 1 , sizeof * buffer ); util_fseek( stream , start_pos , SEEK_SET); util_fread( buffer , sizeof * buffer , buffer_size ,stream , __func__); buffer[buffer_size] = '\0'; diff --git a/ThirdParty/Ert/lib/ecl/fault_block.c b/ThirdParty/Ert/lib/ecl/fault_block.cpp similarity index 97% rename from ThirdParty/Ert/lib/ecl/fault_block.c rename to ThirdParty/Ert/lib/ecl/fault_block.cpp index d0b4f91e86..c8faddd136 100644 --- a/ThirdParty/Ert/lib/ecl/fault_block.c +++ b/ThirdParty/Ert/lib/ecl/fault_block.cpp @@ -23,11 +23,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define FAULT_BLOCK_ID 3297376 @@ -52,7 +52,7 @@ static UTIL_SAFE_CAST_FUNCTION( fault_block , FAULT_BLOCK_ID ) fault_block_type * fault_block_alloc( const fault_block_layer_type * parent_layer , int block_id ) { - fault_block_type * block = util_malloc( sizeof * block ); + fault_block_type * block = (fault_block_type*)util_malloc( sizeof * block ); UTIL_TYPE_ID_INIT( block , FAULT_BLOCK_ID ); block->parent_layer = parent_layer; block->grid = fault_block_layer_get_grid( parent_layer ); diff --git a/ThirdParty/Ert/lib/ecl/fault_block_layer.c b/ThirdParty/Ert/lib/ecl/fault_block_layer.cpp similarity index 96% rename from ThirdParty/Ert/lib/ecl/fault_block_layer.c rename to ThirdParty/Ert/lib/ecl/fault_block_layer.cpp index a73e4e91ea..8f44f521cb 100644 --- a/ThirdParty/Ert/lib/ecl/fault_block_layer.c +++ b/ThirdParty/Ert/lib/ecl/fault_block_layer.cpp @@ -201,7 +201,7 @@ fault_block_layer_type * fault_block_layer_alloc( const ecl_grid_type * grid , i if ((k < 0) || (k >= ecl_grid_get_nz( grid ))) return NULL; else { - fault_block_layer_type * layer = util_malloc( sizeof * layer ); + fault_block_layer_type * layer = (fault_block_layer_type*)util_malloc( sizeof * layer ); UTIL_TYPE_ID_INIT( layer , FAULT_BLOCK_LAYER_ID); layer->grid = grid; layer->k = k; @@ -215,7 +215,7 @@ fault_block_layer_type * fault_block_layer_alloc( const ecl_grid_type * grid , i fault_block_type * fault_block_layer_iget_block( const fault_block_layer_type * layer , int storage_index) { - return vector_iget( layer->blocks , storage_index ); + return (fault_block_type*)vector_iget( layer->blocks , storage_index ); } @@ -224,7 +224,7 @@ fault_block_type * fault_block_layer_get_block( const fault_block_layer_type * l if (storage_index < 0) return NULL; else - return vector_iget( layer->blocks , storage_index ); + return (fault_block_type*)vector_iget( layer->blocks , storage_index ); } @@ -233,7 +233,7 @@ fault_block_type * fault_block_layer_safe_get_block( fault_block_layer_type * la if (storage_index < 0) return fault_block_layer_add_block( layer , block_id ); else - return vector_iget( layer->blocks , storage_index ); + return (fault_block_type*)vector_iget( layer->blocks , storage_index ); } diff --git a/ThirdParty/Ert/lib/ecl/fortio.c b/ThirdParty/Ert/lib/ecl/fortio.c index c9aad26b78..65478d7102 100644 --- a/ThirdParty/Ert/lib/ecl/fortio.c +++ b/ThirdParty/Ert/lib/ecl/fortio.c @@ -97,7 +97,7 @@ UTIL_IS_INSTANCE_FUNCTION( fortio , FORTIO_ID ); UTIL_SAFE_CAST_FUNCTION( fortio, FORTIO_ID ); static fortio_type * fortio_alloc__(const char *filename , bool fmt_file , bool endian_flip_header , bool stream_owner , bool writable) { - fortio_type * fortio = util_malloc(sizeof * fortio ); + fortio_type * fortio = (fortio_type*)util_malloc(sizeof * fortio ); UTIL_TYPE_ID_INIT( fortio, FORTIO_ID ); fortio->filename = util_alloc_string_copy(filename); fortio->endian_flip_header = endian_flip_header; diff --git a/ThirdParty/Ert/lib/ecl/grid_dims.c b/ThirdParty/Ert/lib/ecl/grid_dims.cpp similarity index 89% rename from ThirdParty/Ert/lib/ecl/grid_dims.c rename to ThirdParty/Ert/lib/ecl/grid_dims.cpp index 0d013fd5a8..1d2115b089 100644 --- a/ThirdParty/Ert/lib/ecl/grid_dims.c +++ b/ThirdParty/Ert/lib/ecl/grid_dims.cpp @@ -18,9 +18,9 @@ #include -#include +#include -#include +#include void grid_dims_init( grid_dims_type * dims , int nx, int ny , int nz , int nactive) { @@ -33,7 +33,7 @@ void grid_dims_init( grid_dims_type * dims , int nx, int ny , int nz , int nacti grid_dims_type * grid_dims_alloc( int nx, int ny , int nz , int nactive) { - grid_dims_type * dims = util_malloc( sizeof * dims ); + grid_dims_type * dims = (grid_dims_type*)util_malloc( sizeof * dims ); grid_dims_init( dims , nx , ny , nz , nactive ); return dims; } diff --git a/ThirdParty/Ert/lib/ecl/layer.c b/ThirdParty/Ert/lib/ecl/layer.cpp similarity index 98% rename from ThirdParty/Ert/lib/ecl/layer.c rename to ThirdParty/Ert/lib/ecl/layer.cpp index 20a2180eec..7a79809f31 100644 --- a/ThirdParty/Ert/lib/ecl/layer.c +++ b/ThirdParty/Ert/lib/ecl/layer.cpp @@ -18,10 +18,10 @@ #include #include -#include -#include +#include +#include -#include +#include #define LAYER_TYPE_ID 55185409 @@ -50,14 +50,14 @@ UTIL_SAFE_CAST_FUNCTION( layer , LAYER_TYPE_ID ) layer_type * layer_alloc(int nx , int ny) { - layer_type * layer = util_malloc( sizeof * layer ); + layer_type * layer = (layer_type*)util_malloc( sizeof * layer ); UTIL_TYPE_ID_INIT( layer , LAYER_TYPE_ID ); layer->nx = nx; layer->ny = ny; layer->cell_sum = 0; { int data_size = (layer->nx + 1)* (layer->ny + 1); - layer->data = util_malloc( data_size * sizeof * layer->data ); + layer->data = (cell_type*)util_malloc( data_size * sizeof * layer->data ); { int g; for (g=0; g < data_size; g++) { @@ -524,7 +524,7 @@ static void layer_trace_block_content__( layer_type * layer , bool erase , int i static bool * layer_alloc_visited_mask( const layer_type * layer ) { int total_size = (layer->nx + 1)* (layer->ny + 1); - bool * visited = util_malloc( total_size * sizeof * visited ); + bool * visited = (bool*)util_malloc( total_size * sizeof * visited ); int g; for (g = 0; g < total_size; g++) visited[g] = false; diff --git a/ThirdParty/Ert/lib/ecl/nnc_info.c b/ThirdParty/Ert/lib/ecl/nnc_info.cpp similarity index 90% rename from ThirdParty/Ert/lib/ecl/nnc_info.c rename to ThirdParty/Ert/lib/ecl/nnc_info.cpp index a60e1f4c9e..3db9cf4c42 100644 --- a/ThirdParty/Ert/lib/ecl/nnc_info.c +++ b/ThirdParty/Ert/lib/ecl/nnc_info.cpp @@ -18,13 +18,13 @@ #include -#include -#include -#include +#include +#include +#include -#include -#include -#include +#include +#include +#include #define NNC_INFO_TYPE_ID 675415078 @@ -41,7 +41,7 @@ UTIL_IS_INSTANCE_FUNCTION( nnc_info , NNC_INFO_TYPE_ID ) nnc_info_type * nnc_info_alloc(int lgr_nr) { - nnc_info_type * nnc_info = util_malloc( sizeof * nnc_info ); + nnc_info_type * nnc_info = (nnc_info_type*)util_malloc( sizeof * nnc_info ); UTIL_TYPE_ID_INIT(nnc_info , NNC_INFO_TYPE_ID); nnc_info->lgr_list = vector_alloc_new(); nnc_info->lgr_index_map = int_vector_alloc(0, -1); @@ -56,7 +56,7 @@ nnc_info_type * nnc_info_alloc_copy( const nnc_info_type * src_info ) { int ivec; for (ivec = 0; ivec < vector_get_size( src_info->lgr_list ); ivec++) { - nnc_vector_type * copy_vector = nnc_vector_alloc_copy( vector_iget_const( src_info->lgr_list , ivec)); + nnc_vector_type * copy_vector = nnc_vector_alloc_copy( (const nnc_vector_type*)vector_iget_const( src_info->lgr_list , ivec)); nnc_info_add_vector( copy_info , copy_vector ); } @@ -112,12 +112,12 @@ nnc_vector_type * nnc_info_get_vector( const nnc_info_type * nnc_info , int lgr_ if (-1 == lgr_index) return NULL; else - return vector_iget( nnc_info->lgr_list , lgr_index ); + return (nnc_vector_type*)vector_iget( nnc_info->lgr_list , lgr_index ); } nnc_vector_type * nnc_info_iget_vector( const nnc_info_type * nnc_info , int lgr_index) { - return vector_iget( nnc_info->lgr_list , lgr_index ); + return (nnc_vector_type*)vector_iget( nnc_info->lgr_list , lgr_index ); } @@ -189,7 +189,7 @@ int nnc_info_get_total_size( const nnc_info_type * nnc_info ) { int num_nnc = 0; int ivec; for (ivec = 0; ivec < vector_get_size( nnc_info->lgr_list ); ivec++) { - const nnc_vector_type * nnc_vector = vector_iget( nnc_info->lgr_list , ivec ); + const nnc_vector_type * nnc_vector = (const nnc_vector_type*)vector_iget( nnc_info->lgr_list , ivec ); num_nnc += nnc_vector_get_size( nnc_vector ); } return num_nnc; diff --git a/ThirdParty/Ert/lib/ecl/nnc_vector.c b/ThirdParty/Ert/lib/ecl/nnc_vector.cpp similarity index 91% rename from ThirdParty/Ert/lib/ecl/nnc_vector.c rename to ThirdParty/Ert/lib/ecl/nnc_vector.cpp index 253e44f4be..385fa91fe4 100644 --- a/ThirdParty/Ert/lib/ecl/nnc_vector.c +++ b/ThirdParty/Ert/lib/ecl/nnc_vector.cpp @@ -19,12 +19,12 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include -#include +#include @@ -45,7 +45,7 @@ static UTIL_SAFE_CAST_FUNCTION(nnc_vector , NNC_VECTOR_TYPE_ID) nnc_vector_type * nnc_vector_alloc(int lgr_nr) { - nnc_vector_type * nnc_vector = util_malloc( sizeof * nnc_vector ); + nnc_vector_type * nnc_vector = (nnc_vector_type*)util_malloc( sizeof * nnc_vector ); UTIL_TYPE_ID_INIT(nnc_vector , NNC_VECTOR_TYPE_ID); nnc_vector->grid_index_list = int_vector_alloc(0,0); nnc_vector->nnc_index_list = int_vector_alloc(0,0); @@ -54,7 +54,7 @@ nnc_vector_type * nnc_vector_alloc(int lgr_nr) { } nnc_vector_type * nnc_vector_alloc_copy(const nnc_vector_type * src_vector) { - nnc_vector_type * copy_vector = util_malloc( sizeof * src_vector ); + nnc_vector_type * copy_vector = (nnc_vector_type*)util_malloc( sizeof * src_vector ); UTIL_TYPE_ID_INIT(copy_vector , NNC_VECTOR_TYPE_ID); copy_vector->lgr_nr = src_vector->lgr_nr; diff --git a/ThirdParty/Ert/lib/ecl/smspec_node.c b/ThirdParty/Ert/lib/ecl/smspec_node.cpp similarity index 97% rename from ThirdParty/Ert/lib/ecl/smspec_node.c rename to ThirdParty/Ert/lib/ecl/smspec_node.cpp index b96e0b69e8..a59428f3fb 100644 --- a/ThirdParty/Ert/lib/ecl/smspec_node.c +++ b/ThirdParty/Ert/lib/ecl/smspec_node.cpp @@ -21,20 +21,20 @@ #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 @@ -363,7 +363,7 @@ float smspec_node_get_default( const smspec_node_type * smspec_node ) { smspec_node_type * smspec_node_alloc_new(int params_index, float default_value) { - smspec_node_type * node = util_malloc( sizeof * node ); + smspec_node_type * node = (smspec_node_type*)util_malloc( sizeof * node ); UTIL_TYPE_ID_INIT( node , SMSPEC_TYPE_ID); node->params_index = params_index; @@ -404,7 +404,7 @@ static void smspec_node_set_lgr_name( smspec_node_type * index , const char * lg static void smspec_node_set_lgr_ijk( smspec_node_type * index , int lgr_i , int lgr_j , int lgr_k) { if (index->lgr_ijk == NULL) - index->lgr_ijk = util_calloc( 3 , sizeof * index->lgr_ijk ); + index->lgr_ijk = (int*)util_calloc( 3 , sizeof * index->lgr_ijk ); index->lgr_ijk[0] = lgr_i; index->lgr_ijk[1] = lgr_j; @@ -434,7 +434,7 @@ static void smspec_node_set_num( smspec_node_type * index , const int grid_dims[ index->num = num; if ((index->var_type == ECL_SMSPEC_COMPLETION_VAR) || (index->var_type == ECL_SMSPEC_BLOCK_VAR)) { int global_index = num - 1; - index->ijk = util_calloc( 3 , sizeof * index->ijk ); + index->ijk = (int*)util_calloc( 3 , sizeof * index->ijk ); index->ijk[2] = global_index / ( grid_dims[0] * grid_dims[1] ); global_index -= index->ijk[2] * (grid_dims[0] * grid_dims[1]); index->ijk[1] = global_index / grid_dims[0] ; global_index -= index->ijk[1] * grid_dims[0]; @@ -776,7 +776,7 @@ smspec_node_type* smspec_node_alloc_copy( const smspec_node_type* node ) { if( !node ) return NULL; { - smspec_node_type* copy = util_malloc( sizeof * copy ); + smspec_node_type* copy = (smspec_node_type*)util_malloc( sizeof * copy ); UTIL_TYPE_ID_INIT( copy, SMSPEC_TYPE_ID ); copy->gen_key1 = util_alloc_string_copy( node->gen_key1 ); copy->gen_key2 = util_alloc_string_copy( node->gen_key2 ); @@ -788,14 +788,14 @@ smspec_node_type* smspec_node_alloc_copy( const smspec_node_type* node ) { copy->ijk = NULL; if( node->ijk ) { - copy->ijk = util_calloc( 3 , sizeof * node->ijk ); + copy->ijk = (int*)util_calloc( 3 , sizeof * node->ijk ); memcpy( copy->ijk, node->ijk, 3 * sizeof( * node->ijk ) ); } copy->lgr_name = util_alloc_string_copy( node->lgr_name ); copy->lgr_ijk = NULL; if( node->lgr_ijk ) { - copy->lgr_ijk = util_calloc( 3 , sizeof * node->lgr_ijk ); + copy->lgr_ijk = (int*)util_calloc( 3 , sizeof * node->lgr_ijk ); memcpy( copy->lgr_ijk, node->lgr_ijk, 3 * sizeof( * node->lgr_ijk ) ); } diff --git a/ThirdParty/Ert/lib/ecl/tests/ecl_kw_init.c b/ThirdParty/Ert/lib/ecl/tests/ecl_kw_init.c index 9a95fdfe7e..5ebcee8f88 100644 --- a/ThirdParty/Ert/lib/ecl/tests/ecl_kw_init.c +++ b/ThirdParty/Ert/lib/ecl/tests/ecl_kw_init.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -57,9 +58,29 @@ void test_float() { } +void test_bool() { + size_t N = 100; + bool * data = util_malloc(N * sizeof * data); + ecl_kw_type * kw = ecl_kw_alloc("BOOL", N , ECL_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); + + data[2*i] = true; + data[2*i + 1] = false; + } + + const bool * internal_data = ecl_kw_get_bool_ptr(kw); + + test_assert_int_equal( memcmp(internal_data, data, N * sizeof * data), 0); + ecl_kw_free(kw); + free(data); +} + int main( int argc , char ** argv) { test_int(); test_double(); test_float(); + test_bool(); exit(0); } diff --git a/ThirdParty/Ert/lib/ecl/tests/eclxx_kw.cpp b/ThirdParty/Ert/lib/ecl/tests/eclxx_kw.cpp index 3191250797..7c3e30215c 100644 --- a/ThirdParty/Ert/lib/ecl/tests/eclxx_kw.cpp +++ b/ThirdParty/Ert/lib/ecl/tests/eclxx_kw.cpp @@ -20,10 +20,13 @@ #include #include -#include +#include + +#include #include #include +#include void test_kw_name() { ERT::EclKW< int > kw1( "short", 1 ); @@ -54,10 +57,10 @@ void test_kw_vector_string() { std::vector< const char* > vec = { "short", "sweet", - "padded ", - "verylongkeyword" + "padded " }; + std::vector too_long = {"1234567890"}; ERT::EclKW< const char* > kw( "XYZ", vec ); test_assert_size_t_equal( kw.size(), vec.size() ); @@ -65,10 +68,38 @@ void test_kw_vector_string() { test_assert_string_equal( kw.at( 0 ), "short " ); test_assert_string_equal( kw.at( 1 ), "sweet " ); test_assert_string_equal( kw.at( 2 ), vec.at( 2 ) ); - test_assert_string_equal( kw.at( 3 ), "verylong" ); - test_assert_string_not_equal( kw.at( 2 ), "verylongkeyword" ); + + test_assert_throw( ERT::EclKW("XY", too_long), std::range_error); } +void test_kw_vector_std_string() { + std::vector< const char* > vec = { + "short", + "sweet", + "padded ", + }; + std::vector too_long = {"1234567890"}; + ERT::EclKW< std::string > kw( "XYZ", vec ); + + test_assert_size_t_equal( kw.size(), vec.size() ); + + test_assert_string_equal( kw.at( 0 ).c_str(), "short " ); + 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), std::range_error); +} + +void test_logical() { + //std::vector vec = {true,false,true,false}; + // ERT::EclKW kw("BOOL", vec); + // test_assert_int_equal(kw.size(), vec.size()); + + // for (size_t i=0; i < vec.size(); i++) + // test_assert_true( kw.at(i) == vec[i] ); +} + + void test_move_semantics_no_crash() { std::vector< int > vec = { 1, 2, 3, 4, 5 }; ERT::EclKW< int > kw1( "XYZ", vec ); @@ -96,13 +127,103 @@ void test_resize() { test_assert_int_equal( kw1.size() , 100 ); } +void test_data() { + std::vector d_data = {1,2,3,4}; + std::vector f_data = {10,20,30,40}; + std::vector i_data = {100,200,300,400}; + std::vector b_data = {true,false}; + std::vector s_data = {"S1", "S2", "S3"}; + + ERT::EclKW 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); + 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); + 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); + //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); + 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]); + +} + + +void test_read_write() { + std::vector d_data = {1,2,3,4}; + std::vector f_data = {10,20,30,40}; + std::vector i_data = {100,200,300,400}; + std::vector b_data = {true,false}; + std::vector s_data = {"S1", "S2", "S3"}; + + { + ERT::TestArea ta("test_fwrite"); + { + ERT::FortIO f("test_file", std::ios_base::out); + ERT::write_kw(f, "DOUBLE", d_data); + ERT::write_kw(f, "FLOAT", f_data); + ERT::write_kw(f, "INT", i_data); + ERT::write_kw(f, "BOOL", b_data); + ERT::write_kw(f, "STRING", s_data); + } + + { + 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); + + for (size_t i=0; i < d_data.size(); i++) + test_assert_true(d_data[i] == ecl_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)); + + for (size_t i=0; i < i_data.size(); i++) + test_assert_true(i_data[i] == ecl_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)); + + for (size_t i=0; i < s_data.size(); i++) { + std::string s8 = ecl_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); + } + } +} + + int main (int argc, char **argv) { test_kw_name(); test_kw_vector_assign(); test_kw_vector_string(); + test_kw_vector_std_string(); + test_logical(); test_move_semantics_no_crash(); test_exception_assing_ref_wrong_type(); test_resize(); + test_data(); + test_read_write(); } diff --git a/ThirdParty/Ert/lib/ecl/well_branch_collection.c b/ThirdParty/Ert/lib/ecl/well_branch_collection.cpp similarity index 87% rename from ThirdParty/Ert/lib/ecl/well_branch_collection.c rename to ThirdParty/Ert/lib/ecl/well_branch_collection.cpp index 959159de67..dfc43b96b3 100644 --- a/ThirdParty/Ert/lib/ecl/well_branch_collection.c +++ b/ThirdParty/Ert/lib/ecl/well_branch_collection.cpp @@ -18,14 +18,14 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include +#include +#include +#include #define WELL_BRANCH_COLLECTION_TYPE_ID 67177087 @@ -43,7 +43,7 @@ static UTIL_SAFE_CAST_FUNCTION( well_branch_collection , WELL_BRANCH_COLLECTION_ well_branch_collection_type * well_branch_collection_alloc() { - well_branch_collection_type * branch_collection = util_malloc( sizeof * branch_collection ); + well_branch_collection_type * branch_collection = (well_branch_collection_type*)util_malloc( sizeof * branch_collection ); UTIL_TYPE_ID_INIT( branch_collection , WELL_BRANCH_COLLECTION_TYPE_ID ); branch_collection->__start_segments = vector_alloc_new(); branch_collection->index_map = int_vector_alloc(0 , -1 ); @@ -82,7 +82,7 @@ bool well_branch_collection_has_branch( const well_branch_collection_type * bran const well_segment_type * well_branch_collection_iget_start_segment( const well_branch_collection_type * branches , int index ) { if (index < vector_get_size( branches->__start_segments)) - return vector_iget_const( branches->__start_segments , index); + return (const well_segment_type*)vector_iget_const( branches->__start_segments , index); else return NULL; } diff --git a/ThirdParty/Ert/lib/ecl/well_conn.c b/ThirdParty/Ert/lib/ecl/well_conn.cpp similarity index 77% rename from ThirdParty/Ert/lib/ecl/well_conn.c rename to ThirdParty/Ert/lib/ecl/well_conn.cpp index 74e87521b7..aaa394901c 100644 --- a/ThirdParty/Ert/lib/ecl/well_conn.c +++ b/ThirdParty/Ert/lib/ecl/well_conn.cpp @@ -19,14 +19,14 @@ #include #include -#include -#include +#include +#include -#include -#include +#include +#include -#include -#include +#include +#include #define WELL_CONN_NORMAL_WELL_SEGMENT_ID -999 @@ -92,7 +92,7 @@ UTIL_SAFE_CAST_FUNCTION( well_conn , WELL_CONN_TYPE_ID) static well_conn_type * well_conn_alloc__( int i , int j , int k , double connection_factor , well_conn_dir_enum dir , bool open, int segment_id, bool matrix_connection) { if (well_conn_assert_direction( dir , matrix_connection)) { - well_conn_type * conn = util_malloc( sizeof * conn ); + well_conn_type * conn = (well_conn_type*)util_malloc( sizeof * conn ); UTIL_TYPE_ID_INIT( conn , WELL_CONN_TYPE_ID ); conn->i = i; conn->j = j; @@ -142,9 +142,6 @@ well_conn_type * well_conn_alloc_fracture_MSW( int i , int j , int k , double co return well_conn_alloc__(i , j , k , connection_factor , dir , open , segment_id , false); } - - - /* Observe that the (ijk) and branch values are shifted to zero offset to be aligned with the rest of the ert libraries. @@ -157,73 +154,74 @@ well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw , 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 ); - if (IC > 0) { - well_conn_type * conn; - 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; - double connection_factor = -1; - bool matrix_connection = true; - bool open; - well_conn_dir_enum dir = well_conn_fracX; - - /* Set the status */ - { - int int_status = ecl_kw_iget_int( icon_kw , icon_offset + ICON_STATUS_INDEX ); - if (int_status > 0) - open = true; - else - open = false; - } + int IC =ecl_kw_iget_int( icon_kw , icon_offset + ICON_IC_INDEX ); + if (IC <= 0) + return NULL; /* IC < 0: Connection not in current LGR. */ - /* Set the K value and fracture flag. */ - { - if (header->dualp) { - int geometric_nz = header->nz / 2; - if (k >= geometric_nz) { - k -= geometric_nz; - matrix_connection = false; - } + /* + Out in the wild we have encountered files where the integer value used to + indicate direction has had an invalid value for some connections. In this + 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 ); + if ((int_direction < 0) || (int_direction > ICON_FRACY)) { + fprintf(stderr,"Invalid direction value:%d encountered for well - connection ignored\n",int_direction); + 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; + double connection_factor = -1; + bool matrix_connection = true; + bool is_open = (ecl_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. */ + { + if (header->dualp) { + int geometric_nz = header->nz / 2; + if (k >= geometric_nz) { + k -= geometric_nz; + matrix_connection = false; } } + } + + /* Set the direction flag */ + if (int_direction == ICON_DEFAULT_DIR_VALUE) + int_direction = ICON_DEFAULT_DIR_TARGET; + + switch (int_direction) { + case(ICON_DIRX): + dir = well_conn_dirX; + break; + case(ICON_DIRY): + dir = well_conn_dirY; + break; + case(ICON_DIRZ): + dir = well_conn_dirZ; + break; + case(ICON_FRACX): + dir = well_conn_fracX; + break; + case(ICON_FRACY): + dir = well_conn_fracY; + break; + } - /* Set the direction flag */ - { - int int_direction = ecl_kw_iget_int( icon_kw , icon_offset + ICON_DIRECTION_INDEX ); - if (int_direction == ICON_DEFAULT_DIR_VALUE) - int_direction = ICON_DEFAULT_DIR_TARGET; - - switch (int_direction) { - case(ICON_DIRX): - dir = well_conn_dirX; - break; - case(ICON_DIRY): - dir = well_conn_dirY; - break; - case(ICON_DIRZ): - dir = well_conn_dirZ; - break; - case(ICON_FRACX): - dir = well_conn_fracX; - break; - case(ICON_FRACY): - dir = well_conn_fracY; - break; - default: - util_abort("%s: icon direction value:%d not recognized\n",__func__ , int_direction); - } - } - - if (scon_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); - } + if (scon_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); + } + { int segment_id = ecl_kw_iget_int( icon_kw , icon_offset + ICON_SEGMENT_INDEX ) - ECLIPSE_WELL_SEGMENT_OFFSET + WELL_SEGMENT_OFFSET; - conn = well_conn_alloc__(i,j,k,connection_factor,dir,open,segment_id,matrix_connection); + well_conn_type * conn = well_conn_alloc__(i,j,k,connection_factor,dir,is_open,segment_id,matrix_connection); if (xcon_kw) { const int xcon_offset = header->nxconz * (header->ncwmax * well_nr + conn_nr); @@ -242,8 +240,7 @@ well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw , */ return conn; - } else - return NULL; /* IC < 0: Connection not in current LGR. */ + } } @@ -279,9 +276,9 @@ well_conn_type * well_conn_alloc_wellhead( const ecl_kw_type * iwel_kw , const e } if (matrix_connection) - return well_conn_alloc( conn_i , conn_j , conn_k , connection_factor , open , well_conn_dirZ ); + return well_conn_alloc( conn_i , conn_j , conn_k , connection_factor , (well_conn_dir_enum)open , well_conn_dirZ ); else - return well_conn_alloc_fracture( conn_i , conn_j , conn_k , connection_factor , open , well_conn_dirZ ); + return well_conn_alloc_fracture( conn_i , conn_j , conn_k , connection_factor , (well_conn_dir_enum)open , well_conn_dirZ ); } else // The well is completed in this LGR - however the wellhead is in another LGR. return NULL; diff --git a/ThirdParty/Ert/lib/ecl/well_conn_collection.c b/ThirdParty/Ert/lib/ecl/well_conn_collection.cpp similarity index 86% rename from ThirdParty/Ert/lib/ecl/well_conn_collection.c rename to ThirdParty/Ert/lib/ecl/well_conn_collection.cpp index 6277279614..2e77fd61a3 100644 --- a/ThirdParty/Ert/lib/ecl/well_conn_collection.c +++ b/ThirdParty/Ert/lib/ecl/well_conn_collection.cpp @@ -18,16 +18,16 @@ #include -#include -#include -#include +#include +#include +#include -#include -#include +#include +#include -#include -#include -#include +#include +#include +#include #define WELL_CONN_COLLECTION_TYPE_ID 67150087 @@ -43,7 +43,7 @@ static UTIL_SAFE_CAST_FUNCTION( well_conn_collection , WELL_CONN_COLLECTION_TYPE well_conn_collection_type * well_conn_collection_alloc() { - well_conn_collection_type * wellcc = util_malloc( sizeof * wellcc ); + well_conn_collection_type * wellcc = (well_conn_collection_type*)util_malloc( sizeof * wellcc ); UTIL_TYPE_ID_INIT( wellcc , WELL_CONN_COLLECTION_TYPE_ID ); wellcc->connection_list = vector_alloc_new(); return wellcc; @@ -86,15 +86,16 @@ int well_conn_collection_get_size( const well_conn_collection_type * wellcc ) { const well_conn_type * well_conn_collection_iget_const(const well_conn_collection_type * wellcc , int index) { int size = well_conn_collection_get_size( wellcc ); if (index < size) - return vector_iget_const( wellcc->connection_list , index ); + return (const well_conn_type*)vector_iget_const( wellcc->connection_list , index ); else return NULL; } + well_conn_type * well_conn_collection_iget(const well_conn_collection_type * wellcc , int index) { int size = well_conn_collection_get_size( wellcc ); if (index < size) - return vector_iget( wellcc->connection_list , index ); + return (well_conn_type*)vector_iget( wellcc->connection_list , index ); else return NULL; } diff --git a/ThirdParty/Ert/lib/ecl/well_info.c b/ThirdParty/Ert/lib/ecl/well_info.cpp similarity index 95% rename from ThirdParty/Ert/lib/ecl/well_info.c rename to ThirdParty/Ert/lib/ecl/well_info.cpp index d57fdf8de3..d2e00429b4 100644 --- a/ThirdParty/Ert/lib/ecl/well_info.c +++ b/ThirdParty/Ert/lib/ecl/well_info.cpp @@ -19,23 +19,23 @@ #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 +#include +#include /* @@ -192,7 +192,7 @@ struct well_info_struct { */ well_info_type * well_info_alloc( const ecl_grid_type * grid) { - well_info_type * well_info = util_malloc( sizeof * well_info ); + well_info_type * well_info = (well_info_type*)util_malloc( sizeof * well_info ); well_info->wells = hash_alloc(); well_info->well_names = stringlist_alloc_new(); well_info->grid = grid; @@ -205,7 +205,7 @@ bool well_info_has_well( well_info_type * well_info , const char * well_name ) { } well_ts_type * well_info_get_ts( const well_info_type * well_info , const char *well_name) { - return hash_get( well_info->wells , well_name ); + return (well_ts_type*)hash_get( well_info->wells , well_name ); } static void well_info_add_new_ts( well_info_type * well_info , const char * well_name) { diff --git a/ThirdParty/Ert/lib/ecl/well_rseg_loader.c b/ThirdParty/Ert/lib/ecl/well_rseg_loader.cpp similarity index 85% rename from ThirdParty/Ert/lib/ecl/well_rseg_loader.c rename to ThirdParty/Ert/lib/ecl/well_rseg_loader.cpp index f457cf1f77..29e507409b 100644 --- a/ThirdParty/Ert/lib/ecl/well_rseg_loader.c +++ b/ThirdParty/Ert/lib/ecl/well_rseg_loader.cpp @@ -18,15 +18,15 @@ #include -#include -#include +#include +#include -#include -#include -#include +#include +#include +#include -#include -#include +#include +#include #include @@ -41,14 +41,14 @@ struct well_rseg_loader_struct { well_rseg_loader_type * well_rseg_loader_alloc(ecl_file_view_type * rst_view) { - well_rseg_loader_type * loader = util_malloc(sizeof * loader); + well_rseg_loader_type * loader = (well_rseg_loader_type*)util_malloc(sizeof * loader); int element_count = 4; loader->rst_view = rst_view; loader->relative_index_map = int_vector_alloc(0, 0); loader->absolute_index_map = int_vector_alloc(0, 0); - loader->buffer = util_malloc(element_count * sizeof(double)); + loader->buffer = (char*)util_malloc(element_count * sizeof(double)); loader->kw = RSEG_KW; int_vector_append(loader->relative_index_map, RSEG_DEPTH_INDEX); diff --git a/ThirdParty/Ert/lib/ecl/well_segment.c b/ThirdParty/Ert/lib/ecl/well_segment.cpp similarity index 92% rename from ThirdParty/Ert/lib/ecl/well_segment.c rename to ThirdParty/Ert/lib/ecl/well_segment.cpp index b1b4912cdd..8209506788 100644 --- a/ThirdParty/Ert/lib/ecl/well_segment.c +++ b/ThirdParty/Ert/lib/ecl/well_segment.cpp @@ -18,17 +18,17 @@ #include -#include -#include +#include +#include -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include #define WELL_SEGMENT_TYPE_ID 2209166 @@ -53,7 +53,7 @@ static UTIL_SAFE_CAST_FUNCTION( well_segment , WELL_SEGMENT_TYPE_ID ) well_segment_type * well_segment_alloc(int segment_id , int outlet_segment_id , int branch_id , const double * rseg_data) { - well_segment_type * segment = util_malloc( sizeof * segment ); + well_segment_type * segment = (well_segment_type*)util_malloc( sizeof * segment ); UTIL_TYPE_ID_INIT( segment , WELL_SEGMENT_TYPE_ID ); segment->link_count = 0; @@ -212,7 +212,7 @@ bool well_segment_add_connection( well_segment_type * segment , const char * gri hash_insert_hash_owned_ref( segment->connections , grid_name , well_conn_collection_alloc() , well_conn_collection_free__ ); { - well_conn_collection_type * connections = hash_get( segment->connections , grid_name ); + well_conn_collection_type * connections = (well_conn_collection_type*)hash_get( segment->connections , grid_name ); well_conn_collection_add_ref( connections , conn ); } return true; @@ -223,7 +223,7 @@ bool well_segment_add_connection( well_segment_type * segment , const char * gri const well_conn_collection_type * well_segment_get_connections(const well_segment_type * segment , const char * grid_name ) { if (well_segment_has_grid_connections( segment , grid_name)) - return hash_get( segment->connections , grid_name); + return (const well_conn_collection_type*)hash_get( segment->connections , grid_name); else return NULL; } diff --git a/ThirdParty/Ert/lib/ecl/well_segment_collection.c b/ThirdParty/Ert/lib/ecl/well_segment_collection.cpp similarity index 90% rename from ThirdParty/Ert/lib/ecl/well_segment_collection.c rename to ThirdParty/Ert/lib/ecl/well_segment_collection.cpp index a919ea0c33..dadfe69449 100644 --- a/ThirdParty/Ert/lib/ecl/well_segment_collection.c +++ b/ThirdParty/Ert/lib/ecl/well_segment_collection.cpp @@ -18,18 +18,18 @@ #include -#include -#include +#include +#include -#include -#include +#include +#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include struct well_segment_collection_struct { @@ -40,7 +40,7 @@ struct well_segment_collection_struct { well_segment_collection_type * well_segment_collection_alloc(void) { - well_segment_collection_type * segment_collection = util_malloc( sizeof * segment_collection ); + well_segment_collection_type * segment_collection = (well_segment_collection_type*)util_malloc( sizeof * segment_collection ); segment_collection->__segment_storage = vector_alloc_new(); segment_collection->segment_index_map = int_vector_alloc( 0 , -1 ); @@ -77,7 +77,7 @@ void well_segment_collection_add( well_segment_collection_type * segment_collect well_segment_type * well_segment_collection_iget( const well_segment_collection_type * segment_collection , int index) { - return vector_iget( segment_collection->__segment_storage , index ); + return (well_segment_type*)vector_iget( segment_collection->__segment_storage , index ); } diff --git a/ThirdParty/Ert/lib/ecl/well_state.c b/ThirdParty/Ert/lib/ecl/well_state.cpp similarity index 93% rename from ThirdParty/Ert/lib/ecl/well_state.c rename to ThirdParty/Ert/lib/ecl/well_state.cpp index 91d91862a6..7ee3129efe 100644 --- a/ThirdParty/Ert/lib/ecl/well_state.c +++ b/ThirdParty/Ert/lib/ecl/well_state.cpp @@ -25,27 +25,27 @@ #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 -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include /* @@ -193,7 +193,7 @@ UTIL_IS_INSTANCE_FUNCTION( well_state , WELL_STATE_TYPE_ID) 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 = util_malloc( sizeof * well_state ); + well_state_type * well_state = (well_state_type*)util_malloc( sizeof * well_state ); UTIL_TYPE_ID_INIT( well_state , WELL_STATE_TYPE_ID ); well_state->index_wellhead = vector_alloc_new(); well_state->name_wellhead = hash_alloc(); @@ -340,7 +340,7 @@ static int well_state_get_lgr_well_nr( const well_state_type * well_state , cons while (true) { bool found = false; { - char * lgr_well_name = util_alloc_strip_copy( ecl_kw_iget_ptr( zwel_kw , well_nr * header->nzwelz) ); + char * lgr_well_name = (char*)util_alloc_strip_copy( (const char*)ecl_kw_iget_ptr( zwel_kw , well_nr * header->nzwelz) ); if ( strcmp( well_state->name , lgr_well_name) == 0) found = true; @@ -425,7 +425,7 @@ static void well_state_add_connections__( well_state_type * well_state , xcon_kw = ecl_file_view_iget_named_kw(rst_view, XCON_KW, 0); } - well_conn_collection_type * wellcc = hash_get( well_state->connections , grid_name ); + well_conn_collection_type * wellcc = (well_conn_collection_type*)hash_get( well_state->connections , grid_name ); well_conn_collection_load_from_kw( wellcc , iwel_kw , icon_kw , scon_kw, xcon_kw , well_nr , header ); } ecl_rsthead_free( header ); @@ -518,7 +518,7 @@ bool well_state_add_MSW2( well_state_type * well_state , hash_iter_type * grid_iter = hash_iter_alloc( well_state->connections ); while (!hash_iter_is_complete( grid_iter )) { const char * grid_name = hash_iter_get_next_key( grid_iter ); - const well_conn_collection_type * connections = hash_get( well_state->connections , grid_name ); + const well_conn_collection_type * connections = (const well_conn_collection_type*)hash_get( well_state->connections , grid_name ); well_segment_collection_add_connections( well_state->segments , grid_name , connections ); } hash_iter_free( grid_iter ); @@ -581,7 +581,7 @@ well_state_type * well_state_alloc_from_file2( ecl_file_view_type * file_view , { const int zwel_offset = global_header->nzwelz * global_well_nr; - name = util_alloc_strip_copy(ecl_kw_iget_ptr( global_zwel_kw , zwel_offset )); // Hardwired max 8 characters in Well Name + name = (char*)util_alloc_strip_copy((const char*)ecl_kw_iget_ptr( global_zwel_kw , zwel_offset )); // Hardwired max 8 characters in Well Name } well_state = well_state_alloc(name , global_well_nr , open , type , report_nr , global_header->sim_time); @@ -631,20 +631,20 @@ time_t well_state_get_sim_time( const well_state_type * well_state ) { Will return NULL if no wellhead in this grid. */ const well_conn_type * well_state_iget_wellhead( const well_state_type * well_state , int grid_nr) { - return vector_safe_iget_const( well_state->index_wellhead , grid_nr ); + return (const well_conn_type*)vector_safe_iget_const( well_state->index_wellhead , grid_nr ); } const well_conn_type * well_state_get_wellhead( const well_state_type * well_state , const char * grid_name) { if (hash_has_key( well_state->name_wellhead , grid_name)) - return hash_get( well_state->name_wellhead , grid_name ); + return (const well_conn_type*)hash_get( well_state->name_wellhead , grid_name ); else return NULL; } const well_conn_type * well_state_get_global_wellhead( const well_state_type * well_state ) { if (hash_has_key( well_state->name_wellhead , ECL_GRID_GLOBAL_GRID)) - return hash_get( well_state->name_wellhead , ECL_GRID_GLOBAL_GRID ); + return (const well_conn_type*)hash_get( well_state->name_wellhead , ECL_GRID_GLOBAL_GRID ); else return NULL; } @@ -672,7 +672,7 @@ const char * well_state_get_name( const well_state_type * well_state ) { const well_conn_collection_type * well_state_get_grid_connections( const well_state_type * well_state , const char * grid_name) { if (hash_has_key( well_state->connections , grid_name)) - return hash_get( well_state->connections , grid_name); + return (const well_conn_collection_type*)hash_get( well_state->connections , grid_name); else return NULL; } diff --git a/ThirdParty/Ert/lib/ecl/well_ts.c b/ThirdParty/Ert/lib/ecl/well_ts.cpp similarity index 90% rename from ThirdParty/Ert/lib/ecl/well_ts.c rename to ThirdParty/Ert/lib/ecl/well_ts.cpp index 9680131eb1..2a51809e72 100644 --- a/ThirdParty/Ert/lib/ecl/well_ts.c +++ b/ThirdParty/Ert/lib/ecl/well_ts.cpp @@ -62,12 +62,12 @@ #include #include -#include -#include +#include +#include -#include -#include -#include +#include +#include +#include @@ -91,7 +91,7 @@ struct well_ts_struct { /******************************************************************/ static well_node_type * well_node_alloc( well_state_type * well_state) { - well_node_type * node = util_malloc( sizeof * node ); + well_node_type * node = (well_node_type*)util_malloc( sizeof * node ); UTIL_TYPE_ID_INIT( node , WELL_NODE_TYPE_ID ); node->report_nr = well_state_get_report_nr( well_state ); node->sim_time = well_state_get_sim_time( well_state ); @@ -131,7 +131,7 @@ static int well_node_time_cmp( const void * arg1 , const void * arg2) { /*****************************************************************/ static well_ts_type * well_ts_alloc_empty( ) { - well_ts_type * well_ts = util_malloc( sizeof * well_ts ); + well_ts_type * well_ts = (well_ts_type*)util_malloc( sizeof * well_ts ); UTIL_TYPE_ID_INIT( well_ts , WELL_TS_TYPE_ID ); well_ts->ts = vector_alloc_new(); @@ -157,8 +157,8 @@ static int well_ts_get_index__( const well_ts_type * well_ts , int report_step , return 0; else { - const well_node_type * first_node = vector_iget_const( well_ts->ts , 0 ); - const well_node_type * last_node = vector_get_last_const( well_ts->ts ); + const well_node_type * first_node = (const well_node_type*)vector_iget_const( well_ts->ts , 0 ); + const well_node_type * last_node = (const well_node_type*)vector_get_last_const( well_ts->ts ); if (use_report) { if (report_step < first_node->report_nr) @@ -181,7 +181,7 @@ static int well_ts_get_index__( const well_ts_type * well_ts , int report_step , while (true) { int center_index = (lower_index + upper_index) / 2; - const well_node_type * center_node = vector_iget_const( well_ts->ts , center_index ); + const well_node_type * center_node = (const well_node_type*)vector_iget_const( well_ts->ts , center_index ); double cmp; if (use_report) cmp = center_node->report_nr - report_step; @@ -221,11 +221,11 @@ static int well_ts_get_index( const well_ts_type * well_ts , int report_step , t // Inline check that the index is correct { bool OK = true; - const well_node_type * node = vector_iget_const( well_ts->ts , index ); + const well_node_type * node = (const well_node_type*)vector_iget_const( well_ts->ts , index ); well_node_type * next_node = NULL; if (index < (vector_get_size( well_ts->ts ) - 1)) - next_node = vector_iget( well_ts->ts , index + 1); + next_node = (well_node_type*)vector_iget( well_ts->ts , index + 1); if (use_report) { if (index < 0) { @@ -268,7 +268,7 @@ void well_ts_add_well( well_ts_type * well_ts , well_state_type * well_state ) { vector_append_owned_ref( well_ts->ts , new_node , well_node_free__ ); if (vector_get_size( well_ts->ts ) > 1) { - const well_node_type * last_node = vector_get_last_const(well_ts->ts ); + const well_node_type * last_node = (const well_node_type*)vector_get_last_const(well_ts->ts ); if (new_node->sim_time < last_node->sim_time) // The new node is chronologically before the previous node; // i.e. we must sort the nodes in time. This should probably happen @@ -309,7 +309,7 @@ well_state_type * well_ts_get_last_state( const well_ts_type * well_ts) { well_state_type * well_ts_iget_state( const well_ts_type * well_ts , int index) { - well_node_type * node = vector_iget( well_ts->ts , index ); + well_node_type * node = (well_node_type*)vector_iget( well_ts->ts , index ); return node->well_state; } diff --git a/ThirdParty/Ert/lib/ert_api_config.h.in b/ThirdParty/Ert/lib/ert_api_config.h.in index 08c3e5da96..0a74e7d730 100644 --- a/ThirdParty/Ert/lib/ert_api_config.h.in +++ b/ThirdParty/Ert/lib/ert_api_config.h.in @@ -7,6 +7,7 @@ #cmakedefine ERT_HAVE_OPENDIR #cmakedefine ERT_HAVE_SYMLINK #cmakedefine ERT_HAVE_READLINKAT +#cmakedefine ERT_HAVE_READLINKAT_DECLARATION #cmakedefine ERT_HAVE_GLOB #cmakedefine ERT_HAVE_GETUID #cmakedefine ERT_HAVE_REGEXP diff --git a/ThirdParty/Ert/lib/ert_api_config.hpp.in b/ThirdParty/Ert/lib/ert_api_config.hpp.in new file mode 100644 index 0000000000..78411e4360 --- /dev/null +++ b/ThirdParty/Ert/lib/ert_api_config.hpp.in @@ -0,0 +1 @@ +#include diff --git a/ThirdParty/Ert/lib/geometry/geo_pointset.c b/ThirdParty/Ert/lib/geometry/geo_pointset.cpp similarity index 92% rename from ThirdParty/Ert/lib/geometry/geo_pointset.c rename to ThirdParty/Ert/lib/geometry/geo_pointset.cpp index 32eaa2ea2d..970b2fd2cb 100644 --- a/ThirdParty/Ert/lib/geometry/geo_pointset.c +++ b/ThirdParty/Ert/lib/geometry/geo_pointset.cpp @@ -21,9 +21,9 @@ #include #include -#include +#include -#include +#include #define INIT_SIZE 256 @@ -42,17 +42,17 @@ struct geo_pointset_struct { static void geo_pointset_resize( geo_pointset_type * pointset, int new_alloc_size) { - pointset->xcoord = util_realloc( pointset->xcoord , new_alloc_size * sizeof * pointset->xcoord ); - pointset->ycoord = util_realloc( pointset->ycoord , new_alloc_size * sizeof * pointset->ycoord ); + pointset->xcoord = (double*)util_realloc( pointset->xcoord , new_alloc_size * sizeof * pointset->xcoord ); + pointset->ycoord = (double*)util_realloc( pointset->ycoord , new_alloc_size * sizeof * pointset->ycoord ); if (pointset->internal_z) - pointset->zcoord = util_realloc( pointset->zcoord , new_alloc_size * sizeof * pointset->zcoord); + pointset->zcoord = (double*)util_realloc( pointset->zcoord , new_alloc_size * sizeof * pointset->zcoord); pointset->alloc_size = new_alloc_size; } geo_pointset_type * geo_pointset_alloc( bool internal_z) { - geo_pointset_type * pointset = util_malloc( sizeof * pointset ); + geo_pointset_type * pointset = (geo_pointset_type*)util_malloc( sizeof * pointset ); pointset->xcoord = NULL; pointset->ycoord = NULL; pointset->zcoord = NULL; diff --git a/ThirdParty/Ert/lib/geometry/geo_polygon.c b/ThirdParty/Ert/lib/geometry/geo_polygon.cpp similarity index 95% rename from ThirdParty/Ert/lib/geometry/geo_polygon.c rename to ThirdParty/Ert/lib/geometry/geo_polygon.cpp index 1780a9d0db..516d90de04 100644 --- a/ThirdParty/Ert/lib/geometry/geo_polygon.c +++ b/ThirdParty/Ert/lib/geometry/geo_polygon.cpp @@ -21,12 +21,12 @@ #include #include -#include -#include -#include +#include +#include +#include -#include -#include +#include +#include @@ -45,7 +45,7 @@ UTIL_IS_INSTANCE_FUNCTION( geo_polygon , GEO_POLYGON_TYPE_ID); geo_polygon_type * geo_polygon_alloc(const char * name) { - geo_polygon_type * polygon = util_malloc( sizeof * polygon ); + geo_polygon_type * polygon = (geo_polygon_type*)util_malloc( sizeof * polygon ); UTIL_TYPE_ID_INIT( polygon , GEO_POLYGON_TYPE_ID ); polygon->xcoord = double_vector_alloc( 0 , 0 ); @@ -189,11 +189,11 @@ void geo_polygon_iget_xy(const geo_polygon_type * polygon , int index , double * bool geo_polygon_segment_intersects(const geo_polygon_type * polygon , double x1 , double y1 , double x2 , double y2) { bool intersects = false; - double ** points = util_malloc( 4 * sizeof * points); + double ** points = (double**)util_malloc( 4 * sizeof * points); { int i; for (i = 0; i < 4; i++) - points[i] = util_malloc( 2 * sizeof * points[i]); + points[i] = (double*)util_malloc( 2 * sizeof * points[i]); } points[0][0] = x1; diff --git a/ThirdParty/Ert/lib/geometry/geo_polygon_collection.c b/ThirdParty/Ert/lib/geometry/geo_polygon_collection.cpp similarity index 86% rename from ThirdParty/Ert/lib/geometry/geo_polygon_collection.c rename to ThirdParty/Ert/lib/geometry/geo_polygon_collection.cpp index 269a9032fa..f02ddb1374 100644 --- a/ThirdParty/Ert/lib/geometry/geo_polygon_collection.c +++ b/ThirdParty/Ert/lib/geometry/geo_polygon_collection.cpp @@ -20,13 +20,13 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include +#include +#include @@ -42,7 +42,7 @@ struct geo_polygon_collection_struct { UTIL_IS_INSTANCE_FUNCTION( geo_polygon_collection , GEO_POLYGON_COLLECTION_TYPE_ID) geo_polygon_collection_type * geo_polygon_collection_alloc( ) { - geo_polygon_collection_type * polygons = util_malloc( sizeof * polygons ); + geo_polygon_collection_type * polygons = (geo_polygon_collection_type*)util_malloc( sizeof * polygons ); UTIL_TYPE_ID_INIT( polygons , GEO_POLYGON_COLLECTION_TYPE_ID ); polygons->polygon_list = vector_alloc_new(); polygons->polygon_map = hash_alloc(); @@ -106,10 +106,10 @@ void geo_polygon_collection_free( geo_polygon_collection_type * polygons ) { geo_polygon_type * geo_polygon_collection_iget_polygon(const geo_polygon_collection_type * polygons , int index) { - return vector_iget( polygons->polygon_list , index ); + return (geo_polygon_type*)vector_iget( polygons->polygon_list , index ); } geo_polygon_type * geo_polygon_collection_get_polygon(const geo_polygon_collection_type * polygons , const char * polygon_name) { - return hash_get( polygons->polygon_map , polygon_name ); + return (geo_polygon_type*)hash_get( polygons->polygon_map , polygon_name ); } diff --git a/ThirdParty/Ert/lib/geometry/geo_region.c b/ThirdParty/Ert/lib/geometry/geo_region.cpp similarity index 92% rename from ThirdParty/Ert/lib/geometry/geo_region.c rename to ThirdParty/Ert/lib/geometry/geo_region.cpp index e1def85bec..76a1a1f11a 100644 --- a/ThirdParty/Ert/lib/geometry/geo_region.c +++ b/ThirdParty/Ert/lib/geometry/geo_region.cpp @@ -20,15 +20,15 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include #define GEO_REGION_TYPE_ID 4431973 @@ -47,14 +47,14 @@ struct geo_region_struct { static UTIL_SAFE_CAST_FUNCTION( geo_region , GEO_REGION_TYPE_ID ) geo_region_type * geo_region_alloc( const geo_pointset_type * pointset , bool preselect) { - geo_region_type * region = util_malloc( sizeof * region ); + geo_region_type * region = (geo_region_type*)util_malloc( sizeof * region ); UTIL_TYPE_ID_INIT( region , GEO_REGION_TYPE_ID ); region->pointset = pointset; region->pointset_size = geo_pointset_get_size( pointset ); region->preselect = preselect; region->index_list = int_vector_alloc( 0, 0); - region->active_mask = util_calloc( region->pointset_size , sizeof * region->active_mask ); + region->active_mask = (bool*)util_calloc( region->pointset_size , sizeof * region->active_mask ); geo_region_reset( region ); return region; diff --git a/ThirdParty/Ert/lib/geometry/geo_surface.c b/ThirdParty/Ert/lib/geometry/geo_surface.cpp similarity index 97% rename from ThirdParty/Ert/lib/geometry/geo_surface.c rename to ThirdParty/Ert/lib/geometry/geo_surface.cpp index 7d9b443c77..c3b25e25e4 100644 --- a/ThirdParty/Ert/lib/geometry/geo_surface.c +++ b/ThirdParty/Ert/lib/geometry/geo_surface.cpp @@ -20,11 +20,11 @@ #include #include -#include -#include +#include +#include -#include -#include +#include +#include #define __PI 3.14159265 #define GEO_SURFACE_TYPE_ID 111743 @@ -61,7 +61,7 @@ static void geo_surface_copy_header( const geo_surface_type * src , geo_surface_ } static geo_surface_type * geo_surface_alloc_empty( bool internal_z ) { - geo_surface_type * surface = util_malloc( sizeof * surface ); + geo_surface_type * surface = (geo_surface_type*)util_malloc( sizeof * surface ); UTIL_TYPE_ID_INIT( surface , GEO_SURFACE_TYPE_ID ) surface->pointset = geo_pointset_alloc( internal_z ); return surface; @@ -242,7 +242,7 @@ static bool geo_surface_fload_irap( geo_surface_type * surface , const char * fi double * zcoord = NULL; if (loadz) { - zcoord = util_calloc( surface->nx * surface->ny , sizeof * zcoord ); + zcoord = (double*)util_calloc( surface->nx * surface->ny , sizeof * zcoord ); read_ok = geo_surface_fscanf_zcoord( surface , stream , zcoord ); } diff --git a/ThirdParty/Ert/lib/geometry/geo_util.c b/ThirdParty/Ert/lib/geometry/geo_util.cpp similarity index 98% rename from ThirdParty/Ert/lib/geometry/geo_util.c rename to ThirdParty/Ert/lib/geometry/geo_util.cpp index a0a7a1d077..2dda526704 100644 --- a/ThirdParty/Ert/lib/geometry/geo_util.c +++ b/ThirdParty/Ert/lib/geometry/geo_util.cpp @@ -21,9 +21,9 @@ #include #include -#include +#include -#include +#include #define EPSILON 0.000001 diff --git a/ThirdParty/Ert/lib/include/ert/ecl/EclKW.hpp b/ThirdParty/Ert/lib/include/ert/ecl/EclKW.hpp index 34ad650fcd..68f834428d 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/EclKW.hpp +++ b/ThirdParty/Ert/lib/include/ert/ecl/EclKW.hpp @@ -26,11 +26,9 @@ #include #include -#include -#include -#include - #include +#include +#include #include namespace ERT { @@ -45,12 +43,27 @@ namespace ERT { template<> struct ecl_type< int > { 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< char* > { static const ecl_type_enum type { ECL_CHAR_TYPE }; }; template<> struct ecl_type< const char* > { 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< std::string > + { 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: @@ -98,21 +111,36 @@ namespace ERT { ecl_kw_type* m_kw = nullptr; }; +template<> +inline bool EclKW_ref< bool >::at( size_t i ) const { + return ecl_kw_iget_bool( this->m_kw, i ); +} + + template<> inline const char* EclKW_ref< const char* >::at( size_t i ) const { return ecl_kw_iget_char_ptr( this->m_kw, i ); } +template<> +inline std::string EclKW_ref< std::string >::at( size_t i ) const { + return ecl_kw_iget_char_ptr( this->m_kw, i ); +} + + + /* - The current implementation of "string" storage in the underlying C - ecl_kw structure does not lend itself to easily implement - operator[]. We have therefore explicitly deleted it here. + 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< const char* >::operator[]( size_t i ) = delete; +template<> +bool& EclKW_ref::operator[]( size_t i) = delete; template< typename T > class EclKW : public EclKW_ref< T > { @@ -151,6 +179,14 @@ class EclKW : public EclKW_ref< T > { 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() ); @@ -159,16 +195,87 @@ class EclKW : public EclKW_ref< T > { return EclKW( c_ptr ); } + }; + template<> inline EclKW< const char* >::EclKW( const std::string& kw, const std::vector< const char* >& data ) : EclKW( kw, data.size() ) { auto* ptr = this->get(); - for( size_t i = 0; i < data.size(); ++i ) + 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< std::string >::EclKW( const std::string& kw, + const std::vector< std::string >& 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< std::string >::EclKW( const std::string& kw, + const std::vector< const char* >& 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< bool >& 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()); } } diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_box.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_box.hpp new file mode 100644 index 0000000000..4b1a822b03 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_box.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_coarse_cell.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_coarse_cell.hpp new file mode 100644 index 0000000000..289c1dd7c4 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_coarse_cell.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_endian_flip.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_endian_flip.hpp new file mode 100644 index 0000000000..a0b3ac55e9 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_endian_flip.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_file.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_file.hpp new file mode 100644 index 0000000000..6fade2adb9 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_file.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_file_kw.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_file_kw.hpp new file mode 100644 index 0000000000..35352ecfd1 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_file_kw.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_file_view.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_file_view.hpp new file mode 100644 index 0000000000..4fbb391a83 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_file_view.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.h index c3f78f2029..67c44b9bfb 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.h @@ -18,7 +18,7 @@ #ifndef ERT_ECL_GRAV_H #define ERT_ECL_GRAV_H -#ifdef __plusplus +#ifdef __cplusplus extern "C" { #endif @@ -36,11 +36,12 @@ ecl_grav_type * ecl_grav_alloc( const ecl_grid_type * ecl_grid, const ecl 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 __plusplus +#ifdef __cplusplus } #endif #endif diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.hpp new file mode 100644 index 0000000000..9dbd0ae404 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav_calc.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav_calc.hpp new file mode 100644 index 0000000000..df878a9337 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav_calc.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav_common.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav_common.hpp new file mode 100644 index 0000000000..555ef8dc1c --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grav_common.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.h index 0e8689fa6f..5ae7b115db 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.h @@ -76,6 +76,7 @@ extern "C" { 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); @@ -118,6 +119,9 @@ extern "C" { 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 ); diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.hpp new file mode 100644 index 0000000000..a27e4887ee --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid_cache.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid_cache.hpp new file mode 100644 index 0000000000..32ca2236ef --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid_cache.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid_dims.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid_dims.hpp new file mode 100644 index 0000000000..d32e7d5d77 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_grid_dims.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_init_file.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_init_file.hpp new file mode 100644 index 0000000000..ef37a89689 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_init_file.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_io_config.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_io_config.h index 6792346101..c33f01274b 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_io_config.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_io_config.h @@ -18,6 +18,9 @@ #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; @@ -38,4 +41,7 @@ bool ecl_io_config_get_unified_summary(ecl_io_config_type *); 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/ThirdParty/Ert/lib/include/ert/ecl/ecl_io_config.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_io_config.hpp new file mode 100644 index 0000000000..fdbe583b39 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_io_config.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.h index 9eacaf31ef..21b22bd385 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.h @@ -72,7 +72,6 @@ extern "C" { 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 *); - size_t ecl_kw_get_sizeof_ctype(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); @@ -88,6 +87,7 @@ extern "C" { 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); 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 *); @@ -119,6 +119,7 @@ extern "C" { 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); @@ -140,6 +141,9 @@ extern "C" { 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); @@ -263,6 +267,8 @@ extern "C" { 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 diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.hpp new file mode 100644 index 0000000000..f4ed8bfb4a --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/ecl/ecl_sum_file.c b/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw_grdecl.hpp similarity index 69% rename from ThirdParty/Ert/lib/ecl/ecl_sum_file.c rename to ThirdParty/Ert/lib/include/ert/ecl/ecl_kw_grdecl.hpp index 0d9a033d8c..eb27171f48 100644 --- a/ThirdParty/Ert/lib/ecl/ecl_sum_file.c +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw_grdecl.hpp @@ -1,7 +1,7 @@ /* - Copyright (C) 2011 Statoil ASA, Norway. + Copyright (C) 2018 Statoil ASA, Norway. - The file 'ecl_sum_file.c' is part of ERT - Ensemble based Reservoir Tool. + This file 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 @@ -16,12 +16,5 @@ for more details. */ -#include -#include -#include -#include - -struct ecl_sum_struct { - -}; +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw_magic.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw_magic.hpp new file mode 100644 index 0000000000..d7cfba7c96 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_kw_magic.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_data.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_data.hpp new file mode 100644 index 0000000000..5cca194e38 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_data.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_export.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_export.hpp new file mode 100644 index 0000000000..e2d16c2eb3 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_export.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_geometry.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_geometry.hpp new file mode 100644 index 0000000000..8c9f3c9ab7 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_nnc_geometry.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_region.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_region.h index 87be80a3a0..9ad8e40310 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_region.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_region.h @@ -70,10 +70,13 @@ typedef struct ecl_region_struct ecl_region_type; 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); @@ -152,6 +155,7 @@ typedef struct ecl_region_struct ecl_region_type; 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); /*****************************************************************/ @@ -170,6 +174,16 @@ typedef struct ecl_region_struct ecl_region_type; 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); + + /*****************************************************************/ /* set/get the name */ void ecl_region_set_name( ecl_region_type * region , const char * name ); diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_region.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_region.hpp new file mode 100644 index 0000000000..d51112ae82 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_region.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_cell.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_cell.hpp new file mode 100644 index 0000000000..65ba3f48fc --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_cell.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_file.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_file.hpp new file mode 100644 index 0000000000..3545ee0d42 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_file.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_node.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_node.h index 8faef7cda0..b7f6418cbd 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_node.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_node.h @@ -67,6 +67,8 @@ int ecl_rft_node_cmp( const ecl_rft_node_type * n1 , const ecl_rft_node_type * n 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 diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_node.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_node.hpp new file mode 100644 index 0000000000..623405e7d0 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rft_node.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rst_file.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rst_file.hpp new file mode 100644 index 0000000000..9ecc8a91e1 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rst_file.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h index 28aa0dbaee..cf58ec3e53 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h @@ -95,6 +95,8 @@ extern "C" { 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 ); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.hpp new file mode 100644 index 0000000000..44550950a1 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_smspec.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_smspec.hpp new file mode 100644 index 0000000000..7f59f6a7fe --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_smspec.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_subsidence.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_subsidence.h index 7da533e338..71d0747a1f 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_subsidence.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_subsidence.h @@ -19,7 +19,7 @@ #ifndef ERT_ECL_SUBSIDENCE_H #define ERT_ECL_SUBSIDENCE_H -#ifdef __plusplus +#ifdef __cplusplus extern "C" { #endif @@ -43,8 +43,12 @@ extern "C" { 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); -#ifdef __plusplus + +#ifdef __cplusplus } #endif #endif diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_subsidence.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_subsidence.hpp new file mode 100644 index 0000000000..a8b535ef8a --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_subsidence.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.h index 4585fec8c4..780add6010 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.h @@ -35,7 +35,6 @@ extern "C" { #include #include - typedef struct { char * locale; const char * sep; @@ -53,6 +52,8 @@ extern "C" { /*****************************************************************/ + /* This is a forward declaration. */ +typedef struct ecl_sum_vector_struct ecl_sum_vector_type; typedef struct ecl_sum_struct ecl_sum_type; @@ -136,6 +137,8 @@ typedef struct ecl_sum_struct ecl_sum_type; 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); @@ -143,6 +146,7 @@ typedef struct ecl_sum_struct ecl_sum_type; /* 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 ); @@ -211,7 +215,8 @@ typedef struct ecl_sum_struct ecl_sum_type; 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 , @@ -229,7 +234,6 @@ typedef struct ecl_sum_struct ecl_sum_type; 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 * ecl_case); void ecl_sum_fwrite( const ecl_sum_type * ecl_sum ); void ecl_sum_fwrite_smspec( const ecl_sum_type * ecl_sum ); smspec_node_type * ecl_sum_add_smspec_node(ecl_sum_type * ecl_sum, const smspec_node_type * node); @@ -265,6 +269,18 @@ typedef struct ecl_sum_struct ecl_sum_type; 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 smspec_node_type *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 smspec_node_type *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 diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.hpp new file mode 100644 index 0000000000..7370f32e97 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_data.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_data.h index a04d5363f5..929c1114a6 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_data.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_data.h @@ -24,6 +24,7 @@ extern "C" { #endif #include +#include #include #include @@ -86,8 +87,23 @@ typedef struct ecl_sum_data_struct ecl_sum_data_type ; 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); - double_vector_type * ecl_sum_data_alloc_seconds_solution( const ecl_sum_data_type * data , const smspec_node_type * node , double value, bool rates_clamp_lower); + 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 smspec_node_type * 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 smspec_node_type * smspec_node, + const time_t_vector_type * time_points, + double * output_data); #ifdef __cplusplus diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_data.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_data.hpp new file mode 100644 index 0000000000..9d54a02f6c --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_data.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_index.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_index.hpp new file mode 100644 index 0000000000..1317fbf5a4 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_index.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_tstep.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_tstep.hpp new file mode 100644 index 0000000000..5350247752 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_tstep.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_vector.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_vector.h index 1ab5dc1e8f..6994160437 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_vector.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_vector.h @@ -41,6 +41,8 @@ typedef struct ecl_sum_vector_struct ecl_sum_vector_type; 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); diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_vector.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_vector.hpp new file mode 100644 index 0000000000..8b06dae566 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_sum_vector.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_type.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_type.h index 4848e34dc7..a218330974 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_type.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_type.h @@ -59,7 +59,6 @@ typedef enum { {.value = 5 , .name = "ECL_MESS_TYPE"}, \ {.value = 7 , .name = "ECL_STRING_TYPE"} -#define ECL_TYPE_ENUM_SIZE 7 /* Character data in ECLIPSE files comes as an array of fixed-length @@ -68,7 +67,6 @@ typedef enum { */ #define ECL_STRING8_LENGTH 8 // 'Normal' 8 characters 'CHAR' type. -#define ECL_STRING10_LENGTH 10 // 'Normal' 8 characters 'CHAR' type. #define ECL_TYPE_LENGTH 4 struct ecl_type_struct { @@ -81,7 +79,7 @@ struct ecl_type_struct { #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(int)} +#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} @@ -94,7 +92,7 @@ struct ecl_type_struct { #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(int)} +#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} @@ -114,7 +112,7 @@ 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_ctype_fortio(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); @@ -129,8 +127,8 @@ 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); - +char * ecl_type_get_name(const ecl_data_type); + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_type.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_type.hpp new file mode 100644 index 0000000000..982417c0ea --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_type.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_units.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_units.hpp new file mode 100644 index 0000000000..09fd7dbafa --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_units.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_util.hpp b/ThirdParty/Ert/lib/include/ert/ecl/ecl_util.hpp new file mode 100644 index 0000000000..6118488a7e --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_util.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/fault_block.hpp b/ThirdParty/Ert/lib/include/ert/ecl/fault_block.hpp new file mode 100644 index 0000000000..901d2167b2 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/fault_block.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/fault_block_layer.hpp b/ThirdParty/Ert/lib/include/ert/ecl/fault_block_layer.hpp new file mode 100644 index 0000000000..d2266cd641 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/fault_block_layer.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/grid_dims.hpp b/ThirdParty/Ert/lib/include/ert/ecl/grid_dims.hpp new file mode 100644 index 0000000000..215e1daf11 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/grid_dims.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/layer.h b/ThirdParty/Ert/lib/include/ert/ecl/layer.h index bf9dfcf58d..f1aacf1135 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl/layer.h +++ b/ThirdParty/Ert/lib/include/ert/ecl/layer.h @@ -76,6 +76,9 @@ extern "C" { 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_clear_cells( layer_type * layer); + void layer_update_connected_cells( layer_type * layer , int i , int j , int org_value , int new_value); + void layer_assign( layer_type * layer, int value); void layer_cells_equal( const layer_type * layer , int value , int_vector_type * i_list , int_vector_type * j_list); int layer_count_equal( const layer_type * layer , int value ); diff --git a/ThirdParty/Ert/lib/include/ert/ecl/layer.hpp b/ThirdParty/Ert/lib/include/ert/ecl/layer.hpp new file mode 100644 index 0000000000..97de3b6bcc --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/layer.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/nnc_info.hpp b/ThirdParty/Ert/lib/include/ert/ecl/nnc_info.hpp new file mode 100644 index 0000000000..93b5b155e1 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/nnc_info.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/nnc_vector.hpp b/ThirdParty/Ert/lib/include/ert/ecl/nnc_vector.hpp new file mode 100644 index 0000000000..c2194dcd82 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/nnc_vector.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl/smspec_node.hpp b/ThirdParty/Ert/lib/include/ert/ecl/smspec_node.hpp new file mode 100644 index 0000000000..0a6f2f7f18 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl/smspec_node.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_branch_collection.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_branch_collection.hpp new file mode 100644 index 0000000000..3815a62422 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_branch_collection.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_conn.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_conn.hpp new file mode 100644 index 0000000000..98459f44e6 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_conn.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_conn_collection.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_conn_collection.hpp new file mode 100644 index 0000000000..bbbecd3e6e --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_conn_collection.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_const.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_const.hpp new file mode 100644 index 0000000000..9daefcf46f --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_const.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_info.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_info.hpp new file mode 100644 index 0000000000..df5625079d --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_info.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_rseg_loader.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_rseg_loader.hpp new file mode 100644 index 0000000000..3fbdb9a8e3 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_rseg_loader.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_segment.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_segment.hpp new file mode 100644 index 0000000000..1a423cf493 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_segment.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_segment_collection.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_segment_collection.hpp new file mode 100644 index 0000000000..f15cf65a7e --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_segment_collection.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_state.h b/ThirdParty/Ert/lib/include/ert/ecl_well/well_state.h index 163b4cecb8..aa9427c858 100644 --- a/ThirdParty/Ert/lib/include/ert/ecl_well/well_state.h +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_state.h @@ -97,6 +97,10 @@ extern "C" { double well_state_get_gas_rate( const well_state_type * well_state ); double well_state_get_water_rate( const well_state_type * well_state); double well_state_get_volume_rate( const well_state_type * well_state); + double well_state_get_water_rate_si( const well_state_type * well_state); + double well_state_get_oil_rate_si( const well_state_type * well_state ); + double well_state_get_volume_rate_si( const well_state_type * well_state); + double well_state_get_gas_rate_si( const well_state_type * well_state ); UTIL_IS_INSTANCE_HEADER( well_state ); diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_state.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_state.hpp new file mode 100644 index 0000000000..4166742c82 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_state.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/ecl_well/well_ts.hpp b/ThirdParty/Ert/lib/include/ert/ecl_well/well_ts.hpp new file mode 100644 index 0000000000..9f4463d1c7 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/ecl_well/well_ts.hpp @@ -0,0 +1,20 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + + +#include diff --git a/ThirdParty/Ert/lib/include/ert/geometry/geo_pointset.hpp b/ThirdParty/Ert/lib/include/ert/geometry/geo_pointset.hpp new file mode 100644 index 0000000000..a1f54f309d --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/geometry/geo_pointset.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/geometry/geo_polygon.hpp b/ThirdParty/Ert/lib/include/ert/geometry/geo_polygon.hpp new file mode 100644 index 0000000000..47a0198653 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/geometry/geo_polygon.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/geometry/geo_polygon_collection.hpp b/ThirdParty/Ert/lib/include/ert/geometry/geo_polygon_collection.hpp new file mode 100644 index 0000000000..0b956ad4b8 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/geometry/geo_polygon_collection.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/geometry/geo_region.hpp b/ThirdParty/Ert/lib/include/ert/geometry/geo_region.hpp new file mode 100644 index 0000000000..aca4548a42 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/geometry/geo_region.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/geometry/geo_surface.h b/ThirdParty/Ert/lib/include/ert/geometry/geo_surface.h index a6707372a0..0e6dd12801 100644 --- a/ThirdParty/Ert/lib/include/ert/geometry/geo_surface.h +++ b/ThirdParty/Ert/lib/include/ert/geometry/geo_surface.h @@ -46,6 +46,16 @@ extern "C" { int geo_surface_get_ny( const geo_surface_type * surface ); void geo_surface_iget_xy( const geo_surface_type* surface, int index, double* x, double* y); + void geo_surface_shift( const geo_surface_type * src , double value); + void geo_surface_scale( const geo_surface_type * src , double value); + void geo_surface_isub( geo_surface_type * self , const geo_surface_type * other); + void geo_surface_iset_zvalue(geo_surface_type * surface, int index , double value); + void geo_surface_assign_value( const geo_surface_type * src , double value); + geo_surface_type * geo_surface_alloc_copy( const geo_surface_type * src , bool copy_zdata); + void geo_surface_iadd( geo_surface_type * self , const geo_surface_type * other); + void geo_surface_imul( geo_surface_type * self , const geo_surface_type * other); + void geo_surface_isqrt( geo_surface_type * surface ); + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/lib/include/ert/geometry/geo_surface.hpp b/ThirdParty/Ert/lib/include/ert/geometry/geo_surface.hpp new file mode 100644 index 0000000000..f4030b6ca1 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/geometry/geo_surface.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/geometry/geo_util.hpp b/ThirdParty/Ert/lib/include/ert/geometry/geo_util.hpp new file mode 100644 index 0000000000..b0b3bf1e52 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/geometry/geo_util.hpp @@ -0,0 +1,19 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This file 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#include diff --git a/ThirdParty/Ert/lib/include/ert/nexus/nexus_plot.hpp b/ThirdParty/Ert/lib/include/ert/nexus/nexus_plot.hpp deleted file mode 100644 index 0fc46cd011..0000000000 --- a/ThirdParty/Ert/lib/include/ert/nexus/nexus_plot.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (C) 2017 Statoil ASA, Norway. - - The file 'nexus_plot.hpp' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef NEXUS_PLOT_H -#define NEXUS_PLOT_H - -#include -#include -#include -#include -#include - -typedef struct ecl_sum_struct ecl_sum_type; - -namespace nex { - -struct bad_header : public std::runtime_error { - using std::runtime_error::runtime_error; -}; -struct read_error : public std::runtime_error { - using std::runtime_error::runtime_error; -}; -struct unexpected_eof : public std::runtime_error { - using std::runtime_error::runtime_error; -}; - -class NexusPlot { -public: - NexusPlot( const std::string& ); - NexusPlot( std::istream& ); - - int32_t num_classes = 0; - int32_t day, month, year; - int32_t nx, ny, nz; - int32_t ncomp; - std::vector class_names; - std::vector vars_in_class; - std::vector< std::vector > var_names; - - ecl_sum_type* ecl_summary( const std::string& ecl_case ); - -private: - void load( std::istream& ); -}; - -} - -#endif // NEXUS_PLOT_H diff --git a/ThirdParty/Ert/lib/include/ert/util/arg_pack.hpp b/ThirdParty/Ert/lib/include/ert/util/arg_pack.hpp new file mode 100644 index 0000000000..94c71385e1 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/arg_pack.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef ARG_PACK_CXX +#define ARG_PACK_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/buffer.hpp b/ThirdParty/Ert/lib/include/ert/util/buffer.hpp new file mode 100644 index 0000000000..b002e8981e --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/buffer.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef BUFFER_CXX +#define BUFFER_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/ecl_version.hpp b/ThirdParty/Ert/lib/include/ert/util/ecl_version.hpp new file mode 100644 index 0000000000..3af2a9706b --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/ecl_version.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef ECL_VERSION_CXX +#define ECL_VERSION_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/hash.hpp b/ThirdParty/Ert/lib/include/ert/util/hash.hpp new file mode 100644 index 0000000000..1a2758952a --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/hash.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef HASH_CXX +#define HASH_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/hash_node.hpp b/ThirdParty/Ert/lib/include/ert/util/hash_node.hpp new file mode 100644 index 0000000000..2d6176c592 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/hash_node.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef HASH_NODE_CXX +#define HASH_NODE_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/hash_sll.hpp b/ThirdParty/Ert/lib/include/ert/util/hash_sll.hpp new file mode 100644 index 0000000000..70c64a0b03 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/hash_sll.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef HASH_SLL_CXX +#define HASH_SLL_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/lars.h b/ThirdParty/Ert/lib/include/ert/util/lars.h deleted file mode 100644 index 4acdeb37c6..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/lars.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'lars.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - - -#ifndef ERT_LARS_H -#define ERT_LARS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -typedef struct lars_struct lars_type; - -int lars_get_sample( const lars_type * lars ); -int lars_get_nvar( const lars_type * lars ); -lars_type * lars_alloc1( int nsample , int nvars); -lars_type * lars_alloc2( matrix_type * X , matrix_type * Y , bool internal_copy ); -void lars_estimate(lars_type * lars , int max_vars , double max_beta , bool verbose); -void lars_isetX( lars_type * lars, int sample, int var , double value); -void lars_isetY( lars_type * lars, int sample, double value); -void lars_select_beta( lars_type * lars , int beta_index); -void lars_free( lars_type * lars ); -double lars_eval1( const lars_type * lars , const matrix_type * x); -double lars_eval2( const lars_type * lars , double * x); -double lars_getY0( const lars_type * lars); -double lars_iget_beta( const lars_type * lars , int index); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/log.h b/ThirdParty/Ert/lib/include/ert/util/log.h deleted file mode 100644 index dcaad30d89..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/log.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'log.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_LOG_H -#define ERT_LOG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -//Same as pythons default log levels, but with different numeric values. -typedef enum { - LOG_CRITICAL=0, //OOM. - LOG_ERROR=1, //When something we really expected to work does not, e.g. IO failure. - LOG_WARNING=2, //Important, but not error. E.g. combination of settings which can be intended, but probably are not. - LOG_INFO=3, //Entering functions/parts of the code - LOG_DEBUG=4 //Inside the for-loop, when you need the nitty gritty details. Think TRACE. -} message_level_type; - - -typedef struct log_struct log_type; - - FILE * log_get_stream(log_type * logh ); - void log_reopen( log_type * logh , const char * filename ); - log_type * log_open(const char *filename, int log_level); - void log_add_message(log_type *logh, int message_level , FILE * dup_stream , char* message, bool free_message); - void log_add_message_str(log_type *logh, message_level_type message_level , const char* message); - void log_add_fmt_message(log_type * logh , int message_level , FILE * dup_stream , const char * fmt , ...); - int log_get_level( const log_type * logh); - void log_set_level( log_type * logh , int new_level); - void log_close( log_type * logh ); - void log_sync(log_type * logh); - const char * log_get_filename( const log_type * logh ); - int log_get_level( const log_type * logh); - void log_set_level( log_type * logh , int log_level); - bool log_is_open( const log_type * logh); - bool log_include_message(const log_type *logh , int message_level); - int log_get_msg_count(const log_type * logh); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/lookup_table.h b/ThirdParty/Ert/lib/include/ert/util/lookup_table.h index d08cc7c421..a2ebb1d32e 100644 --- a/ThirdParty/Ert/lib/include/ert/util/lookup_table.h +++ b/ThirdParty/Ert/lib/include/ert/util/lookup_table.h @@ -37,7 +37,7 @@ typedef struct lookup_table_struct lookup_table_type; double lookup_table_get_max_value( lookup_table_type * lookup_table ); double lookup_table_get_min_value( lookup_table_type * lookup_table ); double lookup_table_get_max_arg( lookup_table_type * lookup_table ); - double lookup_table_get_max_arg( lookup_table_type * lookup_table ); + double lookup_table_get_min_arg( lookup_table_type * lookup_table ); int lookup_table_get_size( const lookup_table_type * lt ); void lookup_table_set_low_limit( lookup_table_type * lt , double limit); bool lookup_table_has_low_limit(const lookup_table_type * lt ); diff --git a/ThirdParty/Ert/lib/include/ert/util/lookup_table.hpp b/ThirdParty/Ert/lib/include/ert/util/lookup_table.hpp new file mode 100644 index 0000000000..a3fcd045ac --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/lookup_table.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef LOOKUP_TABLE_CXX +#define LOOKUP_TABLE_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/matrix.h b/ThirdParty/Ert/lib/include/ert/util/matrix.h deleted file mode 100644 index cdbcc26640..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/matrix.h +++ /dev/null @@ -1,194 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'matrix.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_MATRIX_H -#define ERT_MATRIX_H -#include -#include -#include - -#include -#include -#include -#include - -#ifdef HAVE_THREAD_POOL -#include -#endif - -#ifdef _MSC_VER -#define __forceinline inline -#elif __GNUC__ -/* Also clang defines the __GNUC__ symbol */ -#define __forceinline inline __attribute__((always_inline)) -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -struct matrix_struct { - UTIL_TYPE_ID_DECLARATION; - char * name; /* A name of the matrix - for printing - can be NULL. */ - double * data; /* The actual storage */ - bool data_owner; /* is this matrix instance the owner of data? */ - size_t data_size; /* What is the length of data (number of double values). */ - - int rows; /* The number of rows in the matrix. */ - int columns; /* The number of columns in the matrix. */ - int alloc_rows; - int alloc_columns; - int row_stride; /* The distance in data between two conscutive row values. */ - int column_stride; /* The distance in data between to consecutive column values. */ - - /* - Observe that the stride is considered an internal property - if - the matrix is stored to disk and then recovered the strides might - change, and also matrix_alloc_copy() will not respect strides. - */ -}; - -typedef struct matrix_struct matrix_type; - - __forceinline size_t GET_INDEX( const matrix_type * m , size_t i , size_t j) {return m->row_stride *i + m->column_stride *j;} - matrix_type * matrix_fread_alloc(FILE * stream); - void matrix_fread(matrix_type * matrix , FILE * stream); - void matrix_fwrite(const matrix_type * matrix , FILE * stream); - bool matrix_check_dims( const matrix_type * m , int rows , int columns); - void matrix_fscanf_data( matrix_type * matrix , bool row_major_order , FILE * stream ); - void matrix_fprintf( const matrix_type * matrix , const char * fmt , FILE * stream ); - void matrix_dump_csv( const matrix_type * matrix ,const char * filename); - void matrix_pretty_fprint(const matrix_type * matrix , const char * name , const char * fmt , FILE * stream); - void matrix_pretty_fprint_submat(const matrix_type * matrix , const char * name , const char * fmt , FILE * stream, int m, int M, int n, int N); - matrix_type * matrix_alloc(int rows, int columns); - matrix_type * matrix_alloc_identity(int dim); - matrix_type * matrix_safe_alloc(int rows, int columns); - bool matrix_resize(matrix_type * matrix , int rows , int columns , bool copy_content); - bool matrix_safe_resize(matrix_type * matrix , int rows , int columns , bool copy_content); - matrix_type * matrix_alloc_sub_copy( const matrix_type * src , int row_offset , int column_offset , int rows, int columns); - matrix_type * matrix_alloc_copy(const matrix_type * src); - matrix_type * matrix_alloc_column_compressed_copy(const matrix_type * src, const bool_vector_type * mask); - void matrix_column_compressed_memcpy(matrix_type * target, const matrix_type * src, const bool_vector_type * mask); - matrix_type * matrix_safe_alloc_copy(const matrix_type * src); - matrix_type * matrix_realloc_copy(matrix_type * T , const matrix_type * src); - - matrix_type * matrix_alloc_shared(const matrix_type * src , int row , int column , int rows , int columns); - void matrix_free(matrix_type * matrix); - void matrix_safe_free( matrix_type * matrix ); - void matrix_pretty_print(const matrix_type * matrix , const char * name , const char * fmt); - void matrix_set(matrix_type * matrix, double value); - void matrix_set_name( matrix_type * matrix , const char * name); - void matrix_scale(matrix_type * matrix, double value); - void matrix_shift(matrix_type * matrix, double value); - - void matrix_assign(matrix_type * A , const matrix_type * B); - void matrix_inplace_add(matrix_type * A , const matrix_type * B); - void matrix_inplace_sub(matrix_type * A , const matrix_type * B); - void matrix_inplace_mul(matrix_type * A , const matrix_type * B); - void matrix_inplace_div(matrix_type * A , const matrix_type * B); - void matrix_sub(matrix_type * A , const matrix_type * B , const matrix_type * C); - void matrix_mul( matrix_type * A , const matrix_type * B , const matrix_type * C); - void matrix_transpose(const matrix_type * A , matrix_type * T); - void matrix_inplace_add_column(matrix_type * A , const matrix_type * B, int colA , int colB); - void matrix_inplace_sub_column(matrix_type * A , const matrix_type * B, int colA , int colB); - void matrix_inplace_transpose(matrix_type * A ); - - void matrix_iset_safe(matrix_type * matrix , int i , int j, double value); - void matrix_iset(matrix_type * matrix , int i , int j, double value); - double matrix_iget(const matrix_type * matrix , int i , int j); - double matrix_iget_safe(const matrix_type * matrix , int i , int j); - void matrix_iadd(matrix_type * matrix , int i , int j , double value); - void matrix_isub(matrix_type * matrix , int i , int j , double value); - void matrix_imul(matrix_type * matrix , int i , int j , double value); - - - void matrix_inplace_matmul(matrix_type * A, const matrix_type * B); - void matrix_inplace_matmul_mt1(matrix_type * A, const matrix_type * B , int num_threads); -#ifdef HAVE_THREAD_POOL - void matrix_inplace_matmul_mt2(matrix_type * A, const matrix_type * B , thread_pool_type * thread_pool); -#endif - - void matrix_shift_column(matrix_type * matrix , int column, double shift); - void matrix_shift_row(matrix_type * matrix , int row , double shift); - double matrix_get_column_sum(const matrix_type * matrix , int column); - double matrix_get_row_sum(const matrix_type * matrix , int column); - double matrix_get_column_sum2(const matrix_type * matrix , int column); - double matrix_get_row_abssum(const matrix_type * matrix , int row); - double matrix_get_column_abssum(const matrix_type * matrix , int column); - double matrix_get_row_sum2(const matrix_type * matrix , int column); - void matrix_subtract_row_mean(matrix_type * matrix); - void matrix_subtract_and_store_row_mean(matrix_type * matrix, matrix_type * row_mean); - void matrix_scale_column(matrix_type * matrix , int column , double scale_factor); - void matrix_scale_row(matrix_type * matrix , int row , double scale_factor); - void matrix_set_const_column(matrix_type * matrix , const double value , int column); - void matrix_copy_column(matrix_type * target_matrix, const matrix_type * src_matrix , int src_column, int target_column); - void matrix_set_const_row(matrix_type * matrix , const double value , int row); - - double * matrix_get_data(const matrix_type * matrix); - double matrix_orthonormality( const matrix_type * matrix ); - - matrix_type * matrix_alloc_steal_data(int rows , int columns , double * data , int data_size); - void matrix_set_column(matrix_type * matrix , const double * data , int column); - void matrix_set_many_on_column(matrix_type * matrix , int row_offset , int elements , const double * data , int column); - void matrix_ensure_rows(matrix_type * matrix, int rows, bool copy_content); - void matrix_shrink_header(matrix_type * matrix , int rows , int columns); - void matrix_full_size( matrix_type * matrix ); - int matrix_get_rows(const matrix_type * matrix); - int matrix_get_columns(const matrix_type * matrix); - int matrix_get_row_stride(const matrix_type * matrix); - int matrix_get_column_stride(const matrix_type * matrix); - void matrix_get_dims(const matrix_type * matrix , int * rows , int * columns , int * row_stride , int * column_stride); - bool matrix_is_quadratic(const matrix_type * matrix); - bool matrix_equal( const matrix_type * m1 , const matrix_type * m2); - bool matrix_columns_equal( const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2); - - void matrix_diag_set_scalar(matrix_type * matrix , double value); - void matrix_diag_set(matrix_type * matrix , const double * diag); - void matrix_random_init(matrix_type * matrix , rng_type * rng); - void matrix_matlab_dump(const matrix_type * matrix, const char * filename); - - void matrix_imul_col( matrix_type * matrix , int column , double factor); - double matrix_column_column_dot_product(const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2); - double matrix_row_column_dot_product(const matrix_type * m1 , int row1 , const matrix_type * m2 , int col2); - matrix_type * matrix_alloc_view(double * data , int rows , int columns); - matrix_type * matrix_alloc_transpose( const matrix_type * A); - void matrix_copy_row(matrix_type * target_matrix, const matrix_type * src_matrix , int target_row, int src_row); - void matrix_copy_block( matrix_type * target_matrix , int target_row , int target_column , int rows , int columns, - const matrix_type * src_matrix , int src_row , int src_column); - - void matrix_scalar_set( matrix_type * matrix , double value); - void matrix_inplace_diag_sqrt(matrix_type *Cd); - void matrix_create_identiy(int n,matrix_type *Id); - double matrix_trace(const matrix_type *matrix); - double matrix_diag_std(const matrix_type * Sk,double mean); - double matrix_det2( const matrix_type * A); - double matrix_det3( const matrix_type * A); - double matrix_det4( const matrix_type * A); - - #ifdef ERT_HAVE_ISFINITE - bool matrix_is_finite(const matrix_type * matrix); - void matrix_assert_finite( const matrix_type * matrix ); - #endif - - UTIL_SAFE_CAST_HEADER( matrix ); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/matrix_blas.h b/ThirdParty/Ert/lib/include/ert/util/matrix_blas.h deleted file mode 100644 index de28979c5f..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/matrix_blas.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'matrix_blas.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_MATRIX_BLAS -#define ERT_MATRIX_BLAS -#include - -#include - - -#ifdef __cplusplus -extern "C" { -#endif - - -void matrix_dgemm(matrix_type *C , const matrix_type *A , const matrix_type * B , bool transA, bool transB , double alpha , double beta); -void matrix_matmul_with_transpose(matrix_type * C, const matrix_type * A , const matrix_type * B , bool transA , bool transB); -void matrix_matmul(matrix_type * A, const matrix_type *B , const matrix_type * C); -matrix_type * matrix_alloc_matmul(const matrix_type * A, const matrix_type * B); -void matrix_dgemv(const matrix_type * A , const double * x , double * y , bool transA , double alpha , double beta); -void matrix_mul_vector(const matrix_type * A , const double * x , double * y); -void matrix_gram_set( const matrix_type * X , matrix_type * G, bool col); -matrix_type * matrix_alloc_gram( const matrix_type * X , bool col); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/matrix_lapack.h b/ThirdParty/Ert/lib/include/ert/util/matrix_lapack.h deleted file mode 100644 index 0ddb89545e..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/matrix_lapack.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'matrix_lapack.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#ifndef ERT_MATRIX_LAPACK_H -#define ERT_MATRIX_LAPACK_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -/** - This enum is just a simple way to label the different ways the - singular vectors in U and VT are returned to the calling scope. The - low level lapack routine uses a character variable, indicated - below. -*/ - - - - - - typedef enum { - /* A */ DGESVD_ALL, /* Returns all the singular vectors in U/VT. */ - /* S */ DGESVD_MIN_RETURN, /* Return the first min(m,n) vectors in U/VT. */ - /* O */ DGESVD_MIN_OVERWRITE, /* Return the first min(m,n) vectors of U/VT by overwriteing in A. */ - /* N */ DGESVD_NONE} /* Do not compute any singular vectors for U/VT */ - dgesvd_vector_enum; - - - typedef enum { - /* A */ DSYEVX_ALL, /* Compute all the eigenvalues */ - /* V */ DSYEVX_VALUE_INTERVAL, /* Computes eigenvalues in half open interval - for more details. -*/ - - -#ifndef ERT_MATRIX_STAT_H -#define ERT_MATRIX_STAT_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif //__cplusplus - -typedef enum { - LLSQ_SUCCESS = 0, - LLSQ_INVALID_DIM = 1, - LLSQ_UNDETERMINED = 2 -} llsq_result_enum; - - -llsq_result_enum matrix_stat_llsq_estimate( matrix_type * beta , const matrix_type * X , const matrix_type * Y , const matrix_type * S); -llsq_result_enum matrix_stat_polyfit( matrix_type * beta , const matrix_type * X0 , const matrix_type * Y0 , const matrix_type * S); - -#ifdef __cplusplus -} -#endif //__cplusplus - -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/menu.h b/ThirdParty/Ert/lib/include/ert/util/menu.h deleted file mode 100644 index 6306a4abde..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/menu.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'menu.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_MENU_H -#define ERT_MENU_H - -#ifdef __cplusplus -extern "C" { -#endif //__cplusplus - -typedef struct menu_struct menu_type; -typedef struct menu_item_struct menu_item_type; - -typedef void (menu_func_type) (void *); -typedef void (arg_free_ftype) (void *); - -menu_type * menu_alloc(const char * , const char * , const char *); -void menu_run(const menu_type * ); -void menu_free(menu_type * ); -menu_item_type * menu_get_item(const menu_type * , char ); -menu_item_type * menu_add_item(menu_type *, const char * , const char * , menu_func_type * , void * , arg_free_ftype * ); -void menu_add_separator(menu_type * ); -void menu_add_helptext(menu_type * , const char * ); -menu_item_type * menu_get_item(const menu_type * , char ); -void menu_set_title(menu_type *, const char *); - -void menu_item_set_label( menu_item_type * , const char *); -void menu_item_disable( menu_item_type * item ); -void menu_item_enable( menu_item_type * item ); -void menu_add_helptext(menu_type * menu, const char * label ); - -#ifdef __cplusplus -} -#endif //__cplusplus - -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/msg.h b/ThirdParty/Ert/lib/include/ert/util/msg.h deleted file mode 100644 index 02b7674a1d..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/msg.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'msg.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_MSG_H -#define ERT_MSG_H -#ifdef __cplusplus -extern "C" { -#endif -#include - -#include - - -typedef struct msg_struct msg_type; - - - -msg_type * msg_alloc(const char * , bool debug); -void msg_show(msg_type * ); -void msg_free(msg_type * , bool); -void msg_update(msg_type * , const char * ); -void msg_update_int(msg_type * , const char * , int ); -void msg_hide(msg_type *); -void msg_clear_msg(msg_type * msg); - - -UTIL_SAFE_CAST_HEADER( msg ); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/mzran.hpp b/ThirdParty/Ert/lib/include/ert/util/mzran.hpp new file mode 100644 index 0000000000..512eb56ad9 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/mzran.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef MZRAN_CXX +#define MZRAN_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/node_ctype.hpp b/ThirdParty/Ert/lib/include/ert/util/node_ctype.hpp new file mode 100644 index 0000000000..6618717f82 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/node_ctype.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef NODE_CTYPE_CXX +#define NODE_CTYPE_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/node_data.hpp b/ThirdParty/Ert/lib/include/ert/util/node_data.hpp new file mode 100644 index 0000000000..91f5d8c634 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/node_data.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef NODE_DATA_CXX +#define NODE_DATA_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/parser.hpp b/ThirdParty/Ert/lib/include/ert/util/parser.hpp new file mode 100644 index 0000000000..72e400d2d1 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/parser.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef PARSER_CXX +#define PARSER_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/path_fmt.h b/ThirdParty/Ert/lib/include/ert/util/path_fmt.h deleted file mode 100644 index da7fd5db67..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/path_fmt.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'path_fmt.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_PATH_FMT_H -#define ERT_PATH_FMT_H - -#include -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - typedef struct path_fmt_struct path_fmt_type; - - path_fmt_type * path_fmt_alloc_directory_fmt(const char * ); - path_fmt_type * path_fmt_alloc_path_fmt(const char * ); - path_fmt_type * path_fmt_copyc(const path_fmt_type *); - path_fmt_type * path_fmt_scanf_alloc(const char * , int , const node_ctype * , bool ); - char * path_fmt_alloc_path(const path_fmt_type * , bool , ...); - char * path_fmt_alloc_file(const path_fmt_type * , bool , ...); - void path_fmt_free(path_fmt_type * ); - void path_fmt_free__( void * arg ); - const char * path_fmt_get_fmt(const path_fmt_type * ); - void path_fmt_reset_fmt(path_fmt_type * , const char * ); - void path_fmt_make_path(const path_fmt_type * ); - path_fmt_type * path_fmt_realloc_path_fmt( path_fmt_type * path_fmt, const char * fmt ); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/path_stack.hpp b/ThirdParty/Ert/lib/include/ert/util/path_stack.hpp new file mode 100644 index 0000000000..2dbea35ffd --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/path_stack.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef PATH_STACK_CXX +#define PATH_STACK_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/perm_vector.hpp b/ThirdParty/Ert/lib/include/ert/util/perm_vector.hpp new file mode 100644 index 0000000000..53758b9ea9 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/perm_vector.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef PERM_VECTOR_CXX +#define PERM_VECTOR_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/regression.h b/ThirdParty/Ert/lib/include/ert/util/regression.h deleted file mode 100644 index 564461e768..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/regression.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'regression.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_REGRESSION_H -#define ERT_REGRESSION_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif -double regression_scale( matrix_type * X , matrix_type * Y , matrix_type * X_mean , matrix_type * X_norm); -double regression_unscale(const matrix_type * beta , const matrix_type * X_norm , const matrix_type * X_mean , double Y_mean , matrix_type * beta0); -void regression_augmented_OLS(const matrix_type * X , const matrix_type * Y , const matrix_type *E, matrix_type * beta); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/rng.hpp b/ThirdParty/Ert/lib/include/ert/util/rng.hpp new file mode 100644 index 0000000000..d75be17013 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/rng.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef RNG_CXX +#define RNG_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/set.hpp b/ThirdParty/Ert/lib/include/ert/util/set.hpp new file mode 100644 index 0000000000..4a5936ab31 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/set.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef SET_CXX +#define SET_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/ssize_t.hpp b/ThirdParty/Ert/lib/include/ert/util/ssize_t.hpp new file mode 100644 index 0000000000..df855a99cc --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/ssize_t.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef SSIZE_T_CXX +#define SSIZE_T_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/statistics.hpp b/ThirdParty/Ert/lib/include/ert/util/statistics.hpp new file mode 100644 index 0000000000..2d1fe6f10a --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/statistics.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef STATISTICS_CXX +#define STATISTICS_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/stepwise.h b/ThirdParty/Ert/lib/include/ert/util/stepwise.h deleted file mode 100644 index f1eb0a4f21..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/stepwise.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef ERT_STEPWISE_H -#define ERT_STEPWISE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - - typedef struct stepwise_struct stepwise_type; - - - stepwise_type * stepwise_alloc1(int nsample, int nvar, rng_type * rng, const matrix_type* St, const matrix_type* Et); - stepwise_type * stepwise_alloc0(rng_type * rng); - void stepwise_free( stepwise_type * stepwise); - - void stepwise_set_Y0( stepwise_type * stepwise , matrix_type * Y); - void stepwise_set_X0( stepwise_type * stepwise , matrix_type * X); - void stepwise_set_E0( stepwise_type * stepwise , matrix_type * E); - void stepwise_set_beta( stepwise_type * stepwise , matrix_type * b); - void stepwise_set_R2( stepwise_type * stepwise , const double R2); - void stepwise_set_active_set( stepwise_type * stepwise , bool_vector_type * a); - void stepwise_isetY0( stepwise_type * stepwise , int i , double value ); - double stepwise_get_R2(const stepwise_type * stepwise ); - int stepwise_get_nvar( stepwise_type * stepwise ); - int stepwise_get_nsample( stepwise_type * stepwise ); - int stepwise_get_n_active( stepwise_type * stepwise ); - bool_vector_type * stepwise_get_active_set( stepwise_type * stepwise ); - double stepwise_iget_beta(const stepwise_type * stepwise, const int index ); - double stepwise_get_sum_beta(const stepwise_type * stepwise ); - - void stepwise_estimate( stepwise_type * stepwise , double deltaR2_limit , int CV_blocks); - double stepwise_eval( const stepwise_type * stepwise , const matrix_type * x ); - - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/string_util.hpp b/ThirdParty/Ert/lib/include/ert/util/string_util.hpp new file mode 100644 index 0000000000..4cfb76138f --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/string_util.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef STRING_UTIL_CXX +#define STRING_UTIL_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/stringlist.hpp b/ThirdParty/Ert/lib/include/ert/util/stringlist.hpp new file mode 100644 index 0000000000..ea149225dc --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/stringlist.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef STRINGLIST_CXX +#define STRINGLIST_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/struct_vector.hpp b/ThirdParty/Ert/lib/include/ert/util/struct_vector.hpp new file mode 100644 index 0000000000..d91ac14230 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/struct_vector.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef STRUCT_VECTOR_CXX +#define STRUCT_VECTOR_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/subst_func.h b/ThirdParty/Ert/lib/include/ert/util/subst_func.h deleted file mode 100644 index 5dc1369ff5..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/subst_func.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'subst_func.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_SUBST_FUNC_H -#define ERT_SUBST_FUNC_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef char * (subst_func_ftype) (const stringlist_type * , void * ); -typedef struct subst_func_struct subst_func_type; -typedef struct subst_func_pool_struct subst_func_pool_type; - - - char * subst_func_eval( const subst_func_type * subst_func , const stringlist_type * args); - -/*****************************************************************/ - - subst_func_pool_type * subst_func_pool_alloc( ); - void subst_func_pool_free( subst_func_pool_type * pool ); - void subst_func_pool_add_func( subst_func_pool_type * pool , const char * func_name , const char * doc_string , subst_func_ftype * func , bool vararg, int argc_min , int argc_max , void * arg); -subst_func_type * subst_func_pool_get_func( const subst_func_pool_type * pool , const char * func_name ); -bool subst_func_pool_has_func( const subst_func_pool_type * pool , const char * func_name ); -UTIL_IS_INSTANCE_HEADER( subst_func_pool ); - -/*****************************************************************/ -char * subst_func_randint( const stringlist_type * args , void * arg); -char * subst_func_randfloat( const stringlist_type * args , void * arg); -char * subst_func_add( const stringlist_type * args , void * arg); -char * subst_func_mul( const stringlist_type * args , void * arg); -char * subst_func_exp( const stringlist_type * args , void * arg); -char * subst_func_log( const stringlist_type * args , void * arg); -char * subst_func_pow10( const stringlist_type * args , void * arg); - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/test_util.h b/ThirdParty/Ert/lib/include/ert/util/test_util.h index 131ef67735..b1326deeef 100644 --- a/ThirdParty/Ert/lib/include/ert/util/test_util.h +++ b/ThirdParty/Ert/lib/include/ert/util/test_util.h @@ -36,6 +36,8 @@ extern "C" { void test_error_exit( const char * fmt , ...); + void * test_argpack_is_stringlist( void * arg ); + void * thread_pool_test_func1( void * arg ); #define test_exit( fmt, ...) test_exit__( __FILE__ , __LINE__ , fmt , __VA_ARGS__); void test_exit__(const char * file , int line , const char * fmt , ...); diff --git a/ThirdParty/Ert/lib/include/ert/util/test_work_area.hpp b/ThirdParty/Ert/lib/include/ert/util/test_work_area.hpp new file mode 100644 index 0000000000..5d9fbc90bd --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/test_work_area.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef TEST_WORK_AREA_CXX +#define TEST_WORK_AREA_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/thread_pool.h b/ThirdParty/Ert/lib/include/ert/util/thread_pool.h deleted file mode 100644 index 23abb308a2..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/thread_pool.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'thread_pool.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#ifndef ERT_THREAD_POOL_H -#define ERT_THREAD_POOL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - - typedef struct thread_pool_struct thread_pool_type; - - void thread_pool_join(thread_pool_type * ); - thread_pool_type * thread_pool_alloc(int , bool start_queue); - void thread_pool_add_job(thread_pool_type * ,void * (*) (void *) , void *); - void thread_pool_free(thread_pool_type *); - void thread_pool_restart( thread_pool_type * tp ); - void * thread_pool_iget_return_value( const thread_pool_type * pool , int queue_index ); - int thread_pool_get_max_running( const thread_pool_type * pool ); - bool thread_pool_try_join(thread_pool_type * pool, int timeout_seconds); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/time_interval.h b/ThirdParty/Ert/lib/include/ert/util/time_interval.h deleted file mode 100644 index 6d2f13cb83..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/time_interval.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright (C) 2013 Statoil ASA, Norway. - - The file 'time_interval.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_TIME_INTERVAL_H -#define ERT_TIME_INTERVAL_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - - typedef struct time_interval_struct time_interval_type; - - time_interval_type * time_interval_alloc( time_t start_time , time_t end_time ); - time_interval_type * time_interval_alloc_open( ); - time_interval_type * time_interval_alloc_copy( const time_interval_type * src); - void time_interval_reopen( time_interval_type * time_interval); - void time_interval_free( time_interval_type * ti ); - bool time_interval_is_empty( time_interval_type * ti ); - bool time_interval_update( time_interval_type * ti , time_t start_time , time_t end_time); - bool time_interval_contains( const time_interval_type * ti , time_t t); - bool time_interval_has_overlap( const time_interval_type * t1 , const time_interval_type * t2); - bool time_interval_is_adjacent( const time_interval_type * t1 , const time_interval_type * t2); - bool time_interval_update_start( time_interval_type * ti , time_t start_time ); - bool time_interval_update_end( time_interval_type * ti , time_t end_time ); - time_t time_interval_get_start( const time_interval_type * ti); - time_t time_interval_get_end( const time_interval_type * ti); - bool time_interval_extend( time_interval_type * t1 , const time_interval_type * t2); - bool time_interval_intersect( time_interval_type * t1 , const time_interval_type * t2); - bool time_interval_equal( const time_interval_type * t1 , const time_interval_type * t2); - bool time_interval_arg_before( const time_interval_type * ti , time_t arg); - bool time_interval_arg_after( const time_interval_type * ti , time_t arg); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/time_interval.hpp b/ThirdParty/Ert/lib/include/ert/util/time_interval.hpp new file mode 100644 index 0000000000..26073dbf06 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/time_interval.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef TIME_INTERVAL_CXX +#define TIME_INTERVAL_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/timer.hpp b/ThirdParty/Ert/lib/include/ert/util/timer.hpp new file mode 100644 index 0000000000..14a83dd14f --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/timer.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef TIMER_CXX +#define TIMER_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/type_macros.hpp b/ThirdParty/Ert/lib/include/ert/util/type_macros.hpp new file mode 100644 index 0000000000..704643272e --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/type_macros.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef TYPE_MACROS_CXX +#define TYPE_MACROS_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/type_vector_functions.hpp b/ThirdParty/Ert/lib/include/ert/util/type_vector_functions.hpp new file mode 100644 index 0000000000..142f711db9 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/type_vector_functions.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef TYPE_VECTOR_FUNCTIONS_CXX +#define TYPE_VECTOR_FUNCTIONS_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/ui_return.h b/ThirdParty/Ert/lib/include/ert/util/ui_return.h deleted file mode 100644 index 43044a9348..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/ui_return.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (C) 2013 Statoil ASA, Norway. - - The file 'ui_return.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_UI_RETURN_H -#define ERT_UI_RETURN_H - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ui_return_struct ui_return_type; - - -typedef enum { - UI_RETURN_OK = 1, - UI_RETURN_FAIL = 2 -} ui_return_status_enum; - - - -ui_return_type * ui_return_alloc(ui_return_status_enum status); -void ui_return_free(ui_return_type * ui_return); -ui_return_status_enum ui_return_get_status(const ui_return_type * ui_return); -int ui_return_get_error_count(const ui_return_type * ui_return); -bool ui_return_add_error(ui_return_type * ui_return, const char * error_msg); -void ui_return_add_help(ui_return_type * ui_return, const char * help_text); -const char * ui_return_get_first_error(const ui_return_type * ui_return); -const char * ui_return_get_last_error(const ui_return_type * ui_return); -const char * ui_return_get_help(const ui_return_type * ui_return); -const char * ui_return_iget_error( const ui_return_type * ui_return , int index); - - -UTIL_IS_INSTANCE_HEADER(ui_return); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/util.h b/ThirdParty/Ert/lib/include/ert/util/util.h index fe0fe48e06..84b406b9d3 100644 --- a/ThirdParty/Ert/lib/include/ert/util/util.h +++ b/ThirdParty/Ert/lib/include/ert/util/util.h @@ -163,6 +163,7 @@ typedef enum {left_pad = 0, void util_move_file(const char * src_file , const char * target_file); void util_move_file4( const char * src_name , const char * target_name , const char *src_path , const char * target_path); bool util_copy_file(const char * , const char * ); + bool util_copy_file__(const char * src_file , const char * target_file, size_t buffer_size , void * buffer , bool abort_on_error); char * util_alloc_cwd(void); bool util_is_cwd( const char * path ); char * util_alloc_normal_path( const char * input_path ); diff --git a/ThirdParty/Ert/lib/include/ert/util/util.hpp b/ThirdParty/Ert/lib/include/ert/util/util.hpp new file mode 100644 index 0000000000..8d293d4382 --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/util.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef UTIL_CXX +#define UTIL_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/util_env.h b/ThirdParty/Ert/lib/include/ert/util/util_env.h deleted file mode 100644 index 2270867ae1..0000000000 --- a/ThirdParty/Ert/lib/include/ert/util/util_env.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2012 Statoil ASA, Norway. - - The file 'util_env.h' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#ifndef ERT_UTIL_ENV_H -#define ERT_UTIL_ENV_H - - - -#ifdef __cplusplus -extern"C" { -#endif - - char * util_alloc_PATH_executable(const char * executable ); - void util_setenv( const char * variable , const char * value); - const char * util_interp_setenv( const char * variable , const char * value); - void util_unsetenv( const char * variable); - char * util_alloc_envvar( const char * value ); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ThirdParty/Ert/lib/include/ert/util/vector.hpp b/ThirdParty/Ert/lib/include/ert/util/vector.hpp new file mode 100644 index 0000000000..99ddd5a31c --- /dev/null +++ b/ThirdParty/Ert/lib/include/ert/util/vector.hpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2018 Statoil ASA, Norway. + + This 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ERT is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or1 + FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License at + for more details. +*/ + +#ifndef VECTOR_CXX +#define VECTOR_CXX + +#include + +#endif diff --git a/ThirdParty/Ert/lib/nexus/nexus_plot.cpp b/ThirdParty/Ert/lib/nexus/nexus_plot.cpp deleted file mode 100644 index c3c404bf8f..0000000000 --- a/ThirdParty/Ert/lib/nexus/nexus_plot.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - Copyright (C) 2017 Statoil ASA, Norway. - - The file 'nexus_plot.cpp' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include - -#include -#ifdef HAVE_NETINET_IN_H -#include -#elif defined(HAVE_ARPA_INET_H) -#include -#elif defined(HAVE_WINSOCK2_H) -#include -#endif - -#include -#include - - -const std::string NEXUS_PLOT_TYPE_HEADER = "PLOT BIN "; - -namespace { - -template< int N > -std::string read_str(std::istream& stream) { - std::array< char, N> buf; - stream.read( buf.data(), N ); - return std::string( buf.data(), N ); -} - -struct hinfo { - int32_t num_classes; - int32_t day, month, year; - int32_t nx, ny, nz; - int32_t ncomp; - std::vector class_names; - std::vector vars_in_class; - std::vector< std::vector > var_names; -}; - -hinfo headerinfo( std::istream& stream ) { - stream.seekg(4 + 10 + 562 + 264, std::ios::beg); - - std::array< int32_t, 8 > buf {}; - stream.read( (char*)buf.data(), buf.max_size() * 4 ); - if ( !stream.good() ) throw nex::unexpected_eof(""); - - auto ntoh = []( int32_t x ) { return ntohl( x ); }; - std::transform( buf.begin(), buf.end(), buf.begin(), ntoh ); - auto negative = []( int32_t x ) { return x < 0; }; - if ( std::any_of( buf.begin(), buf.end(), negative ) ) - throw nex::bad_header("Negative value, corrupted file"); - - hinfo h = { - buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], - {}, - std::vector< int32_t >( buf[0], 0 ), - std::vector< std::vector >( buf[0], - std::vector()), - }; - - stream.seekg(8, std::ios::cur); - std::array< char, 8 > class_name; - for (int i = 0; i < h.num_classes; i++) { - stream.read(class_name.data(), 8); - h.class_names.push_back(std::string( class_name.data(), 8 )); - } - - stream.seekg(8, std::ios::cur); - stream.read((char*) h.vars_in_class.data(), h.num_classes * 4); - std::transform( h.vars_in_class.begin(), - h.vars_in_class.end(), - h.vars_in_class.begin(), - ntoh ); - if (std::any_of( h.vars_in_class.begin(), h.vars_in_class.end(), negative)) - throw nex::bad_header("Negative value, corrupted file"); - - stream.seekg(8, std::ios::cur); - for (int i = 0; i < h.num_classes; ++i) { - stream.seekg(4, std::ios::cur); - std::vector< char > var_names( h.vars_in_class[i] * 4, 0 ); - stream.read( var_names.data(), h.vars_in_class[i] * 4 ); - for (int k = 0; k < h.vars_in_class[i]; ++k) - h.var_names[i].push_back( std::string( var_names.data() + k*4 ,4 )); - stream.seekg(8, std::ios::cur); - } - stream.seekg(4, std::ios::cur); - - return h; -} - -} - -nex::NexusPlot::NexusPlot( const std::string& filename ) { - std::ifstream stream(filename, std::ios::binary); - if ( !stream.good() ) - throw nex::read_error("Could not open file " + filename); - this->load(stream); -} - -nex::NexusPlot::NexusPlot( std::istream& stream ) { - this->load(stream); -} - -void nex::NexusPlot::load(std::istream& stream) { - struct stream_guard { - stream_guard( std::istream& stream ) : - mask( stream.exceptions() ), - s( stream ) {} - ~stream_guard() { this->s.exceptions( this->mask ); } - std::ios::iostate mask; - std::istream& s; - } g { stream }; - stream.exceptions( std::ios::goodbit ); - - stream.seekg(4, std::ios::beg); // skip 4 bytes - auto type_header = read_str<10>(stream); - - if (type_header.compare(NEXUS_PLOT_TYPE_HEADER) != 0 || !stream.good()) - throw nex::bad_header("Could not verify file type"); - - auto header = headerinfo( stream ); - this->num_classes = header.num_classes; - this->day = header.day; - this->month = header.month; - this->year = header.year; - this->nx = header.nx; - this->ny = header.ny; - this->nz = header.nz; - this->ncomp = header.ncomp; - this->class_names = header.class_names; - this->vars_in_class = header.vars_in_class; - this->var_names = header.var_names; -} - -ecl_sum_type* nex::NexusPlot::ecl_summary( const std::string& ecl_case ) { - bool unified = true; - bool fmt_output = false; - const char* key_join_string = ":"; - time_t sim_start = 0; - bool time_in_days = true; - - ecl_sum_type * ecl_sum = ecl_sum_alloc_writer( ecl_case.c_str(), - fmt_output, - unified, - key_join_string, - sim_start, - time_in_days, - this->nx, this->ny, this->nz); - - return ecl_sum; -} diff --git a/ThirdParty/Ert/lib/nexus/tests/nexus2ecl.cpp b/ThirdParty/Ert/lib/nexus/tests/nexus2ecl.cpp deleted file mode 100644 index 6c8620c958..0000000000 --- a/ThirdParty/Ert/lib/nexus/tests/nexus2ecl.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (C) 2017 Statoil ASA, Norway. - - The file 'nexus2ecl.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include - - -void test_create_ecl_sum(char *root_folder) { - test_work_area_type *work_area = test_work_area_alloc("nexus_header"); - - std::stringstream ss; - ss << root_folder << "/test-data/local/nexus/SPE1.plt"; - std::cout << ss.str() << std::endl; - nex::NexusPlot plt = nex::NexusPlot { ss.str() }; - - ecl_sum_type *ecl_sum = plt.ecl_summary( "ECL_CASE" ); - test_assert_true( ecl_sum_is_instance( ecl_sum )); - ecl_sum_fwrite( ecl_sum ); - ecl_sum_free( ecl_sum ); - test_assert_true( util_file_exists( "ECL_CASE.SMSPEC")); - - test_work_area_free(work_area); -} - - - -int main(int argc, char **argv) { - util_install_signals(); - test_create_ecl_sum(argv[1]); - exit(0); -} diff --git a/ThirdParty/Ert/lib/nexus/tests/nexus_plot_load.cpp b/ThirdParty/Ert/lib/nexus/tests/nexus_plot_load.cpp deleted file mode 100644 index 34e778cd68..0000000000 --- a/ThirdParty/Ert/lib/nexus/tests/nexus_plot_load.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - Copyright (C) 2017 Statoil ASA, Norway. - - The file 'nexus_plot_constructor.cpp' 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include - - -#include -#include - -void test_invalid_header1() { - std::stringstream stream( "xxxxINVALID_HEADER" ); - test_assert_throw(nex::NexusPlot { stream }, nex::bad_header); -} - -void test_invalid_header2() { - std::stringstream stream( "xxx" ); - test_assert_throw(nex::NexusPlot { stream }, nex::bad_header); -} - -void test_valid_header() { - std::stringstream stream( "xxxxPLOT BIN " ); - test_assert_throw(nex::NexusPlot { stream }, nex::unexpected_eof); -} - -void test_spe1_header(char *argv) { - std::stringstream ss; - ss << argv << "/test-data/local/nexus/SPE1.plt"; - auto plt = nex::NexusPlot { ss.str() }; - - std::array< std::string, 9 > class_names = { - "WELL ", "WLLYR ", "NODE ", "CONN ", "REGION ", "FIELD ", - "CONNLIST", "TARGET ", "FLOSTA " - }; - std::array< int, 9 > vars_in_class = { - 56, 52, 4, 43, 69, 58, 20, 25, 25 - }; - - std::array< std::vector< std::string >, 9 > var_names = { - std::vector< std::string > { - "COP ", "CGP ", "CWP ", "CGI ", "CWI ", "QOP ", "QGP ", "QWP ", - "QGI ", "QWI ", "BHP ", "WPH ", "WKH ", "WPAV", "THP ", "COWP", - "QOWP", "GOR ", "WCUT", "WOR ", "QGLG", "CGLG", "DRDN", "DRMX", - "CROP", "CRGP", "CRWP", "CROI", "CRGI", "CRWI", "ROP ", "RGP ", - "RWP ", "ROI ", "RGI ", "RWI ", "ONTM", "ALQ ", "API ", "QCDP", - "CCDP", "YCDP", "ACTV", "STAT", "Q1P ", "Q1I ", "C1P ", "C1I ", - "X1P ", "Y1P ", "Q2P ", "Q2I ", "C2P ", "C2I ", "X2P ", "Y2P " }, - std::vector< std::string > { - "QOP ", "QGP ", "QWP ", "COP ", "CGP ", "CWP ", "CGI ", "CWI ", - "PRES", "HEAD", "RW ", "SKIN", "WI ", "WBC ", "PWB ", "QGI ", - "QWI ", "COWP", "QOWP", "GOR ", "WCUT", "ACTV", "CROP", "CRGP", - "CRWP", "CROI", "CRGI", "CRWI", "ROP ", "RGP ", "RWP ", "ROI ", - "RGI ", "RWI ", "QCDP", "CCDP", "YCDP", "API ", "MD ", "FSEC", - "Q1P ", "Q1I ", "C1P ", "C1I ", "X1P ", "Y1P ", "Q2P ", "Q2I ", - "C2P ", "C2I ", "X2P ", "Y2P " }, - std::vector< std::string > { "PNOD", "PDAT", "TNOD", "ACTV" }, - std::vector< std::string > { - "QGAS", "QOIL", "QWTR", "CGAS", "COIL", "CWTR", "CBFG", "CBFO", - "CBFW", "QGIS", "QOIS", "QWIS", "P_IN", "POUT", "T_IN", "TOUT", - "ACTV", "STAT", "CSTR", "ITRG", "ONTM", "ALQ ", "SETM", "SETA", - "POWM", "POWA", "SPDM", "SPDA", "API ", "DELP", "QTOT", "GVF ", - "EFF ", "POSN", "WCUT", "GOR ", "WOR ", "Q1 ", "Q2 ", "X1 ", - "X2 ", "Y1 ", "Y2 " }, - std::vector< std::string > { - "COP ", "CGP ", "CWP ", "COI ", "CGI ", "CWI ", "PAVT", "PAVH", - "OIP ", "GIP ", "WIP ", "QOP ", "QGP ", "QWP ", "QOI ", "QGI ", - "QWI ", "OIN ", "GIN ", "WIN ", "SO ", "SG ", "SW ", "OREC", - "FGIP", "CIP ", "PAVE", "PAVD", "ROIP", "RGIP", "RWIP", "MRO ", - "MRG ", "MRW ", "NFLX", "PV ", "HCPV", "TAVT", "TAVH", "CROP", - "CRGP", "CRWP", "CROI", "CRGI", "CRWI", "ROP ", "RGP ", "RWP ", - "ROI ", "RGI ", "RWI ", "QCDP", "CCDP", "YCDP", "API ", "GOR ", - "WCUT", "WOR ", "Z1 ", "Z2 ", "MC1 ", "MC2 ", "MC3 ", "C1P ", - "C2P ", "C3P ", "C1I ", "C2I ", "C3I " }, - std::vector< std::string > { - "COP ", "CGP ", "CWP ", "CGI ", "CWI ", "QOP ", "QGP ", "QWP ", - "QGI ", "QWI ", "COWP", "QOWP", "GOR ", "OREC", "GREC", "PAVT", - "PAVH", "QGLG", "CGLG", "WCUT", "NFLX", "CROP", "CRGP", "CRWP", - "CROI", "CRGI", "CRWI", "ROP ", "RGP ", "RWP ", "ROI ", "RGI ", - "RWI ", "OIP ", "GIP ", "WIP ", "QCDP", "CCDP", "YCDP", "WLLS", - "PRDW", "GLFW", "WINJ", "GINJ", "ACTW", "API ", "Q1P ", "Q1I ", - "C1P ", "C1I ", "X1P ", "Y1P ", "Q2P ", "Q2I ", "C2P ", "C2I ", - "X2P ", "Y2P " }, - std::vector< std::string > { - "QOP ", "QGP ", "QWP ", "QOI ", "QGI ", "QWI ", "COP ", "CGP ", - "CWP ", "COI ", "CGI ", "CWI ", "API ", "WCUT", "GOR ", "WOR ", - "Q1P ", "Q1I ", "Q2P ", "Q2I " }, - std::vector< std::string > { - "SQO ", "SQG ", "SQW ", "SQL ", "SQA ", "SQH ", "RQO ", "RQG ", - "RQW ", "RQL ", "RQA ", "RQH ", "TSQO", "TSQG", "TSQW", "TSQL", - "TSQA", "TSQH", "TRQO", "TRQG", "TRQW", "TRQL", "TRQA", "TRQH", - "P " }, - std::vector< std::string > { - "QOP ", "QGP ", "QWP ", "QOI ", "QGI ", "QWI ", "COP ", "CGP ", - "CWP ", "COI ", "CGI ", "CWI ", "WLLS", "PRDW", "GLFW", "WINJ", - "GINJ", "ACTW", "WCUT", "GOR ", "WOR ", "Q1P ", "Q1I ", "Q2P ", - "Q2I " } - }; - - test_assert_int_equal(plt.num_classes, 9); - test_assert_int_equal(plt.day, 1); - test_assert_int_equal(plt.month, 1); - test_assert_int_equal(plt.year, 1980); - test_assert_int_equal(plt.nx, 1); - test_assert_int_equal(plt.ny, 1); - test_assert_int_equal(plt.nz, 1); - test_assert_int_equal(plt.ncomp, 2); - for (int i = 0; i < plt.num_classes; i++) - test_assert_std_string_equal(class_names[i], plt.class_names[i]); - for (int i = 0; i < plt.num_classes; i++) - test_assert_int_equal(vars_in_class[i], plt.vars_in_class[i]); - for (int i = 0; i < plt.num_classes; ++i) { - for (int k = 0; k < plt.vars_in_class[i]; ++k) { - test_assert_std_string_equal(var_names[i][k], plt.var_names[i][k]); - } - } -} - -int main(int argc, char* argv[]) { - test_invalid_header1(); - test_invalid_header2(); - test_valid_header(); - test_spe1_header(argv[1]); - return 0; -} diff --git a/ThirdParty/Ert/lib/util/TestArea.cpp b/ThirdParty/Ert/lib/util/TestArea.cpp index bc6212e2ef..afd204f9ea 100644 --- a/ThirdParty/Ert/lib/util/TestArea.cpp +++ b/ThirdParty/Ert/lib/util/TestArea.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include #include diff --git a/ThirdParty/Ert/lib/util/arg_pack.c b/ThirdParty/Ert/lib/util/arg_pack.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/arg_pack.c rename to ThirdParty/Ert/lib/util/arg_pack.cpp index ce67984434..e204c11be0 100644 --- a/ThirdParty/Ert/lib/util/arg_pack.c +++ b/ThirdParty/Ert/lib/util/arg_pack.cpp @@ -21,13 +21,13 @@ #include #include -#include -#include -#include +#include +#include +#include /** - This file implements a arg_pack structure which is a small + This file implements an arg_pack structure which is a small convienence utility to pack several arguments into one argument. The generic use situtation is when calling functions like e.g. pthread_create() which take one (void *) as argument. You can diff --git a/ThirdParty/Ert/lib/util/buffer.c b/ThirdParty/Ert/lib/util/buffer.cpp similarity index 98% rename from ThirdParty/Ert/lib/util/buffer.c rename to ThirdParty/Ert/lib/util/buffer.cpp index a590ce8c22..a1546dd32f 100644 --- a/ThirdParty/Ert/lib/util/buffer.c +++ b/ThirdParty/Ert/lib/util/buffer.cpp @@ -23,11 +23,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include @@ -272,7 +272,7 @@ void buffer_fseek(buffer_type * buffer , ssize_t offset , int whence) { a buffer with content_size == 20 we can seek to position 20. */ - if ((new_pos >= 0) && (new_pos <= buffer->content_size)) + if ((new_pos >= 0) && (new_pos <= (ssize_t)buffer->content_size)) buffer->pos = new_pos; else util_abort("%s: tried to seek to position:%ld - outside of bounds: [0,%d) \n", @@ -839,7 +839,7 @@ void buffer_fwrite_string(buffer_type * buffer , const char * string) { void buffer_fprintf(const buffer_type * buffer, const char * fmt, FILE * stream) { - int index=0; + size_t index=0; size_t offset = 0; while (true) { char fmt_char = fmt[index]; @@ -891,7 +891,7 @@ static size_t __compress_bound (size_t sourceLen) Return value is the size (in bytes) of the compressed buffer. */ size_t buffer_fwrite_compressed(buffer_type * buffer, const void * ptr , size_t byte_size) { - size_t compressed_size = 0; + unsigned long compressed_size = 0; bool abort_on_error = true; buffer->content_size = buffer->pos; /* Invalidating possible buffer content coming after the compressed content; that is uninterpretable anyway. */ @@ -916,7 +916,7 @@ size_t buffer_fwrite_compressed(buffer_type * buffer, const void * ptr , size_t */ size_t buffer_fread_compressed(buffer_type * buffer , size_t compressed_size , void * target_ptr , size_t target_size) { size_t remaining_size = buffer->content_size - buffer->pos; - size_t uncompressed_size = target_size; + unsigned long uncompressed_size = target_size; if (remaining_size < compressed_size) util_abort("%s: trying to read beyond end of buffer\n",__func__); diff --git a/ThirdParty/Ert/lib/util/ecl_version.c b/ThirdParty/Ert/lib/util/ecl_version.cpp similarity index 93% rename from ThirdParty/Ert/lib/util/ecl_version.c rename to ThirdParty/Ert/lib/util/ecl_version.cpp index 664fa9efd2..24acac01e9 100644 --- a/ThirdParty/Ert/lib/util/ecl_version.c +++ b/ThirdParty/Ert/lib/util/ecl_version.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #define xstr(s) #s #define str(s) xstr(s) diff --git a/ThirdParty/Ert/lib/util/hash.c b/ThirdParty/Ert/lib/util/hash.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/hash.c rename to ThirdParty/Ert/lib/util/hash.cpp index 68e636b8ba..60b62b6590 100644 --- a/ThirdParty/Ert/lib/util/hash.c +++ b/ThirdParty/Ert/lib/util/hash.cpp @@ -23,12 +23,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #ifdef __cplusplus diff --git a/ThirdParty/Ert/lib/util/hash_node.c b/ThirdParty/Ert/lib/util/hash_node.cpp similarity index 96% rename from ThirdParty/Ert/lib/util/hash_node.c rename to ThirdParty/Ert/lib/util/hash_node.cpp index 4d9f6bbbf5..c77b19f993 100644 --- a/ThirdParty/Ert/lib/util/hash_node.c +++ b/ThirdParty/Ert/lib/util/hash_node.cpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/ThirdParty/Ert/lib/util/hash_sll.c b/ThirdParty/Ert/lib/util/hash_sll.cpp similarity index 97% rename from ThirdParty/Ert/lib/util/hash_sll.c rename to ThirdParty/Ert/lib/util/hash_sll.cpp index a91b683be6..569d59f948 100644 --- a/ThirdParty/Ert/lib/util/hash_sll.c +++ b/ThirdParty/Ert/lib/util/hash_sll.cpp @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/ThirdParty/Ert/lib/util/lars.c b/ThirdParty/Ert/lib/util/lars.c deleted file mode 100644 index f7585904b9..0000000000 --- a/ThirdParty/Ert/lib/util/lars.c +++ /dev/null @@ -1,448 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'lars.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define LARS_TYPE_ID 77125439 - -struct lars_struct { - UTIL_TYPE_ID_DECLARATION; - matrix_type * X; - matrix_type * Y; - bool data_owner; - double Y0; - matrix_type * beta0; - - matrix_type * beta; - matrix_type * X_norm; - matrix_type * X_mean; - double Y_mean; -}; - - - -static lars_type * lars_alloc__() { - lars_type * lars = (lars_type*)util_malloc( sizeof * lars ); - UTIL_TYPE_ID_INIT( lars , LARS_TYPE_ID ); - lars->X = NULL; - lars->Y = NULL; - - lars->X_norm = NULL; - lars->X_mean = NULL; - lars->beta = NULL; - lars->beta0 = NULL; - lars->Y = 0; - - return lars; -} - -lars_type * lars_alloc1( int nsample , int nvars) { - lars_type * lars = lars_alloc__(); - lars->X = matrix_alloc( nsample , nvars ); - lars->Y = matrix_alloc( nsample , 1 ); - lars->data_owner = true; - return lars; -} - - -lars_type * lars_alloc2( matrix_type * X , matrix_type * Y , bool internal_copy ) { - lars_type * lars = lars_alloc__(); - if (internal_copy) { - lars->X = matrix_alloc_copy( X ); - lars->Y = matrix_alloc_copy( Y ); - lars->data_owner = true; - } else { - lars->X = X; - lars->Y = Y; - lars->data_owner = false; - } - return lars; -} - -int lars_get_sample( const lars_type * lars ) { - return matrix_get_rows( lars->X ); -} - - -int lars_get_nvar( const lars_type * lars ) { - return matrix_get_columns( lars->X ); -} - - -void lars_isetX( lars_type * lars, int sample, int var , double value) { - matrix_iset( lars->X , sample , var , value ); -} - -void lars_isetY( lars_type * lars, int sample, double value) { - matrix_iset( lars->Y , sample , 0 , value ); -} - -#define MATRIX_SAFE_FREE( m ) if (m != NULL) matrix_free( m ) -void lars_free( lars_type * lars ) { - - if (lars->data_owner) { - MATRIX_SAFE_FREE( lars->X ); - MATRIX_SAFE_FREE( lars->Y ); - } - MATRIX_SAFE_FREE( lars->X_norm ); - MATRIX_SAFE_FREE( lars->X_mean ); - MATRIX_SAFE_FREE( lars->beta ); - MATRIX_SAFE_FREE( lars->beta0 ); - - free( lars ); -} -#undef MATRIX_SAFE_FREE - -/*****************************************************************/ - -static double sgn(double x) { - return copysign(1 , x); // C99 -} - - -static void lars_estimate_init( lars_type * lars, matrix_type * X , matrix_type * Y) { - int nvar = matrix_get_columns( lars->X ); - - matrix_assign( X , lars->X ); - matrix_assign( Y , lars->Y ); - if (lars->X_norm != NULL) - matrix_free( lars->X_norm ); - lars->X_norm = matrix_alloc(1 , nvar ); - - if (lars->X_mean != NULL) - matrix_free( lars->X_mean ); - lars->X_mean = matrix_alloc(1 , nvar ); - - if (lars->beta != NULL) - matrix_free( lars->beta ); - lars->beta = matrix_alloc( nvar , nvar ); - lars->Y_mean = regression_scale( X , Y , lars->X_mean , lars->X_norm); -} - - -double lars_getY0( const lars_type * lars) { - return lars->Y0; -} - -double lars_iget_beta( const lars_type * lars , int index) { - return matrix_iget( lars->beta0 , index , 0 ); -} - - - -void lars_select_beta( lars_type * lars , int beta_index) { - int nvars = matrix_get_rows( lars->beta ); - if (lars->beta0 == NULL) - lars->beta0 = matrix_alloc( nvars , 1 ); - { - matrix_type * beta_vector = matrix_alloc( nvars , 1 ); - matrix_copy_column( beta_vector , lars->beta , 0 , beta_index ); - lars->Y0 = regression_unscale( beta_vector , lars->X_norm , lars->X_mean , lars->Y_mean , lars->beta0 ); - matrix_free( beta_vector ); - } -} - - - -/* - The algorithm can very briefly be summarized as: - - 1. Determine the covariate with greatest correlation to the data and - add this covariate to the model. In the current implementation the - correlations are stored in the matrix @C and the greatest - correlation is stored in the scalar variable @maxC. - - 2. Determine an update direction in the set of active covariates - which is equiangular to all covariates. - - 3. Determine the step length @gamma - which is the exact step length - before a new covariate will enter the active set at the current - correlation level. - - 4. Update the beta estimate and the current 'location' mu. -*/ - -void lars_estimate(lars_type * lars , int max_vars , double max_beta , bool verbose) { - int nvars = matrix_get_columns( lars->X ); - int nsample = matrix_get_rows( lars->X ); - matrix_type * X = matrix_alloc( nsample, nvars ); // Allocate local X and Y variables - matrix_type * Y = matrix_alloc( nsample, 1 ); // which will hold the normalized data - lars_estimate_init( lars , X , Y); // during the estimation process. - { - matrix_type * G = matrix_alloc_gram( X , true ); - matrix_type * mu = matrix_alloc( nsample , 1 ); - matrix_type * C = matrix_alloc( nvars , 1 ); - matrix_type * Y_mu = matrix_alloc_copy( Y ); - int_vector_type * active_set = int_vector_alloc(0,0); - int_vector_type * inactive_set = int_vector_alloc(0,0); - int active_size; - - - if ((max_vars <= 0) || (max_vars > nvars)) - max_vars = nvars; - - { - int i; - for (i=0; i < nvars; i++) - int_vector_iset( inactive_set , i , i ); - } - matrix_set( mu , 0 ); - - while (true) { - double maxC = 0; - - /* - The first step is to calculate the correlations between the - covariates, and the current residual. All the currently inactive - covariates are searched; the covariate with the greatest - correlation with (Y - mu) is selected and added to the active set. - */ - matrix_sub( Y_mu , Y , mu ); // Y_mu = Y - mu - matrix_dgemm( C , X , Y_mu , true , false , 1.0 , 0); // C = X' * Y_mu - { - int i; - int max_set_index = 0; - - for (i=0; i < int_vector_size( inactive_set ); i++) { - int set_index = i; - int var_index = int_vector_iget( inactive_set , set_index ); - double value = fabs( matrix_iget(C , var_index , 0) ); - if (value > maxC) { - maxC = value; - max_set_index = set_index; - } - } - /* - Remove element corresponding to max_set_index from the - inactive set and add it to the active set: - */ - int_vector_append( active_set , int_vector_idel( inactive_set , max_set_index )); - } - active_size = int_vector_size( active_set ); - /* - Now we have calculated the correlations between all the - covariates and the current residual @Y_mu. The correlations are - stored in the matrix @C. The value of the maximum correlation is - stored in @maxC. - - Based on the value of @maxC we have added one new covariate to - the model, technically by moving the index from @inactive_set to - @active_set. - */ - - /*****************************************************************/ - - - { - matrix_type * weights = matrix_alloc( active_size , 1); - double scale; - - /*****************************************************************/ - /* This scope should compute and initialize the variables - @weights and @scale. */ - { - matrix_type * subG = matrix_alloc( active_size , active_size ); - matrix_type * STS = matrix_alloc( active_size , active_size ); - matrix_type * sign_vector = matrix_alloc( active_size , 1); - int i , j; - - /* - STS = S' o S where 'o' is the Schur product and S is given - by: - - [ s1 s2 s3 s4 ] - S = [ s1 s2 s3 s4 ] - [ s1 s2 s3 s4 ] - [ s1 s2 s3 s4 ] - - Where si is the sign of the correlation between (active) - variable 'i' and Y_mu. - */ - - - for (i=0; i < active_size ; i++) { - int vari = int_vector_iget( active_set , i ); - double signi = sgn( matrix_iget( C , vari , 0)); - matrix_iset( sign_vector , i , 0 , signi ); - for (j=0; j < active_size; j++) { - int varj = int_vector_iget( active_set , j ); - double signj = sgn( matrix_iget( C , varj , 0)); - - matrix_iset( STS , i , j , signi * signj ); - } - } - - // Extract the elements from G corresponding to active indices and - // copy to the matrix subG: - for (i=0; i < active_size ; i++) { - int ii = int_vector_iget( active_set , i ); - for (j=0; j < active_size; j++) { - int jj = int_vector_iget( active_set , j ); - - matrix_iset( subG , i , j , matrix_iget(G , ii , jj)); - } - } - - // Weights - matrix_inplace_mul( subG , STS ); - matrix_inv( subG ); - - { - matrix_type * ones = matrix_alloc( active_size , 1 ); - matrix_type * GA1 = matrix_alloc( active_size , 1 ); - - matrix_set( ones , 1.0 ); - matrix_matmul( GA1 , subG , ones ); - scale = 1.0 / sqrt( matrix_get_column_sum( GA1 , 0 )); - - matrix_mul( weights , GA1 , sign_vector ); - matrix_scale( weights , scale ); - - matrix_free( GA1 ); - matrix_free( ones ); - } - - matrix_free( sign_vector ); - matrix_free( subG ); - matrix_free( STS ); - } - - /******************************************************************/ - /* The variables weight and scale have been calculated, proceed - to calculate the step length @gamma. */ - { - int i; - double gamma; - - { - matrix_type * u = matrix_alloc( nsample , 1 ); - int j; - - for (i=0; i < nsample; i++) { - double row_sum = 0; - for (j =0; j < active_size; j++) - row_sum += matrix_iget( X , i , int_vector_iget( active_set , j)) * matrix_iget(weights , j , 0 ); - - matrix_iset( u , i , 0 , row_sum ); - } - - gamma = maxC / scale; - if (active_size < matrix_get_columns( X )) { - matrix_type * equi_corr = matrix_alloc( nvars , 1 ); - matrix_dgemm( equi_corr , X , u , true , false , 1.0 , 0); // equi_corr = X'·u - for (i=0; i < (nvars - active_size); i++) { - int var_index = int_vector_iget( inactive_set , i ); - double gamma1 = (maxC - matrix_iget(C , var_index , 0 )) / ( scale - matrix_iget( equi_corr , var_index , 0)); - double gamma2 = (maxC + matrix_iget(C , var_index , 0 )) / ( scale + matrix_iget( equi_corr , var_index , 0)); - - if ((gamma1 > 0) && (gamma1 < gamma)) - gamma = gamma1; - - if ((gamma2 > 0) && (gamma2 < gamma)) - gamma = gamma2; - - } - matrix_free( equi_corr ); - } - /* Update the current estimated 'location' mu. */ - matrix_scale( u , gamma ); - matrix_inplace_add( mu , u ); - matrix_free( u ); - } - - /* - We have calculated the step length @gamma, and the @weights. Update the @beta matrix. - */ - for (i=0; i < active_size; i++) - matrix_iset( lars->beta , int_vector_iget( active_set , i ) , active_size - 1 , gamma * matrix_iget( weights , i , 0)); - - if (active_size > 1) - for (i=0; i < nvars; i++) - matrix_iadd( lars->beta , i , active_size - 1 , matrix_iget( lars->beta , i , active_size - 2)); - - matrix_free( weights ); - } - } - - if (active_size == max_vars) - break; - - if (max_beta > 0) { - double beta_norm2 = matrix_get_column_abssum( lars->beta , active_size - 1 ); - if (beta_norm2 > max_beta) { - // We stop - we will use an interpolation between this beta estimate and - // the previous, to ensure that the |beta| = max_beta criteria is satisfied. - if (active_size >= 2) { - double beta_norm1 = matrix_get_column_abssum( lars->beta , active_size - 2 ); - double s = (max_beta - beta_norm1)/(beta_norm2 - beta_norm1); - { - int j; - for (j=0; j < nvars; j++) { - double beta1 = matrix_iget( lars->beta , j , active_size - 2 ); - double beta2 = matrix_iget( lars->beta , j , active_size - 1 ); - matrix_iset( lars->beta , j , active_size - 1 , beta1 + s*(beta2 - beta1)); - } - } - } - break; - } - } - } - matrix_free( G ); - matrix_free( mu ); - matrix_free( C ); - matrix_free( Y_mu ); - int_vector_free( active_set ); - int_vector_free( inactive_set ); - matrix_resize( lars->beta , nvars , active_size , true ); - if (verbose) - matrix_pretty_fprint( lars->beta , "beta" , "%12.5f" , stdout ); - lars_select_beta( lars , active_size - 1); - } - matrix_free( X ); - matrix_free( Y ); -} - - -double lars_eval1( const lars_type * lars , const matrix_type * x) { - return lars->Y0 + matrix_row_column_dot_product( x , 0 , lars->beta0 , 0 ); -} - - -double lars_eval2( const lars_type * lars , double * x) { - matrix_type * x_view = matrix_alloc_view( x , 1 , matrix_get_columns( lars->X_mean )); - double y = lars_eval1( lars , x_view ); - matrix_free( x_view ); - return y; -} - - - - - diff --git a/ThirdParty/Ert/lib/util/log.c b/ThirdParty/Ert/lib/util/log.c deleted file mode 100644 index 7e74ebc28b..0000000000 --- a/ThirdParty/Ert/lib/util/log.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'log.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ert/util/build_config.h" - -#ifdef HAVE_FSYNC -#include -#endif - -#ifdef HAVE_PTHREAD -#include -#endif - -#include -#include - -struct log_struct { - char * filename; - FILE * stream; - int fd; - int log_level; - int msg_count; -#ifdef HAVE_PTHREAD - pthread_mutex_t mutex; -#endif -}; - - - -static void log_delete_empty(const log_type * logh) { - if (logh->filename && util_file_exists( logh->filename ) ) { - size_t file_size = util_file_size( logh->filename ); - if (file_size == 0) - remove( logh->filename ); - } -} - -void log_reopen(log_type *logh , const char *filename) { - if (logh->stream != NULL) { /* Close the existing file descriptor. */ - fclose( logh->stream ); - log_delete_empty( logh ); - } - - logh->filename = util_realloc_string_copy( logh->filename , filename ); -#ifdef HAVE_PTHREAD - pthread_mutex_lock( &logh->mutex ); -#endif - - if (filename != NULL) { - logh->stream = util_mkdir_fopen( filename , "a+"); - logh->fd = fileno( logh->stream ); - } else { /* It is ~OK to open a log with NULL filename, but then - log_reopen() with a VALID filename must be - called before it is actually used. */ - logh->stream = NULL; - logh->fd = -1; - } - logh->msg_count = 0; -#ifdef HAVE_PTHREAD - pthread_mutex_unlock( &logh->mutex ); -#endif -} - - -const char * log_get_filename( const log_type * logh ) { - return logh->filename; -} - -int log_get_msg_count( const log_type * logh) { - return logh->msg_count; -} - -int log_get_level( const log_type * logh) { - return logh->log_level; -} - -/** - * If an incoming message is below or equal to the configured log_level, it is included. So a high log_level will - * include more messages. - */ -void log_set_level( log_type * logh , int log_level) { - logh->log_level = log_level; -} - - - -log_type * log_open( const char * filename , int log_level) { - log_type *logh; - - logh = (log_type*)util_malloc(sizeof *logh ); - - logh->msg_count = 0; - logh->log_level = log_level; - logh->filename = NULL; - logh->stream = NULL; -#ifdef HAVE_PTHREAD - pthread_mutex_init( &logh->mutex , NULL ); -#endif - if (filename != NULL && log_level > 0) - log_reopen( logh , filename); - - return logh; -} - - -/** - * The message_level is compared to the configured log_level. Low message_level means "more important". - */ -bool log_include_message(const log_type *logh , int message_level) { - if (message_level <= logh->log_level) - return true; - else - return false; -} - -/** - * Adds a string to the log if message_level is below the threshold. It is the callers duty to either free the string - * or make sure that it is a string literal. - */ -void log_add_message_str(log_type *logh, message_level_type message_level , const char* message){ - //The conversion to (char*) is safe since free_message=false - log_add_message(logh,message_level, NULL, (char*) message,false); -} - - -/** - If dup_stream != NULL the message (without the date/time header) is duplicated on this stream. -*/ -void log_add_message(log_type *logh, int message_level , FILE * dup_stream , char* message, bool free_message) { - if (log_include_message(logh,message_level)) { - - if (logh->stream == NULL) - util_abort("%s: logh->stream == NULL - must call log_reset_filename() first \n",__func__); - -#ifdef HAVE_PTHREAD - pthread_mutex_lock( &logh->mutex ); -#endif - { - struct tm time_fields; - time_t epoch_time; - - time(&epoch_time); - util_time_utc(&epoch_time , &time_fields); - - if (message != NULL) - fprintf(logh->stream,"%02d/%02d - %02d:%02d:%02d %s\n",time_fields.tm_mday, time_fields.tm_mon + 1, time_fields.tm_hour , time_fields.tm_min , time_fields.tm_sec , message); - else - fprintf(logh->stream,"%02d/%02d - %02d:%02d:%02d \n",time_fields.tm_mday, time_fields.tm_mon + 1, time_fields.tm_hour , time_fields.tm_min , time_fields.tm_sec); - - /** We duplicate the message to the stream 'dup_stream'. */ - if ((dup_stream != NULL) && (message != NULL)) - fprintf(dup_stream , "%s\n", message); - - log_sync( logh ); - logh->msg_count++; - } -#ifdef HAVE_PTHREAD - pthread_mutex_unlock( &logh->mutex ); -#endif - if (free_message) - free( message ); - } -} - - - - - -/** - * Adds a formated log message if message_level is below the threshold, fmt is expected to be the format string, - * and "..." contains any arguments to it. - */ -void log_add_fmt_message(log_type * logh , int message_level , FILE * dup_stream , const char * fmt , ...) { - if (log_include_message(logh,message_level)) { - char * message; - va_list ap; - va_start(ap , fmt); - message = util_alloc_sprintf_va( fmt , ap ); - log_add_message( logh , message_level , dup_stream , message , true); - va_end(ap); - } -} - - - - - - -/** - This function can be used to get low level to the FILE pointer of - the stream. To 'ensure' that the data actually hits the disk - you should call log_sync() after writing. - - It is your responsabiulity to avoid racing++ when using the - log_get_stream() function. -*/ - -FILE * log_get_stream(log_type * logh ) { - return logh->stream; -} - - -void log_sync(log_type * logh) { -#ifdef HAVE_FSYNC - fsync( logh->fd ); -#endif - util_fseek( logh->stream , 0 , SEEK_END ); -} - - - -void log_close( log_type * logh ) { - if ((logh->stream != stdout) && (logh->stream != stderr) && (logh->stream != NULL)) - fclose( logh->stream ); /* This closes BOTH the FILE * stream and the integer file descriptor. */ - - log_delete_empty( logh ); - util_safe_free( logh->filename ); - free( logh ); -} - - -bool log_is_open( const log_type * logh) { - if (logh->stream != NULL) - return true; - else - return false; -} diff --git a/ThirdParty/Ert/lib/util/lookup_table.c b/ThirdParty/Ert/lib/util/lookup_table.cpp similarity index 97% rename from ThirdParty/Ert/lib/util/lookup_table.c rename to ThirdParty/Ert/lib/util/lookup_table.cpp index 0e0a139461..f6d0bdf640 100644 --- a/ThirdParty/Ert/lib/util/lookup_table.c +++ b/ThirdParty/Ert/lib/util/lookup_table.cpp @@ -19,10 +19,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include struct lookup_table_struct { bool data_owner; diff --git a/ThirdParty/Ert/lib/util/matrix.c b/ThirdParty/Ert/lib/util/matrix.c deleted file mode 100644 index 8d2b28111e..0000000000 --- a/ThirdParty/Ert/lib/util/matrix.c +++ /dev/null @@ -1,1751 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'matrix.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -/** - This is V E R Y S I M P L E matrix implementation. It is not - designed to be fast/efficient or anything. It is purely a minor - support functionality for the enkf program, and should N O T be - considered as general matrix functionality. -*/ - - - -/** - Many of matrix functions can potentially involve laaarge amounts of - memory. The functions: - - o matrix_alloc(), matrix_resize() and matrix_alloc_copy() will - abort with util_abort() if the memory requirements can not be - satisfied. - - o The corresponding functions matrix_safe_alloc(), - matrix_safe_resize() and matrix_safe_alloc_copy() will not abort, - instead NULL or an unchanged matrix will be returned. When using - these functons it is the responsability of the calling scope to - check return values. - - So the expression "safe" should be interpreted as 'can not abort' - - however the responsability of the calling scope is greater when it - comes to using these functions - things can surely blow up! -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#define MATRIX_TYPE_ID 712108 - -/*#define GET_INDEX(m,i,j) (m->row_stride * (i) + m->column_stride * (j))*/ - -/* - This GET_INDEX function has been forcely inlined for performance. -*/ -/*static size_t GET_INDEX( const matrix_type * m , size_t i , size_t j) { - return m->row_stride *i + m->column_stride *j; -}*/ - -static size_t MATRIX_DATA_SIZE( const matrix_type * m) { - size_t col = m->columns; - size_t stride = m->column_stride; - - return col*stride; -} - - - - -static void matrix_init_header(matrix_type * matrix , int rows , int columns , int row_stride , int column_stride) { - - if (!((column_stride * columns <= row_stride) || (row_stride * rows <= column_stride))) - util_abort("%s: invalid stride combination \n",__func__); - - matrix->data_size = 0; - matrix->alloc_rows = rows; - matrix->alloc_columns = columns; - matrix->row_stride = row_stride; - matrix->column_stride = column_stride; - - matrix_full_size( matrix ); -} - - -/** - This is the low-level function allocating storage. If the input - flag 'safe_mode' is equal to true, the function will return NULL if - the allocation fails, otherwise the function will abort() if the - allocation fails. - - Before returning all elements will be initialized to zero. - - 1. It is based on first free() of the original pointer, and then - subsequently calling malloc() to get new storage. This is to - avoid prohibitive temporary memory requirements during the - realloc() call. - - 2. If the malloc() fails the function will return NULL, i.e. you - will NOT keep the original data pointer. I.e. in this case the - matrix will be invalid. It is the responsability of the calling - scope to do the right thing. - - 3. realloc() functionality - i.e. keeping the original content of - the matrix is implemented at higher level. The memory layout of - the matrix will in general change anyway; so the promise made - by realloc() is not very interesting. -*/ - -static void matrix_realloc_data__( matrix_type * matrix , bool safe_mode ) { - if (matrix->data_owner) { - size_t data_size = MATRIX_DATA_SIZE( matrix ); - if (matrix->data_size == data_size) return; - if (matrix->data != NULL) - free(matrix->data); - - if (safe_mode) { - /* - If safe_mode == true it is 'OK' to fail in the allocation, - otherwise we use util_malloc() which will abort if the memory - is not available. - */ - matrix->data = (double*)malloc( sizeof * matrix->data * data_size ); - } else - matrix->data = (double*)util_malloc( sizeof * matrix->data * data_size ); - - - /* Initializing matrix content to zero. */ - if (matrix->data != NULL) { - size_t i; - for (i = 0; i < data_size; i++) - matrix->data[i] = 0; - } else - data_size = 0; - - /** - Observe that if the allocation failed the matrix will - be returned with data == NULL, and data_size == 0. - */ - matrix->data_size = data_size; - } else - util_abort("%s: can not manipulate memory when is not data owner\n",__func__); -} - - -UTIL_SAFE_CAST_FUNCTION( matrix , MATRIX_TYPE_ID ) - -/** - The matrix objecty is NOT ready for use after this function. -*/ -static matrix_type * matrix_alloc_empty( ) { - matrix_type * matrix = (matrix_type*)util_malloc( sizeof * matrix ); - UTIL_TYPE_ID_INIT( matrix , MATRIX_TYPE_ID ); - matrix->name = NULL; - return matrix; -} - -/* - The freshly allocated matrix is explicitly initialized to zero. If - the variable safe_mode equals true the function will return NULL if - the allocation of data fails, otherwise it will abort() if the - allocation fails. -*/ -static matrix_type * matrix_alloc_with_stride(int rows , int columns , int row_stride , int column_stride, bool safe_mode) { - matrix_type * matrix = NULL; - if ((rows > 0) && (columns > 0)) { - matrix = matrix_alloc_empty(); - matrix->data = NULL; - matrix->data_size = 0; - matrix_init_header( matrix , rows , columns , row_stride , column_stride); - matrix->data_owner = true; - matrix_realloc_data__( matrix , safe_mode ); - if (safe_mode) { - if (matrix->data == NULL) { - /* Allocation failed - we return NULL */ - matrix_free(matrix); - matrix = NULL; - } - } - } - return matrix; -} - - -void matrix_set_name( matrix_type * matrix , const char * name) { - matrix->name = util_realloc_string_copy( matrix->name , name ); -} - - -/** - This function will allocate a matrix object where the data is - shared with the 'src' matrix. A matrix allocated in this way can be - used with all the matrix_xxx functions, but you should be careful - when exporting the data pointer to e.g. lapack routines. -*/ - -matrix_type * matrix_alloc_shared(const matrix_type * src , int row , int column , int rows , int columns) { - if (((row + rows) > src->rows) || ((column + columns) > src->columns)) - util_abort("%s: Invalid matrix subsection src:[%d,%d] Offset:[%d,%d] SubSize:[%d,%d] \n", - __func__, - src->rows , src->columns, - row,column, - rows,columns); - - { - matrix_type * matrix = matrix_alloc_empty(); - - matrix_init_header( matrix , rows , columns , src->row_stride , src->column_stride); - matrix->data = &src->data[ GET_INDEX(src , row , column) ]; - matrix->data_owner = false; - - return matrix; - } -} - - -matrix_type * matrix_alloc_view(double * data , int rows , int columns) { - matrix_type * matrix = matrix_alloc_empty(); - - matrix_init_header( matrix , rows , columns , 1 , rows); - matrix->data = data; - matrix->data_owner = false; - - return matrix; -} - - -/** - This function will allocate a matrix structure; this matrix - structure will TAKE OWNERSHIP OF THE SUPPLIED DATA. This means that - it is (at the very best) highly risky to use the data pointer in - the calling scope after the matrix has been allocated. If the - supplied pointer is too small it is immediately realloced ( in - which case the pointer in the calling scope will be immediately - invalid). -*/ - -matrix_type * matrix_alloc_steal_data(int rows , int columns , double * data , int data_size) { - matrix_type * matrix = matrix_alloc_empty(); - matrix_init_header( matrix , rows , columns , 1 , rows ); - matrix->data_size = data_size; /* Can in general be different from rows * columns */ - matrix->data_owner = true; - matrix->data = data; - if (data_size < rows * columns) - matrix_realloc_data__(matrix , false); - - return matrix; -} - - - -/*****************************************************************/ - -static matrix_type * matrix_alloc__(int rows, int columns , bool safe_mode) { - return matrix_alloc_with_stride( rows , columns , 1 , rows , safe_mode ); /* Must be the stride (1,rows) to use the lapack routines. */ -} - -matrix_type * matrix_alloc(int rows, int columns) { - return matrix_alloc__( rows , columns , false ); -} - -matrix_type * matrix_safe_alloc(int rows, int columns) { - return matrix_alloc__( rows , columns , true ); -} - -matrix_type * matrix_alloc_identity(int dim) { - if (dim < 1) - util_abort("%s: identity matrix must have positive size. \n",__func__); - - matrix_type * idty = matrix_alloc(dim, dim); - for (int i = 0; i < dim; ++i) - matrix_iset(idty, i, i, 1); - return idty; -} - -/*****************************************************************/ - -/** - Will not respect strides - that is considered low level data - layout. -*/ -static matrix_type * matrix_alloc_copy__( const matrix_type * src , bool safe_mode) { - matrix_type * copy = matrix_alloc__( matrix_get_rows( src ), matrix_get_columns( src ) , safe_mode); - if (copy != NULL) - matrix_assign(copy , src); - return copy; -} - - -matrix_type * matrix_alloc_copy(const matrix_type * src) { - return matrix_alloc_copy__(src , false ); -} - -matrix_type * matrix_alloc_column_compressed_copy(const matrix_type * src, const bool_vector_type * mask) { - if (bool_vector_size( mask ) != matrix_get_columns( src )) - util_abort("%s: size mismatch. Src matrix has %d rows mask has:%d elements\n", __func__ , matrix_get_rows( src ) , bool_vector_size( mask )); - { - int target_columns = bool_vector_count_equal( mask , true ); - matrix_type * target = matrix_alloc( matrix_get_rows( src ) , target_columns ); - - matrix_column_compressed_memcpy( target , src , mask ); - return target; - } -} - - -void matrix_column_compressed_memcpy(matrix_type * target, const matrix_type * src, const bool_vector_type * mask) { - if (bool_vector_count_equal( mask , true ) != matrix_get_columns( target )) - util_abort("%s: size mismatch. \n",__func__); - - if (bool_vector_size( mask ) != matrix_get_columns( src)) - util_abort("%s: size mismatch. \n",__func__); - - { - int target_col = 0; - int src_col; - for (src_col = 0; src_col < bool_vector_size( mask ); src_col++) { - if (bool_vector_iget( mask , src_col)) { - matrix_copy_column( target , src , target_col , src_col); - target_col++; - } - } - } -} - - - -matrix_type * matrix_realloc_copy(matrix_type * T , const matrix_type * src) { - if (T == NULL) - return matrix_alloc_copy( src ); - else { - matrix_resize( T , src->rows , src->columns , false ); - matrix_assign( T , src ); - return T; - } -} - - - - -/** - Will return NULL if allocation of the copy failed. -*/ - -matrix_type * matrix_safe_alloc_copy(const matrix_type * src) { - return matrix_alloc_copy__(src , true); -} - -void matrix_copy_block( matrix_type * target_matrix , int target_row , int target_column , int rows , int columns, - const matrix_type * src_matrix , int src_row , int src_column) { - matrix_type * target_view = matrix_alloc_shared(target_matrix , target_row , target_column , rows , columns); - matrix_type * src_view = matrix_alloc_shared( src_matrix , src_row , src_column , rows , columns); - matrix_assign( target_view , src_view ); - matrix_free( target_view ); - matrix_free( src_view ); -} - -matrix_type * matrix_alloc_sub_copy( const matrix_type * src , int row_offset , int column_offset , int rows, int columns) { - matrix_type * copy = matrix_alloc( rows, columns ); - matrix_copy_block( copy , 0 , 0 , rows , columns , src , row_offset , column_offset ); - return copy; -} - - -/*****************************************************************/ - -static bool matrix_resize__(matrix_type * matrix , int rows , int columns , bool copy_content , bool safe_mode) { - if (!matrix->data_owner) - util_abort("%s: sorry - can not resize shared matrizes. \n",__func__); - { - bool resize_OK = true; - - if ((rows != matrix->rows) || (columns != matrix->columns)) { - int copy_rows = util_int_min( rows , matrix->rows ); - int copy_columns = util_int_min( columns , matrix->columns); - matrix_type * copy_view = NULL; - matrix_type * copy = NULL; - - if (copy_content) { - copy_view = matrix_alloc_shared( matrix , 0 , 0 , copy_rows , copy_columns); /* This is the part of the old matrix which should be copied over to the new. */ - copy = matrix_alloc_copy__( copy_view , safe_mode ); /* Now copy contains the part of the old matrix which should be copied over - with private storage. */ - } - { - int old_rows , old_columns, old_row_stride , old_column_stride; - matrix_get_dims( matrix , &old_rows , &old_columns , &old_row_stride , &old_column_stride); /* Storing the old header information - in case the realloc() fails. */ - - matrix_init_header(matrix , rows , columns , 1 , rows); /* Resetting the header for the matrix */ - matrix_realloc_data__(matrix , safe_mode); - if (matrix->data != NULL) { /* Realloc succeeded */ - if (copy_content) { - matrix_type * target_view = matrix_alloc_shared(matrix , 0 , 0 , copy_rows , copy_columns); - matrix_assign( target_view , copy); - matrix_free( target_view ); - } - } else { - /* Failed to realloc new storage; RETURNING AN INVALID MATRIX */ - matrix_init_header(matrix , old_rows , old_columns , old_row_stride , old_column_stride); - resize_OK = false; - } - } - - if (copy_content) { - matrix_free(copy_view); - matrix_free(copy); - } - } - return resize_OK; - } -} - - -/** - If copy content is true the content of the old matrix is carried - over to the new one, otherwise the new matrix is cleared. - - Will always return true (or abort). -*/ -bool matrix_resize(matrix_type * matrix , int rows , int columns , bool copy_content) { - return matrix_resize__(matrix , rows , columns , copy_content , false); -} - - -/** - Return true if the resize succeded, otherwise it will return false - and leave the matrix unchanged. When resize implies expanding a - dimension, the newly created elements will be explicitly - initialized to zero. - - If copy_content is set to false the new matrix will be fully - initialized to zero. -*/ - -bool matrix_safe_resize(matrix_type * matrix , int rows , int columns , bool copy_content) { - return matrix_resize__(matrix , rows , columns , copy_content , true); -} - - - -/** - This function will ensure that the matrix has at least 'rows' - rows. If the present matrix already has >= rows it will return - immediately, otherwise the matrix will be resized. -*/ - -void matrix_ensure_rows(matrix_type * matrix, int rows, bool copy_content) { - if (matrix->rows < rows) - matrix_resize( matrix , rows , matrix->columns , copy_content); -} - - - -/** - This function will reduce the size of the matrix. It will only - affect the headers, and not touch the actual memory of the matrix. -*/ - -void matrix_shrink_header(matrix_type * matrix , int rows , int columns) { - - if (rows <= matrix->rows) - matrix->rows = rows; - - if (columns <= matrix->columns) - matrix->columns = columns; - -} - - -void matrix_full_size( matrix_type * matrix ) { - matrix->rows = matrix->alloc_rows; - matrix->columns = matrix->alloc_columns; -} - - -/*****************************************************************/ - -static void matrix_free_content(matrix_type * matrix) { - if (matrix->data_owner) - util_safe_free(matrix->data); - util_safe_free( matrix->name ); -} - -void matrix_free(matrix_type * matrix) { - matrix_free_content( matrix ); - free(matrix); -} - - -void matrix_safe_free( matrix_type * matrix ) { - if (matrix != NULL) - matrix_free( matrix ); -} - - -/*****************************************************************/ -void matrix_pretty_fprint_submat(const matrix_type * matrix , const char * name , const char * fmt , FILE * stream, int m, int M, int n, int N) { - int i,j; - - if (m<0 || m>M || M >= matrix->rows || n<0 || n>N || N >= matrix->columns) - util_abort("%s: matrix:%s not compatible with print subdimensions. \n",__func__ , matrix->name); - - fprintf(stream , "%s =" , name); - for (i=m; i < M; i++) { - fprintf(stream , " ["); - for (j=n; j < N; j++) - fprintf(stream , fmt , matrix_iget(matrix , i,j)); - fprintf(stream , "]\n"); - } -} -/*****************************************************************/ - -void matrix_pretty_fprint(const matrix_type * matrix , const char * name , const char * fmt , FILE * stream) { - int i,j; - for (i=0; i < matrix->rows; i++) { - - if (i == (matrix->rows / 2)) - fprintf(stream , "%s =" , name); - else { - int l; - for (l = 0; l < strlen(name) + 2; l++) - fprintf(stream , " "); - } - - fprintf(stream , " ["); - for (j=0; j < matrix->columns; j++) - fprintf(stream , fmt , matrix_iget(matrix , i,j)); - fprintf(stream , "]\n"); - } -} - - -void matrix_pretty_print(const matrix_type * matrix , const char * name , const char * fmt) { - matrix_pretty_fprint(matrix , name , fmt , stdout ); -} - - -void matrix_fprintf( const matrix_type * matrix , const char * fmt , FILE * stream ) { - int i,j; - for (i=0; i < matrix->rows; i++) { - for (j=0; j < matrix->columns; j++) - fprintf(stream , fmt , matrix_iget( matrix , i , j)); - fprintf(stream , "\n"); - } -} - - -void matrix_dump_csv( const matrix_type * matrix ,const char * filename) { - FILE * stream = util_fopen(filename , "w"); - for (int i=0; i < matrix->rows; i++) { - for (int j=0; j < matrix->columns - 1; j++) - fprintf(stream , "%g, " , matrix_iget( matrix , i , j)); - fprintf(stream , "%g\n" , matrix_iget( matrix , i , matrix->columns - 1)); - } - fclose( stream ); -} - - -void matrix_fwrite(const matrix_type * matrix , FILE * stream) { - util_fwrite_int( matrix->rows , stream ); - util_fwrite_int( matrix->columns , stream ); - - if (matrix->column_stride == matrix->rows) - util_fwrite( matrix->data , sizeof * matrix->data , matrix->columns * matrix->rows , stream , __func__); - else { - int column; - for (column=0; column < matrix->columns; column++) { - if (matrix->row_stride == 1) { - const double * column_data = &matrix->data[ column * matrix->column_stride ]; - util_fwrite( column_data , sizeof * column_data , matrix->rows , stream , __func__); - } else { - int row; - for (row=0; row < matrix->rows; row++) - util_fwrite_double( matrix->data[ GET_INDEX( matrix , row , column )] , stream); - } - } - } -} - - -void matrix_fread(matrix_type * matrix , FILE * stream) { - int rows = util_fread_int( stream ); - int columns = util_fread_int( stream ); - - matrix_resize( matrix , rows , columns , false); - if (matrix->column_stride == matrix->rows) - util_fread( matrix->data , sizeof * matrix->data , matrix->columns * matrix->rows , stream , __func__); - else { - int column; - for (column=0; column < matrix->columns; column++) { - if (matrix->row_stride == 1) { - double * column_data = &matrix->data[ column * matrix->column_stride ]; - util_fread( column_data , sizeof * column_data , matrix->rows , stream , __func__); - } else { - int row; - for (row=0; row < matrix->rows; row++) - matrix->data[ GET_INDEX( matrix , row , column )] = util_fread_double( stream ); - } - } - } -} - -matrix_type * matrix_fread_alloc(FILE * stream) { - matrix_type * matrix = matrix_alloc(1,1); - matrix_fread(matrix , stream); - return matrix; -} - - -/** - [ a11 a12 ] - [ a21 a22 ] - - - - - row_major_order == true - ----------------------- - a_11 - a_12 - a_21 - a_22 - - - row_major_order == false - ----------------------- - a_11 - a_12 - a_21 - a_22 - - - The @orw_major_order parameter ONLY affects the layout on the file, - and NOT the memory layout of the matrix. -*/ - - -static void __fscanf_and_set( matrix_type * matrix , int row , int col , FILE * stream) { - double value; - if (fscanf(stream , "%lg" , &value) == 1) - matrix_iset( matrix , row , col , value ); - else - util_abort("%s: reading of matrix failed at row:%d col:%d \n",__func__ , row , col); -} - - -void matrix_fscanf_data( matrix_type * matrix , bool row_major_order , FILE * stream ) { - int row,col; - if (row_major_order) { - for (row = 0; row < matrix->columns; row++) { - for (col = 0; col < matrix->columns; col++) { - __fscanf_and_set( matrix , row , col ,stream); - } - } - } else { - for (row = 0; row < matrix->columns; row++) { - for (col = 0; col < matrix->columns; col++) { - __fscanf_and_set( matrix , row , col , stream); - } - } - } -} - - - -/*****************************************************************/ -/* Functions which manipulate one element in the matrix. */ - -static void matrix_assert_ij( const matrix_type * matrix , int i , int j) { - if ((i < 0) || (i >= matrix->rows) || (j < 0) || (j >= matrix->columns)) - util_abort("%s: (i,j) = (%d,%d) invalid. Matrix size: %d x %d \n",__func__ , i,j,matrix->rows , matrix->columns); -} - - -static void matrix_assert_equal_rows( const matrix_type * m1 , const matrix_type * m2) { - if (m1->rows != m2->rows) - util_abort("%s: size mismatch in binary matrix operation %d %d \n",__func__ , m1->rows , m2->rows); -} - - -static void matrix_assert_equal_columns( const matrix_type * m1 , const matrix_type * m2) { - if (m1->columns != m2->columns) - util_abort("%s: size mismatch in binary matrix operation %d %d \n",__func__ , m1->columns , m2->columns); -} - - -void matrix_iset(matrix_type * matrix , int i , int j, double value) { - matrix->data[ GET_INDEX(matrix , i,j) ] = value; -} - - - -void matrix_iset_safe(matrix_type * matrix , int i , int j, double value) { - matrix_assert_ij( matrix , i , j ); - matrix_iset( matrix , i , j , value ); -} - - -double matrix_iget(const matrix_type * matrix , int i , int j) { - return matrix->data[ GET_INDEX(matrix , i, j) ]; -} - - -double matrix_iget_safe(const matrix_type * matrix , int i , int j) { - matrix_assert_ij( matrix , i , j ); - return matrix_iget( matrix , i , j ); -} - - -void matrix_iadd(matrix_type * matrix , int i , int j , double value) { - matrix->data[ GET_INDEX(matrix , i,j) ] += value; -} - - -void matrix_isub(matrix_type * matrix , int i , int j , double value) { - matrix->data[ GET_INDEX(matrix , i,j) ] -= value; -} - - -void matrix_imul(matrix_type * matrix , int i , int j , double value) { - matrix->data[ GET_INDEX(matrix , i,j) ] *= value; -} - - -/*****************************************************************/ -/* One scalar operating on all the elements in the matrix */ - -void matrix_set(matrix_type * matrix, double value) { - int i,j; - for (j=0; j < matrix->columns; j++) - for (i=0; i < matrix->rows; i++) - matrix_iset(matrix , i , j , value); -} - - -void matrix_shift(matrix_type * matrix, double value) { - int i,j; - for (j=0; j < matrix->columns; j++) - for (i=0; i < matrix->rows; i++) - matrix_iadd(matrix , i , j , value); -} - - -void matrix_scale(matrix_type * matrix, double value) { - int i,j; - for (j=0; j < matrix->columns; j++) - for (i=0; i < matrix->rows; i++) - matrix_imul(matrix , i , j , value); -} - -/*****************************************************************/ -/* Functions working on rows & columns */ - -void matrix_set_many_on_column(matrix_type * matrix , int row_offset , int elements , const double * data , int column) { - if ((row_offset + elements) <= matrix->rows) { - if (matrix->row_stride == 1) /* Memory is continous ... */ - memcpy( &matrix->data[ GET_INDEX( matrix , row_offset , column) ] , data , elements * sizeof * data); - else { - int i; - for (i = 0; i < elements; i++) - matrix->data[ row_offset + GET_INDEX( matrix , i , column) ] = data[i]; - } - } else - util_abort("%s: range violation \n" , __func__); -} - -void matrix_set_column(matrix_type * matrix , const double * data , int column) { - matrix_set_many_on_column( matrix , 0 , matrix->rows , data , column ); -} - - -void matrix_set_const_column(matrix_type * matrix , const double value , int column) { - int row; - for (row = 0; row < matrix->rows; row++) - matrix->data[ GET_INDEX( matrix , row , column) ] = value; -} - - -void matrix_set_const_row(matrix_type * matrix , const double value , int row) { - int column; - for (column = 0; column < matrix->columns; column++) - matrix->data[ GET_INDEX( matrix , row , column) ] = value; -} - - -void matrix_copy_column(matrix_type * target_matrix, const matrix_type * src_matrix , int target_column, int src_column) { - matrix_assert_equal_rows( target_matrix , src_matrix ); - { - int row; - for(row = 0; row < target_matrix->rows; row++) - target_matrix->data[ GET_INDEX( target_matrix, row , target_column)] = src_matrix->data[ GET_INDEX( src_matrix, row, src_column)]; - } -} - - -void matrix_scale_column(matrix_type * matrix , int column , double scale_factor) { - int row; - for (row = 0; row < matrix->rows; row++) - matrix->data[ GET_INDEX( matrix , row , column) ] *= scale_factor; -} - -void matrix_scale_row(matrix_type * matrix , int row , double scale_factor) { - int column; - for (column = 0; column < matrix->columns; column++) - matrix->data[ GET_INDEX( matrix , row , column) ] *= scale_factor; -} - -void matrix_copy_row(matrix_type * target_matrix, const matrix_type * src_matrix , int target_row, int src_row) { - matrix_assert_equal_columns( target_matrix , src_matrix ); - { - int col; - for(col = 0; col < target_matrix->columns; col++) - target_matrix->data[ GET_INDEX( target_matrix , target_row , col)] = src_matrix->data[ GET_INDEX( src_matrix, src_row, col)]; - } -} - - -/*****************************************************************/ -/* Functions for dot products between rows/columns in matrices. */ - -double matrix_column_column_dot_product(const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2) { - if (m1->rows != m2->rows) - util_abort("%s: size mismatch \n",__func__); - - if (col1 >= m1->columns || col2 >= m2->columns) - util_abort("%s: size mismatch \n",__func__); - { - int row; - double sum = 0; - for( row = 0; row < m1->rows; row++) - sum += m1->data[ GET_INDEX(m1 , row , col1) ] * m2->data[ GET_INDEX(m2, row , col2) ]; - - return sum; - } -} - - -double matrix_row_column_dot_product(const matrix_type * m1 , int row1 , const matrix_type * m2 , int col2) { - if (m1->columns != m2->rows) - util_abort("%s: size mismatch: m1:[%d,%d] m2:[%d,%d] \n",__func__ , matrix_get_rows( m1 ) , matrix_get_columns( m1 ) , matrix_get_rows( m2 ) , matrix_get_columns( m2 )); - - { - int k; - double sum = 0; - for( k = 0; k < m1->columns; k++) - sum += m1->data[ GET_INDEX(m1 , row1 , k) ] * m2->data[ GET_INDEX(m2, k , col2) ]; - - return sum; - } -} - - - - -/*****************************************************************/ -/* Matrix - matrix operations */ - - -/* Implements assignement: A = B */ -void matrix_assign(matrix_type * A , const matrix_type * B) { - if ((A->rows == B->rows) && (A->columns == B->columns)) { - int i,j; - - if (A->row_stride == B->row_stride) { - if (A->columns == A->row_stride) /** Memory is just one continous block */ - memcpy( A->data , B->data , A->rows * A->columns * sizeof * A->data); - else { - /* Copying columns of data */ - for (j = 0; j < A->columns; j++) - memcpy( &A->data[ GET_INDEX(A , 0 , j)] , &B->data[ GET_INDEX(B , 0 , j) ] , A->rows * sizeof * A->data); - } - } else { - /* Copying element by element */ - for (j = 0; j < A->columns; j++) - for (i=0; i < A->rows; i++) - A->data[ GET_INDEX(A,i,j) ] = B->data[ GET_INDEX(B,i,j) ]; - } - } else - util_abort("%s: size mismatch A:[%d,%d] B:[%d,%d] \n",__func__ , A->rows , A->columns , B->rows , B->columns); -} - - - -void matrix_inplace_sub_column(matrix_type * A , const matrix_type * B, int colA , int colB) { - if ((A->rows == B->rows) && - (colA < A->columns) && - (colB < B->columns)) { - int row; - - for (row = 0; row < A->rows; row++) - A->data[ GET_INDEX(A , row , colA)] -= B->data[ GET_INDEX(B , row , colB)]; - - } else - util_abort("%s: size mismatch \n",__func__); -} - -void matrix_inplace_add_column(matrix_type * A , const matrix_type * B, int colA , int colB) { - if ((A->rows == B->rows) && - (colA < A->columns) && - (colB < B->columns)) { - int row; - - for (row = 0; row < A->rows; row++) - A->data[ GET_INDEX(A , row , colA)] += B->data[ GET_INDEX(B , row , colB)]; - - } else - util_abort("%s: size mismatch \n",__func__); -} - -/* Updates matrix A by adding in matrix B - elementwise. */ -void matrix_inplace_add(matrix_type * A , const matrix_type * B) { - if ((A->rows == B->rows) && (A->columns == B->columns)) { - int i,j; - - for (j = 0; j < A->columns; j++) - for (i=0; i < A->rows; i++) - A->data[ GET_INDEX(A,i,j) ] += B->data[ GET_INDEX(B,i,j) ]; - - } else - util_abort("%s: size mismatch \n",__func__); -} - - -/* Updates matrix A by multiplying in matrix B - elementwise - i.e. Schur product. */ -void matrix_inplace_mul(matrix_type * A , const matrix_type * B) { - if ((A->rows == B->rows) && (A->columns == B->columns)) { - int i,j; - - for (j = 0; j < A->columns; j++) - for (i=0; i < A->rows; i++) - A->data[ GET_INDEX(A,i,j) ] *= B->data[ GET_INDEX(B,i,j) ]; - - } else - util_abort("%s: size mismatch \n",__func__); -} - - -/* - Schur product: A = B * C -*/ - -void matrix_mul( matrix_type * A , const matrix_type * B , const matrix_type * C) { - if ((A->rows == B->rows) && (A->columns == B->columns) && (A->rows == C->rows) && (A->columns == C->columns)) { - int i,j; - - for (j = 0; j < A->columns; j++) - for (i=0; i < A->rows; i++) - A->data[ GET_INDEX(A,i,j) ] = B->data[ GET_INDEX(B,i,j) ] * C->data[ GET_INDEX(B,i,j) ]; - - } else - util_abort("%s: size mismatch \n",__func__); -} - - - -/* Updates matrix A by subtracting matrix B - elementwise. */ -void matrix_inplace_sub(matrix_type * A , const matrix_type * B) { - if ((A->rows == B->rows) && (A->columns == B->columns)) { - int i,j; - - for (j = 0; j < A->columns; j++) - for (i=0; i < A->rows; i++) - A->data[ GET_INDEX(A,i,j) ] -= B->data[ GET_INDEX(B,i,j) ]; - - } else - util_abort("%s: size mismatch A:[%d,%d] B:[%d,%d]\n",__func__ , - matrix_get_rows(A), - matrix_get_columns(A), - matrix_get_rows(B), - matrix_get_columns(B)); -} - - -/* Does the matrix operation: - - A = B - C - - elementwise. -*/ -void matrix_sub(matrix_type * A , const matrix_type * B , const matrix_type * C) { - if ((A->rows == B->rows) && (A->columns == B->columns) && (A->rows == C->rows) && (A->columns == C->columns)) { - int i,j; - - for (j = 0; j < A->columns; j++) - for (i=0; i < A->rows; i++) - A->data[ GET_INDEX(A,i,j) ] = B->data[ GET_INDEX(B,i,j) ] - C->data[ GET_INDEX(B,i,j) ]; - - } else - util_abort("%s: size mismatch \n",__func__); -} - - - - -/* Updates matrix A by dividing matrix B - elementwise. */ -void matrix_inplace_div(matrix_type * A , const matrix_type * B) { - if ((A->rows == B->rows) && (A->columns == B->columns)) { - int i,j; - - for (j = 0; j < A->columns; j++) - for (i=0; i < A->rows; i++) - A->data[ GET_INDEX(A,i,j) ] /= B->data[ GET_INDEX(B,i,j) ]; - - } else - util_abort("%s: size mismatch \n",__func__); -} - - -/** - Observe that A and T should not overlap, i.e. the call - - matrix_transpose(X , X) - - will fail in mysterious ways. -*/ - -void matrix_transpose(const matrix_type * A , matrix_type * T) { - if ((A->columns == T->rows) && (A->rows == T->columns)) { - int i,j; - for (i=0; i < A->rows; i++) { - for (j=0; j < A->columns; j++) { - size_t src_index = GET_INDEX(A , i , j ); - size_t target_index = GET_INDEX(T , j , i ); - - T->data[ target_index ] = A->data[ src_index ]; - } - } - } else - util_abort("%s: size mismatch\n",__func__); -} - - -void matrix_inplace_transpose(matrix_type * A ) { - matrix_type * B = matrix_alloc_transpose( A ); - matrix_free_content( A ); - memcpy( A , B , sizeof * A ); - free( B ); -} - - - -matrix_type * matrix_alloc_transpose( const matrix_type * A) { - matrix_type * B = matrix_alloc( matrix_get_columns( A ) , matrix_get_rows( A )); - matrix_transpose( A , B ); - return B; -} - - - -/** - For this function to work the following must be satisfied: - - columns in A == rows in B == columns in B - - For general matrix multiplactions where A = B * C all have - different dimensions you can use matrix_matmul() (which calls the - BLAS routine dgemm()); -*/ - - -void matrix_inplace_matmul(matrix_type * A, const matrix_type * B) { - if ((A->columns == B->rows) && (B->rows == B->columns)) { - double * tmp = (double*)util_malloc( sizeof * A->data * A->columns ); - int i,j,k; - - for (i=0; i < A->rows; i++) { - - /* Clearing the tmp vector */ - for (k=0; k < B->rows; k++) - tmp[k] = 0; - - for (j=0; j < B->rows; j++) { - double scalar_product = 0; - for (k=0; k < A->columns; k++) - scalar_product += A->data[ GET_INDEX(A,i,k) ] * B->data[ GET_INDEX(B,k,j) ]; - - /* Assign first to tmp[j] */ - tmp[j] = scalar_product; - } - for (j=0; j < A->columns; j++) - A->data[ GET_INDEX(A , i, j) ] = tmp[j]; - } - free(tmp); - } else - util_abort("%s: size mismatch: A:[%d,%d] B:[%d,%d]\n",__func__ , matrix_get_rows(A) , matrix_get_columns(A) , matrix_get_rows(B) , matrix_get_columns(B)); -} - -/*****************************************************************/ -/* If the current build has a thread_pool implementation enabled a - proper matrix_implace_matmul_mt() function will be built, otherwise - only the serial version matrix_inplace_matmul() will be used. */ - - -#ifdef ERT_HAVE_THREAD_POOL - -static void * matrix_inplace_matmul_mt__(void * arg) { - - arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); - int row_offset = arg_pack_iget_int( arg_pack , 0 ); - int rows = arg_pack_iget_int( arg_pack , 1 ); - matrix_type * A = (matrix_type*) arg_pack_iget_ptr( arg_pack , 2 ); - const matrix_type * B = (const matrix_type*)arg_pack_iget_const_ptr( arg_pack , 3 ); - - matrix_type * A_view = matrix_alloc_shared( A , row_offset , 0 , rows , matrix_get_columns( A )); - matrix_inplace_matmul( A_view , B ); - matrix_free( A_view ); - return NULL; -} - -/** - Observe that the calling scope is responsible for passing a - thread_pool in suitable state to this function. This implies one of - the following: - - 1. The thread_pool is newly created, with the @start_queue - argument set to false. - - 2. The thread_pool has been joined __without__ an interevening - call to thread_pool_restart(). - - If the thread_pool has not been correctly prepared, according to - this specification, it will be crash and burn. -*/ - -void matrix_inplace_matmul_mt2(matrix_type * A, const matrix_type * B , thread_pool_type * thread_pool){ - int num_threads = thread_pool_get_max_running( thread_pool ); - arg_pack_type ** arglist = (arg_pack_type**)util_malloc( num_threads * sizeof * arglist ); - int it; - thread_pool_restart( thread_pool ); - { - int rows = matrix_get_rows( A ) / num_threads; - int rows_mod = matrix_get_rows( A ) % num_threads; - int row_offset = 0; - - for (it = 0; it < num_threads; it++) { - int row_size; - arglist[it] = arg_pack_alloc(); - row_size = rows; - if (it < rows_mod) - row_size += 1; - - arg_pack_append_int(arglist[it] , row_offset ); - arg_pack_append_int(arglist[it] , row_size ); - arg_pack_append_ptr(arglist[it] , A ); - arg_pack_append_const_ptr(arglist[it] , B ); - - thread_pool_add_job( thread_pool , matrix_inplace_matmul_mt__ , arglist[it]); - row_offset += row_size; - } - } - thread_pool_join( thread_pool ); - - for (it = 0; it < num_threads; it++) - arg_pack_free( arglist[it] ); - free( arglist ); -} - -void matrix_inplace_matmul_mt1(matrix_type * A, const matrix_type * B , int num_threads){ - thread_pool_type * thread_pool = thread_pool_alloc( num_threads , false ); - matrix_inplace_matmul_mt2( A , B , thread_pool ); - thread_pool_free( thread_pool ); -} - -#else - -void matrix_inplace_matmul_mt1(matrix_type * A, const matrix_type * B , int num_threads){ - matrix_inplace_matmul( A , B ); -} - -#endif - - - - -/*****************************************************************/ -/* Row/column functions */ - -double matrix_get_row_sum(const matrix_type * matrix , int row) { - double sum = 0; - int j; - for (j=0; j < matrix->columns; j++) - sum += matrix->data[ GET_INDEX( matrix , row , j ) ]; - return sum; -} - - -double matrix_get_column_sum(const matrix_type * matrix , int column) { - double sum = 0; - int i; - for (i=0; i < matrix->rows; i++) - sum += matrix->data[ GET_INDEX( matrix , i , column ) ]; - return sum; -} - - -double matrix_get_column_abssum(const matrix_type * matrix , int column) { - double sum = 0; - int i; - for (i=0; i < matrix->rows; i++) - sum += fabs( matrix->data[ GET_INDEX( matrix , i , column ) ] ); - return sum; -} - - -double matrix_get_row_sum2(const matrix_type * matrix , int row) { - double sum2 = 0; - int j; - for ( j=0; j < matrix->columns; j++) { - double m = matrix->data[ GET_INDEX( matrix , row , j ) ]; - sum2 += m*m; - } - return sum2; -} - - -double matrix_get_row_abssum(const matrix_type * matrix , int row) { - double sum_abs = 0; - int j; - for ( j=0; j < matrix->columns; j++) { - double m = matrix->data[ GET_INDEX( matrix , row , j ) ]; - sum_abs += fabs( m ); - } - return sum_abs; -} - -/** - Return the sum of the squares on column. -*/ -double matrix_get_column_sum2(const matrix_type * matrix , int column) { - double sum2 = 0; - int i; - for ( i=0; i < matrix->rows; i++) { - double m = matrix->data[ GET_INDEX( matrix , i , column ) ]; - sum2 += m*m; - } - return sum2; -} - - - -void matrix_shift_column(matrix_type * matrix , int column, double shift) { - int i; - for ( i=0; i < matrix->rows; i++) - matrix->data[ GET_INDEX( matrix , i , column) ] += shift; -} - - -void matrix_shift_row(matrix_type * matrix , int row , double shift) { - int j; - for ( j=0; j < matrix->columns; j++) - matrix->data[ GET_INDEX( matrix , row , j ) ] += shift; -} - - - -/** - For each row in the matrix we will do the operation - - R -> R - -*/ - -void matrix_subtract_row_mean(matrix_type * matrix) { - int i; - for ( i=0; i < matrix->rows; i++) { - double row_mean = matrix_get_row_sum(matrix , i) / matrix->columns; - matrix_shift_row( matrix , i , -row_mean); - } -} - -void matrix_subtract_and_store_row_mean(matrix_type * matrix, matrix_type * row_mean) { - int i; - for ( i=0; i < matrix->rows; i++) { - double mean = matrix_get_row_sum(matrix , i) / matrix->columns; - matrix_shift_row( matrix , i , -mean); - matrix_iset(row_mean , i , 0, mean ); - } -} - -void matrix_imul_col( matrix_type * matrix , int column , double factor) { - int i; - for ( i=0; i < matrix->rows; i++) - matrix_imul( matrix , i , column , factor ); -} - - -/*****************************************************************/ -/** - This function will return the double data pointer of the matrix, - when you use this explicitly you ARE ON YOUR OWN. -*/ - -double * matrix_get_data(const matrix_type * matrix) { - return matrix->data; -} - -/** - The query functions below can be used to ask for the dimensions & - strides of the matrix. -*/ - -int matrix_get_rows(const matrix_type * matrix) { - return matrix->rows; -} - -int matrix_get_columns(const matrix_type * matrix) { - return matrix->columns; -} - -int matrix_get_row_stride(const matrix_type * matrix) { - return matrix->row_stride; -} - -int matrix_get_column_stride(const matrix_type * matrix) { - return matrix->column_stride; -} - - -void matrix_get_dims(const matrix_type * matrix , int * rows , int * columns , int * row_stride , int * column_stride) { - - *rows = matrix->rows; - *columns = matrix->columns; - *row_stride = matrix->row_stride; - *column_stride = matrix->column_stride; - -} - - -bool matrix_is_quadratic(const matrix_type * matrix) { - if (matrix->rows == matrix->columns) - return true; - else - return false; -} - -/** - Goes through all the elements in the matrix - and return true if they are all finite. -*/ - -#ifdef ERT_HAVE_ISFINITE - -bool matrix_is_finite(const matrix_type * matrix) { - int i,j; - for (i = 0; i < matrix->rows; i++) - for (j =0; j< matrix->columns; j++) - if ( !isfinite( matrix->data[ GET_INDEX( matrix , i , j) ])) { - printf("%s(%d,%d) = %g \n",matrix->name , i,j,matrix->data[ GET_INDEX( matrix , i , j) ]); - return false; - } - - return true; -} - -void matrix_assert_finite( const matrix_type * matrix ) { - if (!matrix_is_finite( matrix )) { - if ((matrix->rows * matrix->columns) < 400) - matrix_pretty_fprint( matrix , matrix->name , " %6.3f" , stdout); - - util_abort("%s: matrix:%s is not finite. \n",__func__ , matrix->name); - } -} - -#endif - - - -/** - This function will return the largest deviance from orthonormal - conditions for the matrix - i.e. when this function returns - 0.000000 the matrix is perfectly orthonormal; otherwise it is the - responsability of the calling scope to evaluate. -*/ - -double matrix_orthonormality( const matrix_type * matrix ) { - double max_dev = 0.0; - int col1,col2; - for (col1=0; col1 < matrix->columns; col1++) { - for (col2=col1; col2 < matrix->columns; col2++) { - double dot_product = matrix_column_column_dot_product( matrix , col1 , matrix , col2); - double dev; - - if (col1 == col2) - dev = fabs( dot_product - 1.0 ); - else - dev = fabs( dot_product ); - - if (dev > max_dev) - max_dev = dev; - } - } - return max_dev; -} - - - - - -/** - Return true if the two matrices m1 and m2 are equal. The equality - test is based on element-by-element memcmp() comparison, i.e. the - there is ZERO numerical tolerance in the comparison. - - If the two matrices do not have equal dimension false is returned. -*/ - -bool matrix_equal( const matrix_type * m1 , const matrix_type * m2) { - if (! ((m1->rows == m2->rows) && (m1->columns == m2->columns))) - return false; - { - int i,j; - for (i=0; i < m1->rows; i++) { - for (j=0; j < m1->columns; j++) { - int index1 = GET_INDEX(m1 , i , j); - int index2 = GET_INDEX(m2 , i , j); - double d1 = m1->data[ index1 ]; - double d2 = m2->data[ index2 ]; - - if (d1 != d2) - return false; - } - } - } - - /** OK - we came all the way through - they are equal. */ - return true; -} - - -bool matrix_columns_equal( const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2) { - if (m1->rows != m2->rows) - return false; - - { - int row; - for (row=0; row < m1->rows; row++) { - if (memcmp( &m1->data[ GET_INDEX(m1 , row , col1)] , &m2->data[ GET_INDEX(m2 , row , col2)] , sizeof * m1->data) != 0) - return false; - } - } - - return true; -} - - -/*****************************************************************/ -/* Various special matrices */ - - -/** - Will set the diagonal elements in matrix to the values in diag, - and all remaining elements to zero. Assumes that matrix is - rectangular. -*/ - -void matrix_diag_set(matrix_type * matrix , const double * diag) { - if (matrix->rows == matrix->columns) { - int i; - matrix_set(matrix , 0); - for ( i=0; i < matrix->rows; i++) - matrix->data[ GET_INDEX(matrix , i , i) ] = diag[i]; - } else - util_abort("%s: size mismatch \n",__func__); -} - - -/** - Will set the scalar @value on all the diagonal elements of the - matrix; all off-diagonal elements are explicitly set to zero. -*/ - -void matrix_diag_set_scalar(matrix_type * matrix , double value) { - if (matrix->rows == matrix->columns) { - int i; - matrix_set(matrix , 0); - for ( i=0; i < matrix->rows; i++) - matrix->data[ GET_INDEX(matrix , i , i) ] = value; - } else - util_abort("%s: size mismatch \n",__func__); -} - - -void matrix_scalar_set( matrix_type * matrix , double value) { - int i,j; - for (j=0; j < matrix->columns; j++) - for (i=0; i < matrix->rows; i++) - matrix->data[ GET_INDEX(matrix , i , j) ] = value; -} - - - -/** - Fills the matrix with uniformly distributed random numbers in - [0,1). -*/ - -void matrix_random_init(matrix_type * matrix , rng_type * rng) { - int i,j; - for (j=0; j < matrix->columns; j++) - for (i=0; i < matrix->rows; i++) - matrix->data[ GET_INDEX(matrix , i , j) ] = rng_get_double( rng ); -} - - - -void matrix_clear( matrix_type * matrix ) { - matrix_set( matrix , 0 ); -} - - - -/** - This function dumps the following binary file: - - rows - columns - data(1,1) - data(2,1) - data(3,1) - .... - data(1,2) - data(2,2) - .... - - Not exactly a matlab format. - - The following matlab code can be used to instatiate a matrix based - on the file: - - function m = load_matrix(filename) - fid = fopen(filename); - dims = fread(fid , 2 , 'int32'); - m = fread(fid , [dims(1) , dims(2)] , 'double'); - fclose(fid); - - - >> A = load_matrix( 'filename' ); -*/ - - -void matrix_matlab_dump(const matrix_type * matrix, const char * filename) { - FILE * stream = util_fopen( filename , "w"); - int i,j; - util_fwrite_int( matrix->rows , stream); - util_fwrite_int( matrix->columns , stream); - - for (j=0; j < matrix->columns; j++) - for (i=0; i < matrix->rows; i++) - util_fwrite_double( matrix->data[ GET_INDEX(matrix , i , j) ] , stream); - - fclose(stream); -} - - -// Comment -void matrix_inplace_diag_sqrt(matrix_type *Cd) -{ - int nrows = Cd->rows; - - if (Cd->rows != Cd->columns) { - util_abort("%s: size mismatch \n",__func__); - } - else{ - int i; - for ( i=0; idata[GET_INDEX(Cd , i , i)] = sqrt(Cd->data[GET_INDEX(Cd , i , i)]); - } - } -} - - - -double matrix_trace(const matrix_type *matrix) { - - int nrows = matrix->rows; - double sum = 0; - - if (matrix->rows != matrix->columns) { - util_abort("%s: matrix is not square \n",__func__); - } - else{ - int i; - for ( i=0; idata[GET_INDEX(matrix , i , i)]; - } - } - return sum; -} - - -bool matrix_check_dims( const matrix_type * m , int rows , int columns) { - if (m) { - if ((m->rows == rows) && (m->columns == columns)) - return true; - else - return false; - } else { - util_abort("%s: internal error - trying to dereference NULL matrix pointer \n",__func__); - return false; - } -} - - -double matrix_diag_std(const matrix_type * Sk,double mean) -{ - - if (Sk->rows != Sk->columns) { - util_abort("%s: matrix is not square \n",__func__); - return 0; - } - else{ - int nrows = Sk->rows; - double std = 0; - int i; - - for ( i=0; idata[GET_INDEX(Sk , i , i)] - mean; - std += d*d; - } - - - std = sqrt(std / nrows); - return std; - } -} - -/** - The matrix_det3() and matrix_det4() are explicit implementations of - the determinant of a 3x3 and 4x4 matrices. The ecl_grid class uses - these determinants determine whether a point is inside a cell. By - using this explicit implementation the ecl_grid library has no - LAPACK dependency. -*/ - -double matrix_det2( const matrix_type * A) { - if ((A->rows == 2) && (A->columns == 2)) { - double a00 = A->data[GET_INDEX(A,0,0)]; - double a01 = A->data[GET_INDEX(A,0,1)]; - double a10 = A->data[GET_INDEX(A,1,0)]; - double a11 = A->data[GET_INDEX(A,1,1)]; - - return a00 * a11 - a10 * a01; - } else { - util_abort("%s: hardcoded for 2x2 matrices A is: %d x %d \n",__func__, A->rows , A->columns); - return 0; - } -} - -double matrix_det3( const matrix_type * A) { - if ((A->rows == 3) && (A->columns == 3)) { - double a = A->data[GET_INDEX(A,0,0)]; - double b = A->data[GET_INDEX(A,0,1)]; - double c = A->data[GET_INDEX(A,0,2)]; - - double d = A->data[GET_INDEX(A,1,0)]; - double e = A->data[GET_INDEX(A,1,1)]; - double f = A->data[GET_INDEX(A,1,2)]; - - double g = A->data[GET_INDEX(A,2,0)]; - double h = A->data[GET_INDEX(A,2,1)]; - double i = A->data[GET_INDEX(A,2,2)]; - - return a*e*i + b*f*g + c*d*h - c*e*g - b*d*i - a*f*h; - } else { - util_abort("%s: hardcoded for 3x3 matrices A is: %d x %d \n",__func__, A->rows , A->columns); - return 0; - } -} - - -double matrix_det4( const matrix_type * A) { - if ((A->rows == 4) && (A->columns == 4)) { - double a00 = A->data[GET_INDEX(A,0,0)]; - double a01 = A->data[GET_INDEX(A,0,1)]; - double a02 = A->data[GET_INDEX(A,0,2)]; - double a03 = A->data[GET_INDEX(A,0,3)]; - double a10 = A->data[GET_INDEX(A,1,0)]; - double a11 = A->data[GET_INDEX(A,1,1)]; - double a12 = A->data[GET_INDEX(A,1,2)]; - double a13 = A->data[GET_INDEX(A,1,3)]; - double a20 = A->data[GET_INDEX(A,2,0)]; - double a21 = A->data[GET_INDEX(A,2,1)]; - double a22 = A->data[GET_INDEX(A,2,2)]; - double a23 = A->data[GET_INDEX(A,2,3)]; - double a30 = A->data[GET_INDEX(A,3,0)]; - double a31 = A->data[GET_INDEX(A,3,1)]; - double a32 = A->data[GET_INDEX(A,3,2)]; - double a33 = A->data[GET_INDEX(A,3,3)]; - - /* - double det = (a00*(a11*(a22*a33 - a23*a32)-a12*(a21*a33 - a23*a31)+a13*(a21*a32 - a22*a31)) - - a01*(a10*(a22*a33 - a23*a32)-a12*(a20*a33 - a23*a30)+a13*(a20*a32 - a22*a30)) + - a02*(a10*(a21*a33 - a23*a31)-a11*(a20*a33 - a23*a30)+a13*(a20*a31 - a21*a30)) - - a03*(a10*(a21*a32 - a22*a31)-a11*(a20*a32 - a22*a30)+a12*(a20*a31 - a21*a30))); - */ - double det = 0; - - { - double factors[24] = { a00*a12*a23*a31, - a00*a13*a21*a32, - a00*a11*a22*a33, - a01*a10*a23*a32, - a01*a12*a20*a33, - a01*a13*a22*a30, - a02*a10*a21*a33, - a02*a11*a23*a30, - a02*a13*a20*a31, - a03*a10*a22*a31, - a03*a11*a20*a32, - a03*a12*a21*a30 - -a02*a13*a21*a30, - -a03*a10*a21*a32, - -a03*a11*a22*a30, - -a03*a12*a20*a31, - -a00*a11*a23*a32, - -a00*a12*a21*a33, - -a00*a13*a22*a31, - -a01*a10*a22*a33, - -a01*a12*a23*a30, - -a01*a13*a20*a32, - -a02*a10*a23*a31, - -a02*a11*a20*a33}; - int i; - - for (i = 0; i < 12; i++) - det += (factors[i] + factors[i + 12]); - } - - return det; - } else { - util_abort("%s: hardcoded for 4x4 matrices A is: %d x %d \n",__func__, A->rows , A->columns); - return 0; - } -} - - -#ifdef __cplusplus -} -#endif diff --git a/ThirdParty/Ert/lib/util/matrix_blas.c b/ThirdParty/Ert/lib/util/matrix_blas.c deleted file mode 100644 index 2ac5438433..0000000000 --- a/ThirdParty/Ert/lib/util/matrix_blas.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'matrix_blas.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/*****************************************************************/ -void dgemm_(char * , char * , int * , int * , int * , double * , double * , int * , double * , int * , double * , double * , int *); -void dgemv_(char * , int * , int * , double * , double * , int * , const double * , int * , double * , double * , int * ); -/*****************************************************************/ - - - -/** - y = alpha * op(A)*x + beta * y - - alpha,beta: scalars - x,y : vectors - A : matrix - - - x and y are entered as (double * ). -*/ - - -void matrix_dgemv(const matrix_type * A , const double *x , double * y, bool transA , double alpha , double beta) { - int m = matrix_get_rows( A ); - int n = matrix_get_columns( A ); - int lda = matrix_get_column_stride( A ); - int incx = 1; - int incy = 1; - - char transA_c; - if (transA) - transA_c = 'T'; - else - transA_c = 'N'; - - dgemv_(&transA_c , &m , &n , &alpha , matrix_get_data( A ) , &lda , x , &incx , &beta , y , &incy); -} - - -/** - y = A*x -*/ - -void matrix_mul_vector(const matrix_type * A , const double * x , double * y) { - matrix_dgemv(A , x , y , false , 1 , 0); -} - - - -static void dgemm_debug(const matrix_type *C , const matrix_type *A , const matrix_type * B , bool transA, bool transB) { - printf("\nC = [%d , %d]\n",matrix_get_rows( C ) , matrix_get_columns(C)); - - printf("A: [%d , %d]", matrix_get_rows( A ) , matrix_get_columns(A)); - if (transA) - printf("^T"); - - printf("\nB: [%d , %d]", matrix_get_rows( B ) , matrix_get_columns(B)); - if (transB) - printf("^T"); - - printf("\n\n"); - printf("[%d ,%d] = ",matrix_get_rows( C ) , matrix_get_columns(C)); - if (transA) - printf("[%d ,%d] x ",matrix_get_rows( A ) , matrix_get_columns(A)); - else - printf("[%d ,%d] x ",matrix_get_columns( A ) , matrix_get_rows(A)); - - - if (transB) - printf("[%d ,%d]\n",matrix_get_rows( B ) , matrix_get_columns(B)); - else - printf("[%d ,%d]\n",matrix_get_columns( B ) , matrix_get_rows(B)); - - -} - - - -/** - C = alpha * op(A) * op(B) + beta * C - - op(·) can either be unity or Transpose. -*/ - -void matrix_dgemm(matrix_type *C , const matrix_type *A , const matrix_type * B , bool transA, bool transB , double alpha , double beta) { - int m = matrix_get_rows( C ); - int n = matrix_get_columns( C ); - int lda = matrix_get_column_stride( A ); - int ldb = matrix_get_column_stride( B ); - int ldc = matrix_get_column_stride( C ); - char transA_c; - char transB_c; - int k , innerA, innerB , outerA , outerB; - - if (transA) - k = matrix_get_rows( A ); - else - k = matrix_get_columns( A ); - - - if (transA) { - innerA = matrix_get_rows(A); - outerA = matrix_get_columns(A); - transA_c = 'T'; - } else { - innerA = matrix_get_columns(A); - outerA = matrix_get_rows(A); - transA_c = 'N'; - } - - - if (transB) { - innerB = matrix_get_columns( B ); - outerB = matrix_get_rows( B ); - transB_c = 'T'; - } else { - transB_c = 'N'; - innerB = matrix_get_rows( B ); - outerB = matrix_get_columns( B ); - } - - /* - This is the dimension check which must pass: - - -------------------------------------------------- - A | B | Columns(A) = Rows(B) - Trans(A) | Trans(B) | Rows(A) = Columns(B) - A | Trans(B) | Columns(A) = Columns(B) - Trans(A) | B | Rows(A) = Rows(B) - -------------------------------------------------- - - -------------------------------------------------- - A | Rows(A) = Rows(C) - Trans(A) | Columns(A) = Rows(C) - B | Columns(B) = Columns(C) - Trans(B) | Rows(B) = Columns(B) - -------------------------------------------------- - - */ - - if (innerA != innerB) { - dgemm_debug(C,A,B,transA , transB); - util_abort("%s: matrix size mismatch between A and B \n", __func__); - } - - - if (outerA != matrix_get_rows( C )) { - dgemm_debug(C,A,B,transA , transB); - printf("outerA:%d rows(C):%d \n",outerA , matrix_get_rows( C )); - util_abort("%s: matrix size mismatch between A and C \n",__func__); - } - - - if (outerB != matrix_get_columns( C )) { - dgemm_debug(C,A,B,transA , transB); - util_abort("%s: matrix size mismatch between B and C \n",__func__); - } - - if (ldc < util_int_max(1 , m)) { - dgemm_debug(C,A,B,transA , transB); - fprintf(stderr,"Tried to capture blas message: \"** On entry to DGEMM parameter 13 had an illegal value\"\n"); - fprintf(stderr,"m:%d ldc:%d ldc should be >= max(1,%d) \n",m,ldc,m); - util_abort("%s: invalid value for ldc\n",__func__); - } - - - dgemm_(&transA_c , // 1 - &transB_c , // 2 - &m , // 3 - &n , // 4 - &k , // 5 - &alpha , // 6 - matrix_get_data( A ) , // 7 - &lda , // 8 - matrix_get_data( B ) , // 9 - &ldb , // 10 - &beta , // 11 - matrix_get_data( C ) , // 12 - &ldc); // 13 -} - - - -void matrix_matmul_with_transpose(matrix_type * C, const matrix_type * A , const matrix_type * B , bool transA , bool transB) { - matrix_dgemm( C , A , B , transA , transB , 1 , 0); -} - - -/* - This function does a general matrix multiply of A * B, and stores - the result in C. -*/ - -void matrix_matmul(matrix_type * C, const matrix_type * A , const matrix_type * B) { - matrix_dgemm( C , A , B , false , false , 1 , 0); -} - - -/** - Allocates new matrix C = A·B -*/ - -matrix_type * matrix_alloc_matmul(const matrix_type * A, const matrix_type * B) { - matrix_type * C = matrix_alloc( matrix_get_rows( A ) , matrix_get_columns( B )); - matrix_matmul( C , A , B ); - return C; -} - - - - - -/*****************************************************************/ -/** - Will calculate the Gram matrix: G = X'*X -*/ - -void matrix_gram_set( const matrix_type * X , matrix_type * G, bool col) { - int G_rows = matrix_get_rows( G ); - int G_cols = matrix_get_columns( G ); - int X_rows = matrix_get_rows( X ); - int X_cols = matrix_get_columns( X ); - if (col) { - // Calculate X' · X - if ((G_rows == G_cols) && (X_cols == G_rows)) - matrix_dgemm( G , X , X , true , false , 1 , 0); - else - util_abort("%s: dimension mismatch \n",__func__); - } else { - // Calculate X · X' - if ((G_rows == G_cols) && (X_rows == G_rows)) - matrix_dgemm( G , X , X , false , true , 1 , 0); - else - util_abort("%s: dimension mismatch \n",__func__); - } -} - - -/** - If col == true: G = X' · X - col == false: G = X · X' -*/ - - -matrix_type * matrix_alloc_gram( const matrix_type * X , bool col) { - int X_rows = matrix_get_rows( X ); - int X_columns = matrix_get_columns( X ); - matrix_type * G; - - if (col) - G = matrix_alloc( X_columns , X_columns ); - else - G = matrix_alloc( X_rows , X_rows ); - - matrix_gram_set( X , G , col); - return G; -} - -#ifdef __cplusplus -} -#endif diff --git a/ThirdParty/Ert/lib/util/matrix_lapack.c b/ThirdParty/Ert/lib/util/matrix_lapack.c deleted file mode 100644 index 2a62b0fcbd..0000000000 --- a/ThirdParty/Ert/lib/util/matrix_lapack.c +++ /dev/null @@ -1,640 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'matrix_lapack.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - The external lapack routines -*/ -/*****************************************************************/ -void dgesv_(int * n, - int * nrhs, - double * A, - int * lda, - long int * ipivot, - double * B, - int * ldb, - int * info); -void dgesvd_(char * jobu, - char * jobvt, - int * m, - int * n, - double * A, - int * lda, - double * S, - double * U, - int * ldu, - double * VT, - int * ldvt, - double * work, - int * worksize, - int * info); -void dsyevx_(char * jobz, - char * range, - char * uplo, - int *n, - double * A, - int * lda, - double * vl, - double * vu, - int * il, - int * iu, - double * abstol, - int * m, - double * w, - double *z, - int * ldz, - double * work, - int * lwork, - int * iwork, - int * ifail, - int * info); -void dgeqrf_(int * m, - int * n, - double * A, - int * lda, - double * tau, - double * work, - int * lwork, - int * info); -void dorgqr_(int * m, - int * n, - int * k, - double * A, - int * lda, - double * tau, - double * work, - int * lwork, - int * info); -void dgetrf_(int * M, - int * n, - double * A, - int * lda, - int * ipiv, - int * info); -void dgedi_(double * A, - int * lda, - int * n, - int * ipiv, - double * det, - double * work, - int * job); -void dgetri_(int * n, - double * A, - int * lda, - int * ipiv, - double * work, - int * work_size, - int * info); -/*****************************************************************/ - - - - - - -/** - This file implements (very thin) interfaces for the matrix_type to - some lapack functions. The file does not contain any data - structures, only functions. -*/ - - - -static void matrix_lapack_assert_fortran_layout( const matrix_type * matrix ) { - int rows, columns, row_stride , column_stride; - matrix_get_dims( matrix , &rows , &columns , &row_stride , &column_stride); - if (!( (column_stride >= rows) && (row_stride == 1))) - util_abort("%s: lapack routines require Fortran layout of memory - aborting \n",__func__); -} - - -static void matrix_lapack_assert_square(const matrix_type * matrix) { - matrix_lapack_assert_fortran_layout(matrix ); - { - int rows, columns, row_stride , column_stride; - matrix_get_dims( matrix , &rows , &columns , &row_stride , &column_stride); - if (rows != columns) - util_abort("%s: must have square matrices \n",__func__); - } -} - - -/*****************************************************************/ -/** - Solves the linear equations Ax = B. The solution is stored in B on - return. -*/ - - -void matrix_dgesv(matrix_type * A , matrix_type * B) { - matrix_lapack_assert_square( A ); - matrix_lapack_assert_fortran_layout( B ); - { - int n = matrix_get_rows( A ); - int lda = matrix_get_column_stride( A ); - int ldb = matrix_get_column_stride( B ); - int nrhs = matrix_get_columns( B ); - long int * ipivot = (long int*)util_calloc( n , sizeof * ipivot ); - int info; - - dgesv_(&n , &nrhs , matrix_get_data( A ) , &lda , ipivot , matrix_get_data( B ), &ldb , &info); - if (info != 0) - util_abort("%s: low level lapack routine: dgesv() failed with info:%d \n",__func__ , info); - free(ipivot); - } -} - - -/*****************************************************************/ -/** - Singular Value Decomposition -*/ - - -/** - This little function translates between an integer identifier - (i.e. and enum instance) to one of the characters used by the low - level lapack routine to indicate how the singular vectors should be - returned to the calling scope. - - The meaning of the different enum values is documented in the enum - definition in the header file matrix_lapack.h. -*/ - -static char dgesvd_get_vector_job( dgesvd_vector_enum vector_job) { - char job = 'X'; - switch (vector_job) { - case(DGESVD_ALL): - job = 'A'; - break; - case(DGESVD_MIN_RETURN): - job = 'S'; - break; - case(DGESVD_MIN_OVERWRITE): - job = 'O'; - break; - case(DGESVD_NONE): - job = 'N'; - break; - default: - util_abort("%s: internal error - unrecognized code:%d \n",vector_job); - } - return job; -} - - - -/** - If jobu == DGSEVD_NONE the U matrix can be NULL, same for jobvt. -*/ - -void matrix_dgesvd(dgesvd_vector_enum jobu , dgesvd_vector_enum jobvt , matrix_type * A , double * S , matrix_type * U , matrix_type * VT) { - char _jobu = dgesvd_get_vector_job( jobu ); - char _jobvt = dgesvd_get_vector_job( jobvt ); - int m = matrix_get_rows( A ); - int n = matrix_get_columns( A ); - int lda = matrix_get_column_stride( A ); - int ldu, ldvt; - double * VT_data , *U_data; - int info = 0; - int min_worksize = util_int_max(3* util_int_min(m , n) + util_int_max(m , n) , 5 * util_int_min(m , n)); - double * work; - int worksize; - - - if (U == NULL) { - ldu = 1; - U_data = NULL; - if (jobu != DGESVD_NONE) - util_abort("%s: internal error \n",__func__); - } else { - ldu = matrix_get_column_stride( U ); - U_data = matrix_get_data( U ); - if (jobu == DGESVD_NONE) - util_abort("%s: internal error \n",__func__); - } - - if (VT == NULL) { - ldvt = 1; /* Will fail if set to zero */ - VT_data = NULL; - if (jobvt != DGESVD_NONE) - util_abort("%s: internal error \n",__func__); - } else { - ldvt = matrix_get_column_stride( VT ); - VT_data = matrix_get_data( VT ); - if (jobvt == DGESVD_NONE) - util_abort("%s: internal error \n",__func__); - } - - /* - Query the routine for optimal worksize. - */ - - work = (double*)util_calloc( 1 , sizeof * work ); - worksize = -1; - dgesvd_(&_jobu , /* 1 */ - &_jobvt , /* 2 */ - &m , /* 3 */ - &n , /* 4 */ - matrix_get_data( A ) , /* 5 */ - &lda , /* 6 */ - S , /* 7 */ - U_data , /* 8 */ - &ldu , /* 9 */ - VT_data , /* 10 */ - &ldvt , /* 11 */ - work , /* 12 */ - &worksize , /* 13 */ - &info); /* 14 */ - - - /* Try to allocate optimal worksize. */ - worksize = (int) work[0]; - double * tmp = (double*)realloc( work , sizeof * work * worksize ); - if (tmp == NULL) { - /* Could not allocate optimal worksize - settle for the minimum. This can not fail. */ - worksize = min_worksize; - free(work); - work = (double*)util_calloc( worksize , sizeof * work ); - }else{ - work = tmp; /* The request for optimal worksize succeeded */ - } - - dgesvd_(&_jobu , &_jobvt , &m , &n , matrix_get_data( A ) , &lda , S , U_data , &ldu , VT_data , &ldvt , work , &worksize , &info); - free( work ); -} - - - -/******************************************************************/ -/* Eigenvalues of a symmetric matrix */ -/* Return value is the number of eigenvalues found. */ -/******************************************************************/ - -int matrix_dsyevx(bool compute_eig_vectors , - dsyevx_eig_enum which_values , /* DSYEVX | DSYEVX_VALUE_INTERVAL | DSYEVX_INDEX_INTERVAL */ - dsyevx_uplo_enum uplo, - matrix_type * A , /* The input matrix - is modified by the dsyevx() function. */ - double VL , /* Lower limit when using DSYEVX_VALUE_INTERVAL */ - double VU , /* Upper limit when using DSYEVX_VALUE_INTERVAL */ - int IL , /* Lower index when using DSYEVX_INDEX_INTERVAL */ - int IU , /* Upper index when using DSYEVX_INDEX_INTERVAL */ - double *eig_values , /* The calcualated eigenvalues */ - matrix_type * Z ) { /* The eigenvectors as columns vectors */ - - int lda = matrix_get_column_stride( A ); - int n = matrix_get_rows( A ); - char jobz; - char range; - char uplo_c; - - if (compute_eig_vectors) - jobz = 'V'; - else - jobz = 'N'; - - switch(which_values) { - case(DSYEVX_ALL): - range = 'A'; - break; - case(DSYEVX_VALUE_INTERVAL): - range = 'V'; - break; - case(DSYEVX_INDEX_INTERVAL): - range = 'I'; - break; - default: - util_abort("%s: internal error \n",__func__); - } - - if (uplo == DSYEVX_AUPPER) - uplo_c = 'U'; - else if (uplo == DSYEVX_ALOWER) - uplo_c = 'L'; - else - util_abort("%s: internal error \n",__func__); - - - if (!matrix_is_quadratic( A )) - util_abort("%s: matrix A must be quadratic \n",__func__); - - { - int num_eigenvalues , ldz, info , worksize; - int * ifail = (int*) util_calloc( n , sizeof * ifail ); - int * iwork = (int*) util_calloc( 5 * n , sizeof * iwork ); - double * work = (double*)util_calloc( 1 , sizeof * work ); - double * z_data; - double abstol = 0.0; /* SHopuld */ - - - if (compute_eig_vectors) { - ldz = matrix_get_column_stride( Z ); - z_data = matrix_get_data( Z ); - } else { - /* In this case we can accept that Z == NULL */ - ldz = 1; - z_data = NULL; - } - - /* First call to determine optimal worksize. */ - worksize = -1; - info = 0; - dsyevx_( &jobz, /* 1 */ - &range, /* 2 */ - &uplo_c, /* 3 */ - &n, /* 4 */ - matrix_get_data( A ), /* 5 */ - &lda , /* 6 */ - &VL , /* 7 */ - &VU , /* 8 */ - &IL , /* 9 */ - &IU , /* 10 */ - &abstol , /* 11 */ - &num_eigenvalues , /* 12 */ - eig_values , /* 13 */ - z_data , /* 14 */ - &ldz , /* 15 */ - work , /* 16 */ - &worksize , /* 17 */ - iwork , /* 18 */ - ifail , /* 19 */ - &info); /* 20 */ - - - worksize = (int) work[0]; - { - double * tmp = (double*)realloc(work , sizeof * work * worksize ); - if (tmp == NULL) { - /* - OK - we could not get the optimal worksize, - try again with the minimum. - */ - worksize = 8 * n; - work = (double*)util_realloc(work , sizeof * work * worksize ); - } else - work = tmp; /* The request for optimal worksize succeeded */ - } - /* Second call: do the job */ - info = 0; - dsyevx_( &jobz, - &range, - &uplo_c, - &n, - matrix_get_data( A ), - &lda , - &VL , - &VU , - &IL , - &IU , - &abstol , - &num_eigenvalues , - eig_values , - z_data , - &ldz , - work , - &worksize , - iwork , - ifail , - &info); - - free( ifail ); - free( work ); - free( iwork ); - return num_eigenvalues; - } -} - - -/** - Wrapper function to compute all eigenvalues + eigenvectors with the - matrix_dsyevx() function. -*/ - -int matrix_dsyevx_all(dsyevx_uplo_enum uplo, - matrix_type * A , /* The input matrix - is modified by the dsyevx() function. */ - double *eig_values , /* The calcualated eigenvalues */ - matrix_type * Z ) { /* The eigenvectors as columns vectors */ - int num_eigenvalues; - num_eigenvalues = matrix_dsyevx(true , DSYEVX_ALL , uplo , A , 0,0,0,0, eig_values , Z); - return num_eigenvalues; - -} - - - -/*****************************************************************/ -/* Function to compute QR factorization withe the routine dgeqrf */ - -void matrix_dgeqrf(matrix_type * A , double * tau) { - int lda = matrix_get_column_stride( A ); - int m = matrix_get_rows( A ); - int n = matrix_get_columns( A ); - double * work = (double*)util_calloc(1 , sizeof * work ); - int worksize; - int info; - - - /* Determine optimal worksize. */ - worksize = -1; - dgeqrf_(&m , &n , matrix_get_data( A ), &lda , tau , work , &worksize , &info); - if (info != 0) - util_abort("%s: dgerqf routine failed with info:%d \n",__func__ , info); - worksize = ( int ) work[0]; - { - double * tmp = (double*)realloc(work , sizeof * work * worksize ); - if (tmp == NULL) { - /* - OK - we could not get the optimal worksize, - try again with the minimum. - */ - worksize = n; - work = (double*)util_realloc(work , sizeof * work * worksize ); - } else - work = tmp; /* The request for optimal worksize succeeded */ - } - - - /* Second call - do the actual computation. */ - dgeqrf_(&m , &n , matrix_get_data( A ), &lda , tau , work , &worksize , &info); - if (info != 0) - util_abort("%s: dgerqf routine failed with info:%d \n",__func__ , info); - free( work ); -} - - -/** - Typically to be used after the matrix_dgeqrf() function to construct a orthormal matrix. -*/ - -void matrix_dorgqr(matrix_type * A , double * tau, int num_reflectors) { /* num_reflectors == length of tau. */ - int lda = matrix_get_column_stride( A ); - int m = matrix_get_rows( A ); - int n = matrix_get_columns( A ); - double * work = (double*)util_malloc(sizeof * work ); - int worksize; - int info; - - - /* Determine optimal worksize. */ - worksize = -1; - dorgqr_(&m , &n , &num_reflectors , matrix_get_data( A ), &lda , tau , work , &worksize , &info); - if (info != 0) - util_abort("%s: dorgqf routine failed with info:%d \n",__func__ , info); - worksize = ( int ) work[0]; - { - double * tmp = (double*)realloc(work , sizeof * work * worksize ); - if (tmp == NULL) { - /* - OK - we could not get the optimal worksize, - try again with the minimum. - */ - worksize = n; - work = (double*)util_realloc(work , sizeof * work * worksize ); - } else - work = tmp; /* The request for optimal worksize succeeded */ - } - - - /* Second call - do the actual computation. */ - dorgqr_(&m , &n , &num_reflectors , matrix_get_data( A ), &lda , tau , work , &worksize , &info); - if (info != 0) - util_abort("%s: dorqf routine failed with info:%d \n",__func__ , info); - free( work ); -} - -/*****************************************************************/ - -/*****************************************************************/ -/* Factorization */ - -/* Currently only used as 'support' function for the matrix_det function. */ -static void matrix_dgetrf__( matrix_type * A, int * ipiv, int * info) { - int lda = matrix_get_column_stride( A ); - int m = matrix_get_rows( A ); - int n = matrix_get_columns( A ); - - dgetrf_( &m , &n , matrix_get_data( A ) , &lda , ipiv , info); -} - - -/** - Calculated the determinant of A. The matrix content will be - destroyed. -*/ - -double matrix_det( matrix_type *A ) { - matrix_lapack_assert_square( A ); - { - - int dgetrf_info; - double det = 1; - double det_scale = 0; - int n = matrix_get_columns( A ); - int * ipiv = (int*)util_malloc( n * sizeof * ipiv ); - matrix_dgetrf__( A , ipiv , &dgetrf_info ); - { - int i; - for (i=0; i < n; i++) { - det *= matrix_iget(A , i , i); - if (det == 0) return 0; /* Holy fuck - a float == comparison ?? */ - - if (ipiv[i] != (i + 1)) /* A permutation has taken place. */ - det *= -1; - - - /* Try to avoid overflow/underflow by factoring out the order of magnitude. */ - while (fabs(det) > 10.0) { - det /= 10; - det_scale += 1; - } - - while (fabs(det) < 1.0) { - det *= 10; - det_scale -= 1; - } - } - } - - free( ipiv ); - return det * pow(10 , det_scale ); - } -} - - - - - -/*****************************************************************/ -/* The matrix will be inverted in-place, the inversion is based on LU - factorisation in the routine matrix_dgetrf__( ). - - The return value: - - =0 : Success - >0 : Singular matrix - <0 : Invalid input -*/ - - - - -int matrix_inv( matrix_type * A ) { - matrix_lapack_assert_square( A ); - { - int dgetrf_info; - int info; - int n = matrix_get_columns( A ); - int * ipiv = (int*)util_malloc( n * sizeof * ipiv ); - matrix_dgetrf__( A , ipiv , &dgetrf_info ); - { - int lda = matrix_get_column_stride( A ); - double * work = (double*)util_malloc( sizeof * work ); - int work_size; - - /* First call: determine optimal worksize: */ - work_size = -1; - dgetri_( &n , matrix_get_data( A ), &lda , ipiv , work , &work_size , &info); - - if (info == 0) { - work_size = (int) work[0]; - work = (double*)util_realloc( work , sizeof * work * work_size ); - dgetri_( &n , matrix_get_data( A ), &lda , ipiv , work , &work_size , &info); - } else - util_abort("%s: dgetri_ returned info:%d \n",__func__ , info); - - free( work ); - } - free( ipiv ); - return info; - } -} - - -#ifdef __cplusplus -} -#endif - diff --git a/ThirdParty/Ert/lib/util/matrix_stat.c b/ThirdParty/Ert/lib/util/matrix_stat.c deleted file mode 100644 index d8b47300f5..0000000000 --- a/ThirdParty/Ert/lib/util/matrix_stat.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - Copyright (C) 2015 Statoil ASA, Norway. - - The file 'matrix_stat.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - - -llsq_result_enum matrix_stat_llsq_estimate( matrix_type * beta , const matrix_type * X0 , const matrix_type * Y0 , const matrix_type * S) { - if (matrix_get_rows( beta ) != matrix_get_columns( X0 )) - return LLSQ_INVALID_DIM; - - if (matrix_get_rows( X0 ) != matrix_get_rows( Y0 )) - return LLSQ_INVALID_DIM; - - if (S && matrix_get_rows( S ) != matrix_get_rows( Y0 )) - return LLSQ_INVALID_DIM; - - if (matrix_get_rows(beta) > matrix_get_rows( X0 )) - return LLSQ_UNDETERMINED; - - { - int num_data = matrix_get_rows( X0 ); - int num_var = matrix_get_columns( X0 ); - matrix_type * XX = matrix_alloc( num_var , num_var ); - matrix_type * A = matrix_alloc( num_var , num_data ); - - matrix_type * X,*Y; - - if (S == NULL) { - X = (matrix_type *) X0; - Y = (matrix_type *) Y0; - } else { - X = matrix_alloc_copy( X0 ); - Y = matrix_alloc_copy( Y0 ); - - { - int row,col; - for (row = 0; row < matrix_get_rows( X0 ); row++) { - double sigma = matrix_iget(S , row , 0); - double weigth = 1.0 / (sigma * sigma ); - - for (col = 0; col < matrix_get_columns( X0 ); col++) - matrix_imul( X , row , col , weigth ); - - matrix_imul( Y , row , col , weigth ); - } - } - } - - matrix_matmul_with_transpose( XX , X , X , true , false ); - matrix_inv( XX ); - matrix_matmul_with_transpose( A , XX , X , false , true ); - matrix_matmul(beta , A , Y); - - matrix_free( XX ); - matrix_free( A ); - if (S) { - matrix_free( X ); - matrix_free( Y ); - } - } - - return LLSQ_SUCCESS; -} - - - - -llsq_result_enum matrix_stat_polyfit( matrix_type * beta , const matrix_type * X0 , const matrix_type * Y0 , const matrix_type * S) { - int num_data = matrix_get_rows( X0 ); - int num_var = matrix_get_rows( beta ); - llsq_result_enum result; - matrix_type * X = matrix_alloc( num_data , num_var ); - int row,col; - - for (row = 0; row < matrix_get_rows( X0 ); row++) { - double x1 = matrix_iget( X0 , row , 0 ); - double xp = 1; - for (col = 0; col < num_var; col++) { - matrix_iset(X , row , col , xp); - xp *= x1; - } - } - - result = matrix_stat_llsq_estimate( beta , X , Y0 , S); - matrix_free( X ); - return result; -} - diff --git a/ThirdParty/Ert/lib/util/menu.c b/ThirdParty/Ert/lib/util/menu.c deleted file mode 100644 index f2b791045b..0000000000 --- a/ThirdParty/Ert/lib/util/menu.c +++ /dev/null @@ -1,462 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'menu.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include - -#include -#include -#include - -/** - This file implements a simple character based menu system. The menu - consists of a list of items, where each item has a description, a - function to call, an argument to send to this function, and a set - of keys which will invoke this function. - - - Example: - - menu_type * menu = menu_alloc("Tittel paa menyen" , "qQ"); - menu_add_item(menu , "Alternativ 1" , "1aA" , func1 , arg1); - menu_add_item(menu , "Alternativ 2" , 2Bb" , func2 , arg2); - menu_run(menu); - menu_free(menu); - - In this case we will get a menu looking like this: - - - Tittel paa menyen - 1: Alternativ 1 - 2: Alternativ 2 - q: Quit - ==> __ - - Now typing '1' will invoke the function func1() with argument - arg1. In addition the characters 'a' and 'A' can also be used to - invoke the same function. Function func2(arg2) is invoked with '2', - 'b' or 'B'; finally the menu is exited with 'q' or 'Q' (the - arguments to the alloc call). - - - Observe that (in the current implementation) only single characters - are allowed as activator keys for the various items. I.e. 'save' to - save is not an option' -*/ - - - - - -struct menu_item_struct { - bool separator; /* If this is a separator - in that case all the following fields are moot. */ - bool helptext; /* If this is help text - Only label is present */ - char * key_set; /* The characters which will activate this item , e.g. "sS" - must be a \0 terminated string */ - char * label; /* The label/description of this menu item */ - menu_func_type * func; /* The function called when this item is activated. */ - void * arg; /* The argument passed to func. */ - int label_length; /* The length of the label - zero for separators. */ - arg_free_ftype * free_arg; /* Destructor for the argument - will typically be NULL */ - bool enabled; -}; - - - - -struct menu_struct { - vector_type * items; /* Vector of menu_item_type instances */ - char * quit_keys; /* The keys which can be used to quit from this menu - typically "qQ" */ - char * title; /* The title of this menu */ - char * quit_label; /* The text printed on the back/quit item at the bottom. */ - char * complete_key_set; /* A string containing all the allowed characters - to validata input */ -}; - - - -/** - Free's the menu occupied by one menu item. -*/ -static void menu_item_free(menu_item_type * item) { - if (!item->separator) { - free(item->label); - } - if (!item->separator && !item->helptext){ - free(item->key_set); - } - - - if (item->free_arg != NULL) - item->free_arg(item->arg); - - free(item); -} - -static void menu_item_free__(void * arg) { - menu_item_free( (menu_item_type *) arg ); -} - - - -/** - This function returns true if the first argument contains _any_ of the characters in - the second argument. It is implemented by repeated calss to strchr(); -*/ - -static bool __string_contains(const char * string , const char * char_set) { - bool contains = false; - int i = 0; - do { - if (strchr(string , char_set[i]) != NULL) - contains = true; - i++; - } while (!contains && i < strlen(char_set)); - return contains; -} - - - -/** - This function allocates an empty menu, with title 'title'. This - particular menu will exit when one the keys in quit_keys is - entered. */ - - -menu_type * menu_alloc(const char * title , const char * quit_label , const char * quit_keys) { - menu_type * menu = (menu_type*)util_malloc(sizeof * menu ); - - menu->title = util_alloc_sprintf_escape( title , 0 ); - menu->quit_keys = util_alloc_string_copy( quit_keys ); - menu->items = vector_alloc_new(); - menu->complete_key_set = util_alloc_string_copy( quit_keys ); - menu->quit_label = util_alloc_string_copy( quit_label ); - - return menu; -} - -static menu_item_type * menu_item_alloc_empty() { - menu_item_type * item = (menu_item_type*)util_malloc(sizeof * item ); - - item->label = NULL; - item->key_set = NULL; - item->func = NULL; - item->arg = NULL; - item->separator = false; - item->helptext = false; - item->label_length = 0; - item->free_arg = NULL; - item->enabled = true; - - return item; -} - - -/** - Low level function doing the actual append of a complete item. -*/ -static void menu_append_item__(menu_type * menu , menu_item_type * item) { - vector_append_owned_ref( menu->items , item , menu_item_free__); -} - - -void menu_set_title(menu_type * menu, const char * title) { - menu->title = util_realloc_string_copy(menu->title, title); -} - - -void menu_item_disable( menu_item_type * item ) { - item->enabled = false; -} - -void menu_item_enable( menu_item_type * item ) { - item->enabled = true; -} - - -char menu_item_get_key( const menu_item_type * item ) { - if (item->enabled) - return item->key_set[0]; - else - return '-'; -} - - -void menu_item_call( const menu_item_type * item ) { - if (item->enabled) - item->func(item->arg); -} - - - -void menu_item_set_label(menu_item_type * item , const char * label) { - item->label = util_realloc_string_copy(item->label , label); - item->label_length = strlen(item->label); -} - -/** - Adds (appends) an item to the menu. - - - Obsereve that several keys can be used to invoke a particular - function, however *only* the first key in the key_set is displayed - when the menu is printed on stdout. -*/ - -menu_item_type * menu_add_item(menu_type * menu , const char * label , const char * key_set , menu_func_type * func, void * arg , arg_free_ftype * free_arg) { - if (__string_contains(menu->complete_key_set , key_set)) - util_abort("%s:fatal error when building menu - key(s) in:%s already in use \n",__func__ , key_set); - { - menu_item_type * item = menu_item_alloc_empty(); - item->key_set = util_alloc_string_copy(key_set); - item->func = func; - item->arg = arg; - item->separator = false; - item->helptext = false; - item->free_arg = free_arg; - menu_append_item__(menu , item); - menu_item_set_label(item , label); - menu->complete_key_set = util_strcat_realloc(menu->complete_key_set , key_set); - return item; - } -} - - - - -/** - Will add a '-------------' line to the menu. -*/ -void menu_add_separator(menu_type * menu) { - menu_item_type * item = menu_item_alloc_empty(); - item->separator = true; - menu_append_item__(menu , item); -} - - -/** - Will print helptext to screen -*/ - -void menu_add_helptext(menu_type * menu, const char * label ) { - menu_item_type * item = menu_item_alloc_empty(); - item->helptext = true; - menu_append_item__(menu , item); - menu_item_set_label(item , label); -} - - - - - -/** level == 0 : top line - level == 1 : separator line - level == 2 : bottom line -*/ - -static void __print_line(int l , int level) { - int i; - if (level == 0) - fputc('/' , stdout); - else if (level == 1) - fputc('|' , stdout); - else - fputc('\\' , stdout); - - - for (i=1; i < (l - 1); i++) - fputc('-' , stdout); - - - if (level == 0) - fputc('\\' , stdout); - else if (level == 1) - fputc('|' , stdout); - else - fputc('/' , stdout); - - - fputc('\n' , stdout); -} - -static void __print_sep(int l) { - int i; - printf("| "); - for (i=0; i < l; i++) - fputc('-' , stdout); - printf(" |\n"); -} - - -static void __print_helptext(char * label, int l){ - bool end_reached = false; - char * label_copy = util_alloc_string_copy( label ); - char * first_part = "Dummy3"; - char * second_part = "Dummy4"; - while(!end_reached){ - int i; - if(strlen(label_copy) > l){ - util_binary_split_string_from_max_length(label_copy , " ", l , &first_part , &second_part); - printf("| %s",first_part); - for (i=strlen(first_part); i < l; i++) - fputc(' ' , stdout); - printf(" |\n"); - label_copy = util_realloc_string_copy(label_copy, second_part); - } - else{ - printf("| %s",label_copy); - for (i=strlen(label_copy); i < l; i++) - fputc(' ' , stdout); - printf(" |\n"); - end_reached = true; - } - } -} - - - - -static void menu_display(const menu_type * menu) { - int i; - int length = strlen(menu->title); - for (i = 0; i < vector_get_size(menu->items); i++) { - const menu_item_type * item = (const menu_item_type*)vector_iget_const( menu->items , i); - if(!item->helptext) - length = util_int_max(length , item->label_length); - if(item->helptext) - length = util_int_max(length , 60); /* Hardcoded length for helptext*/ - } - - - printf("\n"); - __print_line(length + 10 , 0); - printf("| "); - util_fprintf_string(menu->title , length + 6 , center_pad , stdout); printf(" |\n"); - __print_line(length + 10 , 1); - for (i=0; i < vector_get_size(menu->items); i++) { - const menu_item_type * item = (const menu_item_type*)vector_iget_const( menu->items , i); - if (item->separator) - __print_sep(length + 6); - else if (item->helptext) - __print_helptext(item->label,length); - else { - printf("| %c: ", menu_item_get_key( item )); - util_fprintf_string(item->label , length + 3 , right_pad , stdout); - printf(" |\n"); - } - } - __print_sep(length + 6); - printf("| %c: ",menu->quit_keys[0]); - util_fprintf_string(menu->quit_label , length + 3 , right_pad , stdout); - printf(" |\n"); - __print_line(length + 10 , 2); - printf("\n"); -} - - - -/** - Reads a string from stdin: If the string is longer than one single - character it is discarded, if it is exactly one character long we - check if it is in the menus set of available command characters, - and return it *IF* it is a valid character. I.e. the return value - from this function is *GUARANTEED* to correspond to a menu item. - - Observe that the function ends with a call to getchar() - this - should remove the traling from the stdin input buffer. -*/ - -static int menu_read_cmd(const menu_type * menu) { - char cmd[256]; - - do { - printf("==> "); - fflush(stdout); fscanf(stdin , "%s" , cmd); /* We read a full string - - but we only consider it if it is exactly *ONE* character long. */ - } while ((strchr(menu->complete_key_set , cmd[0]) == NULL) || strlen(cmd) > 1); - - getchar(); /* Discards trailing from standard input buffer? */ - return cmd[0]; -} - - - - -menu_item_type * menu_get_item(const menu_type * menu, char cmd) { - int item_index = 0; - menu_item_type * item = NULL; - while (item_index < vector_get_size(menu->items)) { - menu_item_type * current_item = (menu_item_type*)vector_iget(menu->items , item_index); - if (!current_item->separator || !current_item->helptext) { - if (strchr(current_item->key_set , cmd) != NULL) { - item = current_item; - break; - } - item_index++; - } - } - - if (item == NULL) - util_abort("%s: could not locate item with key: %c \n",__func__ , cmd); - return item; -} - - - -void menu_run(const menu_type * menu) { - while (1) { - int cmd; - - - menu_display(menu); - cmd = menu_read_cmd(menu); - if (strchr(menu->quit_keys , cmd) != NULL) /* We have recieved a quit command - leave the building. */ - break; - - /* - OK - we start looking through all the available commands to see - which this is. */ - { - int item_index = 0; - while (1) { - const menu_item_type * item = (const menu_item_type*)vector_iget_const(menu->items , item_index); - if (!item->separator) { - if(!item->helptext) { - if (strchr(item->key_set , cmd) != NULL) { - /* Calling the function ... */ - menu_item_call( item ); - break; - } - } - } - item_index++; - } - } - } -} - - - -void menu_free(menu_type * menu) { - free(menu->quit_keys); - free(menu->title); - free(menu->complete_key_set); - free(menu->quit_label); - vector_free(menu->items); - free(menu); -} diff --git a/ThirdParty/Ert/lib/util/msg.c b/ThirdParty/Ert/lib/util/msg.c deleted file mode 100644 index bedc0c49f1..0000000000 --- a/ThirdParty/Ert/lib/util/msg.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'msg.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include - -#include -#include -#include - -#define MSG_TYPE_ID 1999867 - -struct msg_struct { - UTIL_TYPE_ID_DECLARATION; - char * prompt; - char * msg; - int msg_len; - bool visible; - bool debug; -}; - - -static void __msg_assert_visible(const msg_type * msg) { - if (!msg->visible) - util_abort("%s: you must call msg_show() first - aborting.\n",__func__); -} - - -static void __blank_string(int len) { - int i; - for (i = 0; i < len; i++) - fputc('\b' , stdout); - - for (i = 0; i < len; i++) - fputc(' ' , stdout); - - for (i = 0; i < len; i++) - fputc('\b' , stdout); - -} - - -void msg_clear_msg(msg_type * msg) { - __msg_assert_visible(msg); - __blank_string(msg->msg_len); - if (msg->msg != NULL) { - free(msg->msg); - msg->msg_len = 0; - msg->msg = NULL; - } -} - - - -static void msg_clear_prompt(const msg_type * msg) { - __blank_string(strlen(msg->prompt)); -} - - -void msg_hide(msg_type * msg) { - msg_clear_msg(msg); - msg_clear_prompt(msg); - msg->visible = false; -} - - -void msg_set_prompt(msg_type * msg , const char * prompt) { - msg->prompt = util_realloc_string_copy(msg->prompt , prompt); -} - - -void msg_print_msg(const msg_type * msg) { - if (msg->msg != NULL) - printf("%s" , msg->msg); - fflush(stdout); -} - - -void msg_show(msg_type * msg) { - if (!msg->visible) { - printf("%s" , msg->prompt); - msg_print_msg(msg); - msg->visible = true; - } -} - - -void msg_update(msg_type * msg , const char * new_msg) { - __msg_assert_visible(msg); - if (!msg->debug) - msg_clear_msg(msg); - - { - msg->msg = util_realloc_string_copy(msg->msg , new_msg); - if (new_msg == NULL) - msg->msg_len = 0; - else - msg->msg_len = strlen(new_msg); - } - - if (msg->debug) - printf("%s\n",msg->msg); - else - msg_print_msg(msg); -} - - -void msg_update_int(msg_type * msg , const char * fmt , int value) { - char buffer[16]; - sprintf(buffer , fmt , value); - msg_update(msg , buffer); -} - - -UTIL_SAFE_CAST_FUNCTION( msg , MSG_TYPE_ID ) - -msg_type * msg_alloc(const char * prompt, bool debug) { - msg_type * msg = (msg_type*)util_malloc(sizeof * msg ); - UTIL_TYPE_ID_INIT( msg , MSG_TYPE_ID); - msg->prompt = util_alloc_string_copy(prompt); - - msg->msg = NULL; - msg->msg_len = 0; - msg->visible = false; - msg->debug = debug; - return msg; -} - - -void msg_free(msg_type * msg , bool clear) { - if (clear) - msg_hide(msg); - else - printf("\n"); - - free(msg->prompt); - if (msg->msg != NULL) - free(msg->msg); - - free(msg); -} - - - diff --git a/ThirdParty/Ert/lib/util/mzran.c b/ThirdParty/Ert/lib/util/mzran.cpp similarity index 98% rename from ThirdParty/Ert/lib/util/mzran.c rename to ThirdParty/Ert/lib/util/mzran.cpp index 326cfb083d..a6c54eb9b4 100644 --- a/ThirdParty/Ert/lib/util/mzran.c +++ b/ThirdParty/Ert/lib/util/mzran.cpp @@ -19,9 +19,9 @@ #include #include -#include -#include -#include +#include +#include +#include /*****************************************************************/ /* diff --git a/ThirdParty/Ert/lib/util/node_ctype.c b/ThirdParty/Ert/lib/util/node_ctype.cpp similarity index 95% rename from ThirdParty/Ert/lib/util/node_ctype.c rename to ThirdParty/Ert/lib/util/node_ctype.cpp index 08c9219273..32aa3790e3 100644 --- a/ThirdParty/Ert/lib/util/node_ctype.c +++ b/ThirdParty/Ert/lib/util/node_ctype.cpp @@ -19,8 +19,8 @@ #include #include -#include -#include +#include +#include const char * node_ctype_name(node_ctype ctype) { diff --git a/ThirdParty/Ert/lib/util/node_data.c b/ThirdParty/Ert/lib/util/node_data.cpp similarity index 98% rename from ThirdParty/Ert/lib/util/node_data.c rename to ThirdParty/Ert/lib/util/node_data.cpp index c45362b7a6..88af1a6abd 100644 --- a/ThirdParty/Ert/lib/util/node_data.c +++ b/ThirdParty/Ert/lib/util/node_data.cpp @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include +#include +#include /* diff --git a/ThirdParty/Ert/lib/util/parser.c b/ThirdParty/Ert/lib/util/parser.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/parser.c rename to ThirdParty/Ert/lib/util/parser.cpp index 1105a61f46..0d1c1fdc11 100644 --- a/ThirdParty/Ert/lib/util/parser.c +++ b/ThirdParty/Ert/lib/util/parser.cpp @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define PARSER_ESCAPE_CHAR '\\' @@ -498,7 +498,7 @@ static bool fseek_quote_end( char quoter , FILE * stream ) { static bool fgetc_while_equal( FILE * stream , const char * string , bool case_sensitive) { bool equal = true; long int current_pos = util_ftell(stream); - int string_index; + size_t string_index; for ( string_index = 0; string_index < strlen(string); string_index++) { int c = fgetc( stream ); if (!case_sensitive) @@ -625,7 +625,7 @@ void basic_parser_strip_buffer(const basic_parser_type * parser , char ** __buff char * src = *__buffer; char * target = (char*)util_calloc( ( strlen( *__buffer ) + 1) , sizeof * target ); - int src_position = 0; + size_t src_position = 0; int target_position = 0; while (src_position < strlen( src )) { int comment_length; diff --git a/ThirdParty/Ert/lib/util/path_fmt.c b/ThirdParty/Ert/lib/util/path_fmt.c deleted file mode 100644 index 49191ab623..0000000000 --- a/ThirdParty/Ert/lib/util/path_fmt.c +++ /dev/null @@ -1,314 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'path_fmt.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include - -#include "ert/util/build_config.h" -#include -#include -#include -#include - -/** -The basic idea of the path_fmt_type is that it should be possible for -a user to specify an arbirtrary path *WITH* embedded format -strings. It is implemented with the the help av variable length -argument lists. This has the following disadvantages: - - o The code gets ugly - really ugly. - - o It is difficult to provide type-safety on user input. - -Example: - - -path_fmt_type * path_fmt = path_fmt_alloc_directory_fmt("/tmp/ECLIPSE/%s/Run-%d"); - - -Here we have allocated a path_fmt instance which will require two -additional arguments when a full path is created, a string for the -"%s" placeholder and an integer for the %d placeholder: - -char * path = path_fmt_alloc(path_fmt , "BaseCase" , 67); - -=> path = /tmp/ECLIPSE/Basecase/Run-67 - -*/ - -#define PATH_FMT_ID 7519200 - - -struct path_fmt_struct { - UTIL_TYPE_ID_DECLARATION; - char *fmt; - char *file_fmt; - bool is_directory; -}; - - -static UTIL_SAFE_CAST_FUNCTION( path_fmt , PATH_FMT_ID) - -void path_fmt_reset_fmt(path_fmt_type * path , const char * fmt) { - path->fmt = util_realloc_string_copy(path->fmt , fmt); - if (path->is_directory) - path->file_fmt = util_alloc_sprintf("%s/%%s" , fmt); -} - - - -static path_fmt_type * path_fmt_alloc__(const char * fmt , bool is_directory) { - path_fmt_type * path = (path_fmt_type*)util_malloc(sizeof * path ); - UTIL_TYPE_ID_INIT(path , PATH_FMT_ID); - path->fmt = NULL; - path->file_fmt = NULL; - path->is_directory = is_directory; - - path_fmt_reset_fmt(path , fmt); - return path; -} - - -/** - - This function is used to allocate a path_fmt instance which is - intended to hold a directory, if the second argument is true, the - resulting directory will be automatically created when - path_fmt_alloc_path() is later invoked. - - Example: - ------- - path_fmt_type * path_fmt = path_fmt_alloc_directory_fmt("/tmp/scratch/member%d/%d.%d" , true); - .... - .... - char * path = path_fmt_alloc_path(path_fmt , 10 , 12 , 15); - char * file = path_fmt_alloc_file(path_fmt , 8 , 12 , 17, "SomeFile"); - - After the two last function calls we will have: - - o path = "/tmp/scratch/member10/12.15" - and this directory has - been created. - - o file = "/tmp/scratch/member8/12.17/SomeFile - and the directory - /tmp/scratch/member8/12.17 has been created. - - - Observe that the functionality is implemented with the help av - variable length argument lists, and **NO** checking of argument list - versus format string is performed. -*/ - - -path_fmt_type * path_fmt_alloc_directory_fmt(const char * fmt) { - return path_fmt_alloc__(fmt , true); -} - - - -/* - Most general. Can afterwards be used to allocate strings - representing both directories and files. -*/ - -path_fmt_type * path_fmt_alloc_path_fmt(const char * fmt) { - return path_fmt_alloc__(fmt , false ); -} - - - -/** - Present the user with a prompt, and reads format specifier string - from stdin. Currently not possible to specify argument types. -*/ - -path_fmt_type * path_fmt_scanf_alloc(const char * prompt , int types , const node_ctype * type_list, bool is_directory) { - char * fmt; - fmt = util_scanf_alloc_string(prompt); - return path_fmt_alloc__(fmt , is_directory); -} - -path_fmt_type * path_fmt_copyc(const path_fmt_type *path) { - path_fmt_type *new_path = path_fmt_alloc__(path->fmt , path->is_directory); - return new_path; -} - -char * path_fmt_alloc_path_va(const path_fmt_type * path ,bool auto_mkdir, va_list ap) { - char * new_path = util_alloc_sprintf_va(path->fmt , ap ); - if (auto_mkdir) - if (! util_is_directory(new_path) ) - util_make_path(new_path); - return new_path; -} - - -char * path_fmt_alloc_path(const path_fmt_type * path , bool auto_mkdir , ...) { - char * new_path; - va_list ap; - va_start(ap , auto_mkdir); - new_path = path_fmt_alloc_path_va(path ,auto_mkdir , ap); - va_end(ap); - return new_path; -} - - - -/** - This function is used to allocate a filename (full path) from a - path_fmt instance: - - Eaxample: - - path_fmt_type * path_fmt = path_fmt_alloc_directory("/tmp/path%d/X.%02d"); - char * file = path_fmt_alloc_file(path_fmt , 100 , 78 , "SomeFile.txt") - - This will allocate the filename: /tmp/path100/X.78/SomeFile.txt; if - it does not already exist, the underlying directory will be - created. Observe that there is nothing special about the filename - argument (i.e. 'SomeFile.txt' in the current example), it is just - the last argument to the path_fmt_alloc_file() function call - - however it must be a string; i.e. if you are making a purely numeric - filename you must convert to a string. - - Observe that the handling of the variable length argument lists gets - seriously ugly. - - ----------------------------------------------------------------- - - If auto_mkdir == true the function behaves in two different ways - depending on whether the path_instance was allocated as a directory - or as a path: - - * [Directory]: When the path_fmt instance was allocated as a - directory, "/%s" format decriptor will be appended to the format. - - * [Path]: The resulting string will be split on "/", and the path - component will be created. -*/ - - -char * path_fmt_alloc_file(const path_fmt_type * path , bool auto_mkdir , ...) { - if (path->is_directory) { - char * filename; - va_list tmp_va , ap; - va_start(ap , auto_mkdir); - UTIL_VA_COPY(tmp_va , ap); - filename = util_alloc_sprintf_va( path->file_fmt , tmp_va ); - if (auto_mkdir) { - const char * __path = util_alloc_sprintf_va( path->fmt , tmp_va ); - if (! util_is_directory(__path)) - util_make_path( __path ); - free((char *) __path ); - } - va_end(ap); - return filename; - } else { - - char * filename; - va_list tmp_va , ap; - va_start(ap , auto_mkdir); - UTIL_VA_COPY(tmp_va , ap); - filename = util_alloc_sprintf_va( path->fmt , tmp_va ); - if (auto_mkdir) { - char * __path; - util_alloc_file_components(filename , &__path , NULL , NULL); - util_make_path(__path); - free(__path); - } - va_end(ap); - - return filename; - } -} - - - -/** - This function is used to assert that the format in a path_fmt - instance is according to specification. What is checked is that the - format string contains %d, %lfg and %s in as specified in the - input_types vector. - - Observe that %s is mapped to void_pointer - as the node_ctype does not - have typed pointers. -*/ - - -/* -void path_fmt_assert_fmt(const path_fmt_type * path , int num_input , const node_ctype * input_types) { - int input_nr = 0; - int char_nr = 0; - do { - if (path->fmt[char_nr] == '%') { - - } - } -} -*/ - -/* - fmt == NULL - ----------- - The function will return NULL, possibly freeing the incoming - path_fmt instance if that is different from NULL. - - - fmt != NULL - ----------- - The current path_fmt instance will be updated, or a new created. The - new/updated path_fmt instance is returned. -*/ - -path_fmt_type * path_fmt_realloc_path_fmt( path_fmt_type * path_fmt, const char * fmt ) { - if (fmt == NULL) { - if (path_fmt != NULL) - path_fmt_free( path_fmt ); - return NULL; - } else { - if (path_fmt == NULL) - return path_fmt_alloc_path_fmt( fmt ); - else { - path_fmt_reset_fmt( path_fmt , fmt ); - return path_fmt; - } - } -} - - -const char * path_fmt_get_fmt(const path_fmt_type * path) { - if (path == NULL) - return NULL; - else - return path->fmt; -} - - -void path_fmt_free(path_fmt_type * path) { - free(path->fmt); - if (path->is_directory) - free(path->file_fmt); - free(path); -} - - -void path_fmt_free__( void * arg ) { - path_fmt_type * path_fmt = path_fmt_safe_cast( arg ); - path_fmt_free( path_fmt ); -} diff --git a/ThirdParty/Ert/lib/util/path_stack.c b/ThirdParty/Ert/lib/util/path_stack.cpp similarity index 97% rename from ThirdParty/Ert/lib/util/path_stack.c rename to ThirdParty/Ert/lib/util/path_stack.cpp index 3d248849e1..3f71a9191b 100644 --- a/ThirdParty/Ert/lib/util/path_stack.c +++ b/ThirdParty/Ert/lib/util/path_stack.cpp @@ -23,9 +23,9 @@ #include #include -#include -#include -#include +#include +#include +#include /** This file implements the structure path_stack which is vaguely diff --git a/ThirdParty/Ert/lib/util/perm_vector.c b/ThirdParty/Ert/lib/util/perm_vector.cpp similarity index 94% rename from ThirdParty/Ert/lib/util/perm_vector.c rename to ThirdParty/Ert/lib/util/perm_vector.cpp index ff4a1b323b..0b6ccde713 100644 --- a/ThirdParty/Ert/lib/util/perm_vector.c +++ b/ThirdParty/Ert/lib/util/perm_vector.cpp @@ -17,9 +17,9 @@ */ #include -#include -#include -#include +#include +#include +#include #define PERM_VECTOR_TYPE_ID 661433 diff --git a/ThirdParty/Ert/lib/util/regression.c b/ThirdParty/Ert/lib/util/regression.c deleted file mode 100644 index 4b1c3b8dba..0000000000 --- a/ThirdParty/Ert/lib/util/regression.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'regression.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include - -#include -#include -#include -#include -#include - - - -/** - Will normalize the the data in X and Y: - - 1. Y -> Y - - 2. For each column: X -> X - - 3. For each column: ||X|| = 1 - - The mean Y value is returned from the function, and the mean X and - normalization factor for X is returned, for each column, in the - matrices (row vectors) X_mean and X_norm. -*/ - - -double regression_scale(matrix_type * X , matrix_type * Y , matrix_type * X_mean , matrix_type * X_norm) { - int nvar = matrix_get_columns( X ); - int nsample = matrix_get_rows( X ); - - if ( matrix_get_rows( Y ) != nsample) - util_abort("%s: dimension mismatch X:[%d,%d] Y:%d \n",__func__ , nsample , nvar , matrix_get_rows( Y )); - - if ( matrix_get_columns( X_norm ) != nvar) - util_abort("%s: dimension mismtach X_norm \n",__func__); - - if ( matrix_get_columns( X_mean ) != nvar) - util_abort("%s: dimension mismtach X_mean \n",__func__); - - { - double y_mean = matrix_get_column_sum( Y , 0 ) / nsample; - matrix_shift_column( Y , 0 , -y_mean ); - - { - int col; - for (col = 0; col < nvar; col++) { - double mean = matrix_get_column_sum(X , col ) / nsample; - matrix_shift_column(X , col , -mean); - matrix_iset( X_mean , 0 , col , mean ); - } - - for (col=0; col < nvar; col++) { - double norm = 1.0/sqrt( (1.0 / (nsample - 1)) * matrix_get_column_sum2( X , col )); - matrix_iset( X_norm , 0 , col , norm ); - } - } - return y_mean; - } -} - - -double regression_unscale(const matrix_type * beta , const matrix_type * X_norm , const matrix_type * X_mean , double Y_mean , matrix_type * beta0) { - int nvars = matrix_get_rows( beta0 ); - int k; - double yshift = 0; - - for (k=0; k < nvars; k++) { - double scaled_beta = matrix_iget( beta , k , 0 ) * matrix_iget( X_norm , 0 , k); - matrix_iset( beta0 , k , 0 , scaled_beta); - yshift += scaled_beta * matrix_iget( X_mean , 0 , k ); - } - return Y_mean - yshift; -} - - -/** - Performs an ordinary least squares estimation of the parameter - vector beta. - - beta = inv(X'·X)·X'·y -*/ - -void regression_augmented_OLS( const matrix_type * X , const matrix_type * Y , const matrix_type* Z, matrix_type * beta) { - /* - Solves the following especial augmented regression problem: - - [Y ; 0] = [X ; Z] beta + epsilon - - where 0 is the zero matrix of same size as Y. - - The solution to this OLS is: - - inv(X'X + Z'Z) * X' * Y - - The semicolon denotes row concatenation and the apostrophe the transpose. - - */ - int nvar = matrix_get_columns( X ); - matrix_type * Xt = matrix_alloc_transpose( X ); - matrix_type * Xinv = matrix_alloc( nvar , nvar); - matrix_matmul( Xinv , Xt , X ); - - matrix_type * Zt = matrix_alloc_transpose( Z ); - matrix_type * ZtZ = matrix_alloc( nvar , nvar); - matrix_matmul( ZtZ , Zt , Z ); - - // Xinv <- X'X + Z'Z - matrix_inplace_add(Xinv, ZtZ); - - // Sometimes the inversion fails - add a small regularization to diagonal - for (int i = 0; i < nvar; ++i) - matrix_iadd(Xinv, i, i, 1e-10); - - matrix_inv( Xinv ); // Xinv is always invertible - { - matrix_type * tmp = matrix_alloc_matmul( Xinv , Xt ); - matrix_matmul( beta , tmp , Y ); - matrix_free( tmp ); - } - - matrix_free( Xt ); - matrix_free( Xinv ); - matrix_free( Zt ); - matrix_free( ZtZ ); -} - diff --git a/ThirdParty/Ert/lib/util/rng.c b/ThirdParty/Ert/lib/util/rng.cpp similarity index 98% rename from ThirdParty/Ert/lib/util/rng.c rename to ThirdParty/Ert/lib/util/rng.cpp index 2408cd5baf..c940eed166 100644 --- a/ThirdParty/Ert/lib/util/rng.c +++ b/ThirdParty/Ert/lib/util/rng.cpp @@ -20,10 +20,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define RNG_TYPE_ID 66154432 #ifdef __cplusplus @@ -263,7 +263,7 @@ unsigned int rng_get_max_int(const rng_type * rng) { void rng_shuffle( rng_type * rng , char * data , size_t element_size , size_t num_elements) { void * tmp = util_malloc( element_size ); - int index1; + size_t index1; for ( index1=0; index1 < num_elements; index1++) { int index2 = rng_get_int( rng , num_elements ); diff --git a/ThirdParty/Ert/lib/util/set.c b/ThirdParty/Ert/lib/util/set.cpp similarity index 97% rename from ThirdParty/Ert/lib/util/set.c rename to ThirdParty/Ert/lib/util/set.cpp index 68ea5ba2ee..0ee87f81f5 100644 --- a/ThirdParty/Ert/lib/util/set.c +++ b/ThirdParty/Ert/lib/util/set.cpp @@ -21,10 +21,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define SET_TYPE_ID 816523 diff --git a/ThirdParty/Ert/lib/util/statistics.c b/ThirdParty/Ert/lib/util/statistics.cpp similarity index 97% rename from ThirdParty/Ert/lib/util/statistics.c rename to ThirdParty/Ert/lib/util/statistics.cpp index cc6734198e..ead3d3ff45 100644 --- a/ThirdParty/Ert/lib/util/statistics.c +++ b/ThirdParty/Ert/lib/util/statistics.cpp @@ -19,9 +19,9 @@ #include #include -#include -#include -#include +#include +#include +#include double statistics_mean( const double_vector_type * data_vector ) { diff --git a/ThirdParty/Ert/lib/util/stepwise.c b/ThirdParty/Ert/lib/util/stepwise.c deleted file mode 100644 index 4a166bc1f9..0000000000 --- a/ThirdParty/Ert/lib/util/stepwise.c +++ /dev/null @@ -1,456 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include - - - -#define STEPWISE_TYPE_ID 8722106 - -struct stepwise_struct { - UTIL_TYPE_ID_DECLARATION; - - matrix_type * X0; // Externally supplied data. - matrix_type * E0; // Externally supplied data. - matrix_type * Y0; - - matrix_type * beta; // Quantities estimated by the stepwise algorithm - double Y_mean; - matrix_type * X_mean; - matrix_type * X_norm; - bool_vector_type * active_set; - rng_type * rng; // Needed in the cross-validation - double R2; // Final R2 -}; - - - -static double stepwise_estimate__( stepwise_type * stepwise , bool_vector_type * active_rows) { - matrix_type * X; - matrix_type * E; - matrix_type * Y; - - double y_mean = 0; - int ncols = matrix_get_columns( stepwise->X0 ); - int nrows = matrix_get_rows( stepwise->X0 ); - - int nsample = bool_vector_count_equal( active_rows , true ); - int nvar = bool_vector_count_equal( stepwise->active_set , true ); - - - matrix_set( stepwise->beta , 0 ); // It is essential to make sure that old finite values in the beta0 vector do not hang around. - - - /* - Extracting the data used for regression, and storing them in the - temporary local matrices X and Y. Selecting data is based both on - which varibles are active (stepwise->active_set) and which rows - should be used for regression, versus which should be used for - validation (@active_rows). - */ - if ((nsample < nrows) || (nvar < ncols)) { - X = matrix_alloc( nsample , nvar ); - E = matrix_alloc( nsample , nvar ); - Y = matrix_alloc( nsample , 1); - - { - int icol,irow; // Running over all values. - int arow,acol; // Running over active values. - arow = 0; - for (irow = 0; irow < nrows; irow++) { - if (bool_vector_iget( active_rows , irow )) { - acol = 0; - for (icol = 0; icol < ncols; icol++) { - if (bool_vector_iget( stepwise->active_set , icol )) { - matrix_iset( X , arow , acol , matrix_iget( stepwise->X0 , irow , icol )); - matrix_iset( E , arow , acol , matrix_iget( stepwise->E0 , irow , icol )); - acol++; - } - } - - matrix_iset( Y , arow , 0 , matrix_iget( stepwise->Y0 , irow , 0 )); - arow++; - } - } - } - } else { - X = matrix_alloc_copy( stepwise->X0 ); - E = matrix_alloc_copy( stepwise->E0 ); - Y = matrix_alloc_copy( stepwise->Y0 ); - } - - - { - - if (stepwise->X_mean != NULL) - matrix_free( stepwise->X_mean); - - stepwise->X_mean = matrix_alloc( 1 , nvar ); - - if (stepwise->X_norm != NULL) - matrix_free( stepwise->X_norm); - - stepwise->X_norm = matrix_alloc( 1 , nvar ); - - matrix_type * beta = matrix_alloc( nvar , 1); /* This is the beta vector as estimated from the OLS estimator. */ - - regression_augmented_OLS( X , Y , E, beta ); - - - /* - In this code block the beta/tmp_beta vector which is dense with - fewer elements than the full model is scattered into the beta0 - vector which has full size and @nvar elements. - */ - { - int ivar,avar; - avar = 0; - for (ivar = 0; ivar < ncols; ivar++) { - if (bool_vector_iget( stepwise->active_set , ivar )) { - matrix_iset( stepwise->beta , ivar , 0 , matrix_iget( beta , avar , 0)); - avar++; - } - } - } - - - matrix_free( beta ); - } - - matrix_free( X ); - matrix_free( E ); - matrix_free( Y ); - return y_mean; -} - - - - -static double stepwise_eval__( const stepwise_type * stepwise , const matrix_type * x ) { - return matrix_row_column_dot_product( x , 0 , stepwise->beta , 0 ); -} - - - -static double stepwise_test_var( stepwise_type * stepwise , int test_var , int blocks) { - double prediction_error = 0; - - bool_vector_iset( stepwise->active_set , test_var , true ); // Temporarily activate this variable - { - - int nvar = matrix_get_columns( stepwise->X0 ); - int nsample = matrix_get_rows( stepwise->X0 ); - int block_size = nsample / blocks; - bool_vector_type * active_rows = bool_vector_alloc( nsample, true ); - - - - - - /*True Cross-Validation: */ - int * randperms = (int*)util_calloc( nsample , sizeof * randperms ); - for (int i=0; i < nsample; i++) - randperms[i] = i; - - /* Randomly perturb ensemble indices */ - rng_shuffle_int( stepwise->rng , randperms , nsample ); - - - for (int iblock = 0; iblock < blocks; iblock++) { - - int validation_start = iblock * block_size; - int validation_end = validation_start + block_size - 1; - - if (iblock == (blocks - 1)) - validation_end = nsample - 1; - - /* - Ensure that the active_rows vector has a block consisting of - the interval [validation_start : validation_end] which is set to - false, and the remaining part of the vector is set to true. - */ - { - bool_vector_set_all(active_rows, true); - /* - If blocks == 1 that means all datapoint are used in the - regression, and then subsequently reused in the R2 - calculation. - */ - if (blocks > 1) { - for (int i = validation_start; i <= validation_end; i++) { - bool_vector_iset( active_rows , randperms[i] , false ); - } - } - } - - - /* - Evaluate the prediction error on the validation part of the - dataset. - */ - { - stepwise_estimate__( stepwise , active_rows ); - { - int irow; - matrix_type * x_vector = matrix_alloc( 1 , nvar ); - //matrix_type * e_vector = matrix_alloc( 1 , nvar ); - for (irow=validation_start; irow <= validation_end; irow++) { - matrix_copy_row( x_vector , stepwise->X0 , 0 , randperms[irow]); - //matrix_copy_row( e_vector , stepwise->E0 , 0 , randperms[irow]); - { - double true_value = matrix_iget( stepwise->Y0 , randperms[irow] , 0 ); - double estimated_value = stepwise_eval__( stepwise , x_vector ); - prediction_error += (true_value - estimated_value) * (true_value - estimated_value); - //double e_estimated_value = stepwise_eval__( stepwise , e_vector ); - //prediction_error += e_estimated_value*e_estimated_value; - } - - } - matrix_free( x_vector ); - } - } - } - - free( randperms ); - bool_vector_free( active_rows ); - } - - /*inactivate the test_var-variable after completion*/ - bool_vector_iset( stepwise->active_set , test_var , false ); - return prediction_error; -} - - -void stepwise_estimate( stepwise_type * stepwise , double deltaR2_limit , int CV_blocks) { - int nvar = matrix_get_columns( stepwise->X0 ); - int nsample = matrix_get_rows( stepwise->X0 ); - double currentR2 = -1; - bool_vector_type * active_rows = bool_vector_alloc( nsample , true ); - - - /*Reset beta*/ - for (int i = 0; i < nvar; i++) { - matrix_iset(stepwise->beta, i , 0 , 0.0); - } - - - - bool_vector_set_all( stepwise->active_set , false ); - - double MSE_min = 10000000; - double Prev_MSE_min = MSE_min; - double minR2 = -1; - - while (true) { - int best_var = 0; - Prev_MSE_min = MSE_min; - - /* - Go through all the inactive variables, and calculate the - resulting prediction error IF this particular variable is added; - keep track of the variable which gives the lowest prediction error. - */ - for (int ivar = 0; ivar < nvar; ivar++) { - if (!bool_vector_iget( stepwise->active_set , ivar)) { - double newR2 = stepwise_test_var(stepwise , ivar , CV_blocks); - if ((minR2 < 0) || (newR2 < minR2)) { - minR2 = newR2; - best_var = ivar; - } - } - } - - /* - If the best relative improvement in prediction error is better - than @deltaR2_limit, the corresponding variable is added to the - active set, and we return to repeat the loop one more - time. Otherwise we just exit. - */ - - { - MSE_min = minR2; - double deltaR2 = MSE_min / Prev_MSE_min; - - if (( currentR2 < 0) || deltaR2 < deltaR2_limit) { - bool_vector_iset( stepwise->active_set , best_var , true ); - currentR2 = minR2; - bool_vector_set_all(active_rows, true); - stepwise_estimate__( stepwise , active_rows ); - } else { - /* The gain in prediction error is so small that we just leave the building. */ - /* NB! Need one final compuation of beta (since the test_var function does not reset the last tested beta value !) */ - bool_vector_set_all(active_rows, true); - stepwise_estimate__( stepwise , active_rows ); - break; - } - - if (bool_vector_count_equal( stepwise->active_set , true) == matrix_get_columns( stepwise->X0 )) { - stepwise_estimate__( stepwise , active_rows ); - break; /* All variables are active. */ - } - } - } - - stepwise_set_R2(stepwise, currentR2); - bool_vector_free( active_rows ); -} - - - -double stepwise_eval( const stepwise_type * stepwise , const matrix_type * x ) { - double yHat = stepwise_eval__(stepwise, x ); - return yHat; -} - - - -static stepwise_type * stepwise_alloc__( int nsample , int nvar , rng_type * rng) { - stepwise_type * stepwise = (stepwise_type*)util_malloc( sizeof * stepwise ); - - stepwise->X_mean = NULL; - stepwise->X_norm = NULL; - stepwise->Y_mean = 0.0; - stepwise->rng = rng; - stepwise->X0 = NULL; - stepwise->E0 = NULL; - stepwise->Y0 = NULL; - stepwise->active_set = bool_vector_alloc( nvar , true ); - stepwise->beta = matrix_alloc( nvar , 1 ); - - return stepwise; -} - - -stepwise_type * stepwise_alloc0( rng_type * rng) { - stepwise_type * stepwise = (stepwise_type*)util_malloc( sizeof * stepwise ); - - stepwise->rng = rng; - stepwise->X0 = NULL; - stepwise->E0 = NULL; - stepwise->Y0 = NULL; - stepwise->beta = NULL; - stepwise->active_set = NULL; - stepwise->X_mean = NULL; - stepwise->X_norm = NULL; - stepwise->Y_mean = 0.0; - stepwise->R2 = -1.0; - - return stepwise; -} - - - -stepwise_type * stepwise_alloc1( int nsample , int nvar, rng_type * rng, const matrix_type* St, const matrix_type* Et) { - stepwise_type * stepwise = stepwise_alloc__( nsample , nvar , rng); - - stepwise->rng = rng; - stepwise->X0 = matrix_alloc_copy(St); // It would be nice to get rid of these copies, but due to data race it is not possible at the moment - stepwise->E0 = matrix_alloc_copy(Et); - stepwise->Y0 = NULL; //matrix_alloc( nsample , 1 ); - - return stepwise; -} - - -void stepwise_set_Y0( stepwise_type * stepwise , matrix_type * Y) { - stepwise->Y0 = Y; -} - -void stepwise_set_X0( stepwise_type * stepwise , matrix_type * X) { - stepwise->X0 = X; -} - -void stepwise_set_E0( stepwise_type * stepwise , matrix_type * E) { - stepwise->E0 = E; -} - - -void stepwise_set_beta( stepwise_type * stepwise , matrix_type * b) { -if (stepwise->beta != NULL) - matrix_free( stepwise->beta ); - - stepwise->beta = b; -} - -void stepwise_set_active_set( stepwise_type * stepwise , bool_vector_type * a) { - if (stepwise->active_set != NULL) - bool_vector_free( stepwise->active_set ); - - stepwise->active_set = a; -} - -void stepwise_set_R2( stepwise_type * stepwise , const double R2) { - stepwise->R2 = R2; -} - -matrix_type * stepwise_get_X0( stepwise_type * stepwise ) { - return stepwise->X0; -} - -matrix_type * stepwise_get_Y0( stepwise_type * stepwise ) { - return stepwise->Y0; -} - -double stepwise_get_R2(const stepwise_type * stepwise ) { - return stepwise->R2; -} - -int stepwise_get_nsample( stepwise_type * stepwise ) { - return matrix_get_rows( stepwise->X0 ); -} - -int stepwise_get_nvar( stepwise_type * stepwise ) { - return matrix_get_columns( stepwise->X0 ); -} - -int stepwise_get_n_active( stepwise_type * stepwise ) { - return bool_vector_count_equal( stepwise->active_set , true); -} - -bool_vector_type * stepwise_get_active_set( stepwise_type * stepwise ) { - return stepwise->active_set; -} - -double stepwise_iget_beta(const stepwise_type * stepwise, const int index ) { - return matrix_iget( stepwise->beta, index, 0); -} - -double stepwise_get_sum_beta(const stepwise_type * stepwise ) { - return matrix_get_column_abssum( stepwise->beta, 0); -} - -void stepwise_isetY0( stepwise_type * stepwise , int i , double value ) { - matrix_iset( stepwise->Y0, i , 0 , value ); -} - - -void stepwise_free( stepwise_type * stepwise ) { - if (stepwise->active_set != NULL) { - bool_vector_free( stepwise->active_set ); - } - - - if (stepwise->beta != NULL) - matrix_free( stepwise->beta ); - - - if (stepwise->X_mean != NULL) - matrix_free( stepwise->X_mean ); - - - if (stepwise->X_norm != NULL) - matrix_free( stepwise->X_norm ); - - - matrix_free( stepwise->X0 ); - matrix_free( stepwise->E0 ); - matrix_free( stepwise->Y0 ); - - free( stepwise ); -} - diff --git a/ThirdParty/Ert/lib/util/string_util.c b/ThirdParty/Ert/lib/util/string_util.cpp similarity index 96% rename from ThirdParty/Ert/lib/util/string_util.c rename to ThirdParty/Ert/lib/util/string_util.cpp index 12db74bdab..509c565c5b 100644 --- a/ThirdParty/Ert/lib/util/string_util.c +++ b/ThirdParty/Ert/lib/util/string_util.cpp @@ -20,12 +20,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include /*****************************************************************/ @@ -59,7 +59,7 @@ static bool valid_characters( const char * range_string ) { bool valid = false; if (range_string) { - int offset = 0; + size_t offset = 0; valid = true; while (true) { char c = range_string[offset]; diff --git a/ThirdParty/Ert/lib/util/stringlist.c b/ThirdParty/Ert/lib/util/stringlist.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/stringlist.c rename to ThirdParty/Ert/lib/util/stringlist.cpp index 6bd06f9bfe..bf134c4f03 100644 --- a/ThirdParty/Ert/lib/util/stringlist.c +++ b/ThirdParty/Ert/lib/util/stringlist.cpp @@ -32,9 +32,9 @@ #include #endif -#include -#include -#include +#include +#include +#include #define STRINGLIST_TYPE_ID 671855 @@ -718,7 +718,7 @@ int stringlist_select_matching(stringlist_type * names , const char * pattern) { stringlist_clear( names ); { - int i; + size_t i; glob_t * pglob = (glob_t*)util_malloc( sizeof * pglob ); int glob_flags = 0; glob( pattern , glob_flags , NULL , pglob); @@ -843,7 +843,7 @@ int stringlist_append_matching_elements(stringlist_type * target , const stringl static int void_strcmp(const void* s1, const void *s2) { - return strcmp(s1,s2); + return strcmp((char*)s1, (char*)s2); } bool stringlist_unique(const stringlist_type * stringlist ) diff --git a/ThirdParty/Ert/lib/util/struct_vector.c b/ThirdParty/Ert/lib/util/struct_vector.cpp similarity index 98% rename from ThirdParty/Ert/lib/util/struct_vector.c rename to ThirdParty/Ert/lib/util/struct_vector.cpp index d50d108ea8..c79891b810 100644 --- a/ThirdParty/Ert/lib/util/struct_vector.c +++ b/ThirdParty/Ert/lib/util/struct_vector.cpp @@ -19,8 +19,8 @@ #include #include -#include -#include +#include +#include #define STRUCT_VECTOR_TYPE_ID 772562097 diff --git a/ThirdParty/Ert/lib/util/subst_func.c b/ThirdParty/Ert/lib/util/subst_func.c deleted file mode 100644 index 5484872acd..0000000000 --- a/ThirdParty/Ert/lib/util/subst_func.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'subst_func.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - - -#include -#include - -#include -#include -#include -#include -#include - - -#define SUBST_FUNC_TYPE_ID 646781 -#define SUBST_FUNC_POOL_TYPE_ID 7641 - -struct subst_func_pool_struct { - UTIL_TYPE_ID_DECLARATION; - hash_type * func_table; -}; - - - -struct subst_func_struct { - UTIL_TYPE_ID_DECLARATION; - subst_func_ftype * func; - char * name; - char * doc_string; /* doc_string for this function - can be NULL. */ - bool vararg; - int argc_min; - int argc_max; - void * arg; /* 100% unmanaged void argument passed in from the construction. */ -}; - - - -char * subst_func_eval( const subst_func_type * subst_func , const stringlist_type * args) { - if (!subst_func->vararg) { - /* Checking that we have the right number of arguments. */ - int argc = stringlist_get_size( args ); - if (argc < subst_func->argc_min || argc > subst_func->argc_max) { - fprintf(stderr,"Fatal error when appying function:%s - got %d arguments: [",subst_func->name , argc); - stringlist_fprintf(args , " " , stderr); - fprintf(stderr,"] expected %d-%d arguments.\n", subst_func->argc_min , subst_func->argc_max); - util_abort("%s: Fatal error - aborting \n",__func__); - } - } - printf("Running:%s \n",subst_func->name); - return subst_func->func( args , subst_func->arg ); -} - - -subst_func_type * subst_func_alloc( const char * func_name , const char * doc_string , subst_func_ftype * func , bool vararg, int argc_min , int argc_max , void * arg) { - subst_func_type * subst_func = (subst_func_type*)util_malloc( sizeof * subst_func ); - UTIL_TYPE_ID_INIT( subst_func , SUBST_FUNC_TYPE_ID ); - subst_func->func = func; - subst_func->name = util_alloc_string_copy( func_name ); - subst_func->vararg = vararg; - subst_func->argc_min = argc_min; - subst_func->argc_max = argc_max; - subst_func->doc_string = util_alloc_string_copy( doc_string ); - subst_func->arg = arg; - return subst_func; -} - - -void subst_func_free( subst_func_type * subst_func ) { - util_safe_free( subst_func->doc_string ); - free( subst_func->name ); - free( subst_func ); -} - - -UTIL_SAFE_CAST_FUNCTION( subst_func , SUBST_FUNC_TYPE_ID); - -static void subst_func_free__( void * arg ) { - subst_func_free( subst_func_safe_cast( arg )); -} - - - - -/*****************************************************************/ - -UTIL_IS_INSTANCE_FUNCTION( subst_func_pool , SUBST_FUNC_POOL_TYPE_ID); - -subst_func_pool_type * subst_func_pool_alloc( ) { - subst_func_pool_type * pool = (subst_func_pool_type*)util_malloc( sizeof * pool ); - UTIL_TYPE_ID_INIT( pool , SUBST_FUNC_POOL_TYPE_ID ); - pool->func_table = hash_alloc_unlocked(); - return pool; -} - - - -void subst_func_pool_free( subst_func_pool_type * pool ) { - hash_free( pool->func_table ); - free( pool ); -} - - -void subst_func_pool_add_func( subst_func_pool_type * pool , const char * func_name , const char * doc_string , subst_func_ftype * func , bool vararg, int argc_min , int argc_max , void * arg) { - subst_func_type * subst_func = subst_func_alloc( func_name , doc_string , func , vararg , argc_min , argc_max , arg); - hash_insert_hash_owned_ref( pool->func_table , func_name , subst_func , subst_func_free__); -} - - -subst_func_type * subst_func_pool_get_func( const subst_func_pool_type * pool , const char * func_name ) { - return (subst_func_type*)hash_get( pool->func_table , func_name ); -} - -bool subst_func_pool_has_func( const subst_func_pool_type * pool , const char * func_name ) { - return hash_has_key( pool->func_table , func_name ); -} - - -/*****************************************************************/ - -char * subst_func_randint( const stringlist_type * args , void * arg) { - rng_type * rng = rng_safe_cast( arg ); - return util_alloc_sprintf("%u" , rng_forward( rng )); -} - -char * subst_func_randfloat( const stringlist_type * args , void * arg) { - rng_type * rng = rng_safe_cast( arg ); - return util_alloc_sprintf("%12.10f" , 1e9 * rng_get_double( rng )); -} - - -char * subst_func_exp( const stringlist_type * args , void * ext_arg) { - double arg; - if (util_sscanf_double( stringlist_iget(args , 0 ) , &arg)) - return util_alloc_sprintf("%g" , exp(arg)); - else - return NULL; -} - - -char * subst_func_log( const stringlist_type * args , void * ext_arg) { - double arg; - if (util_sscanf_double( stringlist_iget(args , 0 ) , &arg)) - return util_alloc_sprintf("%g" , log(arg)); - else - return NULL; -} - - -char * subst_func_pow10( const stringlist_type * args , void * ext_arg) { - double arg; - if (util_sscanf_double( stringlist_iget(args , 0 ) , &arg)) - return util_alloc_sprintf("%g" , pow(10 , arg)); - else - return NULL; -} - - - -char * subst_func_add( const stringlist_type * args , void * ext_arg) { - double sum = 0; - bool OK = true; - int index; - for (index = 0; index < stringlist_get_size( args ); index++) { - double term; - if (util_sscanf_double( stringlist_iget(args , index ) , &term)) - sum += term; - else - OK = false; - } - - if (OK) - return util_alloc_sprintf("%g" , sum); - else - return NULL; -} - - -char * subst_func_mul( const stringlist_type * args , void * ext_arg) { - double product = 0; - bool OK = true; - int index; - for (index = 0; index < stringlist_get_size( args ); index++) { - double factor; - if (util_sscanf_double( stringlist_iget(args , index ) , &factor)) - product *= factor; - else - OK = false; - } - - - if (OK) - return util_alloc_sprintf("%g" , product); - else - return NULL; -} diff --git a/ThirdParty/Ert/lib/util/test_util.c b/ThirdParty/Ert/lib/util/test_util.cpp similarity index 98% rename from ThirdParty/Ert/lib/util/test_util.c rename to ThirdParty/Ert/lib/util/test_util.cpp index 3d2684d540..9115af6feb 100644 --- a/ThirdParty/Ert/lib/util/test_util.c +++ b/ThirdParty/Ert/lib/util/test_util.cpp @@ -24,12 +24,12 @@ #include #include -#include "ert/util/build_config.h" -#include -#include -#include -#include -#include +#include "ert/util/build_config.hpp" +#include +#include +#include +#include +#include void test_error_exit( const char * fmt , ...) { char * s; diff --git a/ThirdParty/Ert/lib/util/test_work_area.c b/ThirdParty/Ert/lib/util/test_work_area.cpp similarity index 98% rename from ThirdParty/Ert/lib/util/test_work_area.c rename to ThirdParty/Ert/lib/util/test_work_area.cpp index 88116c7e1c..09e394fa92 100644 --- a/ThirdParty/Ert/lib/util/test_work_area.c +++ b/ThirdParty/Ert/lib/util/test_work_area.cpp @@ -16,7 +16,7 @@ for more details. */ -#include +#include #ifdef ERT_HAVE_GETUID #include @@ -29,11 +29,11 @@ #include #include -#include -#include -#include +#include +#include +#include -#include +#include #ifdef ERT_HAVE_OPENDIR #include #include diff --git a/ThirdParty/Ert/lib/util/tests/ert_util_PATH_test.c b/ThirdParty/Ert/lib/util/tests/ert_util_PATH_test.c deleted file mode 100644 index 8b84bb56b8..0000000000 --- a/ThirdParty/Ert/lib/util/tests/ert_util_PATH_test.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright (C) 2012 Statoil ASA, Norway. - - The file 'ert_util_PATH_test.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#include -#include -#include - -#include -#include -#include - - - -int main(int argc , char ** argv) { - unsetenv("PATH"); - { - char ** path_list = util_alloc_PATH_list(); - if (path_list[0] != NULL) - test_error_exit("Failed on empty PATH\n"); - - util_free_NULL_terminated_stringlist( path_list ); - } - - - setenv("PATH" , "/usr/bin:/bin:/usr/local/bin" , 1); - { - char ** path_list = util_alloc_PATH_list(); - if (strcmp(path_list[0] , "/usr/bin") != 0) - test_error_exit("Failed on first path element\n"); - - if (strcmp(path_list[1] , "/bin") != 0) - test_error_exit("Failed on second path element\n"); - - if (strcmp(path_list[2] , "/usr/local/bin") != 0) - test_error_exit("Failed on third path element\n"); - - if (path_list[3] != NULL) - test_error_exit("Failed termination \n"); - - util_free_NULL_terminated_stringlist( path_list ); - } - - - exit(0); -} diff --git a/ThirdParty/Ert/lib/util/tests/ert_util_logh.c b/ThirdParty/Ert/lib/util/tests/ert_util_logh.c deleted file mode 100644 index 91ae801756..0000000000 --- a/ThirdParty/Ert/lib/util/tests/ert_util_logh.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - Copyright (C) 2013 Statoil ASA, Norway. - - The file 'ert_util_logh.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#include -#include - -#include -#include -#include -#include - -#define LOG_FILE "log.txt" - - -void test_open() { - test_work_area_type * work_area = test_work_area_alloc("util/logh"); - { - log_type * logh = log_open( NULL , 0 ); - test_assert_int_equal( 0 , log_get_msg_count( logh )); - test_assert_false( log_is_open( logh )); - log_reopen( logh , LOG_FILE ); - test_assert_true( log_is_open( logh )); - - log_close( logh ); - } - - { - log_type * logh = log_open( LOG_FILE , 0 ); - test_assert_not_NULL(logh); - log_close( logh ); - } - - { - log_type * logh = log_open( LOG_FILE , 1 ); - test_assert_true( log_is_open( logh )); - log_add_message( logh , 1 , NULL , "Message" , false); - test_assert_int_equal( 1 , log_get_msg_count( logh )); - log_close( logh ); - } - - test_work_area_free( work_area ); -} - - -void test_delete_empty() { - test_work_area_type * work_area = test_work_area_alloc("logh_delete_empty"); - { - log_type * logh = log_open( LOG_FILE , 0 ); - test_assert_not_NULL(logh); - log_close( logh ); - - test_assert_false( util_file_exists( LOG_FILE )); - } - - { - log_type * logh = log_open( LOG_FILE , 0 ); - log_reopen( logh , "LOG2.txt"); - log_close( logh ); - - test_assert_false( util_file_exists( LOG_FILE )); - } - - { - log_type * logh = log_open( LOG_FILE , 1 ); - log_add_message( logh , 1 , NULL , "Message" , false); - log_close( logh ); - test_assert_true( util_file_exists( LOG_FILE )); - - logh = log_open( LOG_FILE , 1 ); - log_close( logh ); - test_assert_true( util_file_exists( LOG_FILE )); - } - - test_work_area_free( work_area ); -} - - -/* - Someone else deletes the file before closing - that should not kill the thing. -*/ - -void test_file_deleted() { - log_type * logh = log_open( LOG_FILE , 1 ); - log_add_message( logh , 1 , NULL , "Message" , false); - util_unlink( LOG_FILE ); - test_assert_false( util_file_exists( LOG_FILE )); - log_close( logh ); - test_assert_false( util_file_exists( LOG_FILE )); -} - -int main(int argc , char ** argv) { - test_open(); - test_delete_empty(); - test_file_deleted( ); - exit(0); -} diff --git a/ThirdParty/Ert/lib/util/tests/ert_util_matrix.c b/ThirdParty/Ert/lib/util/tests/ert_util_matrix.c deleted file mode 100644 index c3c47a0953..0000000000 --- a/ThirdParty/Ert/lib/util/tests/ert_util_matrix.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - Copyright (C) 2013 Statoil ASA, Norway. - - The file 'ert_util_matrix.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - - - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - - -void test_resize() { - matrix_type * m1 = matrix_alloc(5,5); - matrix_type * m2 = matrix_alloc(5,5); - rng_type * rng = rng_alloc( MZRAN , INIT_DEFAULT ); - - matrix_random_init( m1 , rng ); - matrix_assign( m2 , m1 ); - - test_assert_true( matrix_equal( m1 , m2 )); - matrix_resize( m1 , 5 , 5 , false ); - test_assert_true( matrix_equal( m1 , m2 )); - matrix_resize( m1 , 5 , 5 , true ); - test_assert_true( matrix_equal( m1 , m2 )); - - rng_free( rng ); - matrix_free( m1 ); - matrix_free( m2 ); -} - - -void test_column_equal() { - matrix_type * m1 = matrix_alloc(5,5); - matrix_type * m2 = matrix_alloc(5,5); - matrix_type * m3 = matrix_alloc(6,5); - rng_type * rng = rng_alloc( MZRAN , INIT_DEFAULT ); - - matrix_random_init( m1 , rng ); - matrix_assign( m2 , m1 ); - - test_assert_true( matrix_columns_equal( m1 , 2 , m2 , 2 )); - test_assert_false( matrix_columns_equal( m1 , 2 , m2 , 3 )); - test_assert_false( matrix_columns_equal( m1 , 2 , m3 , 3 )); - - rng_free( rng ); - matrix_free( m1 ); - matrix_free( m2 ); - matrix_free( m3 ); -} - - - - -void test_create_invalid() { - test_assert_NULL( matrix_alloc(0, 100)); - test_assert_NULL( matrix_alloc(100, 0)); - test_assert_NULL( matrix_alloc(0, 0)); - test_assert_NULL( matrix_alloc(-1, -1)); -} - - - -void test_dims() { - const int rows = 10; - const int columns = 13; - matrix_type * m = matrix_alloc(rows , columns); - - test_assert_true( matrix_check_dims(m , rows , columns)); - test_assert_false( matrix_check_dims(m , rows + 1 , columns)); - test_assert_false( matrix_check_dims(m , rows , columns + 1)); - - matrix_free( m ); -} - - - - -void test_readwrite() { - test_work_area_type * test_area = test_work_area_alloc("matrix-test"); - { - rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); - matrix_type * m1 = matrix_alloc(3 , 3); - matrix_type * m2 = matrix_alloc(3 , 3); - matrix_random_init( m1 , rng ); - matrix_assign(m2 , m1); - - test_assert_true( matrix_equal( m1 , m2 ) ); - { - FILE * stream = util_fopen("m1" , "w"); - matrix_fwrite( m1 , stream ); - fclose( stream ); - } - matrix_random_init( m1 , rng ); - test_assert_false( matrix_equal( m1 , m2 ) ); - { - FILE * stream = util_fopen("m1" , "r"); - matrix_free( m1 ); - m1 = matrix_alloc(1,1); - printf("-----------------------------------------------------------------\n"); - matrix_fread( m1 , stream ); - test_assert_int_equal( matrix_get_rows(m1) , matrix_get_rows( m2)); - test_assert_int_equal( matrix_get_columns(m1) , matrix_get_columns( m2)); - util_fseek( stream , 0 , SEEK_SET); - { - matrix_type * m3 = matrix_fread_alloc( stream ); - test_assert_true( matrix_equal( m2 , m3 )); - matrix_free( m3 ); - } - fclose( stream ); - } - test_assert_true( matrix_equal( m1 , m2 ) ); - - matrix_free( m2 ); - matrix_free( m1 ); - rng_free( rng ); - } - test_work_area_free( test_area ); -} - - -void test_diag_std() { - const int N = 25; - double_vector_type * data = double_vector_alloc( 0,0); - rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); - matrix_type * m = matrix_alloc( N , N ); - double sum1 = 0; - double sum2 = 0; - int i; - - for (i=0; i < N; i++) { - double R = rng_get_double( rng ); - matrix_iset(m , i , i , R); - double_vector_iset( data , i , R ); - - sum1 += R; - sum2 += R*R; - } - { - double mean = sum1 / N; - double std = sqrt( sum2 / N - mean * mean ); - - test_assert_double_equal( std , matrix_diag_std( m , mean )); - test_assert_double_equal( statistics_std( data ) , matrix_diag_std( m , mean )); - test_assert_double_equal( statistics_mean( data ) , mean ); - } - matrix_free( m ); - rng_free( rng ); -} - - - -void test_masked_copy() { - const int N = 25; - bool_vector_type * mask = bool_vector_alloc(N , true); - rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); - matrix_type * m1 = matrix_alloc( N , N ); - matrix_random_init( m1 , rng ); - - bool_vector_iset( mask , 0 , false ); - bool_vector_iset( mask , 10 , false ); - - { - matrix_type * m2 = matrix_alloc_column_compressed_copy( m1 , mask ); - matrix_type * m3 = matrix_alloc( N , N - 2 ); - - test_assert_int_equal( matrix_get_rows( m1 ) , matrix_get_rows( m2 )); - test_assert_int_equal( matrix_get_columns( m1 ) , matrix_get_columns( m2 ) + 2); - - matrix_column_compressed_memcpy( m3 , m1 , mask ); - { - int src_col; - int target_col = 0; - for (src_col = 0; src_col < N; src_col++) { - if (bool_vector_iget( mask , src_col)) { - test_assert_true( matrix_columns_equal( m1 , src_col , m3 , target_col )); - target_col++; - } - } - } - - test_assert_true( matrix_equal( m2 , m3 )); - matrix_free( m3 ); - matrix_free( m2 ); - } - - matrix_free( m1 ); - rng_free( rng ); -} - - -void test_inplace_sub_column() { - const int N = 25; - rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); - matrix_type * m1 = matrix_alloc( N , N ); - matrix_type * m2 = matrix_alloc( N , N ); - - matrix_random_init( m1 , rng ); - matrix_assign( m2 , m1 ); - matrix_inplace_sub_column( m1 , m2 , 0 , 0 ); - { - int row; - for (row = 0; row < N; row++) { - double diff = matrix_iget( m1 , row , 0); - test_assert_true( fabs( diff ) < 1e-6); - } - } -} - - -int main( int argc , char ** argv) { - test_create_invalid(); - test_resize(); - test_column_equal(); - test_dims(); - - test_readwrite(); - test_diag_std(); - test_masked_copy(); - test_inplace_sub_column(); - exit(0); -} diff --git a/ThirdParty/Ert/lib/util/tests/ert_util_matrix_lapack.c b/ThirdParty/Ert/lib/util/tests/ert_util_matrix_lapack.c deleted file mode 100644 index 233a46c711..0000000000 --- a/ThirdParty/Ert/lib/util/tests/ert_util_matrix_lapack.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - Copyright (C) 2015 Statoil ASA, Norway. - - The file 'ert_util_matrix_lapack.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - - - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - - - - -void test_det4() { - matrix_type * m = matrix_alloc(4 , 4 ); - rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); - for (int i=0; i < 10; i++) { - matrix_random_init( m , rng ); - { - double det4 = matrix_det4( m ); - double det = matrix_det( m ); - - test_assert_double_equal( det , det4 ); - } - } - - matrix_free( m ); - rng_free( rng ); -} - - -void test_det3() { - matrix_type * m = matrix_alloc(3 , 3 ); - rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); - matrix_random_init( m , rng ); - - { - double det3 = matrix_det3( m ); - double det = matrix_det( m ); - - test_assert_double_equal( det , det3 ); - } - - matrix_free( m ); - rng_free( rng ); -} - - -void test_det2() { - matrix_type * m = matrix_alloc(2,2); - rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); - matrix_random_init( m , rng ); - { - double det2 = matrix_det2( m ); - double det = matrix_det( m ); - - test_assert_double_equal( det , det2 ); - } - matrix_free( m ); - rng_free( rng ); -} - - - -int main( int argc , char ** argv) { - test_det2(); - test_det3(); - test_det4(); - exit(0); -} diff --git a/ThirdParty/Ert/lib/util/tests/ert_util_matrix_stat.c b/ThirdParty/Ert/lib/util/tests/ert_util_matrix_stat.c deleted file mode 100644 index 6e2ce86bf5..0000000000 --- a/ThirdParty/Ert/lib/util/tests/ert_util_matrix_stat.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - Copyright (C) 2015 Statoil ASA, Norway. - - The file 'ert_util_matrix_stat.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include - - - -void test_invalid_dimensions() { - matrix_type * X = matrix_alloc(10,2); - matrix_type * Y = matrix_alloc(11,1); - matrix_type * S = matrix_alloc(10,1); - matrix_type * beta = matrix_alloc(2,1); - - test_assert_true( matrix_stat_llsq_estimate( beta , X , Y , S ) == LLSQ_INVALID_DIM ); - test_assert_true( matrix_stat_llsq_estimate( beta , X , Y , NULL ) == LLSQ_INVALID_DIM ); - - matrix_resize(beta , 4 , 1 , false ); - matrix_resize(Y , 3 , 1 , false ); - matrix_resize(X , 3 , 4 , false ); - test_assert_true( matrix_stat_llsq_estimate( beta , X , Y , NULL ) == LLSQ_UNDETERMINED ); - - matrix_free( Y ); - matrix_free( S ); - matrix_free( beta ); - matrix_free( X ); -} - - -void test_no_sigma() { - const double A = 4.00; - const double B = -2; - const double C = 0.25; - - const double xmin = 0; - const double xmax = 1; - int size = 20; - int P = 3; - matrix_type * X = matrix_alloc(size,P); - matrix_type * Y = matrix_alloc(size,1); - matrix_type * beta = matrix_alloc(P,1); - - int i; - for (i = 0; i < size; i++) { - double x = xmin + i * (xmax - xmin) / (size - 1); - - double y = A + B*x + C*x*x; - matrix_iset( X , i , 0 , 1 ); - matrix_iset( X , i , 1 , x ); - matrix_iset( X , i , 2 , x*x ); - - matrix_iset( Y , i , 0 , y); - } - - test_assert_true( matrix_stat_llsq_estimate( beta , X , Y , NULL ) == LLSQ_SUCCESS ); - - test_assert_double_equal( A , matrix_iget( beta , 0 , 0 )); - test_assert_double_equal( B , matrix_iget( beta , 1 , 0 )); - test_assert_double_equal( C , matrix_iget( beta , 2 , 0 )); - - - matrix_free( Y ); - matrix_free( beta ); - matrix_free( X ); -} - - -void test_with_sigma() { - const double A = 4.00; - const double B = -2; - const double C = 0.25; - - const double xmin = 0; - const double xmax = 1; - int size = 20; - int P = 3; - matrix_type * X = matrix_alloc(size,P); - matrix_type * Y = matrix_alloc(size,1); - matrix_type * beta = matrix_alloc(P,1); - matrix_type * S = matrix_alloc(size,1); - - int i; - for (i = 0; i < size; i++) { - double x = xmin + i * (xmax - xmin) / (size - 1); - - double y = A + B*x + C*x*x; - matrix_iset( X , i , 0 , 1 ); - matrix_iset( X , i , 1 , x ); - matrix_iset( X , i , 2 , x*x ); - - matrix_iset( Y , i , 0 , y); - matrix_iset( S , i , 0 , 1); - } - - test_assert_true( matrix_stat_llsq_estimate( beta , X , Y , S ) == LLSQ_SUCCESS ); - - test_assert_double_equal( A , matrix_iget( beta , 0 , 0 )); - test_assert_double_equal( B , matrix_iget( beta , 1 , 0 )); - test_assert_double_equal( C , matrix_iget( beta , 2 , 0 )); - - matrix_free( S ); - matrix_free( Y ); - matrix_free( beta ); - matrix_free( X ); -} - - -void test_polyfit() { - const double A = 4.00; - const double B = -2; - const double C = 0.25; - - const double xmin = 0; - const double xmax = 1; - int size = 20; - int P = 3; - matrix_type * X = matrix_alloc(size,1); - matrix_type * Y = matrix_alloc(size,1); - matrix_type * beta = matrix_alloc(P,1); - - int i; - for (i = 0; i < size; i++) { - double x = xmin + i * (xmax - xmin) / (size - 1); - - double y = A + B*x + C*x*x; - matrix_iset( X , i , 0 , x ); - matrix_iset( Y , i , 0 , y); - } - - test_assert_true( matrix_stat_polyfit( beta , X , Y , NULL) == LLSQ_SUCCESS ); - - test_assert_double_equal( A , matrix_iget( beta , 0 , 0 )); - test_assert_double_equal( B , matrix_iget( beta , 1 , 0 )); - test_assert_double_equal( C , matrix_iget( beta , 2 , 0 )); - - matrix_free( Y ); - matrix_free( beta ); - matrix_free( X ); -} - - - - - -int main() { - util_install_signals(); - test_invalid_dimensions(); - test_no_sigma(); - test_with_sigma(); - test_polyfit(); - exit(0); -} diff --git a/ThirdParty/Ert/lib/util/tests/ert_util_time_interval.c b/ThirdParty/Ert/lib/util/tests/ert_util_time_interval.c deleted file mode 100644 index 7a40e4e145..0000000000 --- a/ThirdParty/Ert/lib/util/tests/ert_util_time_interval.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - Copyright (C) 2012 Statoil ASA, Norway. - - The file 'ert_util_time_interval.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#include -#include -#include - -#include -#include -#include - - - -int main( int argc , char ** argv) { - time_t start_time = util_make_date_utc(1,1,2000); - time_t end_time = util_make_date_utc(1,1,2010); - time_t in = util_make_date_utc( 1,1,2005); - time_t before = util_make_date_utc( 1,1,1995); - time_t after = util_make_date_utc( 1,1,2015); - - { - time_interval_type * ti = time_interval_alloc( start_time , end_time ); - test_assert_not_NULL( ti ); - test_assert_false( time_interval_is_empty( ti )); - - test_assert_true( time_interval_contains( ti , start_time )); - test_assert_true( time_interval_contains( ti , in )); - test_assert_false( time_interval_contains( ti , before )); - test_assert_false( time_interval_contains( ti , end_time )); - test_assert_false( time_interval_contains( ti , after )); - - test_assert_false( time_interval_update( ti , end_time , start_time )); - test_assert_true( time_interval_is_empty( ti )); - - test_assert_false( time_interval_contains( ti , start_time )); - test_assert_false( time_interval_contains( ti , in )); - test_assert_false( time_interval_contains( ti , before )); - test_assert_false( time_interval_contains( ti , end_time )); - test_assert_false( time_interval_contains( ti , after )); - - test_assert_true( time_interval_update( ti , start_time , end_time )); - test_assert_false( time_interval_is_empty( ti )); - - time_interval_free( ti ); - } - - { - time_interval_type * ti = time_interval_alloc( end_time , start_time ); - test_assert_not_NULL( ti ); - test_assert_true( time_interval_is_empty( ti )); - test_assert_true( time_interval_update( ti , start_time , end_time )); - test_assert_false( time_interval_is_empty( ti )); - time_interval_free( ti ); - } - - { - time_interval_type * t1 = time_interval_alloc( start_time , end_time ); - time_interval_type * t2 = time_interval_alloc( in , after ); - time_interval_type * t3 = time_interval_alloc( end_time , start_time ); - time_interval_type * t4 = time_interval_alloc( before , start_time ); - time_interval_type * t5 = time_interval_alloc( end_time , after ); - - test_assert_true( time_interval_has_overlap( t1 , t2 )); - - test_assert_true( time_interval_is_empty( t3 )); - test_assert_false( time_interval_has_overlap( t1 , t3 )); - test_assert_false( time_interval_has_overlap( t3 , t1 )); - test_assert_false( time_interval_has_overlap( t3 , t3 )); - test_assert_false( time_interval_has_overlap( t4 , t5 )); - test_assert_false( time_interval_has_overlap( t1 , t5 )); - - - time_interval_free( t1 ); - time_interval_free( t2 ); - } - - { - time_interval_type * ti = time_interval_alloc_open(); - - test_assert_false( time_interval_is_empty( ti )); - - test_assert_true( time_interval_contains( ti , start_time )); - test_assert_true( time_interval_contains( ti , in )); - test_assert_true( time_interval_contains( ti , before )); - test_assert_true( time_interval_contains( ti , end_time )); - test_assert_true( time_interval_contains( ti , after )); - - test_assert_true( time_interval_update_start( ti , start_time )); - test_assert_true( time_interval_contains( ti , start_time )); - test_assert_true( time_interval_update_start( ti , in )); - test_assert_false( time_interval_contains( ti , start_time )); - test_assert_false( time_interval_is_empty( ti )); - - test_assert_false( time_interval_update_end( ti , start_time )); - test_assert_true( time_interval_is_empty( ti )); - test_assert_true( time_interval_update_end( ti , end_time )); - test_assert_false( time_interval_is_empty( ti )); - test_assert_false( time_interval_contains( ti , start_time )); - - time_interval_free( ti ); - } - - { - time_interval_type * t1 = time_interval_alloc( start_time , end_time ); - - test_assert_time_t_equal( start_time , time_interval_get_start( t1 )); - test_assert_time_t_equal( end_time , time_interval_get_end( t1 )); - test_assert_false( time_interval_is_empty( t1 )); - - test_assert_false( time_interval_update_end( t1 , before )); - test_assert_true( time_interval_is_empty( t1 )); - test_assert_time_t_equal( start_time , time_interval_get_start( t1 )); - test_assert_time_t_equal( before , time_interval_get_end( t1 )); - - test_assert_true( time_interval_update_end( t1 , in )); - test_assert_false( time_interval_is_empty( t1 )); - test_assert_time_t_equal( start_time , time_interval_get_start( t1 )); - test_assert_time_t_equal( in , time_interval_get_end( t1 )); - - time_interval_free( t1 ); - } - - { - time_interval_type * t1 = time_interval_alloc( start_time , in ); - time_interval_type * t2 = time_interval_alloc( in , end_time ); - time_interval_type * t3 = time_interval_alloc( start_time , end_time); - - test_assert_true( time_interval_is_adjacent( t1 , t2 )); - test_assert_true( time_interval_is_adjacent( t2 , t1 )); - - test_assert_false( time_interval_is_adjacent( t1 , t3 )); - test_assert_false( time_interval_is_adjacent( t3 , t1 )); - test_assert_false( time_interval_is_adjacent( t2 , t3 )); - test_assert_false( time_interval_is_adjacent( t3 , t2 )); - - time_interval_free( t1 ); - time_interval_free( t2 ); - time_interval_free( t3 ); - } - - - - { - time_interval_type * t1 = time_interval_alloc( start_time , end_time ); - time_interval_type * t2 = time_interval_alloc( in , end_time ); - time_interval_type * t3 = time_interval_alloc( end_time , after ); - time_interval_type * t4 = time_interval_alloc( before , start_time ); - - test_assert_true( time_interval_extend(t1 , t2 )); - test_assert_time_t_equal( start_time , time_interval_get_start( t1 )); - test_assert_time_t_equal( end_time , time_interval_get_end( t1 )); - - test_assert_true( time_interval_extend(t1 , t3 )); - test_assert_time_t_equal( start_time , time_interval_get_start( t1 )); - test_assert_time_t_equal( after , time_interval_get_end( t1 )); - - test_assert_true( time_interval_update_start(t1 , in )); - test_assert_time_t_equal( in , time_interval_get_start( t1 )); - - - test_assert_false( time_interval_extend(t1 , t4 )); - test_assert_time_t_equal( in , time_interval_get_start( t1 )); - test_assert_time_t_equal( after , time_interval_get_end( t1 )); - - - test_assert_true( time_interval_update_end(t4 , in )); - test_assert_true( time_interval_extend(t1 , t4 )); - test_assert_time_t_equal( before , time_interval_get_start( t1 )); - test_assert_time_t_equal( after , time_interval_get_end( t1 )); - - - time_interval_free( t1 ); - time_interval_free( t2 ); - time_interval_free( t3 ); - time_interval_free( t4 ); - } - - { - time_interval_type * t1 = time_interval_alloc( start_time , end_time ); - time_interval_type * t2 = time_interval_alloc( in , end_time ); - time_interval_type * t3 = time_interval_alloc( end_time , after ); - time_interval_type * t4 = time_interval_alloc( before , start_time ); - - test_assert_true( time_interval_intersect(t1 , t2 )); - test_assert_time_t_equal( in , time_interval_get_start( t1 )); - test_assert_time_t_equal( end_time , time_interval_get_end( t1 )); - - time_interval_free( t1 ); - time_interval_free( t2 ); - time_interval_free( t3 ); - time_interval_free( t4 ); - } - - { - time_interval_type * t1 = time_interval_alloc( start_time , end_time ); - time_interval_type * t2 = time_interval_alloc( start_time , end_time ); - time_interval_type * t3 = time_interval_alloc( end_time , after ); - time_interval_type * t4 = time_interval_alloc_copy( t1 ); - - test_assert_true( time_interval_equal( t1 , t2 )); - test_assert_false( time_interval_equal( t1 , t3 )); - - test_assert_true( time_interval_equal( t4 , t2 )); - test_assert_false( time_interval_equal( t4 , t3 )); - - test_assert_ptr_not_equal( t4 , t1 ); - time_interval_free( t1 ); - time_interval_free( t2 ); - time_interval_free( t3 ); - time_interval_free( t4 ); - } - - { - time_interval_type * t1 = time_interval_alloc( start_time , end_time ); - - test_assert_true( time_interval_arg_before( t1 , before )); - test_assert_true( time_interval_arg_after( t1 , after)); - - test_assert_false( time_interval_arg_before( t1 , start_time )); - test_assert_false( time_interval_arg_before( t1 , in )); - test_assert_false( time_interval_arg_before( t1 , after )); - - test_assert_false( time_interval_arg_after( t1 , start_time)); - test_assert_false( time_interval_arg_after( t1 , in)); - test_assert_true( time_interval_arg_after( t1 , after)); - - time_interval_free( t1 ); - } - - exit(0); -} diff --git a/ThirdParty/Ert/lib/util/tests/ert_util_ui_return.c b/ThirdParty/Ert/lib/util/tests/ert_util_ui_return.c deleted file mode 100644 index 82a711d12d..0000000000 --- a/ThirdParty/Ert/lib/util/tests/ert_util_ui_return.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright (C) 2013 Statoil ASA, Norway. - - The file 'enkf_ui_return_type.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include - -#include -#include - - - - -void test_create() { - ui_return_status_enum status = UI_RETURN_OK; - ui_return_type * ui_return = ui_return_alloc(status); - test_assert_true( ui_return_is_instance( ui_return )); - test_assert_int_equal( status , ui_return_get_status(ui_return)); - ui_return_free( ui_return ); -} - - -void test_default() { - ui_return_status_enum status = UI_RETURN_OK; - ui_return_type * ui_return = ui_return_alloc(status); - - test_assert_int_equal( 0 , ui_return_get_error_count(ui_return)); - test_assert_NULL( ui_return_get_first_error( ui_return)); - test_assert_NULL( ui_return_get_last_error( ui_return)); - test_assert_NULL( ui_return_get_help(ui_return)); - ui_return_free( ui_return); -} - -void test_errors_inconsistent() { - ui_return_status_enum status = UI_RETURN_OK; - ui_return_type * ui_return = ui_return_alloc(status); - - test_assert_int_equal( 0 , ui_return_get_error_count(ui_return)); - test_assert_false( ui_return_add_error( ui_return , "ERROR1")); - test_assert_int_equal( 0 , ui_return_get_error_count(ui_return)); - ui_return_free( ui_return); -} - - -void test_errors_consistent() { - ui_return_status_enum status = UI_RETURN_FAIL; - ui_return_type * ui_return = ui_return_alloc(status); - - test_assert_int_equal( 0 , ui_return_get_error_count(ui_return)); - test_assert_true( ui_return_add_error( ui_return , "ERROR1")); - test_assert_int_equal(1, ui_return_get_error_count(ui_return)); - test_assert_string_equal("ERROR1", ui_return_get_first_error(ui_return)); - test_assert_string_equal("ERROR1", ui_return_get_last_error(ui_return)); - - test_assert_true(ui_return_add_error(ui_return, "ERROR2")); - test_assert_int_equal(2, ui_return_get_error_count(ui_return)); - test_assert_string_equal("ERROR1", ui_return_get_first_error(ui_return)); - test_assert_string_equal("ERROR2", ui_return_get_last_error(ui_return)); - - test_assert_string_equal("ERROR1" , ui_return_iget_error(ui_return , 0)); - test_assert_string_equal("ERROR2" , ui_return_iget_error(ui_return , 1)); - - ui_return_free( ui_return); -} - - -void test_help() { - ui_return_type * ui_return = ui_return_alloc(UI_RETURN_OK); - - ui_return_add_help(ui_return , "HELP1"); - test_assert_string_equal( "HELP1" , ui_return_get_help(ui_return)); - - ui_return_add_help(ui_return , "HELP2"); - test_assert_string_equal( "HELP1 HELP2" , ui_return_get_help(ui_return)); - - ui_return_free( ui_return); -} - -int main(int argc , char ** argv) { - test_create(); - test_default(); - test_errors_inconsistent(); - exit(0); -} diff --git a/ThirdParty/Ert/lib/util/thread_pool1.c b/ThirdParty/Ert/lib/util/thread_pool1.c deleted file mode 100644 index d365a67e30..0000000000 --- a/ThirdParty/Ert/lib/util/thread_pool1.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'thread_pool1.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#include -#include -#include -#include -#include - -struct thread_pool_struct { - int pool_size; - int jobs_running; - pthread_t *thread_list; -}; - - - - - -static void thread_pool_resize(thread_pool_type * pool, int new_size) { - pool->pool_size = new_size; - pool->thread_list = realloc(pool->thread_list , new_size * sizeof * pool->thread_list); -} - - - -void thread_pool_join(thread_pool_type * pool) { - int i; - if (pool->pool_size == 0) - return; - else { - for (i=0; i < pool->jobs_running; i++) - pthread_join(pool->thread_list[i] , NULL); /* Second argument: void **value_ptr */ - pool->jobs_running = 0; - } -} - - -thread_pool_type * thread_pool_alloc(int pool_size) { - thread_pool_type * pool = util_malloc(sizeof *pool); - pool->thread_list = NULL; - thread_pool_resize(pool , pool_size); - pool->jobs_running = 0; - return pool; -} - - - -void thread_pool_add_job(thread_pool_type * pool , - void * (start_func) (void *) , void *arg) { - - if (pool->pool_size == 0) - start_func(arg); - else { - - if (pool->jobs_running == pool->pool_size) - thread_pool_join(pool); - - { - int pthread_return = pthread_create( &pool->thread_list[pool->jobs_running] , NULL , start_func , arg); - if (pthread_return != 0) - util_abort("%s: failed to add new job pthread_create return value: %d.\n",__func__ , pthread_return); - } - - pool->jobs_running++; - } - -} - -void thread_pool_free(thread_pool_type * pool) { - if (pool->thread_list != NULL) free(pool->thread_list); - free(pool); -} - - diff --git a/ThirdParty/Ert/lib/util/thread_pool_posix.c b/ThirdParty/Ert/lib/util/thread_pool_posix.c deleted file mode 100644 index 8288013b48..0000000000 --- a/ThirdParty/Ert/lib/util/thread_pool_posix.c +++ /dev/null @@ -1,485 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'thread_pool_posix.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ - -#define _GNU_SOURCE /* Must define this to get access to pthread_rwlock_t */ -#include -#include -#include -#include -#include -#include - -#include "ert/util/build_config.h" - -#include -#include -#include - - -/** - This file implements a small thread_pool object based on - pthread_create() function calls. The characetristics of this - implementation is as follows: - - 1. The jobs are mangaged by a separate thread - dispatch_thread. - 2. The new jobs are just appended to the queue, the - dispatch_thread sees them in the queue and dispatches them. - 3. The dispatch thread manages a list of thread_pool_job_slot_type - instances - one slot for each actually running job. - - Example - ------- - - 1. Start with creating a thread pool object. The arguments to the - allocater are the (maximum) number of concurrently running - threads and a boolean flag of whether the queue should start - immediately (that is in general the case). - - thread_pool_type * tp = thread_pool_alloc( NUM_THREADS , immediate_start); - - - 2. Add the jobs you want to run: - - thread_pool_add_job( tp , some_function , argument_to_some_function ); - - Here the prototype for the function which is being run is - - void * (some_func) (void *); - - I.e. it expects a (void *) input pointer, and also returns a - (void *) pointer as output. The thread pool implementation does - not touch the input and output of some_function. - - - 3. When all the jobs have been added you inform the thread pool of - that by calling: - - thread_pool_join( tp ); - - This function will not return before all the added jobs have run - to completion. - - - 4. Optional: If you want to get the return value from the function - you supplied, you can use: - - thread_pool_iget_return_value( tp , index ); - - To get the return value from function nr index. - - - 5. Optional: The thread pool will probably mainly be used only once, - but after a join it is possible to reuse a thread pool, but then - you MUST call thread_pool_restart() before adding jobs again. - - - 6. When you are really finished: thread_pool_free( tp ); - -*/ - - -typedef void * (start_func_ftype) (void *) ; - - -/** - Internal struct which is used as queue node. -*/ -typedef struct { - thread_pool_type * pool; /* A back-reference to the thread_pool holding the queue. */ - int slot_index; /* The index in the space [0,max_running) of the job slot where this job is running. */ - int queue_index; /* The index of the current tp_arg in the queue. */ - void * func_arg; /* The arguments to this job - supplied by the calling scope. */ - start_func_ftype * func; /* The function to call - supplied by the calling scope. */ - void * return_value; -} thread_pool_arg_type; - - - -/** - Internal struct used to keep track of the job slots. -*/ -typedef struct { - pthread_t thread; /* The thread variable currently (or more correct:last) running. */ - int run_count; /* The number of times this slot has been used - just to check whether the slot has been used AT ALL when/if joining. */ - bool running; /* Is the job_slot running now?? */ -} thread_pool_job_slot_type; - - - - -#define THREAD_POOL_TYPE_ID 71443207 -struct thread_pool_struct { - UTIL_TYPE_ID_DECLARATION; - thread_pool_arg_type * queue; /* The jobs to be executed are appended in this vector. */ - int queue_index; /* The index of the next job to run. */ - int queue_size; /* The number of jobs in the queue - including those which are complete. [Should be protected / atomic / ... ] */ - int queue_alloc_size; /* The allocated size of the queue. */ - - int max_running; /* The max number of concurrently running jobs. */ - bool join; /* Flag set by the main thread to inform the dispatch thread that joining should start. */ - bool accepting_jobs; /* True|False whether the dispatch thread is running. */ - - thread_pool_job_slot_type * job_slots; /* A vector to @max_running job slots, each slot can be reused several times.*/ - pthread_t dispatch_thread; - pthread_rwlock_t queue_lock; -}; - - -static UTIL_SAFE_CAST_FUNCTION( thread_pool , THREAD_POOL_TYPE_ID ) - - -/** - This function will grow the queue. It is called by the main thread - (i.e. the context of the calling scope), and the queue is read by - the dispatch_thread - i.e. access to the queue must be protected by - rwlock. -*/ - -static void thread_pool_resize_queue( thread_pool_type * pool, int queue_length ) { - pthread_rwlock_wrlock( &pool->queue_lock ); - { - pool->queue = (thread_pool_arg_type*)util_realloc( pool->queue , queue_length * sizeof * pool->queue ); - pool->queue_alloc_size = queue_length; - } - pthread_rwlock_unlock( &pool->queue_lock ); -} - - -/** - This function updates an element in the queue, the function is - called by the executing threads, on the same time the main thread - might be resizing the thread, we therefor take a read lock during - execution of this function. (Write lock is not necessary because we - will not change the queue pointer itself, only something it points - to.) -*/ - -static void thread_pool_iset_return_value( thread_pool_type * pool , int index , void * return_value) { - pthread_rwlock_rdlock( &pool->queue_lock ); - { - pool->queue[ index ].return_value = return_value; - } - pthread_rwlock_unlock( &pool->queue_lock ); -} - - -void * thread_pool_iget_return_value( const thread_pool_type * pool , int queue_index ) { - return pool->queue[ queue_index ].return_value; -} - - -/** - The pthread_create() call which this is all about, does not start - the user supplied function. Instead it will start an instance of - this function, which will do some housekeeping before calling the - user supplied function. -*/ - -static void * thread_pool_start_job( void * arg ) { - thread_pool_arg_type * tp_arg = (thread_pool_arg_type * ) arg; - thread_pool_type * tp = tp_arg->pool; - int slot_index = tp_arg->slot_index; - void * func_arg = tp_arg->func_arg; - start_func_ftype * func = tp_arg->func; - void * return_value; - - - return_value = func( func_arg ); /* Starting the real external function */ - tp->job_slots[ slot_index ].running = false; /* We mark the job as completed. */ - free( arg ); - - if (return_value != NULL) - thread_pool_iset_return_value( tp , tp_arg->queue_index , return_value); - - return NULL; -} - - - -/** - This function is run by the dispatch_thread. The thread will keep - an eye on the queue, and dispatch new jobs when there are free - slots available. -*/ - -static void * thread_pool_main_loop( void * arg ) { - thread_pool_type * tp = thread_pool_safe_cast( arg ); - { - const int usleep_init = 1000; /* The sleep time when there are free slots available - but no jobs wanting to run. */ - int internal_offset = 0; /* Keep track of the (index of) the last job slot fired off - minor time saving. */ - while (true) { - if (tp->queue_size > tp->queue_index) { - /* - There are jobs in the queue which would like to run - - let us see if we can find a slot for them. - */ - int counter = 0; - bool slot_found = false; - do { - int slot_index = (counter + internal_offset) % tp->max_running; - thread_pool_job_slot_type * job_slot = &tp->job_slots[ slot_index ]; - if (!job_slot->running) { - /* OK thread[slot_index] is ready to take this job.*/ - thread_pool_arg_type * tp_arg; - - /* - The queue might be updated by the main thread - we must - take a copy of the node we are interested in. - */ - pthread_rwlock_rdlock( &tp->queue_lock ); - tp_arg = (thread_pool_arg_type*)util_alloc_copy( &tp->queue[ tp->queue_index ] , sizeof * tp_arg ); - pthread_rwlock_unlock( &tp->queue_lock ); - - tp_arg->slot_index = slot_index; - job_slot->running = true; - /* - Here is the actual pthread_create() call creating an - additional running thread. - */ - - /*Cleanup of previous run threads. Needed to avoid memory leak*/ - if (job_slot->run_count > 0) - pthread_join(job_slot->thread, NULL); - - pthread_create( &job_slot->thread , NULL , thread_pool_start_job , tp_arg ); - job_slot->run_count += 1; - tp->queue_index++; - internal_offset += (counter + 1); - slot_found = true; - } else - counter++; - } while (!slot_found && (counter < tp->max_running)); - - if (!slot_found) { - util_yield(); - } - } else - util_usleep(usleep_init); /* There are no jobs wanting to run. */ - - /*****************************************************************/ - /* - We exit explicitly from this loop when both conditions apply: - - 1. tp->join == true : The calling scope has signaled that it will not submit more jobs. - 2. tp->queue_size == tp->queue_index : This function has submitted all the jobs in the queue. - */ - if ((tp->join) && (tp->queue_size == tp->queue_index)) - break; - } /* End of while() loop */ - } - - /* - There are no more jobs in the queue, and the main scope has - signaled that join should start. Observe that we join only the - jobs corresponding to explicitly running job_slots; when a job - slot is used multiple times the first jobs run in the job_slot - will not be explicitly joined. - */ - { - int i; - for (i=0; i < tp->max_running; i++) { - thread_pool_job_slot_type job_slot = tp->job_slots[i]; - if (job_slot.run_count > 0) - pthread_join( job_slot.thread , NULL ); - } - } - /* When we are here all the jobs have completed. */ - return NULL; -} - - - - -/** - This function initializes a couple of counters, and starts up the - dispatch thread. If the thread_pool should be reused after a join, - this function must be called before adding new jobs. - - The functions thread_pool_restart() and thread_pool_join() should - be joined up like open/close and malloc/free combinations. -*/ - -void thread_pool_restart( thread_pool_type * tp ) { - if (tp->accepting_jobs) - util_abort("%s: fatal error - tried restart already running thread pool\n",__func__); - { - tp->join = false; - tp->queue_index = 0; - tp->queue_size = 0; - { - int i; - for (i=0; i < tp->max_running; i++) { - tp->job_slots[i].run_count = 0; - tp->job_slots[i].running = false; - } - } - - /* Starting the dispatch thread. */ - pthread_create( &tp->dispatch_thread , NULL , thread_pool_main_loop , tp ); - tp->accepting_jobs = true; - } -} - - - -/** - This function is called by the calling scope when all the jobs have - been submitted, and we just wait for them to complete. - - This function just sets the join switch to true - this again tells - the dispatch_thread to start the join process on the worker - threads. -*/ - -void thread_pool_join(thread_pool_type * pool) { - pool->join = true; /* Signals to the main thread that joining can start. */ - if (pool->max_running > 0) { - pthread_join( pool->dispatch_thread , NULL ); /* Wait for the main thread to complete. */ - pool->accepting_jobs = false; - } -} - -/* - This will try to join the thread; if the manager thread has not - completed within @timeout_seconds the function will return false. If - the join fails the queue will be reset in a non-joining state and it - will be open for more jobs. Probably not in a 100% sane state. -*/ - -bool thread_pool_try_join(thread_pool_type * pool, int timeout_seconds) { - bool join_ok = true; - - pool->join = true; /* Signals to the main thread that joining can start. */ - if (pool->max_running > 0) { - time_t timeout_time = time( NULL ); - util_inplace_forward_seconds_utc(&timeout_time , timeout_seconds ); - -#ifdef HAVE_TIMEDJOIN - - struct timespec ts; - ts.tv_sec = timeout_time; - ts.tv_nsec = 0; - - { - int join_return = pthread_timedjoin_np( pool->dispatch_thread , NULL , &ts); /* Wait for the main thread to complete. */ - if (join_return == 0) - pool->accepting_jobs = false; - else { - pool->join = false; - join_ok = false; - } - } - -#else - - while(true) { - if (pthread_kill(pool->dispatch_thread, 0) == 0){ - util_yield(); - } else { - pthread_join(pool->dispatch_thread, NULL); - pool->accepting_jobs = false; - break; - } - - time_t now = time(NULL); - - if(util_difftime_seconds(now, timeout_time) <= 0) { - join_ok = false; - break; - } - } - -#endif - - - - } - return join_ok; -} - - - - -/** - max_running is the maximum number of concurrent threads. If - @start_queue is true the dispatch thread will start immediately. If - the function is called with @start_queue == false you must first - call thread_pool_restart() BEFORE you can start adding jobs. -*/ - -thread_pool_type * thread_pool_alloc(int max_running , bool start_queue) { - thread_pool_type * pool = (thread_pool_type*)util_malloc( sizeof *pool ); - UTIL_TYPE_ID_INIT( pool , THREAD_POOL_TYPE_ID ); - pool->job_slots = (thread_pool_job_slot_type*)util_calloc( max_running , sizeof * pool->job_slots ); - pool->max_running = max_running; - pool->queue = NULL; - pool->accepting_jobs = false; - pthread_rwlock_init( &pool->queue_lock , NULL); - thread_pool_resize_queue( pool , 32 ); - if (start_queue) - thread_pool_restart( pool ); - return pool; -} - - - -void thread_pool_add_job(thread_pool_type * pool , start_func_ftype * start_func , void * func_arg ) { - if (pool->max_running == 0) /* Blocking non-threaded mode: */ - start_func( func_arg ); - else { - if (pool->accepting_jobs) { - if (pool->queue_size == pool->queue_alloc_size) - thread_pool_resize_queue( pool , pool->queue_alloc_size * 2); - - /* - The new job is added to the queue - the main thread is watching - the queue and will pick up the new job. - */ - { - int queue_index = pool->queue_size; - - pool->queue[ queue_index ].pool = pool; - pool->queue[ queue_index ].func_arg = func_arg; - pool->queue[ queue_index ].func = start_func; - pool->queue[ queue_index ].return_value = NULL; - pool->queue[ queue_index ].queue_index = queue_index; - } - pool->queue_size++; /* <- This is shared between this thread and the dispatch thread */ - } else - util_abort("%s: thread_pool is not running - restart with thread_pool_restart()?? \n",__func__); - } -} - - - -/* - Observe that this function does not join the worker threads, - i.e. you should call thread_pool_join() first (otherwise the thing - will go up in flames). -*/ - - -void thread_pool_free(thread_pool_type * pool) { - util_safe_free( pool->job_slots ); - util_safe_free( pool->queue ); - free(pool); -} - -int thread_pool_get_max_running( const thread_pool_type * pool ) { - return pool->max_running; -} diff --git a/ThirdParty/Ert/lib/util/time_interval.c b/ThirdParty/Ert/lib/util/time_interval.c deleted file mode 100644 index 32d1a9be54..0000000000 --- a/ThirdParty/Ert/lib/util/time_interval.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - Copyright (C) 2013 Statoil ASA, Norway. - - The file 'time_interval.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#include -#include - -#include -#include - -#define TIME_INTERVAL_EMPTY (time_t) -1 -#define TIME_T_MAX (time_t) ((1UL << (( sizeof(time_t) << 3) -1 )) -1 ) -#define TIME_T_MIN -TIME_T_MAX - - -struct time_interval_struct { - bool valid; - time_t start_time; - time_t end_time; -}; - - -/* - If you set something invalid - the whole interval is destroyed. -*/ - -bool time_interval_update( time_interval_type * ti , time_t start_time , time_t end_time) { - ti->start_time = start_time; - ti->end_time = end_time; - - ti->valid = (start_time <= end_time) ? true : false; - return ti->valid; -} - - -bool time_interval_update_start( time_interval_type * ti , time_t start_time ) { - return time_interval_update( ti , start_time , ti->end_time ); -} - - -bool time_interval_update_end( time_interval_type * ti , time_t end_time ) { - return time_interval_update( ti , ti->start_time , end_time ); -} - - -void time_interval_reopen( time_interval_type * time_interval) { - time_interval_update( time_interval , TIME_T_MIN , TIME_T_MAX); -} - - -time_interval_type * time_interval_alloc( time_t start_time , time_t end_time ) { - time_interval_type * ti = (time_interval_type*)util_malloc( sizeof * ti ); - time_interval_update( ti , start_time , end_time ); - return ti; -} - - -time_interval_type * time_interval_alloc_open( ) { - return time_interval_alloc( TIME_T_MIN , TIME_T_MAX ); -} - -time_interval_type * time_interval_alloc_copy( const time_interval_type * src) { - return time_interval_alloc( src->start_time , src->end_time ); -} - - -void time_interval_free( time_interval_type * ti ) { - free( ti ); -} - - -bool time_interval_is_empty( time_interval_type * ti ) { - return (ti->end_time <= ti->start_time); -} - - -bool time_interval_contains( const time_interval_type * ti , time_t t) { - if (!ti->valid) - return false; - else { - if (t < ti->start_time) - return false; - else if (t >= ti->end_time) - return false; - else - return true; - } -} - - - -bool time_interval_has_overlap( const time_interval_type * t1 , const time_interval_type * t2) { - if (t1->valid && t2->valid) { - if (time_interval_contains(t1 , t2->start_time)) - return true; - - if (time_interval_contains(t1 , t2->end_time)) - return true; - - return false; - } else - return false; -} - -bool time_interval_is_adjacent( const time_interval_type * t1 , const time_interval_type * t2) { - if ((t1->end_time == t2->start_time) || (t1->start_time == t2->end_time)) - return true; - else - return false; -} - - -time_t time_interval_get_start( const time_interval_type * ti) { - return ti->start_time; -} - - - -time_t time_interval_get_end( const time_interval_type * ti) { - return ti->end_time; -} - - -bool time_interval_extend( time_interval_type * t1 , const time_interval_type * t2) { - if (time_interval_has_overlap(t1,t2) || time_interval_is_adjacent( t1 , t2)) { - time_t start_time = util_time_t_min( t1->start_time , t2->start_time ); - time_t end_time = util_time_t_max( t1->end_time , t2->end_time ); - - return time_interval_update(t1 , start_time , end_time); - } else - return false; -} - - -bool time_interval_intersect( time_interval_type * t1 , const time_interval_type * t2) { - if (time_interval_has_overlap(t1,t2) || time_interval_is_adjacent( t1 , t2)) { - time_t start_time = util_time_t_max( t1->start_time , t2->start_time ); - time_t end_time = util_time_t_min( t1->end_time , t2->end_time ); - - return time_interval_update(t1 , start_time , end_time); - } else - return false; -} - - -bool time_interval_equal( const time_interval_type * t1 , const time_interval_type * t2) { - if ((t1->start_time == t2->start_time) && (t1->end_time == t2->end_time)) - return true; - else - return false; -} - - -bool time_interval_arg_after( const time_interval_type * ti , time_t arg) { - return util_after( arg , ti->end_time ); -} - - -bool time_interval_arg_before( const time_interval_type * ti , time_t arg) { - return util_before( arg , ti->start_time ); -} diff --git a/ThirdParty/Ert/lib/util/timer.c b/ThirdParty/Ert/lib/util/timer.cpp similarity index 98% rename from ThirdParty/Ert/lib/util/timer.c rename to ThirdParty/Ert/lib/util/timer.cpp index e4672fa7c9..49dd562754 100644 --- a/ThirdParty/Ert/lib/util/timer.c +++ b/ThirdParty/Ert/lib/util/timer.cpp @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/ThirdParty/Ert/lib/util/type_vector_functions.c b/ThirdParty/Ert/lib/util/type_vector_functions.cpp similarity index 93% rename from ThirdParty/Ert/lib/util/type_vector_functions.c rename to ThirdParty/Ert/lib/util/type_vector_functions.cpp index 8aab49197b..2dec9f3f1e 100644 --- a/ThirdParty/Ert/lib/util/type_vector_functions.c +++ b/ThirdParty/Ert/lib/util/type_vector_functions.cpp @@ -18,11 +18,11 @@ #include -#include -#include -#include +#include +#include +#include -#include +#include int_vector_type * bool_vector_alloc_active_list( const bool_vector_type * mask ) { diff --git a/ThirdParty/Ert/lib/util/ui_return.c b/ThirdParty/Ert/lib/util/ui_return.c deleted file mode 100644 index e1b30f8e80..0000000000 --- a/ThirdParty/Ert/lib/util/ui_return.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - - * - * Created on: Aug 28, 2013 - * Author: joaho - */ -/* - Copyright (C) 2013 Statoil ASA, Norway. - - The file 'ui_return.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#include - -#include -#include -#include -#include - - -#define UI_RETURN_TYPE_ID 6122209 - -struct ui_return_struct { - UTIL_TYPE_ID_DECLARATION; - ui_return_status_enum status; - stringlist_type * error_list; - char * help_text; -}; - - -UTIL_IS_INSTANCE_FUNCTION(ui_return , UI_RETURN_TYPE_ID) - - -ui_return_type * ui_return_alloc(ui_return_status_enum status) { - ui_return_type * ui_return = (ui_return_type*)util_malloc( sizeof * ui_return ); - UTIL_TYPE_ID_INIT(ui_return , UI_RETURN_TYPE_ID); - ui_return->status = status; - ui_return->help_text = NULL; - ui_return->error_list = stringlist_alloc_new(); - return ui_return; -} - - -void ui_return_free( ui_return_type * ui_return ) { - stringlist_free(ui_return->error_list); - util_safe_free( ui_return->help_text); - free( ui_return); -} - - -ui_return_status_enum ui_return_get_status(const ui_return_type * ui_return) { - return ui_return->status; -} - - -bool ui_return_add_error(ui_return_type *ui_return , const char * error_msg) { - if (ui_return->status != UI_RETURN_OK) - stringlist_append_copy( ui_return->error_list , error_msg); - - return (ui_return->status != UI_RETURN_OK); -} - - -int ui_return_get_error_count( const ui_return_type * ui_return ) { - return stringlist_get_size( ui_return->error_list ); -} - - -const char * ui_return_get_first_error( const ui_return_type * ui_return) { - if (stringlist_get_size(ui_return->error_list)) - return stringlist_front( ui_return->error_list); - else - return NULL; -} - - -const char * ui_return_get_last_error( const ui_return_type * ui_return) { - if (stringlist_get_size(ui_return->error_list)) - return stringlist_back( ui_return->error_list); - else - return NULL; -} - -const char * ui_return_iget_error( const ui_return_type * ui_return , int index) { - return stringlist_iget(ui_return->error_list , index); -} - - -const char * ui_return_get_help(const ui_return_type * ui_return) { - return ui_return->help_text; -} - - -void ui_return_add_help(ui_return_type * ui_return, const char * help_text) { - if (ui_return->help_text) { - int new_length = strlen(ui_return->help_text) + strlen(help_text) + 1 + 1; - ui_return->help_text = (char*)util_realloc(ui_return->help_text , new_length * sizeof * ui_return->help_text); - - strcat(ui_return->help_text , " "); - strcat(ui_return->help_text , help_text); - } else - ui_return->help_text = util_alloc_string_copy( help_text); -} - - diff --git a/ThirdParty/Ert/lib/util/util.c b/ThirdParty/Ert/lib/util/util.c index 8b301cb4e1..94e42f9c81 100644 --- a/ThirdParty/Ert/lib/util/util.c +++ b/ThirdParty/Ert/lib/util/util.c @@ -284,7 +284,8 @@ static bool EOL_CHAR(char c) { numbers, but deterministic runtime. */ -void util_fread_dev_random(int buffer_size , char * buffer) { +void util_fread_dev_random(int buffer_size_ , char * buffer) { + size_t buffer_size = buffer_size_; FILE * stream = util_fopen("/dev/random" , "r"); if (fread(buffer , 1 , buffer_size , stream) != buffer_size) util_abort("%s: failed to read:%d bytes from /dev/random \n",__func__ , buffer_size); @@ -293,7 +294,8 @@ void util_fread_dev_random(int buffer_size , char * buffer) { } -void util_fread_dev_urandom(int buffer_size , char * buffer) { +void util_fread_dev_urandom(int buffer_size_ , char * buffer) { + size_t buffer_size = buffer_size_; FILE * stream = util_fopen("/dev/urandom" , "r"); if (fread(buffer , 1 , buffer_size , stream) != buffer_size) util_abort("%s: failed to read:%d bytes from /dev/random \n",__func__ , buffer_size); @@ -401,7 +403,8 @@ bool util_double_approx_equal( double d1 , double d2) { } -char * util_alloc_substring_copy(const char *src , int offset , int N) { +char * util_alloc_substring_copy(const char *src , int offset , int N_) { + size_t N = N_; char *copy; if ((N + offset) < strlen(src)) { copy = (char*)util_calloc(N + 1 , sizeof * copy ); @@ -461,7 +464,7 @@ char * util_realloc_dequoted_string(char *s) { } void util_strupr(char *s) { - int i; + size_t i; for (i=0; i < strlen(s); i++) s[i] = toupper(s[i]); } @@ -478,7 +481,7 @@ char * util_alloc_strupr_copy(const char * s) { Replaces all occurences of c1 in s with c2. */ void util_string_tr(char * s, char c1, char c2) { - int i; + size_t i; for (i=0; i < strlen(s);i++) if (s[i] == c1) s[i] = c2; } @@ -811,11 +814,11 @@ char * util_alloc_realpath__(const char * input_path) { { char ** path_list; - char ** path_stack; + const char ** path_stack; int path_len; util_path_split( abs_path , &path_len , &path_list ); - path_stack = util_malloc( path_len * sizeof * path_stack ); + path_stack = (const char **) util_malloc( path_len * sizeof * path_stack ); for (int i=0; i < path_len; i++) path_stack[i] = NULL; @@ -1135,7 +1138,7 @@ bool util_char_in(char c , int set_size , const char * set) { isspace(). */ bool util_string_isspace(const char * s) { - int index = 0; + size_t index = 0; while (index < strlen(s)) { if (!isspace( s[index] )) return false; @@ -2000,8 +2003,8 @@ char * util_fread_alloc_file_content(const char * filename , int * buffer_size) bool util_copy_stream(FILE *src_stream , FILE *target_stream , size_t buffer_size , void * buffer , bool abort_on_error) { while ( ! feof(src_stream)) { - int bytes_read; - int bytes_written; + size_t bytes_read; + size_t bytes_written; bytes_read = fread (buffer , 1 , buffer_size , src_stream); if (bytes_read < buffer_size && !feof(src_stream)) { @@ -2419,7 +2422,7 @@ bool util_entry_writable( const char * entry ) { -static int util_get_path_length(const char * file) { +static size_t util_get_path_length(const char * file) { if (util_is_directory(file)) return strlen(file); else { @@ -2434,7 +2437,7 @@ static int util_get_path_length(const char * file) { static int util_get_base_length(const char * file) { - int path_length = util_get_path_length(file); + size_t path_length = util_get_path_length(file); const char * base_start; const char * last_point; long character_index; @@ -3304,9 +3307,10 @@ char * util_realloc_string_copy(char * old_string , const char *src ) { } -char * util_realloc_substring_copy(char * old_string , const char *src , int len) { +char * util_realloc_substring_copy(char * old_string , const char *src , int len_) { + size_t len = len_; if (src != NULL) { - int str_len; + size_t str_len; char *copy; if (strlen(src) < len) str_len = strlen(src); @@ -3692,7 +3696,7 @@ void util_binary_split_string(const char * __src , const char * sep_set, bool sp char * src; if (__src != NULL) { - int offset = 0; + size_t offset = 0; int len; /* 1: Remove leading split characters. */ while ((offset < strlen(__src)) && (strchr(sep_set , __src[offset]) != NULL)) @@ -3781,7 +3785,7 @@ void util_binary_split_string_from_max_length(const char * __src , const char * char * second_part = NULL; if (__src != NULL) { char * src; - int pos; + size_t pos; /* Removing leading separators. */ pos = 0; while ((pos < strlen(__src)) && (strchr(sep_set , __src[pos]) != NULL)) @@ -3863,7 +3867,7 @@ int static util_string_replace_inplace__(char ** _buffer , const char * expr , c int len_expr = strlen( expr ); int len_subs = strlen( subs ); int size = strlen(buffer); - int offset = 0; + size_t offset = 0; int match_count = 0; char * match = NULL; @@ -4355,14 +4359,14 @@ FILE * util_mkdir_fopen( const char * filename , const char * mode ) { void util_fwrite(const void *ptr , size_t element_size , size_t items, FILE * stream , const char * caller) { - int items_written = fwrite(ptr , element_size , items , stream); + size_t items_written = fwrite(ptr , element_size , items , stream); if (items_written != items) util_abort("%s/%s: only wrote %d/%d items to disk - aborting: %s(%d) .\n",caller , __func__ , items_written , items , strerror(errno) , errno); } void util_fread(void *ptr , size_t element_size , size_t items, FILE * stream , const char * caller) { - int items_read = fread(ptr , element_size , items , stream); + size_t items_read = fread(ptr , element_size , items , stream); if (items_read != items) util_abort("%s/%s: only read %d/%d items from disk - aborting.\n %s(%d) \n",caller , __func__ , items_read , items , strerror(errno) , errno); } @@ -4491,9 +4495,10 @@ void util_fprintf_int(int value , int width , FILE * stream) { -void util_fprintf_string(const char * s , int width , string_alignement_type alignement , FILE * stream) { +void util_fprintf_string(const char * s , int width_ , string_alignement_type alignement , FILE * stream) { char fmt[32]; - int i; + size_t i; + size_t width = width_; if (alignement == left_pad) { i = 0; if (width > strlen(s)) { @@ -4502,7 +4507,7 @@ void util_fprintf_string(const char * s , int width , string_alignement_type ali } fprintf(stream , "%s", s); } else if (alignement == right_pad) { - sprintf(fmt , "%%-%ds" , width); + sprintf(fmt , "%%-%lus" , width); fprintf(stream , fmt , s); } else { int total_pad = width - strlen(s); @@ -4908,7 +4913,7 @@ void util_make_path(const char *_path) { int i = 0; active_path = (char*)util_calloc(strlen(path) + 1 , sizeof * active_path ); do { - int n = strcspn(path , UTIL_PATH_SEP_STRING); + size_t n = strcspn(path , UTIL_PATH_SEP_STRING); if (n < strlen(path)) n += 1; path += n; diff --git a/ThirdParty/Ert/lib/util/util_abort_gnu.c b/ThirdParty/Ert/lib/util/util_abort_gnu.c index 153fff6843..1e651fd8b9 100644 --- a/ThirdParty/Ert/lib/util/util_abort_gnu.c +++ b/ThirdParty/Ert/lib/util/util_abort_gnu.c @@ -179,7 +179,7 @@ static void util_fprintf_backtrace(FILE * stream) { if (util_addr2line_lookup(bt_addr[i], &func_name , &file_name , &line_nr)) { int pad_length; - char * function; + const char * function; // Seems it can return true - but with func_name == NULL?! Static/inlinded functions? if (func_name) function = func_name; @@ -282,7 +282,7 @@ void util_abort__(const char * file , const char * function , int line , const c if (__abort_program_message != NULL) { #if !defined(__GLIBC__) /* allocate a temporary buffer to hold the path */ - char* program_invocation_name = alloca (PATH_MAX); + char* program_invocation_name = (char*)alloca (PATH_MAX); # if defined(__APPLE__) uint32_t buflen = PATH_MAX; _NSGetExecutablePath (program_invocation_name, &buflen); diff --git a/ThirdParty/Ert/lib/util/util_abort_simple.c b/ThirdParty/Ert/lib/util/util_abort_simple.c index 9f7363f414..56586fd994 100644 --- a/ThirdParty/Ert/lib/util/util_abort_simple.c +++ b/ThirdParty/Ert/lib/util/util_abort_simple.c @@ -4,7 +4,7 @@ */ #include #include - +#include #include #include diff --git a/ThirdParty/Ert/lib/util/util_endian.c b/ThirdParty/Ert/lib/util/util_endian.cpp similarity index 100% rename from ThirdParty/Ert/lib/util/util_endian.c rename to ThirdParty/Ert/lib/util/util_endian.cpp diff --git a/ThirdParty/Ert/lib/util/util_env.c b/ThirdParty/Ert/lib/util/util_env.c deleted file mode 100644 index 753646b86a..0000000000 --- a/ThirdParty/Ert/lib/util/util_env.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - Copyright (C) 2012 Statoil ASA, Norway. - - The file 'util_env.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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ERT is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License at - for more details. -*/ -#include -#include -#include - -#include "ert/util/build_config.h" - -#include -#include -#include - -#ifdef HAVE_POSIX_SETENV -#define PATHVAR_SPLIT ":" - -void util_unsetenv( const char * variable ) { - unsetenv( variable ); -} - -void util_setenv( const char * variable , const char * value) { - int overwrite = 1; - setenv( variable , value , overwrite ); -} - -#else - -#include - -#define PATHVAR_SPLIT ";" -void util_setenv( const char * variable , const char * value) { - SetEnvironmentVariable( variable , NULL ); -} - -void util_unsetenv( const char * variable ) { - util_setenv( variable , NULL ); -} -#endif - -/** - Will return a NULL terminated list char ** of the paths in the PATH - variable. -*/ - -char ** util_alloc_PATH_list() { - char ** path_list = NULL; - char * path_env = getenv("PATH"); - if (path_env != NULL) { - int path_size; - - util_split_string(path_env , PATHVAR_SPLIT , &path_size , &path_list); - path_list = (char**)util_realloc( path_list , (path_size + 1) * sizeof * path_list); - path_list[path_size] = NULL; - } else { - path_list = (char**)util_malloc( sizeof * path_list); - path_list[0] = NULL; - } - return path_list; -} - -/** - This function searches through the content of the (currently set) - PATH variable, and allocates a string containing the full path - (first match) to the executable given as input. - - * If the entered executable already is an absolute path, a copy of - the input is returned *WITHOUT* consulting the PATH variable (or - checking that it exists). - - * If the executable starts with "./" getenv("PWD") is prepended. - - * If the executable is not found in the PATH list NULL is returned. -*/ - - -char * util_alloc_PATH_executable(const char * executable) { - if (util_is_abs_path(executable)) { - if (util_is_executable(executable)) - return util_alloc_string_copy(executable); - else - return NULL; - } else if (strncmp(executable , "./" , 2) == 0) { - char * cwd = util_alloc_cwd(); - char * path = util_alloc_filename(cwd , &executable[2] , NULL); - - /* The program has been invoked as ./xxxx */ - if (!(util_is_file(path) && util_is_executable( path ))) { - free( path ); - path = NULL; - } - free( cwd ); - - return path; - } else { - char * full_path = NULL; - char ** path_list = util_alloc_PATH_list(); - int ipath = 0; - - while (true) { - if (path_list[ipath] != NULL) { - char * current_attempt = util_alloc_filename(path_list[ipath] , executable , NULL); - - if ( util_is_file( current_attempt ) && util_is_executable( current_attempt )) { - full_path = current_attempt; - break; - } else { - free(current_attempt); - ipath++; - } - } else - break; - } - - util_free_NULL_terminated_stringlist(path_list); - return full_path; - } -} - - - - - -/** - This function updates an environment variable representing a path, - before actually updating the environment variable the current value - is checked, and the following rules apply: - - 1. If @append == true, and @value is already included in the - environment variable; nothing is done. - - 2. If @append == false, and the variable already starts with - @value, nothing is done. - - A pointer to the updated(?) environment variable is returned. -*/ - -const char * util_update_path_var(const char * variable, const char * value, bool append) { - const char * current_value = getenv( variable ); - if (current_value == NULL) - /* The (path) variable is not currently set. */ - util_setenv( variable , value ); - else { - bool update = true; - - { - char ** path_list; - int num_path; - util_split_string( current_value , ":" , &num_path , &path_list); - if (append) { - int i; - for (i = 0; i < num_path; i++) { - if (util_string_equal( path_list[i] , value)) - update = false; /* The environment variable already contains @value - no point in appending it at the end. */ - } - } else { - if (util_string_equal( path_list[0] , value)) - update = false; /* The environment variable already starts with @value. */ - } - util_free_stringlist( path_list , num_path ); - } - - if (update) { - char * new_value; - if (append) - new_value = util_alloc_sprintf("%s:%s" , current_value , value); - else - new_value = util_alloc_sprintf("%s:%s" , value , current_value); - util_setenv( variable , new_value ); - free( new_value ); - } - - } - return getenv( variable ); -} - - - -/** - This is a thin wrapper around the setenv() call, with the twist - that all $VAR expressions in the @value parameter are replaced with - getenv() calls, so that the function call: - - util_setenv("PATH" , "$HOME/bin:$PATH") - - Should work as in the shell. If the variables referred to with ${} - in @value do not exist the literal string, i.e. '$HOME' is - retained. - - If @value == NULL a call to unsetenv( @variable ) will be issued. -*/ - -const char * util_interp_setenv( const char * variable , const char * value) { - char * interp_value = util_alloc_envvar( value ); - if (interp_value != NULL) { - util_setenv( variable , interp_value); - free( interp_value ); - } else - util_unsetenv( variable ); - - return getenv( variable ); -} - - - -/** - This function will take a string as input, and then replace all if - $VAR expressions with the corresponding environment variable. If - the environament variable VAR is not set, the string literal $VAR - is retained. The return value is a newly allocated string. - - If the input value is NULL - the function will just return NULL; -*/ - - -char * util_alloc_envvar( const char * value ) { - if (value == NULL) - return NULL; - else { - buffer_type * buffer = buffer_alloc( 1024 ); /* Start by filling up a buffer instance with - the current content of @value. */ - buffer_fwrite_char_ptr( buffer , value ); - buffer_rewind( buffer ); - - - while (true) { - if (buffer_strchr( buffer , '$')) { - const char * data = (const char*)buffer_get_data( buffer ); - int offset = buffer_get_offset( buffer ) + 1; /* Points at the first character following the '$' */ - int var_length = 0; - - /* Find the length of the variable name */ - while (true) { - char c; - c = data[offset + var_length]; - if (!(isalnum( c ) || c == '_')) /* Any character which is NOT in the set [a-Z,0-9_] marks the end of the variable. */ - break; - - if (c == '\0') /* The end of the string. */ - break; - - var_length += 1; - } - - { - char * var_name = util_alloc_substring_copy( data , offset - 1 , var_length + 1); /* Include the leading $ */ - const char * var_value = getenv( &var_name[1] ); - - if (var_value != NULL) - buffer_search_replace( buffer , var_name , var_value); /* The actual string replacement. */ - else - buffer_fseek( buffer , var_length , SEEK_CUR ); /* The variable is not defined, and we leave the $name. */ - - free( var_name ); - } - } else break; /* No more $ to replace */ - } - - - buffer_shrink_to_fit( buffer ); - { - char * expanded_value = (char*)buffer_get_data( buffer ); - buffer_free_container( buffer ); - return expanded_value; - } - } -} diff --git a/ThirdParty/Ert/lib/util/util_getuid.c b/ThirdParty/Ert/lib/util/util_getuid.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/util_getuid.c rename to ThirdParty/Ert/lib/util/util_getuid.cpp index 678803a476..4b22ab5752 100644 --- a/ThirdParty/Ert/lib/util/util_getuid.c +++ b/ThirdParty/Ert/lib/util/util_getuid.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include diff --git a/ThirdParty/Ert/lib/util/util_lockf.c b/ThirdParty/Ert/lib/util/util_lockf.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/util_lockf.c rename to ThirdParty/Ert/lib/util/util_lockf.cpp index 6b7b120de2..9114b9d0d9 100644 --- a/ThirdParty/Ert/lib/util/util_lockf.c +++ b/ThirdParty/Ert/lib/util/util_lockf.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/ThirdParty/Ert/lib/util/util_opendir.c b/ThirdParty/Ert/lib/util/util_opendir.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/util_opendir.c rename to ThirdParty/Ert/lib/util/util_opendir.cpp index 3205364699..6984baf67f 100644 --- a/ThirdParty/Ert/lib/util/util_opendir.c +++ b/ThirdParty/Ert/lib/util/util_opendir.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/ThirdParty/Ert/lib/util/util_spawn.c b/ThirdParty/Ert/lib/util/util_spawn.cpp similarity index 97% rename from ThirdParty/Ert/lib/util/util_spawn.c rename to ThirdParty/Ert/lib/util/util_spawn.cpp index 76a08ea9f5..429e05c95d 100644 --- a/ThirdParty/Ert/lib/util/util_spawn.c +++ b/ThirdParty/Ert/lib/util/util_spawn.cpp @@ -1,5 +1,5 @@ -#include -#include "ert/util/build_config.h" +#include +#include "ert/util/build_config.hpp" #include #include @@ -10,7 +10,7 @@ #include #include -#include +#include extern char **environ; diff --git a/ThirdParty/Ert/lib/util/util_symlink.c b/ThirdParty/Ert/lib/util/util_symlink.cpp similarity index 94% rename from ThirdParty/Ert/lib/util/util_symlink.c rename to ThirdParty/Ert/lib/util/util_symlink.cpp index e68796d534..bfa79dd893 100644 --- a/ThirdParty/Ert/lib/util/util_symlink.c +++ b/ThirdParty/Ert/lib/util/util_symlink.cpp @@ -2,9 +2,9 @@ #include #include -#include "ert/util/build_config.h" -#include -#include +#include "ert/util/build_config.hpp" +#include +#include #ifndef ERT_HAVE_SYMLINK @@ -91,12 +91,14 @@ char * util_alloc_link_target(const char * link) { #ifdef ERT_HAVE_READLINKAT +#if !defined(ERT_HAVE_READLINKAT_DECLARATION) /* The manual page says that the readlinkat() function should be in the unistd.h header file, but not on RedHat5. On RedHat6 it is. */ extern ssize_t readlinkat (int __fd, __const char *__restrict __path, char *__restrict __buf, size_t __len); +#endif /* !defined(ERT_HAVE_READLINKAT_DECLARATION) */ char * util_alloc_atlink_target(const char * path , const char * link) { if (util_is_abs_path( link )) diff --git a/ThirdParty/Ert/lib/util/util_unlink.c b/ThirdParty/Ert/lib/util/util_unlink.cpp similarity index 93% rename from ThirdParty/Ert/lib/util/util_unlink.c rename to ThirdParty/Ert/lib/util/util_unlink.cpp index 5f3af54979..4cf13ecfa8 100644 --- a/ThirdParty/Ert/lib/util/util_unlink.c +++ b/ThirdParty/Ert/lib/util/util_unlink.cpp @@ -16,9 +16,9 @@ for more details. */ -#include "ert/util/build_config.h" +#include "ert/util/build_config.hpp" -#include +#include #if defined(HAVE_WINDOWS_UNLINK) diff --git a/ThirdParty/Ert/lib/util/util_zlib.c b/ThirdParty/Ert/lib/util/util_zlib.cpp similarity index 97% rename from ThirdParty/Ert/lib/util/util_zlib.c rename to ThirdParty/Ert/lib/util/util_zlib.cpp index 17d59e586f..95c813b68b 100644 --- a/ThirdParty/Ert/lib/util/util_zlib.c +++ b/ThirdParty/Ert/lib/util/util_zlib.cpp @@ -5,7 +5,7 @@ #include -#include +#include /** This function reads data from the input pointer data, and writes a @@ -134,7 +134,7 @@ void util_fwrite_compressed(const void * _data , int size , FILE * stream) { util_compress_buffer(&data[offset] , this_block_size , zbuffer , &compressed_size); fwrite(&compressed_size , sizeof compressed_size , 1 , stream); { - int bytes_written = fwrite(zbuffer , 1 , compressed_size , stream); + unsigned long bytes_written = fwrite(zbuffer , 1 , compressed_size , stream); if (bytes_written < compressed_size) util_abort("%s: wrote only %d/%ld bytes to compressed file - aborting \n",__func__ , bytes_written , compressed_size); } @@ -171,7 +171,7 @@ void util_fread_compressed(void *__data , FILE * stream) { int uncompress_result; fread(&compressed_size , sizeof compressed_size , 1 , stream); { - int bytes_read = fread(zbuffer , 1 , compressed_size , stream); + unsigned long bytes_read = fread(zbuffer , 1 , compressed_size , stream); if (bytes_read < compressed_size) util_abort("%s: read only %d/%d bytes from compressed file - aborting \n",__func__ , bytes_read , compressed_size); diff --git a/ThirdParty/Ert/lib/util/vector.c b/ThirdParty/Ert/lib/util/vector.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/vector.c rename to ThirdParty/Ert/lib/util/vector.cpp index 09ae564438..64b0043038 100644 --- a/ThirdParty/Ert/lib/util/vector.c +++ b/ThirdParty/Ert/lib/util/vector.cpp @@ -19,10 +19,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define VECTOR_TYPE_ID 551087 diff --git a/ThirdParty/Ert/lib/util/vector_template.c b/ThirdParty/Ert/lib/util/vector_template.cpp similarity index 99% rename from ThirdParty/Ert/lib/util/vector_template.c rename to ThirdParty/Ert/lib/util/vector_template.cpp index ccd85fd551..80958d44e9 100644 --- a/ThirdParty/Ert/lib/util/vector_template.c +++ b/ThirdParty/Ert/lib/util/vector_template.cpp @@ -98,9 +98,9 @@ #include #include -#include -#include -#include +#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/ThirdParty/Ert/lib/util/thread_pool.c b/ThirdParty/Ert/lib/vector_template.hpp.in similarity index 71% rename from ThirdParty/Ert/lib/util/thread_pool.c rename to ThirdParty/Ert/lib/vector_template.hpp.in index e23026b4ea..f4574fdda5 100644 --- a/ThirdParty/Ert/lib/util/thread_pool.c +++ b/ThirdParty/Ert/lib/vector_template.hpp.in @@ -1,7 +1,7 @@ /* Copyright (C) 2011 Statoil ASA, Norway. - The file 'thread_pool.c' is part of ERT - Ensemble based Reservoir Tool. + The file 'vector_template.hpp' 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 @@ -16,12 +16,9 @@ for more details. */ -#include "ert/util/build_config.h" -#include +#ifndef ERT_@TYPE@_VECTOR_CXX +#define ERT_@TYPE@_VECTOR_CXX + +#include -#ifdef HAVE_PTHREAD -#include "thread_pool_posix.c" -#else -Error - should not be be here. #endif - diff --git a/ThirdParty/Ert/python/CMakeLists.txt b/ThirdParty/Ert/python/CMakeLists.txt index f3d5cd1a9a..4ed4cd838e 100644 --- a/ThirdParty/Ert/python/CMakeLists.txt +++ b/ThirdParty/Ert/python/CMakeLists.txt @@ -4,6 +4,12 @@ set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/M include(init_python) init_python( 2.7 ) +find_python_package(pandas 0.17 ${PYTHON_INSTALL_PREFIX}) +if (NOT DEFINED PY_pandas) + message(WARNING "Pandas module not found Python wrappers not enabled. Install with: \"pip install pandas\"") + set( ENABLE_PYTHON OFF PARENT_SCOPE ) + return() +endif() find_python_package(numpy 1.7.1 ${PYTHON_INSTALL_PREFIX}) if (NOT DEFINED PY_numpy) diff --git a/ThirdParty/Ert/python/ecl/ecl_type.py b/ThirdParty/Ert/python/ecl/ecl_type.py index ca4d9c6831..477aeddb50 100644 --- a/ThirdParty/Ert/python/ecl/ecl_type.py +++ b/ThirdParty/Ert/python/ecl/ecl_type.py @@ -46,7 +46,7 @@ class EclDataType(BaseCClass): _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_ctype_fortio_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)") diff --git a/ThirdParty/Ert/python/ecl/summary/ecl_sum.py b/ThirdParty/Ert/python/ecl/summary/ecl_sum.py index 1b7c79568a..2d2970ad9e 100644 --- a/ThirdParty/Ert/python/ecl/summary/ecl_sum.py +++ b/ThirdParty/Ert/python/ecl/summary/ecl_sum.py @@ -21,10 +21,11 @@ in the C source files ecl_sum.c, ecl_smspec.c and ecl_sum_data in the libecl/src directory. """ - +import warnings import numpy import datetime import os.path +import ctypes # Observe that there is some convention conflict with the C code # regarding order of arguments: The C code generally takes the time @@ -142,7 +143,11 @@ class EclSum(BaseCClass): _add_tstep = EclPrototype("ecl_sum_tstep_ref ecl_sum_add_tstep(ecl_sum, int, double)") _export_csv = EclPrototype("void ecl_sum_export_csv(ecl_sum, char*, stringlist, char*, char*)") _identify_var_type = EclPrototype("ecl_sum_var_type ecl_sum_identify_var_type(char*)", bind = False) - + _get_last_value = EclPrototype("double ecl_sum_get_last_value_gen_key(ecl_sum, char*)") + _get_first_value = EclPrototype("double ecl_sum_get_first_value_gen_key(ecl_sum, char*)") + _init_numpy_vector = EclPrototype("void ecl_sum_init_double_vector(ecl_sum, char*, double*)") + _init_numpy_vector_interp = EclPrototype("void ecl_sum_init_double_vector_interp(ecl_sum, char*, time_t_vector, double*)") + _init_numpy_datetime64 = EclPrototype("void ecl_sum_init_datetime64_vector(ecl_sum, int64*, int)") def __init__(self, load_case, join_string=":", include_restart=True): @@ -395,6 +400,7 @@ class EclSum(BaseCClass): also available as the 'values' property of an EclSumVector instance. """ + warnings.warn("The method get_values() has been deprecated - use numpy_vector() instead.", DeprecationWarning) if self.has_key(key): key_index = self._get_general_var_index(key) if report_only: @@ -413,6 +419,121 @@ class EclSum(BaseCClass): else: raise KeyError("Summary object does not have key:%s" % key) + def _make_time_vector(self, time_index): + time_points = TimeVector() + for t in time_index: + time_points.append(t) + return time_points + + def numpy_vector(self, key, time_index = None): + """Will return numpy vector of all the values corresponding to @key. + + The optional argument @time_index can be used to limit the time points + where you want evaluation. The time_index argument should be a list of + datetime instances. The values will be interpolated to the time points + given in the time_index vector. If the time points in the time_inedx + vector are outside of the simulated range you will get an extrapolated + value: + + Rates -> 0 + Not rate -> first or last simulated value. + + The function will raise KeyError if the requested key does not exist. + If many keys are needed it will be faster to use the pandas_frame() + function. + """ + if key not in self: + raise KeyError("No such key:%s" % key) + + if time_index is None: + np_vector = numpy.zeros(len(self)) + self._init_numpy_vector(key ,np_vector.ctypes.data_as(ctypes.POINTER(ctypes.c_double))) + return np_vector + else: + time_vector = self._make_time_vector(time_index) + np_vector = numpy.zeros(len(time_vector)) + self._init_numpy_vector_interp(key, time_vector, np_vector.ctypes.data_as(ctypes.POINTER(ctypes.c_double))) + return np_vector + + + @property + def numpy_dates(self): + """ + Will return numpy vector of numpy.datetime64() values for all the simulated timepoints. + """ + np_dates = numpy.zeros(len(self), dtype="datetime64[ms]") + self._init_numpy_datetime64(np_dates.ctypes.data_as(ctypes.POINTER(ctypes.c_int64)), 1000) + return np_dates + + + @property + def dates(self): + """ + Will return ordinary Python list of datetime.datetime() objects of simulated timepoints. + """ + np_dates = self.numpy_dates + return np_dates.tolist() + + + def pandas_frame(self, time_index = None, column_keys = None): + """Will create a pandas frame with summary data. + + By default you will get all time points in the summary case, but by + using the time_index argument you can control which times you are + interested in. If you have supplied a time_index argument the data will + be interpolated to these time values. If the time points in the + time_index vector are outside of the simulated range you will get an + extrapolated value: + + Rates -> 0 + Not rate -> first or last simulated value. + + + By default the frame will contain all the summary vectors in the case, + but this can be controlled by using the column_keys argument. The + column_keys should be a list of strings, and each summary vector + matching one of the elements in the @column_keys will get a column in + the frame, you can use wildcards like "WWCT:*" and "*:OP". If you + supply a column_keys argument which does not resolve to any valid + summary keys you will get a ValueError exception. + + + sum = EclSum(case) + monthly_dates = sum.time_range(interval="1M") + data = sum.pandas_frame(time_index = monthly_dates, column_keys=["F*PT"]) + + FOPT FGPT FWPT + 2010-01-01 100.7 200.0 25.0 + 2010-02-01 150.7 275.0 67.6 + 2010-03-01 276.7 310.6 67.0 + 2010-04-01 672.7 620.4 78.7 + .... + """ + from ecl.summary import EclSumKeyWordVector + import pandas + if column_keys is None: + keywords = EclSumKeyWordVector(self, add_keywords = True) + else: + keywords = EclSumKeyWordVector(self) + for key in column_keys: + keywords.add_keywords(key) + + + if len(keywords) == 0: + raise ValueError("No valid key") + + if time_index is None: + time_index = self.numpy_dates + data = numpy.zeros([len(time_index), len(keywords)]) + EclSum._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(self, keywords, time_points, data.ctypes.data_as(ctypes.POINTER(ctypes.c_double))) + + frame = pandas.DataFrame(index = time_index, columns=list(keywords), data=data) + return frame + def get_key_index(self, key): """ @@ -440,7 +561,7 @@ class EclSum(BaseCClass): return None - def get_last_value(self, key): + def last_value(self, key): """ Will return the last value corresponding to @key. @@ -452,14 +573,31 @@ class EclSum(BaseCClass): The alternative method 'last' will return a EclSumNode instance with some extra time related information. """ - return self[key].last_value + if not key in self: + raise KeyError("No such key:%s" % key) + + return self._get_last_value(key) + + + def first_value(self, key): + """ + Will return first value corresponding to @key. + """ + if not key in self: + raise KeyError("No such key:%s" % key) + + return self._get_first_value(key) + + def get_last_value(self,key): + warnings.warn("The function get_last_value() is deprecated, use last_value() instead",DeprecationWarning) + return self.last_value(key) def get_last(self, key): """ Will return the last EclSumNode corresponding to @key. If you are only interested in the final value, you can use the - get_last_value() method. + last_value() method. """ return self[key].last @@ -694,7 +832,7 @@ class EclSum(BaseCClass): if t < CTime(self.start_time): total.append(0) elif t >= CTime(self.end_time): - total.append(self.get_last_value(totalKey)) + total.append(self.last_value(totalKey)) else: total.append(self.get_interp(totalKey, date=t)) tmp = total << 1 @@ -899,16 +1037,6 @@ class EclSum(BaseCClass): else: return self.__days - @property - def dates(self): - """ - Will return a list of simulation dates. - - The list will be an ordinary Python list, and the dates will - be in terms ordinary Python datetime values. - """ - return self.get_dates(False) - def get_dates(self, report_only=False): """ Will return a list of simulation dates. @@ -1373,8 +1501,10 @@ class EclSum(BaseCClass): import ecl.summary.ecl_sum_keyword_vector -EclSum._dump_csv_line = EclPrototype("void ecl_sum_fwrite_interp_csv_line(ecl_sum, time_t, ecl_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)", bind=False) +EclSum._dump_csv_line = EclPrototype("void ecl_sum_fwrite_interp_csv_line(ecl_sum, time_t, ecl_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)", bind=False) +EclSum._init_pandas_frame = EclPrototype("void ecl_sum_init_double_frame(ecl_sum, ecl_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*)", bind=False) monkey_the_camel(EclSum, 'varType', EclSum.var_type, classmethod) monkey_the_camel(EclSum, 'addVariable', EclSum.add_variable) diff --git a/ThirdParty/Ert/python/ecl/util/test/ecl_mock/ecl_sum_mock.py b/ThirdParty/Ert/python/ecl/util/test/ecl_mock/ecl_sum_mock.py index a2f1e210f2..9fc8b7a8b1 100644 --- a/ThirdParty/Ert/python/ecl/util/test/ecl_mock/ecl_sum_mock.py +++ b/ThirdParty/Ert/python/ecl/util/test/ecl_mock/ecl_sum_mock.py @@ -20,8 +20,8 @@ def createEclSum( case, ecl_sum = EclSum.restart_writer(case , restart_case, restart_step, sim_start , dims[0] , dims[1] , dims[2]) var_list = [] - for (kw,wgname,num) in keys: - var_list.append( ecl_sum.addVariable( kw , wgname = wgname , num = num) ) + for (kw,wgname,num,unit) in keys: + var_list.append( ecl_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. diff --git a/ThirdParty/Ert/python/python/CMakeLists.txt b/ThirdParty/Ert/python/python/CMakeLists.txt deleted file mode 100644 index 59be104ca7..0000000000 --- a/ThirdParty/Ert/python/python/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -configure_file(test_env.py.in ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/test_env.py ) - -add_subdirectory(cwrap) -add_subdirectory( ecl ) - -if (INSTALL_ERT_LEGACY) - add_subdirectory( legacy/ert ) -endif() diff --git a/ThirdParty/Ert/python/python/cwrap/CMakeLists.txt b/ThirdParty/Ert/python/python/cwrap/CMakeLists.txt deleted file mode 100644 index a6b98b1b08..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - basecclass.py - basecenum.py - basecvalue.py - cfile.py - clib.py - metacwrap.py - prototype.py -) - -add_python_package("cwrap" ${PYTHON_INSTALL_PREFIX}/cwrap "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/python/python/cwrap/__init__.py b/ThirdParty/Ert/python/python/cwrap/__init__.py deleted file mode 100644 index 027cab1f70..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/__init__.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -""" -The cwrap package contains several small utility modules to simplify -the process of interacting with a C library: - - clib: This module contains the function load() which will load a - shared library using the ctypes.CDLL(); the function has - facilities for trying several different names when loading the - library. - - cfile: This module implemenets the class CFILE which can be used to - extract the underlying FILE pointer from a Python filehandle, to - facilitate use of Python filehandles for functions expecting a - FILE pointer. -""" - -__author__ = 'Jean-Paul Balabanian, Joakim Hove, and PG Drange' -__copyright__ = 'Copyright 2016, Statoil ASA' -__credits__ = __author__ -__license__ = 'GPL' -__version__ = '0.0.1' -__maintainer__ = __author__ -__email__ = __author__ -__status__ = 'Prototype' - -from .basecclass import BaseCClass -from .basecenum import BaseCEnum -from .basecvalue import BaseCValue - -from .cfile import CFILE -from .clib import load, lib_name - -from .metacwrap import MetaCWrap -from .prototype import REGISTERED_TYPES, Prototype, PrototypeError - -__all__ = ['BaseCClass', 'BaseCEnum', 'BaseCValue', 'CFILE', - 'MetaCWrap', 'Prototype', 'load', 'lib_name'] diff --git a/ThirdParty/Ert/python/python/cwrap/basecclass.py b/ThirdParty/Ert/python/python/cwrap/basecclass.py deleted file mode 100644 index 306a8375bd..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/basecclass.py +++ /dev/null @@ -1,156 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import (absolute_import, division, - print_function, unicode_literals) - -import six - -import ctypes -from .metacwrap import MetaCWrap - -@six.add_metaclass(MetaCWrap) -class BaseCClass(object): - namespaces = {} - - def __init__(self, c_pointer, parent=None, is_reference=False): - if not c_pointer: - raise ValueError("Must have a valid (not null) pointer value!") - - if c_pointer < 0: - raise ValueError("The pointer value is negative! This may be correct, but usually is not!") - - self.__c_pointer = c_pointer - self.__parent = parent - self.__is_reference = is_reference - - def __new__(cls, *more, **kwargs): - obj = super(BaseCClass, cls).__new__(cls) - obj.__c_pointer = None - obj.__parent = None - obj.__is_reference = False - - return obj - - def _address(self): - return self.__c_pointer - - def _ad_str(self): - return 'at 0x%x' % self._address() - - @classmethod - def from_param(cls, c_class_object): - if c_class_object is not None and not isinstance(c_class_object, BaseCClass): - raise ValueError("c_class_object must be a BaseCClass instance!") - - if c_class_object is None: - return ctypes.c_void_p() - else: - return ctypes.c_void_p(c_class_object.__c_pointer) - - @classmethod - def createPythonObject(cls, c_pointer): - if c_pointer is not None: - new_obj = cls.__new__(cls) - BaseCClass.__init__(new_obj, c_pointer=c_pointer, parent=None, is_reference=False) - return new_obj - else: - return None - - @classmethod - def createCReference(cls, c_pointer, parent=None): - if c_pointer is not None: - new_obj = cls.__new__(cls) - BaseCClass.__init__(new_obj, c_pointer=c_pointer, parent=parent, is_reference=True) - return new_obj - else: - return None - - @classmethod - def storageType(cls): - return ctypes.c_void_p - - def convertToCReference(self, parent): - self.__is_reference = True - self.__parent = parent - - - def setParent(self, parent=None): - if self.__is_reference: - self.__parent = parent - else: - raise UserWarning("Can only set parent on reference types!") - - return self - - def isReference(self): - """ @rtype: bool """ - return self.__is_reference - - def parent(self): - return self.__parent - - def __eq__(self, other): - # This is the last resort comparison function; it will do a - # plain pointer comparison on the underlying C object; or - # Python is-same-object comparison. - if isinstance(other, BaseCClass): - return self.__c_pointer == other.__c_pointer - else: - return super(BaseCClass , self) == other - - def __hash__(self): - # Similar to last resort comparison; this returns the hash of the - # underlying C pointer. - return hash(self.__c_pointer) - - def free(self): - raise NotImplementedError("A BaseCClass requires a free method implementation!") - - def _create_repr(self, args = ''): - """Representation on the form (e.g.) 'EclFile(...) at 0x1729'.""" - return "{0}({1}) {2}".format(self.__class__.__name__, args, self._ad_str()) - - def __repr__(self): - """Representation on the form (e.g.) 'EclFile(...) at 0x1729'.""" - return self._create_repr() - - def __del__(self): - if self.free is not None: - if not self.__is_reference: - # Important to check the c_pointer; in the case of failed object creation - # we can have a Python object with c_pointer == None. - if self.__c_pointer: - self.free() - - def _invalidateCPointer(self): - self.__c_pointer = None - - - def __bool__(self): - """The BaseCClass instance will evaluate to true if it is bound to an - underlying C object, otherwise it will evaluate to False. More - elaborate bool tests should be implemented in the derived - class. - """ - if self.__c_pointer: - return True - else: - return False - - - def __nonzero__(self): - return self.__bool__( ) diff --git a/ThirdParty/Ert/python/python/cwrap/basecenum.py b/ThirdParty/Ert/python/python/cwrap/basecenum.py deleted file mode 100644 index b86e1b0d64..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/basecenum.py +++ /dev/null @@ -1,169 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import absolute_import, division, print_function, unicode_literals - -import six - -import ctypes -from .metacwrap import MetaCWrap - -@six.add_metaclass(MetaCWrap) -class BaseCEnum(object): - enum_namespace = {} - - def __init__(self, *args, **kwargs): - if not self in self.enum_namespace[self.__class__]: - raise NotImplementedError("Can not be instantiated directly!") - - def __new__(cls, *args, **kwargs): - if len(args) == 1: - enum = cls.__resolveEnum(args[0]) - - if enum is None: - raise ValueError("Unknown enum value: %i" % args[0]) - - return enum - else: - obj = super(BaseCEnum, cls).__new__(cls, *args) - obj.name = None - obj.value = None - return obj - - @classmethod - def from_param(cls, c_class_object): - if not isinstance(c_class_object, BaseCEnum): - raise ValueError("c_class_object must be an BaseCEnum instance!") - return c_class_object.value - - @classmethod - def addEnum(cls, name, value): - name = str(name) - if not isinstance(value, int): - raise ValueError("Value must be an integer!") - - enum = cls.__new__(cls) - enum.name = name - enum.value = value - - setattr(cls, name, enum) - - if cls not in cls.enum_namespace: - cls.enum_namespace[cls] = [] - - cls.enum_namespace[cls].append(enum) - - @classmethod - def enums(cls): - return list(cls.enum_namespace[cls]) - - def __eq__(self, other): - if isinstance(other, self.__class__): - return self.value == other.value - - if isinstance(other, int): - return self.value == other - - return False - - def __hash__(self): - return hash(self.value) - - def __str__(self): - return self.name - - def __repr__(self): - cn = self.__class__.__name__ - na = self.name - va = self.value - return '%s(name = "%s", value = %s)' % (cn, na, va) - - def __add__(self, other): - self.__assertOtherIsSameType(other) - value = self.value + other.value - return self.__resolveOrCreateEnum(value) - - def __or__(self, other): - self.__assertOtherIsSameType(other) - value = self.value | other.value - return self.__resolveOrCreateEnum(value) - - - def __xor__(self, other): - self.__assertOtherIsSameType(other) - value = self.value ^ other.value - return self.__resolveOrCreateEnum(value) - - def __and__(self, other): - self.__assertOtherIsSameType(other) - value = self.value & other.value - return self.__resolveOrCreateEnum(value) - - def __int__(self): - return self.value - - def __contains__(self, item): - return self & item == item - - @classmethod - def __createEnum(cls, value): - enum = cls.__new__(cls) - enum.name = "Unnamed '%s' enum with value: %i" % (str(cls.__name__), value) - enum.value = value - return enum - - @classmethod - def __resolveOrCreateEnum(cls, value): - enum = cls.__resolveEnum(value) - - if enum is not None: - return enum - - return cls.__createEnum(value) - - @classmethod - def __resolveEnum(cls, value): - for enum in cls.enum_namespace[cls]: - if enum.value == value: - return enum - return None - - def __assertOtherIsSameType(self, other): - assert isinstance(other, self.__class__), "Can only operate on enums of same type: %s =! %s" % ( - self.__class__.__name__, other.__class__.__name__) - - - @classmethod - def populateEnum(cls, library, enum_provider_function): - try: - func = getattr(library, enum_provider_function) - except AttributeError: - raise ValueError("Could not find enum description function: %s - can not load enum: %s." % (enum_provider_function, cls.__name__)) - - func.restype = ctypes.c_char_p - func.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)] - - index = 0 - while True: - value = ctypes.c_int() - name = func(index, ctypes.byref(value)) - - if name: - cls.addEnum(name, value.value) - index += 1 - else: - break - diff --git a/ThirdParty/Ert/python/python/cwrap/basecvalue.py b/ThirdParty/Ert/python/python/cwrap/basecvalue.py deleted file mode 100644 index 2c9f582792..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/basecvalue.py +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import (absolute_import, division, - print_function, unicode_literals) - -import six - -from ctypes import (pointer, c_long, c_int, c_bool, c_float, c_double, c_byte, - c_short, c_char, c_ubyte, c_ushort, c_uint, c_ulong) - -from .metacwrap import MetaCWrap - -@six.add_metaclass(MetaCWrap) -class BaseCValue(object): - DATA_TYPE = None - LEGAL_TYPES = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_bool, c_char, c_float, c_double] - - def __init__(self, value): - super(BaseCValue, self).__init__() - - if not self.DATA_TYPE in self.LEGAL_TYPES: - raise ValueError("DATA_TYPE must be one of these CTypes classes: %s" % BaseCValue.LEGAL_TYPES) - - self.__value = self.cast(value) - - - def value(self): - return self.__value.value - - @classmethod - def storageType(cls): - return cls.type() - - @classmethod - def type(cls): - return cls.DATA_TYPE - - @classmethod - def cast(cls, value): - return cls.DATA_TYPE(value) - - def setValue(self, value): - self.__value = self.cast(value) - - def asPointer(self): - return pointer(self.__value) - - @classmethod - def from_param(cls, c_value_object): - if c_value_object is not None and not isinstance(c_value_object, BaseCValue): - raise ValueError("c_class_object must be a BaseCValue instance!") - - return c_value_object.__value diff --git a/ThirdParty/Ert/python/python/cwrap/cfile.py b/ThirdParty/Ert/python/python/cwrap/cfile.py deleted file mode 100644 index 4b46d420f9..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/cfile.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import ctypes -import six -from .prototype import Prototype, PrototypeError -from .basecclass import BaseCClass - -class CFILE(BaseCClass): - """ - Utility class to map a Python file handle <-> FILE* in C - """ - TYPE_NAME = "FILE" - - _as_file = Prototype(ctypes.pythonapi, "void* PyFile_AsFile(py_object)") - - def __init__(self, py_file): - """ - Takes a python file handle and looks up the underlying FILE * - - The purpose of the CFILE class is to be able to use python - file handles when calling C functions which expect a FILE - pointer. A CFILE instance should be created based on the - Python file handle, and that should be passed to the function - expecting a FILE pointer. - - The implementation is based on the ctypes object - pythonapi which is ctypes wrapping of the CPython api. - - C-function: - void fprintf_hello(FILE * stream , const char * msg); - - Python wrapper: - lib = clib.load( "lib.so" ) - fprintf_hello = Prototype(lib, "void fprintf_hello( FILE , char* )") - - Python use: - py_fileH = open("file.txt" , "w") - fprintf_hello( CFILE( py_fileH ) , "Message ...") - py_fileH.close() - - If the supplied argument is not of type py_file the function - will raise a TypeException. - - Examples: ecl.ecl.ecl_kw.EclKW.fprintf_grdecl() - """ - c_ptr = self._as_file(py_file) - try: - super(CFILE, self).__init__(c_ptr) - except ValueError as e: - raise TypeError("Sorry - the supplied argument is not a valid Python file handle!") - - self.py_file = py_file - - - def __del__(self): - pass diff --git a/ThirdParty/Ert/python/python/cwrap/clib.py b/ThirdParty/Ert/python/python/cwrap/clib.py deleted file mode 100644 index 8fb87a6518..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/clib.py +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'clib.py' 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 the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -"""Convenience module for loading shared library. -""" - -import platform -import ctypes -import os - -so_extension = {"linux" : "so", - "linux2" : "so", - "linux3" : "so", - "win32" : "dll", - "win64" : "dll", - "darwin" : "dylib" } - - -# Passing None to the CDLL() function means to open a lib handle to -# the current runnning process, i.e. like dlopen( NULL ). We must -# special case this to avoid creating the bogus argument 'None.so'. - -def lib_name(lib , path = None , so_version = ""): - if lib is None: - return None - else: - platform_key = platform.system().lower() - - if platform_key == "darwin": - so_name = "%s%s.%s" % (lib, so_version, so_extension[ platform_key ]) - else: - so_name = "%s.%s%s" % (lib, so_extension[ platform_key ], so_version) - - if path: - return os.path.join( path , so_name ) - else: - return so_name - - - - -def load( lib, so_version = None, path = None): - """Thin wrapper around the ctypes.CDLL function for loading shared - library. - - If the path argument is non Null the function will first try to - load with full path. If that fails it wil also try to load without - a path component, invoking normal dlopen() semantics. - """ - - dll = None - lib_files = [ lib_name( lib , path = path , so_version = so_version) ] - if path: - lib_files.append( lib_name( lib , path = None , so_version = so_version) ) - - for lib_file in lib_files: - try: - dll = ctypes.CDLL(lib_file , ctypes.RTLD_GLOBAL) - return dll - except Exception as exc: - error = exc - - error_msg = "\nFailed to load shared library:%s\n\ndlopen() error: %s\n" % (lib , error) - - LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH") - if not LD_LIBRARY_PATH: - LD_LIBRARY_PATH = "" - - error_msg += """ -The runtime linker has searched through the default location of shared -libraries, and also the locations mentioned in your LD_LIBRARY_PATH -variable. Your current LD_LIBRARY_PATH setting is: - - LD_LIBRARY_PATH: %s - -You might need to update this variable? -""" % LD_LIBRARY_PATH - raise ImportError(error_msg) diff --git a/ThirdParty/Ert/python/python/cwrap/metacwrap.py b/ThirdParty/Ert/python/python/cwrap/metacwrap.py deleted file mode 100644 index 52ccb970ce..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/metacwrap.py +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import (absolute_import, division, - print_function, unicode_literals) -import six - -import re -from types import MethodType - -from .prototype import Prototype - - -def snakeCase(name): - s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) - return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() - - -class MetaCWrap(type): - def __init__(cls, name, bases, attrs): - super(MetaCWrap, cls).__init__(name, bases, attrs) - - is_return_type = False - storage_type = None - - if "TYPE_NAME" in attrs: - type_name = attrs["TYPE_NAME"] - else: - type_name = snakeCase(name) - - if hasattr(cls, "DATA_TYPE") or hasattr(cls, "enums"): - is_return_type = True - - if hasattr(cls, "storageType"): - storage_type = cls.storageType() - - Prototype.registerType(type_name, cls, is_return_type=is_return_type, storage_type=storage_type) - - if hasattr(cls, "createCReference"): - Prototype.registerType("%s_ref" % type_name, cls.createCReference, is_return_type=True, storage_type=storage_type) - - if hasattr(cls, "createPythonObject"): - Prototype.registerType("%s_obj" % type_name, cls.createPythonObject, is_return_type=True, storage_type=storage_type) - - - for key, attr in attrs.items(): - if isinstance(attr, Prototype): - attr.resolve() - attr.__name__ = key - - if attr.shouldBeBound(): - method = MethodType(attr, None, cls) - #method = six.create_bound_method(attr, cls) - setattr(cls, key, method) diff --git a/ThirdParty/Ert/python/python/cwrap/prototype.py b/ThirdParty/Ert/python/python/cwrap/prototype.py deleted file mode 100644 index 28348e31d7..0000000000 --- a/ThirdParty/Ert/python/python/cwrap/prototype.py +++ /dev/null @@ -1,177 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import ctypes -import inspect -import re - -import sys - -class TypeDefinition(object): - def __init__(self, type_class_or_function, is_return_type, storage_type): - self.storage_type = storage_type - self.is_return_type = is_return_type - self.type_class_or_function = type_class_or_function - - -REGISTERED_TYPES = {} -""":type: dict[str,TypeDefinition]""" - - -def _registerType(type_name, type_class_or_function, is_return_type=True, storage_type=None): - if type_name in REGISTERED_TYPES: - raise PrototypeError("Type: '%s' already registered!" % type_name) - - REGISTERED_TYPES[type_name] = TypeDefinition(type_class_or_function, is_return_type, storage_type) - - # print("Registered: %s for class: %s" % (type_name, repr(type_class_or_function))) - -_registerType("void", None) -_registerType("void*", ctypes.c_void_p) -_registerType("uint", ctypes.c_uint) -_registerType("uint*", ctypes.POINTER(ctypes.c_uint)) -_registerType("int", ctypes.c_int) -_registerType("int*", ctypes.POINTER(ctypes.c_int)) -_registerType("int64", ctypes.c_int64) -_registerType("int64*", ctypes.POINTER(ctypes.c_int64)) -_registerType("size_t", ctypes.c_size_t) -_registerType("size_t*", ctypes.POINTER(ctypes.c_size_t)) -_registerType("bool", ctypes.c_bool) -_registerType("bool*", ctypes.POINTER(ctypes.c_bool)) -_registerType("long", ctypes.c_long) -_registerType("long*", ctypes.POINTER(ctypes.c_long)) -_registerType("char", ctypes.c_char) -_registerType("char*", ctypes.c_char_p) -_registerType("char**", ctypes.POINTER(ctypes.c_char_p)) -_registerType("float", ctypes.c_float) -_registerType("float*", ctypes.POINTER(ctypes.c_float)) -_registerType("double", ctypes.c_double) -_registerType("double*", ctypes.POINTER(ctypes.c_double)) -_registerType("py_object", ctypes.py_object) - -PROTOTYPE_PATTERN = "(?P[a-zA-Z][a-zA-Z0-9_*]*) +(?P[a-zA-Z]\w*) *[(](?P[a-zA-Z0-9_*, ]*)[)]" - -class PrototypeError(Exception): - pass - - -class Prototype(object): - pattern = re.compile(PROTOTYPE_PATTERN) - - def __init__(self, lib, prototype, bind=False, allow_attribute_error=False): - super(Prototype, self).__init__() - self._lib = lib - self._prototype = prototype - self._bind = bind - self._func = None - self.__name__ = prototype - self._resolved = False - self._allow_attribute_error = allow_attribute_error - - - - def _parseType(self, type_name): - """Convert a prototype definition type from string to a ctypes legal type.""" - type_name = type_name.strip() - - if type_name in REGISTERED_TYPES: - type_definition = REGISTERED_TYPES[type_name] - return type_definition.type_class_or_function, type_definition.storage_type - raise ValueError("Unknown type: %s" % type_name) - - - def shouldBeBound(self): - return self._bind - - def resolve(self): - match = re.match(Prototype.pattern, self._prototype) - if not match: - raise PrototypeError("Illegal prototype definition: %s\n" % self._prototype) - else: - restype = match.groupdict()["return"] - function_name = match.groupdict()["function"] - self.__name__ = function_name - arguments = match.groupdict()["arguments"].split(",") - - try: - func = getattr(self._lib, function_name) - except AttributeError: - if self._allow_attribute_error: - return - raise PrototypeError("Can not find function: %s in library: %s" % (function_name , self._lib)) - - if not restype in REGISTERED_TYPES or not REGISTERED_TYPES[restype].is_return_type: - sys.stderr.write("The type used as return type: %s is not registered as a return type.\n" % restype) - - return_type = self._parseType(restype) - - if inspect.isclass(return_type): - sys.stderr.write(" Correct type may be: %s_ref or %s_obj.\n" % (restype, restype)) - - return None - - return_type, storage_type = self._parseType(restype) - - func.restype = return_type - - if storage_type is not None: - func.restype = storage_type - - def returnFunction(result, func, arguments): - return return_type(result) - - func.errcheck = returnFunction - - if len(arguments) == 1 and arguments[0].strip() == "": - func.argtypes = [] - else: - argtypes = [self._parseType(arg)[0] for arg in arguments] - if len(argtypes) == 1 and argtypes[0] is None: - argtypes = [] - func.argtypes = argtypes - - self._func = func - - - def __call__(self, *args): - if not self._resolved: - self.resolve() - self._resolved = True - - if self._func is None: - if self._allow_attribute_error: - raise NotImplementedError("Function:%s has not been properly resolved - missing library symbol?" % self.__name__) - else: - raise PrototypeError("Prototype has not been properly resolved") - - return self._func(*args) - - def __repr__(self): - bound = "" - if self.shouldBeBound(): - bound = ", bind=True" - - return 'Prototype("%s"%s)' % (self._prototype, bound) - - @classmethod - def registerType(cls, type_name, type_class_or_function, is_return_type=True, storage_type=None): - if storage_type is None and (inspect.isfunction(type_class_or_function)): - storage_type = ctypes.c_void_p - - _registerType(type_name, - type_class_or_function, - is_return_type = is_return_type, - storage_type = storage_type) diff --git a/ThirdParty/Ert/python/python/ecl/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/CMakeLists.txt deleted file mode 100644 index 3ba6f862bc..0000000000 --- a/ThirdParty/Ert/python/python/ecl/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -set(PYTHON_SOURCES - __init__.py -) -add_python_package("python.ecl" ${PYTHON_INSTALL_PREFIX}/ecl "${PYTHON_SOURCES}" True) - -add_subdirectory(ecl) -add_subdirectory(geo) -add_subdirectory(test) -add_subdirectory(util) -add_subdirectory(well) - -configure_file(ecl_lib_info_build.py.in ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl/__ecl_lib_info.py ) -configure_file(ecl_lib_info_install.py.in ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl_lib_info_install.py ) -install(FILES ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl_lib_info_install.py DESTINATION ${PYTHON_INSTALL_PREFIX}/ecl RENAME __ecl_lib_info.py) diff --git a/ThirdParty/Ert/python/python/ecl/__init__.py b/ThirdParty/Ert/python/python/ecl/__init__.py deleted file mode 100644 index 3163485b17..0000000000 --- a/ThirdParty/Ert/python/python/ecl/__init__.py +++ /dev/null @@ -1,130 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file '__init__.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -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 -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, -i.e. standard locations configured with ld.so.conf and the environment -variable LD_LIBRARY_PATH. - -To avoid conflict with other application using the ert libraries the -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 -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 - behaviours can be imposed: - - Existing path: the package will look in the path pointed to - by ERT_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 -alternative fails, the loader will try the default load behaviour -before giving up completely. -""" -import os.path -import sys - -import warnings -warnings.simplefilter('always', DeprecationWarning) # see #1437 - -from cwrap import load as cwrapload - -try: - import ert_site_init -except ImportError: - pass - - -required_version_hex = 0x02070000 - -ecl_lib_path = None -ert_so_version = "" -__version__ = "0.0.0" - - -# 1. Try to load the __ecl_lib_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: - import __ecl_lib_info - ecl_lib_path = __ecl_lib_info.lib_path - ert_so_version = __ecl_lib_info.so_version - __version__ = __ecl_lib_info.__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 -# 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") -if env_lib_path: - if os.path.isdir( env_lib_path ): - ert_lib_path = os.getenv("ERT_LIBRARY_PATH") - else: - sys.stderr.write("Warning: Environment variable ERT_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.isdir( ecl_lib_path ): - ecl_lib_path = None - - -if sys.hexversion < required_version_hex: - raise Exception("ERT Python requires Python 2.7.") - -# This load() function is *the* function actually loading shared -# libraries. - -def load(name): - return cwrapload(name, path=ecl_lib_path, so_version=ert_so_version) - - -from .util import EclVersion -from .util import updateAbortSignals - -updateAbortSignals( ) - -def root(): - """ - Will print the filesystem root of the current ert package. - """ - return os.path.abspath( os.path.join( os.path.dirname( __file__ ) , "../")) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/ecl/CMakeLists.txt deleted file mode 100644 index 9b9ba88b03..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - ecl_3d_file.py - ecl_3dkw.py - ecl_file.py - ecl_file_view.py - ecl_grav.py - ecl_grav_calc.py - ecl_grid.py - ecl_init_file.py - ecl_kw.py - ecl_npv.py - ecl_region.py - ecl_restart_file.py - ecl_rft.py - ecl_rft_cell.py - ecl_smspec_node.py - ecl_subsidence.py - ecl_sum.py - ecl_sum_keyword_vector.py - ecl_sum_node.py - ecl_sum_tstep.py - ecl_sum_vector.py - ecl_util.py - fortio.py - ecl_sum_keyword_vector.py - ecl_cmp.py - ecl_sum_var_type.py - ecl_type.py - ecl_grid_generator.py - cell.py -) - -add_python_package("python.ecl.ecl" ${PYTHON_INSTALL_PREFIX}/ecl/ecl "${PYTHON_SOURCES}" True) - -add_subdirectory(faults) -add_subdirectory(rft) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/__init__.py b/ThirdParty/Ert/python/python/ecl/ecl/__init__.py deleted file mode 100644 index 8f0d16b365..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/__init__.py +++ /dev/null @@ -1,115 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file '__init__.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Package for working with ECLIPSE files. - -The ecl package contains several classes for working with ECLIPSE -files. The ecl package is a wrapper around the libecl library from the -ERT distribution. Mainly the package is organized with modules -ecl_xxx.py with a class EclXXX. The module ecl_xxx.py will generaly -wrap the content of the c-file ecl_xxx.c The main content is: - - 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. - - ecl_grid/EclGrid: This will load an ECLIPSE GRID or EGRID file, and - can then subsequently be used for queries about the grid. - - ecl_grid_generator/EclGridGenerator: This can be used to generate various - grids. - - 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. - - ecl_rft/[EclRFTFile , EclRFT , EclRFTCell]: Loads an ECLIPSE RFT/PLT - file, and can afterwords be used to support various queries. - - 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_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. - -In addition there are some modules which do not follow the one class -per module organization: - - ecl_util: This is mainly a collection of constants, and a few - stateless functions. - - ecl: This module is purely for convenience, all the symbols in the - package are explicitly imported into this module, ensuring that - all symbols in the package are available under the common - namespace 'ecl'. - -""" -import ecl.util -import ecl.geo - -from cwrap import Prototype - - -class EclPrototype(Prototype): - lib = ecl.load("libecl") - - def __init__(self, prototype, bind=True): - super(EclPrototype, self).__init__(EclPrototype.lib, prototype, bind=bind) - -ECL_LIB = ecl.load("libecl") - -from .cell import Cell -from .ecl_util import EclFileEnum, EclFileFlagEnum, EclPhaseEnum, EclUnitTypeEnum , EclUtil -from .ecl_type import EclTypeEnum, EclDataType -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_rft_cell import EclPLTCell, EclRFTCell -from .ecl_rft import EclRFT, EclRFTFile -from .fortio import FortIO, openFortIO -from .ecl_kw import EclKW -from .ecl_3dkw import Ecl3DKW -from .ecl_file_view import EclFileView -from .ecl_file import EclFile , openEclFile -from .ecl_3d_file import Ecl3DFile -from .ecl_init_file import EclInitFile -from .ecl_restart_file import EclRestartFile -from .ecl_grid import EclGrid -from .ecl_region import EclRegion -from .ecl_subsidence import EclSubsidence -from .ecl_grav_calc import phase_deltag, deltag -from .ecl_grav import EclGrav -from .ecl_sum_node import EclSumNode -from .ecl_sum_vector import EclSumVector -from .ecl_npv import EclNPV , NPVPriceVector -from .ecl_cmp import EclCmp -from .ecl_grid_generator import EclGridGenerator diff --git a/ThirdParty/Ert/python/python/ecl/ecl/cell.py b/ThirdParty/Ert/python/python/ecl/ecl/cell.py deleted file mode 100644 index 5824d6fc47..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/cell.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -class Cell(object): - - def __init__(self, grid, global_index): - self._grid = grid - self._idx = global_index - self._ijk = grid.get_ijk(global_index=self._idx) - self._aidx = grid.get_active_index(global_index=self._idx) - - @property - def volume(self): - return self._grid.cell_volume(global_index=self._idx) - - @property - def global_index(self): - return self._idx - - @property - def active_index(self): - return self._aidx - - @property - def ijk(self): - return self._ijk - @property - def i(self): - return self._ijk[0] - @property - def j(self): - return self._ijk[1] - @property - def k(self): - return self._ijk[2] - - @property - def active(self): - return self._aidx >= 0 - - def eval(self, kw): - return self._grid.grid_value(kw, self.i, self.j, self.k) - - @property - def fracture(self): - return self._grid.active_fracture_index(global_index=self._idx) - - @property - def dz(self): - return self._grid.cell_dz(global_index=self._idx) - - @property - def dimension(self): - return self._grid.get_cell_dims(global_index=self._idx) - - @property - def valid_geometry(self): - return self._grid.valid_cell_geometry(global_index=self._idx) - - @property - def valid(self): - return not self._grid.cell_invalid(global_index=self._idx) - - def __contains__(self, coord): - """ - Will check if this cell contains point given by world - coordinates (x,y,z)=coord. - """ - if len(coord) != 3: - raise ValueError('Cell contains takes a triple (x,y,z), was given %s.' % coord) - x,y,z = coord - return self._grid._cell_contains(self._idx, x,y,z) - - def __eq__(self, other): - if isinstance(other, Cell): - idx_eq = self.global_index == other.global_index - return idx_eq and self._grid == other._grid - return NotImplemented - - def __neq__(self, other): - if isinstance(other, Cell): - return not self == other - return NotImplemented - - def hash(self): - return hash((self._idx, self._aidx, self.ijk)) - - @property - def coordinate(self): - return self._grid.get_xyz(global_index=self._idx) - - @property - def corners(self): - """ - Return xyz for each of the eight vertices, indexed by: - - lower layer: upper layer - - 2---3 6---7 - | | | | - 0---1 4---5 - """ - cs = lambda c : self._grid.get_cell_corner(c, global_index=self._idx) - return [cs(i) for i in range(8)] - - def __repr__(self): - act = 'active' if self.active else 'inactive' - pos = '(%.3f, %.3f, %.3f)' % self.coordinate - cnt = '%d, %d, %d, %s, %s, grid=%s' % (self.i, self.j, self.k, - act, pos, - self._grid.get_name()) - - return 'Cell(%s)' % cnt diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_3d_file.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_3d_file.py deleted file mode 100644 index 7625a2de7c..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_3d_file.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.ecl import EclFile, Ecl3DKW - - -class Ecl3DFile(EclFile): - - def __init__(self, grid, filename, flags=0): - self.grid = grid - super(Ecl3DFile, self).__init__(filename, flags) - - - def __getitem__(self, index): - return_arg = super(Ecl3DFile, 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 - for kw in kw_list: - try: - Ecl3DKW.castFromKW(kw, self.grid) - except ValueError: - pass - - return return_arg diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_3dkw.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_3dkw.py deleted file mode 100644 index 0f6a91994a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_3dkw.py +++ /dev/null @@ -1,239 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'ecl_3dkw.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import (absolute_import, division, - print_function, unicode_literals) - -from ecl.util import monkey_the_camel -from .ecl_kw import EclKW - -class Ecl3DKW(EclKW): - """ - 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 - PORO or SATNUM. - - The Ecl3DKW class has an attached EclGrid 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. - - Usage example: - - from ecl.ecl import EclInitFile,EclGrid - - grid = EclGrid("ECLIPSE.EGRID") - file = EclInitFile(grid , "ECLIPSE.INIT") - - 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])) - - In the example we open an ECLIPSE INIT file and extract the PERMX - and PORV properties, and then iterate over all the cells in the - grid. - - In the INIT file the PORV keyword is stored with all cells, - whereas the PERMX keyword typically only has the active cells - stored, this active/inactive gymnastics is handled - transparently. With the call: - - permx_kw.setDefault( -1 ) - - we say that we want the value -1 for all inactive cells in the - PERMX property. - - """ - def __init__(self, kw , grid , value_type , default_value = 0 , global_active = False): - if global_active: - size = grid.getGlobalSize() - else: - size = grid.getNumActive( ) - super(Ecl3DKW , 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) - return new_kw - - @classmethod - def read_grdecl( cls , grid , fileH , kw , strict = True , ecl_type = None): - """ - Will load an Ecl3DKW instance from a grdecl formatted filehandle. - - See the base class EclKW.read_grdecl() for more documentation. - """ - kw = super(Ecl3DKW , cls).read_grdecl( fileH , kw , strict , ecl_type) - Ecl3DKW.castFromKW(kw , grid) - return kw - - - - def __getitem__(self , index): - """Will return item [g] or [i,j,k]. - - The __getitem__() methods supports both scalar indexing like - [g] and tuples [i,j,k]. If the input argument is given as a - [i,j,k] tuple it is converted to an active index before the - final lookup. - - If the [i,j,k] input corresponds to an inactive cell in a - keyword with only nactive elements the default value will be - returned. By default the default value will be 0, but another - value can be assigned with the setDefault() method. - """ - if isinstance(index , tuple): - global_index = self.grid.get_global_index( ijk = index ) - if self.global_active: - index = global_index - else: - if not self.grid.active( global_index = global_index): - return self.getDefault() - else: - index = self.grid.get_active_index( ijk = index ) - - - return super(Ecl3DKW , self).__getitem__( index ) - - - - - def __setitem__(self , index , value): - """Set the value of at index [g] or [i,j,k]. - - The __setitem__() methods supports both scalar indexing like - [g] and tuples [i,j,k]. If the input argument is given as a - [i,j,k] tuple it is converted to an active index before the - final assignment. - - If you try to assign an inactive cell in a keyword with only - nactive elements a ValueError() exception will be raised. - """ - if isinstance(index , tuple): - global_index = self.grid.get_global_index( ijk = index ) - if self.global_active: - index = global_index - else: - if not self.grid.active( global_index = global_index): - raise ValueError("Tried to assign value to inactive cell: (%d,%d,%d)" % index) - else: - index = self.grid.get_active_index( ijk = index ) - - - return super(Ecl3DKW , self).__setitem__( index , value ) - - - @classmethod - def cast_from_kw(cls, kw, grid, default_value=0): - """Will convert a normal EclKW to a Ecl3DKW. - - The method will convert a normal EclKW instance to Ecl3DKw - instance with an attached grid and a default value. - - The method will check that size of the keyword is compatible - with the grid dimensions, i.e. the keyword must have either - nactive or nx*ny*nz elements. If the size of the keyword is - not compatible with the grid dimensions a ValueError exception - is raised. - - Example: - - 1. Load the poro keyword from a grdecl formatted file. - 2. Convert the keyword to a 3D keyword. - - - from ecl.ecl import EclGrid,EclKW,Ecl3DKW - - grid = EclGrid("ECLIPSE.EGRID") - poro = EclKW.read_grdecl(open("poro.grdecl") , "PORO") - Ecl3DKW.castFromKW( poro , grid ) - - print('Porosity in cell (10,11,12):%g' % poro[10,11,12]) - """ - if len(kw) == grid.getGlobalSize(): - kw.global_active = True - elif len(kw) == grid.getNumActive(): - kw.global_active = False - else: - raise ValueError("Size mismatch - must have size matching global/active size of grid") - - - kw.__class__ = cls - kw.default_value = default_value - kw.grid = grid - if len(kw) == grid.getGlobalSize(): - kw.global_active = True - else: - kw.global_active = False - - kw.setDefault( default_value ) - return kw - - - def compressed_copy(self): - """Will return a EclKW copy with nactive elements. - - The returned copy will be of type EclKW; 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. - """ - return self.grid.compressedKWCopy( self ) - - - def global_copy(self): - """Will return a EclKW copy with nx*ny*nz elements. - - The returned copy will be of type EclKW; 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. - """ - return self.grid.globalKWCopy( self , self.getDefault() ) - - - - def dims(self): - return (self.grid.getNX() , self.grid.getNY() , self.grid.getNZ()) - - - def set_default(self, default_value): - self.default_value = default_value - - - 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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_cmp.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_cmp.py deleted file mode 100644 index bd85dcde2b..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_cmp.py +++ /dev/null @@ -1,184 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'ecl_cmp.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.util import monkey_the_camel -from ecl.ecl import EclSum - -class EclCase(object): - - def __init__(self, case): - self.case = case - - self.grid = None - self.restart = None - self.init = None - self.summary = None - - self.loadSummary() - - - def __contains__(self, key): - return key in self.summary - - - def keys(self): - return self.summary.keys() - - - def wells(self): - return self.summary.wells() - - def load_summary(self): - self.summary = EclSum(self.case) - - - def start_time_equal(self, other): - if self.summary.getDataStartTime() == other.summary.getDataStartTime(): - return True - else: - return False - - def end_time_equal(self, other): - if self.summary.getEndTime() == other.summary.getEndTime(): - return True - else: - return False - - - def cmp_summary_vector(self, other, key, sample=100): - if key in self and key in other: - days_total = min(self.summary.getSimulationLength(), other.summary.getSimulationLength()) - dt = days_total / (sample - 1) - days = [ x * dt for x in range(sample) ] - - ref_data = self.summary.get_interp_vector(key, days_list=days) - test_data = other.summary.get_interp_vector(key, days_list=days) - diff_data = ref_data - test_data - - ref_sum = sum(ref_data) - diff_sum = sum(abs(diff_data)) - return (diff_sum, ref_sum) - else: - raise KeyError("Key:%s was not present in both cases" % key) - - - - - -class EclCmp(object): - - def __init__(self, test_case, ref_case): - """Class to compare to simulation cases with Eclipse formatted result files. - - The first argument is supposed to be the test_case and the - second argument is the reference case. The arguemnts should be - the basenames of the simulation, with an optional path - prefix - an extension is accepted, but will be ignored. - - 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.initCheck() - - - def init_check(self): - """A crude initial check to verify that the cases can be meaningfully - compared. - """ - if not self.test_case.startTimeEqual(self.ref_case): - raise ValueError("The two cases do not start at the same time - can not be compared") - - - def has_summary_vector(self, key): - """ - Will check if both test and refernce have @key. - """ - return (key in self.test_case, key in self.ref_case) - - - def end_time_equal(self): - """ - Will check that ref_case and test_case are equally long. - """ - return self.test_case.endTimeEqual(self.ref_case) - - - - def cmp_summary_vector(self, key, sample=100): - """Will compare the summary vectors according to @key. - - The comparison is based on evaluating the integrals: - - I0 = \int R(t) dt - - delta = \int | R(t) - T(t)| dt - - numericall. R(t) is the reference solution and T(t) is - testcase solution. The return value is a tuple: - - (delta, I0) - - 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") - - if delta/scale < 0.0001: - print("Equal enough") - else: - print("Different ..") - - The upper limit for the integrals is: - - max(length(ref_case), length(test_case)) - - meaning that two simulations which don't have the same - end-time will compare as equal if they compare equal in the - common part. If that is not OK you should call the - endTimeEqual() method independently. - """ - return self.test_case.cmpSummaryVector(self.ref_case, key, sample=sample) - - - def test_keys(self): - """ - Will return a list of summary keys in the test case. - """ - return self.test_case.keys() - - - def test_wells(self): - """ - Will return a list of wells keys in the test case. - """ - 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(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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_file.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_file.py deleted file mode 100644 index c8fd6c7280..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_file.py +++ /dev/null @@ -1,718 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_file.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -The ecl_file module contains functionality to load a an ECLIPSE 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 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" ) - 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. - -[1]: In particular for restart files, which do not have a special - RestartFile class, there is some specialized functionality. -""" -import re -import types -import datetime -import ctypes - -from cwrap import BaseCClass -from ecl.util import CTime -from ecl.util import monkey_the_camel -from ecl.ecl import EclPrototype, EclKW, EclFileEnum, EclFileView - - -class EclFile(BaseCClass): - TYPE_NAME = "ecl_file" - _open = EclPrototype("void* ecl_file_open( char* , int )" , bind = False) - _get_file_type = EclPrototype("ecl_file_enum ecl_util_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 )") - _iget_restart_days = EclPrototype("double ecl_file_iget_restart_sim_days( ecl_file , int )") - _get_restart_index = EclPrototype("int ecl_file_get_restart_index( ecl_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)") - _fwrite = EclPrototype("void ecl_file_fwrite_fortio( ecl_file , fortio , int)") - _has_report_step = EclPrototype("bool ecl_file_has_report_step( ecl_file , int)") - _has_sim_time = EclPrototype("bool ecl_file_has_sim_time( ecl_file , time_t )") - _get_global_view = EclPrototype("ecl_file_view_ref ecl_file_get_global_view( ecl_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) - - - @staticmethod - def get_filetype(filename): - fmt_file = ctypes.c_bool() - report_step = ctypes.c_int() - - file_type = EclFile._get_file_type( filename , ctypes.byref( fmt_file ) , ctypes.byref(report_step)) - if file_type in [EclFileEnum.ECL_RESTART_FILE , EclFileEnum.ECL_SUMMARY_FILE]: - report_step = report_step.value - else: - report_step = None - - if file_type in [EclFileEnum.ECL_OTHER_FILE , EclFileEnum.ECL_DATA_FILE]: - fmt_file = None - else: - fmt_file = fmt_file.value - - - return (file_type , report_step , fmt_file ) - - - - @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.") - - - - @classmethod - 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 - you should use the has_report_step() method instead. - """ - obj = EclFile( filename ) - return obj.has_report_step( report_step ) - - - @classmethod - def contains_sim_time( cls , filename , dtime ): - """ - Will check if the @filename contains simulation at @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: - - 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 - you should use the has_sim_time() method instead. - """ - obj = EclFile( filename ) - return obj.has_sim_time( dtime ) - - @property - def report_list(self): - report_steps = [] - try: - seqnum_list = self["SEQNUM"] - for s in seqnum_list: - report_steps.append( s[0] ) - except KeyError: - # OK - we did not have seqnum; that might be because this - # a non-unified restart file; or because this is not a - # restart file at all. - fname = self.getFilename( ) - matchObj = re.search("\.[XF](\d{4})$" , fname) - if matchObj: - report_steps.append( int(matchObj.group(1)) ) - else: - raise TypeError('Tried get list of report steps from file "%s" - which is not a restart file' % fname) - - - return report_steps - - - - @classmethod - def file_report_list( cls , filename ): - """ - Will identify the available report_steps from @filename. - """ - - file = EclFile( filename ) - return file.report_list - - - - def __repr__(self): - fn = self.getFilename() - wr = ', read/write' if self._writable() else '' - return self._create_repr('"%s"%s' % (fn,wr)) - - - def __init__( self , filename , flags = 0 , index_filename = None): - """ - Loads the complete file @filename. - - Will create a new EclFile 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 - content of the keywords in the file. - - ecl.ECL_FILE_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 - open concurrently. - - When the file has been loaded the EclFile instance can be used - to query for and get reference to the EclKW instances - constituting the file, like e.g. SWAT from a restart file or - FIPNUM from an INIT file. - """ - if index_filename is None: - c_ptr = self._open( filename , flags ) - else: - c_ptr = self._fast_open(filename, index_filename, flags) - - if c_ptr is None: - raise IOError('Failed to open file "%s"' % filename) - else: - super(EclFile , self).__init__(c_ptr) - self.global_view = self._get_global_view( ) - self.global_view.setParent( self ) - - - def save_kw( self , kw ): - """ - Will write the @kw back to file. - - This function should typically be used in situations like this: - - 1. Create an EclFile instance around an ECLIPSE output 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 - optional read_only flag set to False. - - 2. You can only modify the content of the keyword; if you - try to modify the header in any way (i.e. size, datatype - 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 - function will fail. - """ - if self._writable( ): - self._save_kw( kw ) - else: - raise IOError('save_kw: the file "%s" has been opened read only.' % self.getFilename( )) - - - def __len__(self): - return len(self.global_view) - - - def close(self): - if self: - self._close( ) - self._invalidateCPointer( ) - - - def free(self): - self.close() - - - def block_view(self, kw, kw_index): - if not kw in self: - raise KeyError('No such keyword "%s".' % kw) - ls = self.global_view.numKeywords(kw) - idx = kw_index - if idx < 0: - idx += ls - if 0 <= idx < ls: - return self.global_view.blockView(kw, idx) - raise IndexError('Index out of range, must be in [0, %d), was %d.' % (ls, kw_index)) - - - def block_view2(self, start_kw, stop_kw, start_index): - return self.global_view.blockView2( start_kw , stop_kw, start_index ) - - - def restart_view(self, seqnum_index=None, report_step=None, sim_time=None, sim_days=None): - return self.global_view.restartView( seqnum_index, report_step , sim_time, sim_days ) - - - def select_block(self, kw, kw_index): - raise NotImplementedError("The select_block implementation has been removed - use EclFileView") - - - def select_global( self ): - raise NotImplementedError("The select_global implementation has been removed - use EclFileView") - - - 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") - """ - Will select a restart section as the active section. - - You must specify a report step with the @report_step argument, - a true time with the @sim_time argument or a plain index to - select restart block. If none of arguments are given exception - TypeError will be raised. If present the @sim_time argument - should be a datetime instance. - - If the restart section you ask for can not be found the method - will raise a ValueError exeception. To protect against this - you can query first with the has_report_step(), - has_sim_time() or num_report_steps() methods. - - This method should be used when you have already loaded the - complete file; if you only want to load a section from the - file you can use the classmethod restart_block(). - - The method will return 'self' which can be used to aid - readability. - """ - - - - def select_last_restart( self ): - raise NotImplementedError("The select_restart_section implementation has been removed - use EclFileView") - """ - Will select the last SEQNUM block in restart file. - - Works by searching for the last SEQNUM keyword; the SEQNUM - Keywords are only present in unified restart files. If this - is a non-unified restart file (or not a restart file at all), - the method will do nothing and return False. - """ - - - - - - def __getitem__(self , index): - """ - Implements [] operator; index can be integer or key. - - Will look up EclKW instances from the current EclFile - instance. The @index argument can either be an integer, in - which case the method will return EclKW number @index, or - alternatively a keyword string, in which case the method will - return a list of EclKW instances with that keyword: - - restart_file = ecl_file.EclFile("ECLIPSE.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: - - swat9 = restart_file["SWAT"][9] - - Will return the 10'th SWAT keyword from the restart file. The - following example will iterate over all the SWAT keywords in a - restart file: - - restart_file = ecl_file.EclFile("ECLIPSE.UNRST") - for swat in restart_file["SWAT"]: - .... - """ - if isinstance(index, int): - ls = len(self) - idx = index - if idx < 0: - idx += ls - if 0 <= idx < ls: - return self.global_view[idx] - else: - raise IndexError('Index must be in [0, %d), was: %d.' % (ls, index)) - return self.global_view[index] - - - def iget_kw( self , index , copy = False): - """ - Will return EclKW instance nr @index. - - In the files loaded with the EclFile implementation the - ECLIPSE keywords come sequentially in a long series, an INIT - file might have the following keywords: - - INTEHEAD - LOGIHEAD - DOUBHEAD - PORV - DX - DY - DZ - PERMX - PERMY - PERMZ - MULTX - MULTY - ..... - - The iget_kw() method will give you a EclKW reference to - keyword nr @index. This functionality is also available - through the index operator []: - - file = EclFile( "ECLIPSE.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. - - The method iget_named_kw() which lets you specify the name of - the keyword you are interested in is in general more useful - than this method. - """ - kw = self[index] - if copy: - return EclKW.copy( kw ) - else: - return kw - - - 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. - - This function assumes that the current EclFile 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" ) - 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 - out of scope. If the optional argument @copy is True the - returned kw will be a true copy. - - If the file does not have the keyword at the specified time - the function will raise IndexError(); if the file does not - have the keyword at all - KeyError will be raised. - """ - index = self._get_restart_index( CTime( dtime ) ) - if index >= 0: - if self.num_named_kw(kw_name) > index: - kw = self.iget_named_kw( kw_name , index ) - if copy: - return EclKW.copy( kw ) - else: - return kw - else: - if self.has_kw(kw_name): - raise IndexError('Does not have keyword "%s" at time:%s.' % (kw_name , dtime)) - else: - raise KeyError('Keyword "%s" not recognized.' % kw_name) - else: - raise IndexError('Does not have keyword "%s" at time:%s.' % (kw_name , dtime)) - - - def replace_kw( self , old_kw , new_kw): - """ - Will replace @old_kw with @new_kw in current EclFile 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 - 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 - the SWAT keyword from a restart file: - - swat = file.iget_named_kw( "SWAT" , 0 ) - new_swat = swat * 0.25 - 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 - 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 - # can not give away something we do not alreeady own. - if not new_kw.data_owner: - new_kw = EclKW.copy( new_kw ) - - # The ecl_file instance will take responsability for freeing - # this ecl_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. - """ - return len(self) - - @property - def unique_size( self ): - """ - The number of unique keyword (names) in the current EclFile object. - """ - return self.global_view.uniqueSize( ) - - - - def keys(self): - """ - Will return a list of unique kw names - like keys() on a dict. - """ - header_dict = {} - for index in range(len(self)): - kw = self[index] - header_dict[ kw.getName() ] = True - return header_dict.keys() - - - @property - def headers(self): - """ - Will return a list of the headers of all the keywords. - """ - header_list = [] - for index in range(self.size): - kw = self[index] - header_list.append( kw.header ) - return header_list - - @property - 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 - is not a restart file it will not contain any 'SEQNUM' - keywords and the method will simply return an empty list. - """ - steps = [] - seqnum_list = self["SEQNUM"] - for kw in self["SEQNUM"]: - steps.append( kw[0] ) - return steps - - @property - def report_dates( self ): - """ - Will return a list of the dates for all report steps. - - The method works by iterating through the whole restart file - looking for 'SEQNUM/INTEHEAD' keywords; the method can - probably be tricked by other file types also containing an - INTEHEAD keyword. - """ - if self.has_kw('SEQNUM'): - dates = [] - for index in range( self.num_named_kw( 'SEQNUM' )): - dates.append( self.iget_restart_sim_time( index )) - return dates - elif 'INTEHEAD' in self: - # This is a uber-hack; should export the ecl_rsthead - # object as ctypes structure. - intehead = self["INTEHEAD"][0] - year = intehead[66] - month = intehead[65] - day = intehead[64] - date = datetime.datetime( year , month , day ) - return [ date ] - return None - - - @property - def dates( self ): - """ - Will return a list of the dates for all report steps. - """ - return self.report_dates - - - def num_named_kw( self , kw): - """ - The number of keywords with name == @kw in the current EclFile object. - """ - return self.global_view.numKeywords( kw ) - - - def has_kw( self , kw , num = 0): - """ - Check if current EclFile 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. - """ - - return self.num_named_kw( kw ) > num - - def __contains__(self , kw): - """ - Check if the current file contains keyword @kw. - """ - return self.has_kw( kw ) - - def has_report_step( self , report_step ): - """ - Checks if the current EclFile has report step @report_step. - - If the EclFile 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. - """ - return self._has_report_step( report_step ) - - def num_report_steps( self ): - """ - Returns the total number of report steps in the restart file. - - Works by counting the number of 'SEQNUM' instances, and will - happily return 0 for a non-restart file. Observe that the - report_steps present in a unified restart file are in general - not consecutive, i.e. the last report step will typically be - much higher than the return value from this function. - """ - return len( self["SEQNUM"] ) - - - - def has_sim_time( self , dtime ): - """ - Checks if the current EclFile 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 - keyword(s), but is still not a restart file. The @dtime - argument should be a normal python datetime instance. - """ - return self._has_sim_time( CTime(dtime) ) - - - def iget_restart_sim_time( self , index ): - """ - Will locate restart block nr @index and return the true time - as a datetime instance. - """ - ct = CTime(self._iget_restart_time( index )) - return ct.datetime() - - - def iget_restart_sim_days( self , index ): - """ - Will locate restart block nr @index and return the number of days - (in METRIC at least ...) since the simulation started. - - """ - return self._iget_restart_days( index ) - - - def get_filename(self): - """ - Name of the file currently loaded. - """ - fn = self._get_src_file() - return str(fn) if fn else '' - - def fwrite( self , fortio ): - """ - Will write current EclFile 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 - FortIO stream already opened for writing: - - import ecl.ecl.ecl as ecl - ... - fortio = ecl.FortIO( "FILE.XX" ) - file.fwrite( fortio ) - fortio.close() - - """ - self._fwrite( fortio , 0 ) - - def write_index(self, index_file_name): - if not self._write_index(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 - - def __enter__(self): - return self.__ecl_file - - def __exit__(self, exc_type, exc_val, exc_tb): - self.__ecl_file.close() - return False - - -def openEclFile( file_name , flags = 0): - print('The function openEclFile is deprecated, use open_ecl_file.') - return open_ecl_file(file_name, flags) - -def open_ecl_file(file_name, flags=0): - return EclFileContextManager(EclFile(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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_file_view.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_file_view.py deleted file mode 100644 index 1c90a235a7..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_file_view.py +++ /dev/null @@ -1,200 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import absolute_import, division, print_function, unicode_literals -from six import string_types -from cwrap import BaseCClass -from ecl.util import monkey_the_camel -from ecl.util import CTime -from ecl.ecl import EclPrototype - -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)") - _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_size = EclPrototype("int ecl_file_view_get_num_distinct_kw( ecl_file_view )") - _create_block_view = EclPrototype("ecl_file_view_ref ecl_file_view_add_blockview( ecl_file_view , char*, int )") - _create_block_view2 = EclPrototype("ecl_file_view_ref ecl_file_view_add_blockview2( ecl_file_view , char*, char*, int )") - _restart_view = EclPrototype("ecl_file_view_ref ecl_file_view_add_restart_view( ecl_file_view , int, int, time_t, double )") - - - def __init__(self): - raise NotImplementedError("Can not instantiate directly") - - - 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()) - - def iget_named_kw(self, kw_name, index): - if not kw_name in self: - raise KeyError("No such keyword: %s" % kw_name) - - if index >= self.numKeywords(kw_name): - raise IndexError("Too large index: %d" % index) - - return self._iget_named_kw(kw_name, index).setParent(parent=self) - - - - def __getitem__(self, index): - """ - Implements [] operator; index can be integer or key. - - Will look up EclKW instances from the current EclFile - instance. The @index argument can either be an integer, in - which case the method will return EclKW number @index, or - alternatively a keyword string, in which case the method will - return a list of EclKW instances with that keyword: - - restart_file = ecl_file.EclFile("ECLIPSE.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: - - swat9 = restart_file["SWAT"][9] - - Will return the 10'th SWAT keyword from the restart file. The - following example will iterate over all the SWAT keywords in a - restart file: - - restart_file = ecl_file.EclFile("ECLIPSE.UNRST") - for swat in restart_file["SWAT"]: - .... - """ - - if isinstance(index, int): - ls = len(self) - idx = index - if idx < 0: - idx += ls - if 0 <= idx < ls: - return self.__iget(idx) - else: - raise IndexError('Index must be in [0, %d), was: %d.' % (ls, index)) - - if isinstance(index, slice): - indices = index.indices(len(self)) - kw_list = [] - for i in range(*indices): - kw_list.append(self[i]) - return kw_list - else: - if isinstance(index, bytes): - index = index.decode('ascii') - if isinstance(index, string_types): - if index in self: - kw_index = index - kw_list = [] - for index in range(self.numKeywords(kw_index)): - kw_list.append( self.iget_named_kw(kw_index, index)) - return kw_list - else: - raise KeyError("Unrecognized keyword:\'%s\'" % index) - else: - raise TypeError("Index must be integer or string (keyword)") - - - def __len__(self): - return self._get_size() - - - def __contains__(self, kw): - if self.numKeywords(kw) > 0: - return True - else: - return False - - - def num_keywords(self, kw): - return self._get_num_named_kw(kw) - - - def unique_size(self): - return self._get_unique_size() - - def block_view2(self, start_kw, stop_kw, start_index): - idx = start_index - if start_kw: - if not start_kw in self: - raise KeyError("The keyword:%s is not in file" % start_kw) - - ls = self.numKeywords(start_kw) - if idx < 0: - idx += ls - if not (0 <= idx < ls): - raise IndexError('Index must be in [0, %d), was: %d.' % (ls, start_index)) - - if stop_kw: - if not stop_kw in self: - raise KeyError("The keyword:%s is not in file" % stop_kw) - - view = self._create_block_view2(start_kw, stop_kw, idx) - view.setParent(parent=self) - return view - - - def block_view(self, kw, kw_index): - num = self.numKeywords(kw) - - if num == 0: - raise KeyError("Unknown keyword: %s" % kw) - - idx = kw_index - if idx < 0: - idx += num - - if not (0 <= idx < num): - raise IndexError('Index must be in [0, %d), was: %d.' % (num, kw_index)) - - view = self._create_block_view(kw, kw_index) - view.setParent(parent=self) - return view - - - def restart_view(self, seqnum_index=None, report_step=None, sim_time=None, sim_days=None): - if report_step is None: - report_step = -1 - - if sim_time is None: - sim_time = -1 - - if sim_days is None: - sim_days = -1 - - if seqnum_index is None: - seqnum_index = -1 - - view = self._restart_view(seqnum_index, report_step, CTime(sim_time), sim_days) - if view is None: - raise ValueError("No such restart block could be identiefied") - - view.setParent(parent=self) - 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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_grav.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_grav.py deleted file mode 100644 index caffe5d597..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_grav.py +++ /dev/null @@ -1,217 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_grav.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Calculate dynamic change in gravitational strength. - -The ecl_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. -""" -from cwrap import BaseCClass -from ecl.util import monkey_the_camel -from ecl.ecl import EclPhaseEnum, EclPrototype - -class EclGrav(BaseCClass): - """ - Holding ECLIPSE results for calculating gravity changes. - - The EclGrav 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. - - Typical use of the EclGrav class involves the following steps: - - 1. Create the EclGrav 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)") - _add_survey_PORMOD = EclPrototype("void* ecl_grav_add_survey_PORMOD(ecl_grav, char*, ecl_file_view)") - _add_survey_FIP = EclPrototype("void* ecl_grav_add_survey_FIP(ecl_grav, char*, ecl_file_view)") - _add_survey_RFIP = EclPrototype("void* ecl_grav_add_survey_RFIP(ecl_grav, char*, ecl_file_view)") - _new_std_density = EclPrototype("void ecl_grav_new_std_density(ecl_grav, int, double)") - _add_std_density = EclPrototype("void ecl_grav_add_std_density(ecl_grav, int, int, double)") - _eval = EclPrototype("double ecl_grav_eval(ecl_grav, char*, char*, ecl_region, double, double, double, int)") - - - - def __init__(self, grid, init_file): - """ - Creates a new EclGrav instance. - - The input arguments @grid and @init_file should be instances - of EclGrid and EclFile 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) - - self.dispatch = {"FIP" : self.add_survey_FIP, - "RFIP" : self.add_survey_RFIP, - "PORMOD" : self.add_survey_PORMOD, - "RPORV" : self.add_survey_RPORV} - - - def add_survey_RPORV(self, survey_name, restart_view): - """ - 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 - 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 - to load the @restart_view argument is: - - import datetime - from ecl.ecl import EclRestartFile - ... - ... - date = datetime.datetime(year, month, day) - rst_file = EclRestartFile("ECLIPSE.UNRST") - restart_view1 = rst_file.restartView(sim_time=date) - restart_view2 = rst_file.restartView(report_step=67) - - The pore volume of each cell will be calculated based on the - RPORV keyword from the restart files. The methods - add_survey_PORMOD() and add_survey_FIP() are alternatives - which are based on other keywords. - """ - self._add_survey_RPORV(survey_name, restart_view) - - def add_survey_PORMOD(self, survey_name, restart_view): - """ - Add new survey based on PORMOD keyword. - - The pore volum is calculated from the initial pore volume and - the PORV_MOD keyword from the restart file; see - add_survey_RPORV() for further details. - """ - self._add_survey_PORMOD(survey_name, restart_view) - - def add_survey_FIP(self, survey_name, restart_view): - """ - Add new survey based on FIP keywords. - - This method adds a survey as add_survey_RPORV() and - add_survey_PORMOD; but the mass content in each cell is - calculated based on the FIPxxx keyword along with the mass - density at standard conditions of the respective phases. - - The mass density at standard conditions must be specified with - the new_std_density() (and possibly also add_std_density()) - method before calling the add_survey_FIP() method. - """ - self._add_survey_FIP(survey_name, restart_view) - - def add_survey_RFIP(self, survey_name, restart_view): - """ - Add new survey based on RFIP keywords. - - This method adds a survey as add_survey_RPORV() and - add_survey_PORMOD; but the mass content in each cell is - calculated based on the RFIPxxx keyword along with the - per-cell mass density of the respective phases. - """ - self._add_survey_RFIP(survey_name, restart_view) - - def add_survey(self, name, restart_view, method): - method = self.dispatch[ method ] - return method(name, restart_view) - - def eval(self, base_survey, monitor_survey, pos, region=None, - phase_mask=EclPhaseEnum.ECL_OIL_PHASE + EclPhaseEnum.ECL_GAS_PHASE + EclPhaseEnum.ECL_WATER_PHASE): - """ - Calculates the gravity change between two surveys. - - This is the method everything is leading up to; will calculate - the change in gravitational strength, in units of micro Gal, - between the two surveys named @base_survey and - @monitor_survey. - - The monitor survey can be 'None' - the resulting answer has - nothing whatsovever to do with gravitation, but can be - interesting to determine the numerical size of the quantities - which are subtracted in a 4D study. - - The @pos argument should be a tuple of three elements with the - (utm_x, utm_y, depth) position where we want to evaluate the - change in gravitational strength. - - If supplied the optional argument @region should be an - EclRegion() 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'. - """ - return self._eval(base_survey, monitor_survey, region, pos[0], pos[1], pos[2], phase_mask) - - - 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. - - @default_density is the density, at standard conditions, for - this particular phase. By default @default_density will be - used for all the cells in the model; by using the - add_std_density() method you can specify different densities - for different PVT regions. - - The new_std_density() and add_std_density() methods must be - used before you use the add_survey_FIP() method to add a - survey based on the FIP keyword. - """ - self._new_std_density(phase_enum, default_density) - - def add_std_density(self, phase_enum, pvtnum, density): - """ - Add standard conditions density for PVT region @pvtnum. - - The new_std_density() method will add a standard conditions - density which applies to all cells in the model. Using the - add_std_density() method it is possible to add standard - conditions densities on a per PVT region basis. You can add - densities for as many PVT regions as you like, and then fall - back to the default density for the others. - - The new_std_density() method must be called before calling the - add_std_density() method. - - The new_std_density() and add_std_density() methods must be - used before you use the add_survey_FIP() method to add a - survey based on the FIP keyword. - """ - self._add_std_density(phase_enum, pvtnum, density) - - - def free(self): - self._free() - -monkey_the_camel(EclGrav, 'addSurvey', EclGrav.add_survey) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_grav_calc.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_grav_calc.py deleted file mode 100644 index ef98811eb8..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_grav_calc.py +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.ecl import EclPrototype - -__arglist = 'double, double, double, ' -__arglist += 'ecl_grid, ecl_file, ' -__arglist += 'ecl_kw, ecl_kw, ecl_kw, ecl_kw, ecl_kw, ecl_kw' -_phase_deltag = EclPrototype("double ecl_grav_phase_deltag(%s)" % __arglist) - -def phase_deltag(xyz, grid, init, sat1, rho1, porv1, sat2, rho2, porv2): - return _phase_deltag(xyz[0], xyz[1], xyz[2], - grid.c_ptr, init.c_ptr, - sat1.c_ptr, rho1.c_ptr, porv1.c_ptr, - sat2.c_ptr, rho2.c_ptr, porv2.c_ptr) - - -def deltag(xyz, grid, init_file, restart_file1, restart_file2): - """ - 1. All restart files should have water, i.e. the SWAT keyword. - 2. All phases present in the restart file should also be present as densities, - in addition the model must contain one additional phase - which should have a density. - 3. The restart files can never contain oil saturation. - """ - - swat1 = restart_file1.iget_named_kw("SWAT", 0) - swat2 = restart_file2.iget_named_kw("SWAT", 0) - - phase_list = [(swat1, swat2)] - - if restart_file1.has_kw("SGAS"): - # This is a three phase Water / Gas / Oil system - sgas1 = restart_file1.iget_named_kw("SGAS", 0) - sgas2 = restart_file2.iget_named_kw("SGAS", 0) - - soil1 = 1 - (sgas1 + swat1) - soil2 = 1 - (sgas2 + swat2) - soil1.name = "SOIL" - soil2.name = "SOIL" - phase_list += [(sgas1, sgas2), - (soil1, soil2)] - else: - # This is a two phase Water / xxx System. Will look for - # OIL_DEN and GAS_DEN keywords to determine whether it is a - # Water / Oil or Water / Gas system. - - if restart_file1.has_kw("OIL_DEN"): - # Oil / Water system - soil1 = 1 - swat1 - soil2 = 1 - swat2 - soil1.name = "SOIL" - soil2.name = "SOIL" - phase_list += [(soil1, soil2)] - else: - # Gas / Water system - sgas1 = 1 - swat1 - sgas2 = 1 - swat2 - sgas1.name = "SGAS" - sgas2.name = "SGAS" - phase_list += [(sgas1, sgas2)] - - porv1 = restart_file1.iget_named_kw("RPORV", 0) - porv2 = restart_file2.iget_named_kw("RPORV", 0) - - deltag = 0 - for (sat1, sat2) in phase_list: - rho_name = "%s_DEN" % sat1.name[1:] - rho1 = restart_file1.iget_named_kw(rho_name, 0) - rho2 = restart_file2.iget_named_kw(rho_name, 0) - deltag += phase_deltag(xyz, grid, init_file, sat1, rho1, porv1, sat2, rho2, porv2) - return deltag diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_grid.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_grid.py deleted file mode 100644 index a2db004a11..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_grid.py +++ /dev/null @@ -1,1301 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_grid.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -""" -Module to load and query ECLIPSE 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. -""" -import ctypes - -import warnings -import numpy -import sys -import os.path -import math -import itertools -from cwrap import CFILE, BaseCClass -from ecl.util import monkey_the_camel -from ecl.util import IntVector -from ecl.ecl import EclPrototype, EclDataType, EclKW, FortIO, EclUnitTypeEnum, Cell - - -class EclGrid(BaseCClass): - """ - Class for loading and internalizing ECLIPSE 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)", bind = False) - _alloc_rectangular = EclPrototype("ecl_grid_obj ecl_grid_alloc_rectangular(int, int, int, double, double, double, int*)", bind = False) - _exists = EclPrototype("bool ecl_grid_exists(char*)", bind = False) - - _get_numbered_lgr = EclPrototype("ecl_grid_ref ecl_grid_get_lgr_from_lgr_nr(ecl_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)") - _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_index3 = EclPrototype("int ecl_grid_get_global_index3(ecl_grid, 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_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 = EclPrototype("void ecl_grid_get_xyz3(ecl_grid, int, int, int, double*, double*, double*)") - _get_xyz1 = EclPrototype("void ecl_grid_get_xyz1(ecl_grid, 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 = EclPrototype("void ecl_grid_get_corner_xyz(ecl_grid, int, int, int, double*, double*, double*)") - _get_xyz1A = EclPrototype("void ecl_grid_get_xyz1A(ecl_grid, int, double*, double*, double*)") - _get_ij_xy = EclPrototype("bool ecl_grid_get_ij_from_xy(ecl_grid, double, double, int, int*, int*)") - _get_ijk_xyz = EclPrototype("int ecl_grid_get_global_index_from_xyz(ecl_grid, double, double, double, int)") - _cell_contains = EclPrototype("bool ecl_grid_cell_contains_xyz1(ecl_grid, int, double, double, double)") - _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 = 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 = 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 = EclPrototype("void ecl_grid_get_column_property(ecl_grid, ecl_kw, int, int, double_vector)") - _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 = 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 = EclPrototype("void ecl_grid_fprintf_grdecl2(ecl_grid, FILE, ecl_unit_enum) ") - _fwrite_GRID2 = EclPrototype("void ecl_grid_fwrite_GRID2(ecl_grid, char*, ecl_unit_enum)") - _fwrite_EGRID2 = EclPrototype("void ecl_grid_fwrite_EGRID2(ecl_grid, char*, ecl_unit_enum)") - _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 = EclPrototype("void ecl_grid_global_kw_copy(ecl_grid, ecl_kw, ecl_kw)") - _create_volume_keyword = EclPrototype("ecl_kw_obj ecl_grid_alloc_volume_kw(ecl_grid, 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)") - - - - @classmethod - def load_from_grdecl(cls, filename): - """Will create a new EclGrid 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 - are required: - - SPECGRID ZCORN COORD - - In addition the function will look for and use the ACTNUM and - MAPAXES keywords if they are found; if ACTNUM is not found all - cells are assumed to be active. - - 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 - faster. - """ - - if os.path.isfile(filename): - with open(filename) as f: - specgrid = EclKW.read_grdecl(f, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False) - zcorn = EclKW.read_grdecl(f, "ZCORN") - coord = EclKW.read_grdecl(f, "COORD") - try: - actnum = EclKW.read_grdecl(f, "ACTNUM", ecl_type=EclDataType.ECL_INT) - except ValueError: - actnum = None - - try: - mapaxes = EclKW.read_grdecl(f, "MAPAXES") - except ValueError: - mapaxes = None - - return EclGrid.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. - """ - if FortIO.isFortranFile(filename): - return EclGrid(filename) - else: - return EclGrid.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 - SPECGRID, ZCORN, COORD and ACTNUM keywords, so a somewhat - involved way to create a EclGrid 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) - - grid = EclGrid.create(specgrid_kw, zcorn_kw, coord_kw, actnum_kw) - - If you are so inclined ... - """ - return cls._grdecl_create(specgrid[0], specgrid[1], specgrid[2], zcorn, coord, actnum, mapaxes) - - @classmethod - def create_rectangular(cls, dims, dV, actnum=None): - """ - Will create a new rectangular grid. @dims = (nx,ny,nz) @dVg = (dx,dy,dz) - - With the default value @actnum == None all cells will be active, - """ - - warnings.warn("EclGrid.createRectangular is deprecated. " + - "Please used the similar method in EclGridGenerator!", - DeprecationWarning) - - if actnum is None: - ecl_grid = cls._alloc_rectangular(dims[0], dims[1], dims[2], dV[0], dV[1], dV[2], None) - else: - if not isinstance(actnum, IntVector): - tmp = IntVector(initial_size=len(actnum)) - for (index, value) in enumerate(actnum): - tmp[index] = value - actnum = tmp - - if not len(actnum) == dims[0] * dims[1] * dims[2]: - raise ValueError("ACTNUM size mismatch: len(ACTNUM):%d Expected:%d" % (len(actnum), dims[0] * dims[1] * dims[2])) - ecl_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: - raise MemoryError("Failed to allocated regualar grid") - - return ecl_grid - - def __init__(self, filename, apply_mapaxes=True): - """ - Will create a grid structure from an EGRID or GRID file. - """ - c_ptr = self._fread_alloc(filename, apply_mapaxes) - if c_ptr: - super(EclGrid, self).__init__(c_ptr) - else: - raise IOError("Loading grid from:%s failed" % filename) - - - def free(self): - self._free() - - def _nicename(self): - """name is often full path to grid, if so, output basename, else name""" - name = self.getName() - if os.path.isfile(name): - name = os.path.basename(name) - return name - - def __repr__(self): - """Returns, e.g.: - EclGrid("NORNE_ATW2013.EGRID", 46x112x22, global_size=113344, active_size=44431) at 0x28c4a70 - """ - name = self._nicename() - if name: - name = '"%s", ' % name - g_size = self.getGlobalSize() - a_size = self.getNumActive() - xyz_s = '%dx%dx%d' % (self.getNX(),self.getNY(),self.getNZ()) - return self._create_repr('%s%s, global_size=%d, active_size=%d' % (name, xyz_s, g_size, a_size)) - - def __len__(self): - """ - len(grid) wil return the total number of cells. - """ - return self._get_global_size() - - 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") - return self._equal(other, include_lgr, include_nnc, verbose) - - - def dual_grid(self): - """Is this grid dual porosity model?""" - return self._dual_grid() - - def get_dims(self): - """A tuple of four elements: (nx, ny, nz, nactive).""" - return (self.getNX(), - self.getNY(), - self.getNZ(), - self.getNumActive()) - - - @property - def nx(self): - return self._get_nx() - - def get_nx(self): - """ The number of elements in the x direction""" - return self._get_nx() - - @property - def ny(self): - return self._get_ny() - - def get_ny(self): - """ The number of elements in the y direction""" - return self._get_ny() - - @property - def nz(self): - return self._get_nz() - - def get_nz(self): - """ The number of elements in the z direction""" - return self._get_nz() - - def get_global_size(self): - """Returns the total number of cells in this grid""" - return self._get_global_size() - - def get_num_active(self): - """The number of active cells in the grid.""" - return self._get_active() - - - def get_num_active_fracture(self): - """The number of active cells in the grid.""" - return self._get_active_fracture() - - - def get_bounding_box_2d(self, layer=0, lower_left=None, upper_right=None): - if 0 <= layer <= self.getNZ(): - x = ctypes.c_double() - y = ctypes.c_double() - z = ctypes.c_double() - - if lower_left is None: - i1 = 0 - j1 = 0 - else: - i1,j1 = lower_left - if not 0 < i1 < self.getNX(): - raise ValueError("lower_left i coordinate invalid") - - if not 0 < j1 < self.getNY(): - raise ValueError("lower_left j coordinate invalid") - - - if upper_right is None: - i2 = self.getNX() - j2 = self.getNY() - else: - i2,j2 = upper_right - - if not 1 < i2 <= self.getNX(): - raise ValueError("upper_right i coordinate invalid") - - if not 1 < j2 <= self.getNY(): - raise ValueError("upper_right j coordinate invalid") - - if not i1 < i2: - raise ValueError("Must have lower_left < upper_right") - - if not j1 < j2: - raise ValueError("Must have lower_left < upper_right") - - - - self._get_corner_xyz(i1, j1, layer, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z)) - p0 = (x.value, y.value) - - self._get_corner_xyz(i2, j1, layer, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z)) - p1 = (x.value, y.value ) - - self._get_corner_xyz( i2, j2, layer, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z)) - p2 = (x.value, y.value ) - - self._get_corner_xyz(i1, j2, layer, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z)) - p3 = (x.value, y.value ) - - return (p0,p1,p2,p3) - else: - raise ValueError("Invalid layer value:%d Valid range: [0,%d]" % (layer, self.getNZ())) - - - def get_name(self): - """ - Name of the current grid, returns a string. - - For the main grid this is the filename given to the - constructor when loading the grid; for an LGR this is the name - of the LGR. If the grid instance has been created with the - create() classmethod this can be None. - """ - n = self._get_name() - return str(n) if n else '' - - def cell(self, global_index=None, active_index=None, i=None, j=None, k=None): - if global_index is not None: - return Cell(self, global_index) - if active_index is not None: - return Cell(self, self.global_index(active_index=active_index)) - if i is not None: - return Cell(self, self.global_index(ijk=(i,j,k))) - - def __getitem__(self, global_index): - if isinstance(global_index, tuple): - i,j,k = global_index - return self.cell(i=i, j=j, k=k) - return self.cell(global_index=global_index) - - def __iter__(self): - for i in range(len(self)): - yield self[i] - - def cells(self, active=False): - """Iterator over all the (active) cells""" - if not active: - for c in self: - yield c - else: - for i in range(self.get_num_active()): - yield self.cell(active_index=i) - - def global_index(self, active_index=None, ijk=None): - """ - Will convert either active_index or (i,j,k) to global index. - """ - return self.__global_index(active_index=active_index, ijk=ijk) - - def __global_index(self, active_index=None, global_index=None, ijk=None): - """ - Will convert @active_index or @ijk to global_index. - - This method will convert @active_index or @ijk to a global - index. Exactly one of the arguments @active_index, - @global_index or @ijk must be supplied. - - The method is used extensively internally in the EclGrid - class; most methods which take coordinate input pass through - this method to normalize the coordinate representation. - """ - - set_count = 0 - if not active_index is None: - set_count += 1 - - if not global_index is None: - set_count += 1 - - if ijk: - set_count += 1 - - if not set_count == 1: - raise ValueError("Exactly one of the kewyord arguments active_index, global_index or ijk must be set") - - if not active_index is None: - global_index = self._get_global_index1A( active_index) - elif ijk: - nx = self.getNX() - ny = self.getNY() - nz = self.getNZ() - - i,j,k = ijk - - if not 0 <= i < nx: - raise IndexError("Invalid value i:%d Range: [%d,%d)" % (i, 0, nx)) - - if not 0 <= j < ny: - raise IndexError("Invalid value j:%d Range: [%d,%d)" % (j, 0, ny)) - - if not 0 <= k < nz: - raise IndexError("Invalid value k:%d Range: [%d,%d)" % (k, 0, nz)) - - global_index = self._get_global_index3(i,j,k) - else: - if not 0 <= global_index < self.getGlobalSize(): - raise IndexError("Invalid value global_index:%d Range: [%d,%d)" % (global_index, 0, self.getGlobalSize())) - return global_index - - - def get_active_index(self, ijk=None, global_index=None): - """ - Lookup active index based on ijk or global index. - - Will determine the active_index of a cell, based on either - @ijk = (i,j,k) or @global_index. If the cell specified by the - input arguments is not active the function will return -1. - """ - gi = self.__global_index(global_index=global_index, ijk=ijk) - return self._get_active_index1(gi) - - - def get_active_fracture_index(self, ijk=None, global_index=None): - """ - For dual porosity - get the active fracture index. - """ - gi = self.__global_index(global_index=global_index, ijk=ijk) - return self._get_active_fracture_index1(gi) - - - def get_global_index1F(self, active_fracture_index): - """ - Will return the global index corresponding to active fracture index. - """ - return self._get_global_index1F(active_fracture_index) - - - def cell_invalid(self, ijk=None, global_index=None, active_index=None): - """ - Tries to check if a cell is invalid. - - Cells which are used to represent numerical aquifers are - typically located in UTM position (0,0); these cells have - completely whacked up shape and size, and should **NOT** be - used in calculations involving real world coordinates. To - protect against this a heuristic is used identify such cells - and mark them as invalid. There might be other sources than - numerical aquifers to this problem. - """ - gi = self.__global_index(global_index=global_index, ijk=ijk, active_index=active_index) - return self._invalid_cell(gi) - - - def valid_cell_geometry(self, ijk=None, global_index=None, active_index=None): - """Checks if the cell has valid geometry. - - There are at least two reasons why a cell might have invalid - gemetry: - - 1. In the case of GRID files it is not necessary to supply - the geometry for all the cells; in that case this - function will return false for cells which do not have - valid coordinates. - - 2. Cells which are used to represent numerical aquifers are - typically located in UTM position (0,0); these cells have - completely whacked up shape and size; these cells are - identified by a heuristic - which might fail - - If the validCellGeometry() returns false for a particular - cell functions which calculate cell volumes, real world - coordinates and so on - should not be used. - """ - gi = self.__global_index(global_index=global_index, ijk=ijk, active_index=active_index) - return self._valid_cell(gi) - - - - def active(self, ijk=None, global_index=None): - """ - Is the cell active? - - See documentation og get_xyz() for explanation of parameters - @ijk and @global_index. - """ - gi = self.__global_index(global_index=global_index, ijk=ijk) - active_index = self._get_active_index1(gi) - if active_index >= 0: - return True - else: - return False - - - def get_global_index(self, ijk=None, active_index=None): - """ - Lookup global index based on ijk or active index. - """ - gi = self.__global_index(active_index=active_index, ijk=ijk) - return gi - - - def get_ijk(self, active_index=None, global_index=None): - """ - Lookup (i,j,k) for a cell, based on either active index or global index. - - The return value is a tuple with three elements (i,j,k). - """ - i = ctypes.c_int() - j = ctypes.c_int() - k = ctypes.c_int() - - gi = self.__global_index(active_index=active_index, global_index=global_index) - self._get_ijk1(gi, ctypes.byref(i), ctypes.byref(j), ctypes.byref(k)) - - return (i.value, j.value, k.value) - - - def get_xyz(self, active_index=None, global_index=None, ijk=None): - """ - Find true position of cell center. - - Will return world position of the center of a cell in the - grid. The return value is a tuple of three elements: - (utm_x, utm_y, depth). - - The cells of a grid can be specified in three different ways: - - (i,j,k) : As a tuple of i,j,k values. - - global_index : A number in the range [0,nx*ny*nz). The - global index is related to (i,j,k) as: - - global_index = i + j*nx + k*nx*ny - - active_index : A number in the range [0,nactive). - - For many of the EclGrid methods a cell can be specified using - any of these three methods. Observe that one and only method is - allowed: - - OK: - pos1 = grid.get_xyz(active_index=100) - pos2 = grid.get_xyz(ijk=(10,20,7)) - - Crash and burn: - 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 - is in contrast to ECLIPSE which has an offset 1 interface. - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - - x = ctypes.c_double() - y = ctypes.c_double() - z = ctypes.c_double() - self._get_xyz1(gi, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z)) - return (x.value, y.value, z.value) - - - def get_node_pos(self, i, j, k): - """Will return the (x,y,z) for the node given by (i,j,k). - - Observe that this method does not consider cells, but the - nodes in the grid. This means that the valid input range for - i,j and k are are upper end inclusive. To get the four - bounding points of the lower layer of the grid: - - p0 = grid.getNodePos(0, 0, 0) - p1 = grid.getNodePos(grid.getNX(), 0, 0) - p2 = grid.getNodePos(0, grid.getNY(), 0) - p3 = grid.getNodePos(grid.getNX(), grid.getNY(), 0) - - """ - if not 0 <= i <= self.getNX(): - raise IndexError("Invalid I value:%d - valid range: [0,%d]" % (i, self.getNX())) - - if not 0 <= j <= self.getNY(): - raise IndexError("Invalid J value:%d - valid range: [0,%d]" % (j, self.getNY())) - - if not 0 <= k <= self.getNZ(): - raise IndexError("Invalid K value:%d - valid range: [0,%d]" % (k, self.getNZ())) - - x = ctypes.c_double() - y = ctypes.c_double() - z = ctypes.c_double() - self._get_corner_xyz(i,j,k, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z)) - return (x.value, y.value, z.value) - - - def get_cell_corner(self, corner_nr, active_index=None, global_index=None, ijk=None): - """ - Will look up xyz of corner nr @corner_nr - - - lower layer: upper layer - - 2---3 6---7 - | | | | - 0---1 4---5 - - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - x = ctypes.c_double() - y = ctypes.c_double() - z = ctypes.c_double() - self._get_cell_corner_xyz1(gi, corner_nr, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z)) - return (x.value, y.value, z.value) - - def get_node_xyz(self, i,j,k): - """ - This function returns the position of Vertex (i,j,k). - - The coordinates are in the inclusive interval [0,nx] x [0,ny] x [0,nz]. - """ - nx = self.getNX() - ny = self.getNY() - nz = self.getNZ() - - corner = 0 - - if i == nx: - i -= 1 - corner += 1 - - if j == ny: - j -= 1 - corner += 2 - - if k == nz: - k -= 1 - corner += 4 - - if self._ijk_valid(i, j, k): - return self.getCellCorner(corner, global_index=i + j*nx + k*nx*ny) - else: - raise IndexError("Invalid coordinates: (%d,%d,%d) " % (i,j,k)) - - - - def get_layer_xyz(self, xy_corner, layer): - nx = self.getNX() - - (j, i) = divmod(xy_corner, nx + 1) - k = layer - return self.getNodeXYZ(i,j,k) - - - - def distance(self, global_index1, global_index2): - dx = ctypes.c_double() - dy = ctypes.c_double() - dz = ctypes.c_double() - self._get_distance(global_index1, global_index2, ctypes.byref(dx), ctypes.byref(dy), ctypes.byref(dz)) - return (dx.value, dy.value, dz.value) - - - def depth(self, active_index=None, global_index=None, ijk=None): - """ - Depth of the center of a cell. - - Returns the depth of the center of the cell given by - @active_index, @global_index or @ijk. See method get_xyz() for - documentation of @active_index, @global_index and @ijk. - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - return self._get_depth( gi) - - def top(self, i, j): - """ - Top of the reservoir; in the column (@i, @j). - Returns average depth of the four top corners. - """ - return self._get_top(i, j) - - def top_active(self, i, j): - """ - Top of the active part of the reservoir; in the column (@i, @j). - Raises ValueError if (i,j) column is inactive. - """ - for k in range(self.getNZ()): - a_idx = self.get_active_index(ijk=(i,j,k)) - if a_idx >= 0: - return self._get_top1A(a_idx) - raise ValueError('No active cell in column (%d,%d)' % (i,j)) - - def bottom(self, i, j): - """ - Bottom of the reservoir; in the column (@i, @j). - """ - return self._get_bottom( i, j) - - def locate_depth(self, depth, i, j): - """ - Will locate the k value of cell containing specified depth. - - Will scan through the grid column specified by the input - arguments @i and @j and search for a cell containing the depth - given by input argument @depth. The return value is the k - value of cell containing @depth. - - If @depth is above the top of the reservoir the function will - return -1, and if @depth is below the bottom of the reservoir - the function will return -nz. - """ - return self._locate_depth( depth, i, j) - - - def find_cell(self, x, y, z, start_ijk=None): - """ - Lookup cell containg true position (x,y,z). - - Will locate the cell in the grid which contains the true - position (@x,@y,@z), the return value is as a triplet - (i,j,k). The underlying C implementation is not veeery - efficient, and can potentially take quite long time. If you - provide a good intial guess with the parameter @start_ijk (a - tuple (i,j,k)) things can speed up quite substantially. - - If the location (@x,@y,@z) can not be found in the grid, the - method will return None. - """ - start_index = 0 - if start_ijk: - start_index = self.__global_index(ijk=start_ijk) - - global_index = self._get_ijk_xyz(x, y, z, start_index) - if global_index >= 0: - i = ctypes.c_int() - j = ctypes.c_int() - k = ctypes.c_int() - self._get_ijk1(global_index, - ctypes.byref(i), ctypes.byref(j), ctypes.byref(k)) - return (i.value, j.value, k.value) - return None - - def cell_contains(self, x, y, z, active_index=None, global_index=None, ijk=None): - """ - Will check if the cell contains point given by world - coordinates (x,y,z). - - See method get_xyz() for documentation of @active_index, - @global_index and @ijk. - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - return self._cell_contains(gi, x,y,z) - - - def find_cell_xy(self, x, y, k): - """Will find the i,j of cell with utm coordinates x,y. - - The @k input is the layer you are interested in, the allowed - values for k are [0,nz]. If the coordinates (x,y) are found to - be outside the grid a ValueError exception is raised. - """ - if 0 <= k <= self.getNZ(): - i = ctypes.c_int() - j = ctypes.c_int() - ok = self._get_ij_xy(x,y,k, ctypes.byref(i), ctypes.byref(j)) - if ok: - return (i.value, j.value) - else: - raise ValueError("Could not find the point:(%g,%g) in layer:%d" % (x,y,k)) - else: - raise IndexError("Invalid layer value:%d" % k) - - - @staticmethod - def d_cmp(a,b): - return cmp(a[0], b[0]) - - - def find_cell_corner_xy(self, x, y, k): - """Will find the corner nr of corner closest to utm coordinates x,y. - - The @k input is the layer you are interested in, the allowed - values for k are [0,nz]. If the coordinates (x,y) are found to - be outside the grid a ValueError exception is raised. - """ - i,j = self.findCellXY(x,y,k) - if k == self.getNZ(): - k -= 1 - corner_shift = 4 - else: - corner_shift = 0 - - nx = self.getNX() - x0,y0,z0 = self.getCellCorner(corner_shift, ijk=(i,j,k)) - d0 = math.sqrt((x0 - x)*(x0 - x) + (y0 - y)*(y0 - y)) - c0 = i + j*(nx + 1) - - x1,y1,z1 = self.getCellCorner(1 + corner_shift, ijk=(i,j,k)) - d1 = math.sqrt((x1 - x)*(x1 - x) + (y1 - y)*(y1 - y)) - c1 = i + 1 + j*(nx + 1) - - x2,y2,z2 = self.getCellCorner(2 + corner_shift, ijk=(i,j,k)) - d2 = math.sqrt((x2 - x)*(x2 - x) + (y2 - y)*(y2 - y)) - c2 = i + (j + 1)*(nx + 1) - - x3,y3,z3 = self.getCellCorner(3 + corner_shift, ijk=(i,j,k)) - d3 = math.sqrt((x3 - x)*(x3 - x) + (y3 - y)*(y3 - y)) - c3 = i + 1 + (j + 1)*(nx + 1) - - l = [(d0, c0), (d1,c1), (d2, c2), (d3,c3)] - l.sort(EclGrid.d_cmp) - return l[0][1] - - - - def cell_regular(self, active_index=None, global_index=None, ijk=None): - """ - The ECLIPSE 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 - own centerpoint - which is actually not as trivial as it - sounds. - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - return self._cell_regular( gi) - - - def cell_volume(self, active_index=None, global_index=None, ijk=None): - """ - Calculate the volume of a cell. - - Will calculate the total volume of the cell. See method - get_xyz() for documentation of @active_index, @global_index - and @ijk. - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - return self._get_cell_volume(gi) - - - def cell_dz(self, active_index=None, global_index=None, ijk=None): - """ - The thickness of a cell. - - Will calculate the (average) thickness of the cell. See method - get_xyz() for documentation of @active_index, @global_index - and @ijk. - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - return self._get_cell_thickness( gi) - - - def get_cell_dims(self, active_index=None, global_index=None, ijk=None): - """Will return a tuple (dx,dy,dz) for cell dimension. - - The dx and dy values are best effor estimates of the cell size - along the i and j directions respectively. The three values - are guaranteed to satisfy: - - dx * dy * dz = dV - - See method get_xyz() for documentation of @active_index, - @global_index and @ijk. - - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - dx = self._get_cell_dx(gi) - dy = self._get_cell_dy(gi) - dz = self._get_cell_thickness( gi) - return (dx,dy,dz) - - - - def get_num_lgr(self): - - """ - How many LGRs are attached to this main grid? - - How many LGRs are attached to this main grid; the grid - instance doing the query must itself be a main grid. - """ - return self._num_lgr() - - - - def has_lgr(self, lgr_name): - """ - Query if the grid has an LGR with name @lgr_name. - """ - if self._has_named_lgr(lgr_name): - return True - else: - return False - - - def get_lgr(self, lgr_key): - """Get EclGrid instance with LGR content. - - Return an EclGrid 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 - for further queries about LGRs. - - If the grid does not contain an LGR with this name/nr - exception KeyError will be raised. - - """ - lgr = None - if isinstance(lgr_key, int): - if self._has_numbered_lgr(lgr_key): - lgr = self._get_numbered_lgr(lgr_key) - else: - if self._has_named_lgr(lgr_key): - lgr = self._get_named_lgr(lgr_key) - - if lgr is None: - raise KeyError("No such LGR: %s" % lgr_key) - - lgr.setParent(self) - return lgr - - - - def get_cell_lgr(self, active_index=None, global_index=None, ijk=None): - """ - Get EclGrid 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 - LGR. Will return None if the cell in question has not been - refined, the return value can be used for further queries. - - See get_xyz() for documentation of the input parameters. - """ - gi = self.__global_index(ijk=ijk, active_index=active_index, global_index=global_index) - lgr = self._get_cell_lgr(gi) - if lgr: - lgr.setParent(self) - return lgr - else: - raise IndexError("No LGR defined for this cell") - - - 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 - 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 - appropriate 1D index. - - Depending on the length of kw the input arguments are - converted either to an active index or to a global index. If - the length of kw does not fit with either the global size of - the grid or the active size of the grid things will fail hard. - """ - return self._grid_value(kw, i, j, k) - - - def load_column(self, kw, i, j, column): - """ - Load the values of @kw from the column specified by (@i,@j). - - The method will scan through all k values of the input field - @kw for fixed values of i and j. The size of @kw must be - either nactive or nx*ny*nz. - - The input argument @column should be a DoubleVector instance, - observe that if size of @kw == nactive k values corresponding - to inactive cells will not be modified in the @column - instance; in that case it is important that @column is - initialized with a suitable default value. - """ - self._load_column( kw, i, j, column) - - - def create_kw(self, array, kw_name, pack): - """ - Creates an EclKW 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 - is true the resulting keyword will have length 'nactive', - otherwise the element will have length nx*ny*nz. - """ - if array.ndim == 3: - dims = array.shape - if dims[0] == self.getNX() and dims[1] == self.getNY() and dims[2] == self.getNZ(): - dtype = array.dtype - if dtype == numpy.int32: - type = EclDataType.ECL_INT - elif dtype == numpy.float32: - type = EclDataType.ECL_FLOAT - elif dtype == numpy.float64: - type = EclDataType.ECL_DOUBLE - else: - sys.exit("Do not know how to create ecl_kw from type:%s" % dtype) - - if pack: - size = self.getNumActive() - else: - size = self.getGlobalSize() - - if len(kw_name) > 8: - # Silently truncate to length 8 - ECLIPSE has it's challenges. - kw_name = kw_name[0:8] - - kw = EclKW(kw_name, size, type) - active_index = 0 - global_index = 0 - for k in range(self.getNZ()): - for j in range(self.getNY()): - for i in range(self.getNX()): - if pack: - if self.active(global_index=global_index): - kw[active_index] = array[i,j,k] - active_index += 1 - else: - if dtype == numpy.int32: - kw[global_index] = int(array[i,j,k]) - else: - kw[global_index] = array[i,j,k] - - global_index += 1 - return kw - raise ValueError("Wrong size / dimension on array") - - - def coarse_groups(self): - """ - Will return the number of coarse groups in this grid. - """ - return self._num_coarse_groups() - - - def in_coarse_group(self, global_index=None, ijk=None, active_index=None): - """ - Will return True or False if the cell is part of coarse group. - """ - global_index = self.__global_index(active_index=active_index, ijk=ijk, global_index=global_index) - return self._in_coarse_group1(global_index) - - - def create_3d(self, ecl_kw, default = 0): - """ - Creates a 3D numpy array object with the data from @ecl_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. - - The methods createKW() does the inverse operation; creating an - EclKW 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() - method: - - value = grid.grid_value(ecl_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(): - for i in range(kwa.size): - array[i] = kwa[i] - else: - data_index = 0 - for global_index in range(self.getGlobalSize()): - if self.active(global_index=global_index): - array[global_index] = kwa[data_index] - data_index += 1 - - array = array.reshape([self.getNX(), self.getNY(), self.getNZ()], order='F') - return array - 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), self.getNumActive(), - self.getGlobalSize()) - raise ValueError(err_msg) - - def save_grdecl(self, pyfile, output_unit=EclUnitTypeEnum.ECL_METRIC_UNITS): - """ - Will write the the grid content as grdecl formatted keywords. - - Will only write the main grid. - """ - cfile = CFILE(pyfile) - self._fprintf_grdecl2(cfile, output_unit) - - def save_EGRID(self, filename, output_unit=EclUnitTypeEnum.ECL_METRIC_UNITS): - """ - Will save the current grid as a EGRID file. - """ - self._fwrite_EGRID2(filename, output_unit) - - def save_GRID(self, filename, output_unit=EclUnitTypeEnum.ECL_METRIC_UNITS): - """ - Will save the current grid as a EGRID file. - """ - self._fwrite_GRID2( filename, output_unit) - - - def write_grdecl(self, ecl_kw, pyfile, special_header=None, default_value=0): - """ - Writes an EclKW instance as an ECLIPSE grdecl formatted file. - - The input argument @ecl_kw must be an EclKW 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, - float, double or bool. In the case of bool the default value - must be specified as 1 (True) or 0 (False). - - The input argument @pyfile should be a valid python filehandle - opened for writing; i.e. - - pyfile = open("PORO.GRDECL", "w") - grid.write_grdecl(poro_kw , pyfile, default_value=0.0) - grid.write_grdecl(permx_kw, pyfile, default_value=0.0) - pyfile.close() - - """ - - if len(ecl_kw) == self.getNumActive() or len(ecl_kw) == self.getGlobalSize(): - cfile = CFILE(pyfile) - self._fwrite_grdecl(ecl_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), self.getNumActive(), self.getGlobalSize())) - - - def exportACTNUM(self): - actnum = IntVector(initial_size=self.getGlobalSize()) - self._init_actnum(actnum.getDataPtr()) - return actnum - - - 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) - self._compressed_kw_copy(kw_copy, kw) - return kw_copy - else: - raise ValueError("The input keyword must have nx*n*nz or nactive elements. Size:%d invalid" % len(kw)) - - 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.assign(default_value) - self._global_kw_copy(kw_copy, kw) - return kw_copy - else: - raise ValueError("The input keyword must have nx*n*nz or nactive elements. Size:%d invalid" % len(kw)) - - - def export_ACTNUM_kw(self): - actnum = EclKW("ACTNUM", self.getGlobalSize(), EclDataType.ECL_INT) - self._init_actnum(actnum.getDataPtr()) - return actnum - - - def create_volume_keyword(self, active_size=True): - """Will create a EclKW initialized with cell volumes. - - The purpose of this method is to create a EclKW 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: - - soil = 1 - sgas - swat - cell_volume = grid.createVolumeKeyword() - tmp = cell_volume * soil - oip = tmp.sum() - - The oil in place calculation shown above could easily be - implemented by iterating over the soil kw, however using the - volume keyword has two advantages: - - 1. The calculation of cell volumes is quite time consuming, - by storing the results in a kw they can be reused. - - 2. By using the compact form 'oip = cell_volume * soil' the - inner loop iteration will go in C - which is faster. - - By default the kw will only have values for the active cells, - but by setting the optional variable @active_size to False you - will get volume values for all cells in the grid. - """ - - return self._create_volume_keyword(active_size) - - def export_coord(self): - return self._export_coord() - - def export_zcorn(self): - return self._export_zcorn() - - def export_actnum(self): - return self._export_actnum() - - def export_mapaxes(self): - if not self._use_mapaxes(): - return None - - return self._export_mapaxes() - -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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_grid_generator.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_grid_generator.py deleted file mode 100644 index 6837439f39..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_grid_generator.py +++ /dev/null @@ -1,708 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# The file 'ecl_grid_generator.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import itertools, numpy -from math import sqrt - -from ecl.util import monkey_the_camel -from ecl.util import IntVector -from ecl.ecl import EclGrid, EclKW, EclDataType, EclPrototype - -def flatten(l): - return [elem for sublist in l for elem in sublist] - -def divide(l, size): - return [l[i:i+size:] for i in range(0, len(l), size)] - -def duplicate_inner(l): - return [elem for elem in l for i in range(2)][1:-1:] - -def construct_floatKW(name, values): - kw = EclKW(name, len(values), EclDataType.ECL_FLOAT) - for i, value in enumerate(values): - kw[i] = value - return kw - -def pre_mapaxes_translation(translation, mapaxes): - if mapaxes is None: - return translation - - x, y, z = translation - - unit_y = numpy.array((mapaxes[0]-mapaxes[2], mapaxes[1]-mapaxes[3])); - unit_y /= sqrt(numpy.sum(unit_y*unit_y)) - - unit_x = numpy.array((mapaxes[4]-mapaxes[2], mapaxes[5]-mapaxes[3])); - unit_x /= sqrt(numpy.sum(unit_x*unit_x)) - - det = 1.0 / (unit_x[0]*unit_y[1] - unit_x[1] * unit_y[0]); - - return ( - ( x*unit_y[1] - y*unit_y[0]) * det, - (-x*unit_x[1] + y*unit_x[0]) * det, - z - ) - -class EclGridGenerator: - - _alloc_rectangular = EclPrototype("ecl_grid_obj ecl_grid_alloc_rectangular(int, int, int, double, double, double, int*)", bind=False) - - @classmethod - def create_rectangular(cls, dims, dV, actnum=None): - """ - Will create a new rectangular grid. @dims = (nx,ny,nz) @dVg = (dx,dy,dz) - - With the default value @actnum == None all cells will be active, - """ - if actnum is None: - ecl_grid = cls._alloc_rectangular( - dims[0], dims[1], dims[2], - dV[0], dV[1], dV[2], - None - ) - else: - if not isinstance(actnum, IntVector): - tmp = IntVector(initial_size=len(actnum)) - for (index, value) in enumerate(actnum): - tmp[index] = value - actnum = tmp - - if not len(actnum) == dims[0]*dims[1]*dims[2]: - raise ValueError( - "ACTNUM size mismatch: len(ACTNUM):%d Expected:%d" - % (len(actnum), dims[0]*dims[1]*dims[2]) - ) - - ecl_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: - raise MemoryError("Failed to allocated regualar grid") - - return ecl_grid - - @classmethod - def create_single_cell_grid(cls, corners): - """ - Provided with the corners of the grid in a similar manner as the eight - corners are output for a single cell, this method will create a grid - consisting of a single cell with the specified corners as its corners. - """ - - zcorn = [corners[i][2] for i in range(8)] - - coord = [(corners[i], corners[i+4]) for i in range(4)] - coord = flatten(flatten(coord)) - - def construct_floatKW(name, values): - kw = EclKW(name, len(values), EclDataType.ECL_FLOAT) - for i in range(len(values)): - kw[i] = values[i] - return kw - - grid = EclGrid.create( - (1, 1, 1), - construct_floatKW("ZCORN", zcorn), - construct_floatKW("COORD", coord), - None - ) - - if not corners == [grid.getCellCorner(i, 0) for i in range(8)]: - raise AssertionError("Failed to generate single cell grid. " + - "Did not end up the expected corners.") - - return grid - - @classmethod - def create_zcorn(cls, dims, dV, offset=1, escape_origo_shift=(1,1,0), - irregular_offset=False, irregular=False, concave=False, - faults=False): - - cls.__assert_zcorn_parameters(dims, dV, offset, escape_origo_shift, - irregular_offset, irregular, concave, faults) - - nx, ny, nz = dims - dx, dy, dz = dV - - # Compute zcorn - z = escape_origo_shift[2] - zcorn = [z]*(4*nx*ny) - for k in range(nz-1): - z = z+dz - local_offset = offset + (dz/2. if irregular_offset and k%2 == 0 else 0) - - layer = [] - for i in range(ny+1): - shift = ((i if concave else 0) + (k/2 if irregular else 0)) % 2 - path = [z if i%2 == shift else z+local_offset for i in range(nx+1)] - layer.append(duplicate_inner(path)) - - zcorn = zcorn + (2*flatten(duplicate_inner(layer))) - - z = z+dz - zcorn = zcorn + ([z]*(4*nx*ny)) - - if faults: - # Ensure that drop does not align with grid structure - drop = (offset+dz)/2. if abs(offset-dz/2.) > 0.2 else offset + 0.4 - zcorn = cls.__create_faults(nx, ny, nz, zcorn, drop) - - - if z != escape_origo_shift[2] + nz*dz: - raise ValueError("%f != %f" % (z, escape_origo_shift[2] + nz*dz)) - - cls.assert_zcorn(nx, ny, nz, zcorn) - return construct_floatKW("ZCORN", zcorn) - - @classmethod - def create_coord(cls, dims, dV, escape_origo_shift=(1,1,0), - scale=1, translation=(0,0,0), rotate=False, misalign=False): - - nx, ny, nz = dims - dx, dy, dz = dV - - # Compute coord - z = escape_origo_shift[2] + nz*dz - coord = [] - for j, i in itertools.product(range(ny+1), range(nx+1)): - x, y = i*dx+escape_origo_shift[0], j*dy+escape_origo_shift[1] - coord = coord + [x, y, escape_origo_shift[2], x, y, z] - - # Apply transformations - lower_center = ( - nx*dx/2. + escape_origo_shift[0], - ny*dy/2. + escape_origo_shift[1] - ) - - if misalign: - coord = cls.__misalign_coord(coord, dims, dV) - - coord = cls.__scale_coord(coord, scale, lower_center) - - if rotate: - coord = cls.__rotate_coord(coord, lower_center) - - coord = cls.__translate_lower_coord(coord, translation) - - cls.assert_coord(nx, ny, nz, coord) - return construct_floatKW("COORD", coord) - - @classmethod - def __assert_zcorn_parameters(cls, dims, dV, offset, escape_origo_shift, - irregular_offset, irregular, concave, faults): - - nx, ny, nz = dims - dx, dy, dz = dV - - # Validate arguments - if min(dims + dV) <= 0: - raise ValueError("Expected positive grid and cell dimentions") - - if offset < 0: - raise ValueError("Expected non-negative offset") - - if irregular and offset + (dz/2. if irregular_offset else 0) > dz: - raise AssertionError("Arguments can result in self-" + - "intersecting cells. Increase dz, deactivate eiter " + - "irregular or irregular_offset, or decrease offset to avoid " + - "any problems") - - @classmethod - def create_grid(cls, dims, dV, offset=1, - escape_origo_shift=(1,1,0), - irregular_offset=False, irregular=False, concave=False, - faults=False, scale=1, translation=(0,0,0), rotate=False, - misalign=False): - """ - Will create a new grid where each cell is a parallelogram (skewed by z-value). - The number of cells are given by @dims = (nx, ny, nz) and the dimention - of each cell by @dV = (dx, dy, dz). - - All cells are guaranteed to not be self-intersecting. Hence, no twisted - cells and somewhat meaningfull cells. - - @offset gives how much the layers should fluctuate or "wave" as you - move along the X-axis. - - @irregular_offset decides whether the offset should be constant or - increase by dz/2 every now and then. - - @irregular if true some of the layers will be inclining and others - declining at the start. - - @concave decides whether the cells are to be convex or not. In - 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. - - @faults decides if there are to be faults in the grid. - - @scale A positive number that scales the "lower" endpoint of all - coord's. In particular, @scale != 1 creates trapeziod cells in both the XZ - and YZ-plane. - - @translation the lower part of the grid is translated ("slided") by the specified - additive factor. - - @rotate the lower part of the grid is rotated 90 degrees around its - center. - - @misalign will toggle COORD's slightly in various directions to break - alignment - - Note that cells in the lowermost layer can have multiple corners - at the same point. - - For testing it should give good coverage of the various scenarios this - method can produce, by leting @dims be (10,10,10), @dV=(2,2,2), @offset=1, - and try all 4 different configurations of @concave and - @irregular_offset. - """ - - zcorn = cls.create_zcorn(dims, dV, offset, escape_origo_shift, - irregular_offset, irregular, concave, faults) - - coord = cls.create_coord(dims, dV, escape_origo_shift, scale, - translation, rotate, misalign) - - return EclGrid.create(dims, zcorn, coord, None) - - @classmethod - def __create_faults(cls, nx, ny, nz, zcorn, drop): - """ - Will create several faults consisting of all cells such that either its - i or j index is 1 modulo 3. - """ - - plane_size = 4*nx*ny - for x, y, z in itertools.product(range(nx), range(ny), range(nz)): - if x%3 != 1 and y%3 != 1: - continue - - corner = [0]*8 - corner[0] = 2*z*plane_size + 4*y*nx + 2*x - corner[1] = corner[0] + 1 - corner[2] = corner[0] + 2*nx - corner[3] = corner[2] + 1 - - for i in range(4, 8): - corner[i] = corner[i-4] + plane_size - - for c in corner: - zcorn[c] = zcorn[c] + drop - - return zcorn - - @classmethod - def assert_zcorn(cls, nx, ny, nz, zcorn, twisted_check=True): - """ - - Raises an AssertionError if the zcorn is not as expected. In - patricular, it is verified that: - - - zcorn has the approperiate length (8*nx*ny*nz) and - - that no cell is twisted. - - """ - - if len(zcorn) != 8*nx*ny*nz: - raise AssertionError( - "Expected len(zcorn) to be %d, was %d" % - (8*nx*ny*nz, len(zcorn)) - ) - - plane_size = 4*nx*ny - for p in range(8*nx*ny*nz - plane_size): - if zcorn[p] > zcorn[p + plane_size] and twisted_check: - raise AssertionError( - "Twisted cell was created. " + - "Decrease offset or increase dz to avoid this!" - ) - - @classmethod - def __scale_coord(cls, coord, scale, lower_center): - coord = numpy.array([ - map(float, coord[i:i+6:]) - for i in range(0, len(coord), 6) - ]) - origo = numpy.array(3*[0.] + list(lower_center) + [0]) - scale = numpy.array(3*[1.] + 2*[scale] + [1]) - - coord = scale * (coord-origo) + origo - return coord.flatten().tolist() - - @classmethod - def __misalign_coord(cls, coord, dims, dV): - nx, ny, nz = dims - - coord = numpy.array([ - map(float, coord[i:i+6:]) - for i in range(0, len(coord), 6) - ]) - - tf = lambda i, j: 1./2 if abs(i)+abs(j) <= 1 else 0.25 - adjustment = numpy.array([ - (0, 0, 0, i*tf(i,j)*dV[0], j*tf(i,j)*dV[1], 0) for i, j in itertools.product([-1, 0, 1], repeat=2) - ]) - - for i, c in enumerate(coord): - # Leave the outermost coords alone - if i < nx+1 or i >= len(coord)-(nx+1): - continue - if i%(nx+1) in [0, nx]: - continue - - c += adjustment[i%len(adjustment)] - - return coord.flatten().tolist() - - @classmethod - def __rotate_coord(cls, coord, lower_center): - coord = numpy.array([ - map(float, coord[i:i+6:]) - for i in range(0, len(coord), 6) - ]) - - origo = numpy.array(3*[0.] + list(lower_center) + [0]) - coord -= origo - - for c in coord: - c[3], c[4] = -c[4], c[3] - - coord += origo - return coord.flatten().tolist() - - @classmethod - def __translate_lower_coord(cls, coord, translation): - coord = numpy.array([ - map(float, coord[i:i+6:]) - for i in range(0, len(coord), 6) - ]) - translation = numpy.array(3*[0.] + list(translation)) - - coord = coord + translation - return coord.flatten().tolist() - - @classmethod - def assert_coord(cls, nx, ny, nz, coord, negative_values=False): - """ - - Raises an AssertionError if the coord is not as expected. In - particular, it is verified that: - - - coord has the approperiate length (6*(nx+1)*(ny+1)) and - - that all values are positive unless negative_values are - explicitly allowed. - - """ - - if len(coord) != 6*(nx+1)*(ny+1): - raise AssertionError( - "Expected len(coord) to be %d, was %d" % - (6*(nx+1)*(ny+1), len(coord)) - ) - - if not negative_values and min(coord) < 0: - raise AssertionError("Negative COORD values was generated. " + - "This is likely due to a tranformation. " + - "Increasing the escape_origio_shift will most likely " + - "fix the problem") - - @classmethod - def assert_actnum(cls, nx, ny, nz, actnum): - """ - - Raises an AssertionError if the actnum is not as expected. In - particular, it is verified that: - - - actnum has the approperiate length nx*ny*nz and - - that all values are either 0 or 1. - - """ - - if actnum is None: - return - - if len(actnum) != nx*ny*nz: - raise AssertionError( - "Expected the length of ACTNUM to be %d, was %s." - %(nx*ny*nz, len(actnum)) - ) - - if set(actnum)-set([0,1]): - raise AssertionError( - "Expected ACTNUM to consist of 0's and 1's, was %s." - % ", ".join(map(str, set(actnum))) - ) - - @classmethod - def extract_coord(cls, dims, coord, ijk_bounds): - nx, ny, nz = dims - (lx, ux), (ly, uy), (lz, uz) = ijk_bounds - new_nx, new_ny, new_nz = ux-lx+1, uy-ly+1, uz-lz+1 - - cls.assert_coord(nx, ny, nz, coord, negative_values=True) - - # Format COORD - coord = divide(divide(coord, 6), nx+1) - - # Extract new COORD - new_coord = [coord_slice[lx:ux+2:] - for coord_slice in coord[ly:uy+2]] - - # Flatten and verify - new_coord = flatten(flatten(new_coord)) - cls.assert_coord(new_nx, new_ny, new_nz, new_coord, - negative_values=True) - - return construct_floatKW("COORD", new_coord) - - @classmethod - def extract_zcorn(cls, dims, zcorn, ijk_bounds): - nx, ny, nz = dims - (lx, ux), (ly, uy), (lz, uz) = ijk_bounds - new_nx, new_ny, new_nz = ux-lx+1, uy-ly+1, uz-lz+1 - - cls.assert_zcorn(nx, ny, nz, zcorn, twisted_check=False) - - # Format ZCORN - zcorn = divide(divide(zcorn, 2*nx), 2*ny) - - # Extract new ZCORN - new_zcorn = [ - y_slice[2*lx:2*ux+2:] - for z_slice in zcorn[2*lz:2*uz+2:] - for y_slice in z_slice[2*ly:2*uy+2:] - ] - - # Flatten and verify - new_zcorn = flatten(new_zcorn) - cls.assert_zcorn(new_nx, new_ny, new_nz, new_zcorn) - - return construct_floatKW("ZCORN", new_zcorn) - - @classmethod - def extract_actnum(cls, dims, actnum, ijk_bounds): - if actnum is None: - return None - - nx, ny, nz = dims - (lx, ux), (ly, uy), (lz, uz) = ijk_bounds - new_nx, new_ny, new_nz = ux-lx+1, uy-ly+1, uz-lz+1 - - cls.assert_actnum(nx, ny, nz, actnum) - - actnum = divide(divide(actnum, nx), ny) - - new_actnum = [ - y_slice[lx:ux+1:] - for z_slice in actnum[lz:uz+1:] - for y_slice in z_slice[ly:uy+1:] - ] - - 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) - for i, value in enumerate(new_actnum): - actnumkw[i] = value - - return actnumkw - - @classmethod - def __translate_coord(cls, coord, translation): - coord = numpy.array([ - map(float, coord[i:i+6:]) - for i in range(0, len(coord), 6) - ]) - translation = numpy.array(list(translation) + list(translation)) - - coord = coord + translation - return construct_floatKW("COORD", coord.flatten().tolist()) - - - @classmethod - def extract_subgrid(cls, grid, ijk_bounds, - decomposition_change=False, translation=None): - - """ - Extracts a subgrid from the given grid according to the specified - bounds. - - @ijk_bounds: The bounds describing the subgrid. Should be a tuple of - length 3, where each element gives the bound for the i, j, k - coordinates of the subgrid to be described, respectively. Each bound - should either be an interval of the form (a, b) where 0 <= a <= b < nx - or a single integer a which is equivialent to the bound (a, a). - - NOTE: The given bounds are including endpoints. - - @decomposition_change: Depending on the given ijk_bounds, libecl 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, - unless decompostion_change is set to True. - - @translation: Gives the possibility of translating the subgrid. Should - be given as a tuple (dx, dy, dz), where each coordinate of the grid - will be moved by di in direction i. - - """ - - gdims = grid.getDims()[:-1:] - nx, ny, nz = gdims - ijk_bounds = cls.assert_ijk_bounds(gdims, ijk_bounds) - - coord = grid.export_coord() - cls.assert_coord(nx, ny, nz, coord, negative_values=True) - - zcorn = grid.export_zcorn() - cls.assert_zcorn(nx, ny, nz, zcorn) - - actnum = grid.export_actnum() - cls.assert_actnum(nx, ny, nz, actnum) - - mapaxes = grid.export_mapaxes() - - sub_data = cls.extract_subgrid_data( - gdims, - coord, zcorn, - ijk_bounds=ijk_bounds, - actnum=actnum, - mapaxes=mapaxes, - decomposition_change=decomposition_change, - translation=translation - ) - - 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) - - @classmethod - def extract_subgrid_data(cls, dims, coord, zcorn, ijk_bounds, actnum=None, - mapaxes=None, decomposition_change=False, translation=None): - """ - - Extracts subgrid data from COORD, ZCORN and potentially ACTNUM. It - returns similar formatted data for the subgrid described by the bounds. - - @dims: The dimentions (nx, ny, nz) of the grid - - @coord: The COORD data of the grid. - - @zcorn: The ZCORN data of the grid. - - @ijk_bounds: The bounds describing the subgrid. Should be a tuple of - length 3, where each element gives the bound for the i, j, k - coordinates of the subgrid to be described, respectively. Each bound - should either be an interval of the form (a, b) where 0 <= a <= b < nx - or a single integer a which is equivialent to the bound (a, a). - - NOTE: The given bounds are including endpoints. - - @actnum: The ACTNUM data of the grid. - - @mapaxes The MAPAXES data of the grid. - - @decomposition_change: Depending on the given ijk_bounds, libecl 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, - unless decompostion_change is set to True. - - @translation: Gives the possibility of translating the subgrid. Should - be given as a tuple (dx, dy, dz), where each coordinate of the grid - will be moved by di in direction i. - - """ - coord, zcorn = list(coord), list(zcorn) - actnum = None if actnum is None else list(actnum) - - ijk_bounds = cls.assert_ijk_bounds(dims, ijk_bounds) - cls.assert_decomposition_change(ijk_bounds, decomposition_change) - - nx, ny, nz = dims - (lx, ux), (ly, uy), (lz, uz) = ijk_bounds - new_nx, new_ny, new_nz = ux-lx+1, uy-ly+1, uz-lz+1 - - new_coord = cls.extract_coord(dims, coord, ijk_bounds) - new_zcorn = cls.extract_zcorn(dims, zcorn, ijk_bounds) - new_actnum = cls.extract_actnum(dims, actnum, ijk_bounds) - - if translation is not None: - mtranslation = pre_mapaxes_translation(translation, mapaxes) - new_coord = cls.__translate_coord(new_coord, mtranslation) - - for i in range(len(new_zcorn)): - new_zcorn[i] += translation[2] - - return new_coord, new_zcorn, new_actnum - - @classmethod - def assert_ijk_bounds(cls, dims, ijk_bounds): - ijk_bounds = list(ijk_bounds) - - for i in range(len(ijk_bounds)): - if isinstance(ijk_bounds[i], int): - ijk_bounds[i] = [ijk_bounds[i]] - if len(ijk_bounds[i]) == 1: - ijk_bounds[i] += ijk_bounds[i] - - if len(ijk_bounds) != 3: - raise ValueError( - "Expected ijk_bounds to contain three intervals, " + - "contained only %d" % len(ijk_bounds)) - - for n, bound in zip(dims, ijk_bounds): - if len(bound) != 2: - raise ValueError( - "Expected bound to consist of two elements, was %s", - str(bound)) - - if not (isinstance(bound[0], int) and isinstance(bound[1], int)): - raise TypeError( - "Expected bound to consist of two integers, ", - "was %s (%s)" - %(str(bound), str((map(type,bound)))) - ) - - if not (0 <= bound[0] <= bound[1] < n): - raise ValueError( - "Expected bounds to have the following format: " + - "0 <= lower bound <= upper_bound < ni, "+ - "was %d <=? %d <=? %d -# for more details. - -from ecl.ecl import EclFileEnum, EclFile, Ecl3DFile - - -class EclInitFile(Ecl3DFile): - - def __init__(self, grid, filename, flags=0): - 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 a restart file.' - err += ' Please follow the Eclipse naming conventions.' - raise ValueError(err % filename) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_kw.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_kw.py deleted file mode 100644 index 6618abdd90..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_kw.py +++ /dev/null @@ -1,1173 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_kw.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Support for working with one keyword from ECLIPSE file. - -ECLIPSE 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' - 0.05 0.08 0.08 0.10 - 0.11 0.11 0.10 0.09 - .... - -I.e. it starts with of header consisting of a 8 characters name, a -length and a datatype, immediately followed by the actual -data. - -Altough the term "restart format" is used to describe the format, this -particular format is not limited to restart files; it is (at least) -used in INIT, EGRID, GRID, Snnn, UNSMRY, SMSPEC, UNRST, Xnnnn and RFT -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. -""" - -from __future__ import absolute_import, division, print_function, unicode_literals - -import ctypes -import warnings -import numpy - -from cwrap import CFILE, BaseCClass -from ecl.util import monkey_the_camel -from ecl.ecl import EclDataType -from ecl.ecl import EclTypeEnum, EclUtil, EclPrototype - -def dump_type_deprecation_warning(): - warnings.warn("EclTypeEnum is deprecated. " + - "You should instead provide an EclDataType", - 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 warn_and_cast_data_type(data_type): - if isinstance(data_type, EclDataType): - return data_type - if isinstance(data_type, EclTypeEnum): - 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.") - - dump_type_deprecation_warning() - return EclDataType(data_type) - -class EclKW(BaseCClass): - """ - The EclKW class contains the information from one ECLIPSE 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. - - Many of the special __xxx___() functions have been implemented, so - that the EclKW 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. - """ - - int_kw_set = set(["PVTNUM", "FIPNUM", "EQLNUM", "FLUXNUM", "MULTNUM", "ACTNUM", "SPECGRID", "REGIONS"]) - - TYPE_NAME = "ecl_kw" - _alloc_new = EclPrototype("void* ecl_kw_alloc_python(char*, int, ecl_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)", bind = False) - _fseek_grdecl = EclPrototype("bool ecl_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)") - _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)") - _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*)") - _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)"); - - _int_sum = EclPrototype("int ecl_kw_element_sum_int(ecl_kw)") - _float_sum = EclPrototype("double ecl_kw_element_sum_float(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)") - - _assert_binary = EclPrototype("bool ecl_kw_size_and_numeric_type_equal(ecl_kw, ecl_kw)") - _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)") - - _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_double = EclPrototype("void ecl_kw_max_min_double(ecl_kw, double*, double*)") - _fix_uninitialized = EclPrototype("void ecl_kw_fix_uninitialized(ecl_kw,int, int, int, int*)") - _first_different = EclPrototype("int ecl_kw_first_different(ecl_kw, ecl_kw, int, double, double)") - _resize = EclPrototype("void ecl_kw_resize(ecl_kw, int)") - - @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") - - ecl_kw.__private_init() - return ecl_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") - - ecl_kw.__private_init() - return ecl_kw - - - - @classmethod - def add_int_kw(cls, kw): - """Will add keyword @kw to the standard set of integer keywords.""" - cls.int_kw_set.add(kw) - - @classmethod - def del_int_kw(cls, kw): - """Will remove keyword @kw from the standard set of integer keywords.""" - cls.int_kw_set.discard(kw) - - @classmethod - def int_keywords(cls): - """Will return the current set of integer keywords.""" - return cls.int_kw_set - - - def slice_copy(self, slice_range): - (start, stop, step) = slice_range.indices(len(self)) - if stop > start: - return self._slice_copyc(start, stop, step) - else: - return None - - - def copy(self): - """ - Will create a deep copy of the current kw instance. - """ - return self._copyc() - - - - - @classmethod - def read_grdecl(cls, fileH, kw, strict=True, ecl_type=None): - """ - Function to load an EclKW instance from a grdecl formatted filehandle. - - This constructor can be used to load an EclKW instance from a - grdecl formatted file; the input files for petrophysical - properties are typically given as grdecl files. - - The @file argument should be a Python filehandle to an open - file. The @kw argument should be the keyword header you are - searching for, e.g. "PORO" or "PVTNUM"[1], the method will - then search forward through the file to look for this @kw. If - the keyword can not be found the method will return None. The - searching will start from the current position in the file; so - if you want to reposition the file pointer you should use the - seek() method of the file object first. - - Observe that there is a strict 8 character limit on @kw - - altough you could in principle use an arbitrary external - program to create grdecl files with more than 8 character - length headers, this implementation will refuse to even try - loading them. In that case you will have to rename the - keywords in your file - sorry. A TypeError exception - will be raised if @kw has more than 8 characters. - - The implementation in ert can read integer and float type - keywords from grdecl files; however the grdecl files have no - datatype header, and it is impossible to determine the type - reliably by inspection. Hence the type must be known when - 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 - the type: - - special_int_kw = EclKW.read_grdecl(fileH, 'INTKW', ecl_type=ECL_INT) - - If ecl_type is different from ECL_INT or - ECL_FLOAT a TypeError exception will be raised. - - If ecl_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. - - pvtnum_kw = EclKW.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. - - EclKw reads grdecl with EclDataType - poro_kw = EclKW.read_grdecl(fileH, 'PORO') - - - Observe that since the grdecl files are quite weakly - structured it is difficult to verify the integrity of the - files, malformed input might therefor pass unnoticed before - things blow up at a later stage. - - [1]: It is possible, but not recommended, to pass in None for - @kw, in which case the method will load the first keyword - it finds in the file. - """ - - cfile = CFILE(fileH) - if kw: - if len(kw) > 8: - raise TypeError("Sorry keyword:%s is too long, must be eight characters or less." % kw) - - if ecl_type is None: - if cls.int_kw_set.__contains__(kw): - ecl_type = EclDataType.ECL_INT - else: - ecl_type = EclDataType.ECL_FLOAT - - ecl_type = warn_and_cast_data_type(ecl_type) - - if not isinstance(ecl_type, EclDataType): - raise TypeError("Expected EclDataType, was: %s" % type(ecl_type)) - - if not ecl_type in [EclDataType.ECL_FLOAT, EclDataType.ECL_INT]: - raise ValueError("The type:%s is invalid when loading keyword:%s" % (ecl_type.type_name, kw)) - - return cls._load_grdecl(cfile, kw, strict, ecl_type) - - - @classmethod - def fseek_grdecl(cls, fileH, kw, rewind=False): - """ - Will search through the open file and look for string @kw. - - If the search succeeds the function will return and the file - pointer will be positioned at the start of the kw, if the - search fails the function will return false and the file - pointer will be repositioned at the position it had prior to - the call. - - Only @kw instances which are found at the beginning of a line - (with optional leading space characters) are considered, - i.e. searching for the string PERMX in the cases below will - fail: - - -- PERMX - EQUIL PERMX / - - - The function will start searching from the current position in - the file and forwards, if the optional argument @rewind is - true the function rewind to the beginning of the file and - search from there after the initial search. - """ - cfile = CFILE(fileH) - return cls._fseek_grdecl(kw, rewind, cfile) - - - @classmethod - def fread(cls, fortio): - """ - Will read a new EclKW instance from the open FortIO file. - """ - return cls._fread_alloc(fortio) - - - def free(self): - self._free() - - def __repr__(self): - si = len(self) - nm = self.getName() - mm = 'type=%s' % str(self.getEclType()) - if self.isNumeric(): - mi, ma = self.getMinMax() - mm = 'min=%.2f, max=%.2f' % (mi,ma) - ad = self._ad_str() - fmt = 'EclKW(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. - - This method will create a grand spanking new EclKW - 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) - - """ - if len(name) > 8: - raise ValueError("Sorry - maximum eight characters in keyword name") - - 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)) - - c_ptr = self._alloc_new(name, size, data_type) - super(EclKW, self).__init__(c_ptr) - self.__private_init() - - - - def __private_init(self): - self.data_ptr = None - - if self.data_type.is_int(): - self.data_ptr = self._int_ptr() - self.dtype = numpy.int32 - self.str_fmt = "%8d" - elif self.data_type.is_float(): - self.data_ptr = self._float_ptr() - self.dtype = numpy.float32 - self.str_fmt = "%13.4f" - elif self.data_type.is_double(): - self.data_ptr = self._double_ptr() - self.dtype = numpy.float64 - self.str_fmt = "%13.4f" - else: - # Iteration not supported for CHAR / BOOL - self.data_ptr = None - self.dtype = None - if self.data_type.is_char(): - self.str_fmt = "%8s" - elif self.data_type.is_bool(): - self.str_fmt = "%d" - elif self.data_type.is_mess(): - self.str_fmt = "%s" #"Message type" - 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) - - def sub_copy(self, offset, count, new_header=None): - """ - Will create a new block copy of the src keyword. - - If @new_header == None the copy will get the same 'name' as - the src, otherwise the keyword will get the @new_header as - header. - - The copy will start at @block of the src keyword and copy - @count elements; a negative value of @count is interpreted as - 'the rest of the elements' - - new1 = src.sub_copy(0, 10, new_header="NEW1") - new2 = src.sub_copy(10, -1, new_header="NEW2") - - If the count or index arguments are in some way invalid the - method will raise IndexError. - """ - if offset < 0 or offset >= len(self): - raise IndexError("Offset:%d invalid - valid range:[0,%d)" % (offset, len(self))) - - if offset + count > len(self): - raise IndexError("Invalid value of (offset + count):%d" % (offset + count)) - - return self._sub_copy(new_header, offset, count) - - - def is_numeric(self): - """ - Will check if the keyword contains numeric data, i.e int, float or double. - """ - return self.data_type.is_numeric() - - def ecl_kw_instance(self): - return True - - - - def __len__(self): - """ - Returns the number of elements. Implements len() - """ - return self._get_size() - - - def __deep_copy__(self, memo): - """ - Python special routine used to perform deep copy. - """ - ecl_kw = self.copy() - return ecl_kw - - - def __getitem__(self, index): - """ - Function to support index based lookup: y = kw[index] - """ - if isinstance(index,int): - length = len(self) - if index < 0: - # We allow one level of negative indexing - index += len(self) - - if index < 0 or index >= length: - raise IndexError - else: - if self.data_ptr: - return self.data_ptr[ index ] - else: - if self.data_type.is_bool(): - return self._iget_bool(index) - elif self.data_type.is_char(): - return self._iget_char_ptr(index) - elif self.data_type.is_string(): - return self._iget_string_ptr(index) - else: - raise TypeError("Internal implementation error ...") - elif isinstance(index, slice): - return self.slice_copy(index) - else: - raise TypeError("Index should be integer type") - - - def __setitem__(self, index,value): - """ - Function to support index based assignment: kw[index] = value - """ - if isinstance(index, int): - length = len(self) - if index < 0: - # Will only wrap backwards once - index = len(self) + index - - if index < 0 or index >= length: - raise IndexError - else: - if self.data_ptr: - self.data_ptr[ index ] = value - else: - if self.data_type.is_bool(): - self._iset_bool(index, value) - elif self.data_type.is_char(): - return self._iset_char_ptr(index, value) - elif self.data_type.is_string(): - return self._iset_string_ptr(index, value) - else: - raise SystemError("Internal implementation error ...") - elif isinstance(index, slice): - (start, stop, step) = index.indices(len(self)) - index = start - while index < stop: - self[index] = value - index += step - else: - raise TypeError("Index should be integer type") - - - ################################################################# - - - def __IMUL__(self, factor, mul=True): - if self.isNumeric(): - if hasattr(factor, "ecl_kw_instance"): - if self.assert_binary(factor): - if mul: - self._imul(factor) - else: - self._idiv(factor) - else: - raise TypeError("Type mismatch") - else: - if not mul: - factor = 1.0 / factor - - if self.data_type.is_int(): - if isinstance(factor, int): - self._scale_int(factor) - else: - raise TypeError("Type mismatch") - else: - if isinstance(factor, int) or isinstance(factor, float): - self._scale_float(factor) - else: - raise TypeError("Only muliplication with scalar supported") - else: - raise TypeError("Not numeric type") - - return self - - - def __IADD__(self, delta, add=True): - if self.isNumeric(): - if type(self) == type(delta): - if self.assert_binary(delta): - if add: - self._iadd(delta) - else: - self._isub(delta) - else: - raise TypeError("Type / size mismatch") - else: - if add: - sign = 1 - else: - sign = -1 - - if self.data_type.is_int(): - if isinstance(delta, int): - self._shift_int(delta * sign) - else: - raise TypeError("Type mismatch") - else: - if isinstance(delta, int) or isinstance(delta, float): - self._shift_float(delta * sign) # Will call the _float() or _double() function in the C layer. - else: - raise TypeError("Type mismatch") - else: - raise TypeError("Type / size mismatch") - - return self - - def __iadd__(self, delta): - return self.__IADD__(delta, True) - - def __isub__(self, delta): - return self.__IADD__(delta, False) - - def __imul__(self, delta): - return self.__IMUL__(delta, True) - - def __idiv__(self, delta): - return self.__IMUL__(delta, False) - - - ################################################################# - - def __abs__(self): - if self.isNumeric(): - copy = self.copy() - copy._iabs() - return copy - else: - raise TypeError("The __abs__() function is only implemented for numeric types") - - - - def __add__(self, delta): - copy = self.copy() - copy += delta - return copy - - def __radd__(self, delta): - return self.__add__(delta) - - def __sub__(self, delta): - copy = self.copy() - copy -= delta - return copy - - def __rsub__(self, delta): - return self.__sub__(delta) * -1 - - def __mul__(self, factor): - copy = self.copy() - copy *= factor - return copy - - def __rmul__(self, factor): - return self.__mul__(factor) - - def __div__(self, factor): - copy = self.copy() - copy /= factor - return copy - - # No __rdiv__() - - def sum(self, mask = None, force_active = False): - """ - Will calculate the sum of all the elements in the keyword. - - String: Raise ValueError exception. - Bool: The number of true values - """ - if mask is None: - if self.data_type.is_int(): - return self._int_sum() - elif self.data_type.is_float(): - return self._float_sum() - elif self.data_type.is_double(): - return self._float_sum() - elif self.data_type.is_bool(): - sum = 0 - for elm in self: - if elm: - sum += 1 - return sum - else: - raise ValueError('The keyword "%s" is of string type - sum is not implemented' % self.getName()) - - return mask.sum_kw(self, force_active) - - - - def assert_binary(self, other): - """ - Utility function to assert that keywords @self and @other can - be combined. - """ - return self._assert_binary(other) - - ################################################################# - - 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 - instance. The @value parameter can either be a scalar, or - another EclKW 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 - 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") - - poro = init["PORO"][0] - eqlnum = init["EQLNUM"][0] - reg.select_below(poro, 0.10) - - eqlnum.assign(88, mask = reg) - - The EclRegion 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 - the active indices if the kw has nactive elements. By setting - the optional argument @force_active to true, you can force the - method to only modify the active indices, even though the - keyword has nx*ny*nz elements; if the keyword has nactive - elements the @force_active flag is not considered. - """ - if self.isNumeric(): - if type(value) == type(self): - if mask is not None: - mask.copy_kw(self, value, force_active) - else: - if self.assert_binary(value): - self._copy_data(value) - else: - raise TypeError("Type / size mismatch") - else: - if mask is not None: - mask.set_kw(self, value, force_active) - else: - if self.data_type.is_int(): - if isinstance(value, int): - self._set_int(value) - else: - raise TypeError("Type mismatch") - else: - if isinstance(value, int) or isinstance(value, float): - self._set_float(value) - else: - raise TypeError("Only muliplication with scalar supported") - - - def add(self, other, mask=None, force_active=False): - """ - See method assign() for documentation of optional arguments - @mask and @force_active. - """ - if mask is not None: - mask.iadd_kw(self, other, force_active) - else: - return self.__iadd__(other) - - def sub(self, other, mask=None, force_active=False): - """ - See method assign() for documentation of optional arguments - @mask and @force_active. - """ - if mask is not None: - mask.isub_kw(self, other, force_active) - else: - return self.__isub__(other) - - def mul(self, other, mask=None, force_active=False): - """ - See method assign() for documentation of optional arguments - @mask and @force_active. - """ - if mask is not None: - mask.imul_kw(self, other, force_active) - else: - return self.__imul__(other) - - def div(self, other, mask=None, force_active=False): - """ - See method assign() for documentation of optional arguments - @mask and @force_active. - """ - if mask is not None: - mask.idiv_kw(self, other, force_active) - else: - return self.__idiv__(other) - - 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 - vector as input, and return a scalar value of the same type; - optionally you can supply a second argument with the @arg - attribute: - - def cutoff(x, limit): - if x > limit: - return x - else: - return 0 - - - kw.apply(math.sin) - kw.apply(cutoff, arg=0.10) - - - See method assign() for documentation of optional arguments - @mask and @force_active. - """ - if mask is not None: - active_list = mask.kw_index_list(self, force_active) - if arg: - for index in active_list: - self.data_ptr[index] = func(self.data_ptr[index], arg) - else: - for index in active_list: - self.data_ptr[index] = func(self.data_ptr[index]) - else: - if arg: - for i in range(len(self)): - self.data_ptr[i] = func(self.data_ptr[i], arg) - else: - for i in range(len(self)): - self.data_ptr[i] = func(self.data_ptr[i]) - - - def equal(self, other): - """ - Will check if the two keywords are (exactly) equal. - - The check is based on the content of the keywords, and not - pointer comparison. - """ - if isinstance(other, EclKW): - return self._equal(other) - else: - raise TypeError("Can only compare with another EclKW") - - - def __eq__(self, other): - return self.equal(other) - - def __hash__(self): - return hash(self._get_header()) - - - def equal_numeric(self, other, epsilon=1e-6, abs_epsilon=None, rel_epsilon=None): - """Will check if two numerical keywords are ~nearly equal. - - - If the keywords are of type integer, the comparison is - absolute. - - If you pass in xxx_epsilon <= 0 the xxx_epsilon will be - ignored in the test. - - """ - if isinstance(other, EclKW): - if abs_epsilon is None: - abs_epsilon = epsilon - - if rel_epsilon is None: - rel_epsilon = epsilon - - return self._equal_numeric(other, abs_epsilon, rel_epsilon) - else: - raise TypeError("Can only compare with another EclKW") - - - ################################################################# - - def deep_copy(self): - ecl_kw = self.__deep_copy__({}) - return ecl_kw - - def fort_io_size(self): - """ - The number of bytes this keyword would occupy in a BINARY file. - """ - return self._get_fortio_size() - - def set_name(self, name): - if len(name) > 8: - raise ValueError("Sorry: the name property must be max 8 characters long :-(") - self._set_header(name) - - @property - def name(self): - n = self._get_header() - return str(n) if n else '' - - @name.setter - def name(self, value): - self.set_name(value) - - def get_name(self): - return self.name - - def resize(self, new_size): - """ - Will set the new size of the kw to @new_size. - """ - if new_size >= 0: - self._resize(new_size) - - # Iteration is based on a pointer to the underlying storage, - # that will generally by reset by the resize() call; i.e. we - # need to call the __private_init() method again. - self.__private_init() - - - def get_min_max(self): - """ - Will return a touple (min,max) for numerical types. - - Will raise TypeError exception if the keyword is not of - numerical type. - """ - if self.data_type.is_float(): - min_ = ctypes.c_float() - max_ = ctypes.c_float() - self._max_min_float(ctypes.byref(max_), ctypes.byref(min_)) - elif self.data_type.is_double(): - min_ = ctypes.c_double() - max_ = ctypes.c_double() - self._max_min_double(ctypes.byref(max_), ctypes.byref(min_)) - elif self.data_type.is_int(): - min_ = ctypes.c_int() - max_ = ctypes.c_int() - self._max_min_int(ctypes.byref(max_), ctypes.byref(min_)) - else: - raise TypeError("min_max property not defined for keywords of type: %s" % self.type) - return (min_.value, max_.value) - - - def get_max(self): - mm = self.getMinMax() - return mm[1] - - - def get_min(self): - mm = self.getMinMax() - return mm[0] - - @property - def type(self): - return self.getEclType() - - @property - def data_type(self): - return self._get_data_type() - - @property - def type_name(self): - return self.data_type.type_name - - def type_name(self): - return self.data_type.type_name - - def get_ecl_type(self): - warnings.warn("EclTypeEnum is deprecated. " + - "You should instead provide an EclDataType", - DeprecationWarning) - - return self._get_type() - - - - - @property - def header(self): - return (self.getName(), len(self), self.typeName()) - - @property - def array(self): - a = self.data_ptr - if not a == None: - a.size = len(self) - a.__parent__ = self # Inhibit GC - return a - - - def str_data(self, width, index1, index2, fmt): - """ - Helper function for str() method. - """ - data = [] - s = "" - for index in range(index1, index2): - data.append(self[index]) - for index in range(len(data)): - s += fmt % data[ index ] - if index % width == (width - 1): - s+= "\n" - return s - - - def str(self, width=5, max_lines=10, fmt=None): - """ - Return string representation of kw for pretty printing. - - The function will return a string consisting of a header, and - then a chunk of data. The data will be formatted in @width - columns, and a maximum of @max_lines lines. If @max_lines is - not sufficient the first elements in the kewyord are - represented, a .... continuation line and then the last part - of the keyword. If @max_lines is None all of the vector will - be printed, irrespective of how long it is. - - If a value is given for @fmt that is used as format string for - each element, otherwise a type-specific default format is - used. If given the @fmt string should contain spacing between - the elements. The implementation of the builtin method - __str__() is based on this method. - """ - s = "%-8s %8d %-4s\n" % (self.getName(), len(self), self.typeName()) - lines = len(self) // width - if not fmt: - fmt = self.str_fmt + " " - - if max_lines is None or lines <= max_lines: - s += self.str_data(width, 0, len(self), fmt) - else: - s1 = width * max_lines // 2 - s += self.str_data(width , 0, s1, fmt) - s += " .... \n" - s += self.str_data(width , len(self) - s1, len(self), fmt) - - return s - - def __str__(self): - """ - Return string representation - see method str(). - """ - return self.str(width=5, max_lines=10) - - - def numpy_view(self): - """Will return a numpy view to the underlying data. - - The data in this numpy array is *shared* with the EclKW - instance, meaning that updates in one will be reflected in the - other. - """ - - if self.dtype is numpy.float64: - ct = ctypes.c_double - elif self.dtype is numpy.float32: - ct = ctypes.c_float - elif self.dtype is numpy.int32: - ct = ctypes.c_int - else: - raise ValueError("Invalid type - numpy array only valid for int/float/double") - - ap = ctypes.cast(self.data_ptr, ctypes.POINTER(ct * len(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. - - The numpy array has a separate copy of the data, so that - changes to either the numpy array or the EclKW will *not* be - reflected in the other datastructure. This is in contrast to - the EclKW.numpyView() method where the underlying data is - shared. - """ - view = self.numpyView() - return numpy.copy(view) - - def fwrite(self, fortio): - self._fwrite(fortio) - - def write_grdecl(self, file): - """ - Will write keyword in GRDECL format. - - This method will write the current keyword in GRDECL format, - the @file argument must be a Python file handle to an already - opened file. In the example below we load the porosity from an - 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) - - reg.select_below(poro, 0.05) - poro.assign(0.0, mask=reg) - - fileH = open("poro2.grdecl", "w") - poro.write_grdecl(fileH) - fileH.close() - - """ - cfile = CFILE(file) - self._fprintf_grdecl(cfile) - - - - def fprintf_data(self, file, fmt=None): - """ - Will print the keyword data formatted to file. - - The @file argument should be a python file handle to a file - opened for writing. The @fmt argument is used as fprintf() - format specifier, observe that the format specifier should - include a separation character between the elements. If no - @fmt argument is supplied the default str_fmt specifier is - used for every element, separated by a newline. - - In the case of boolean data the function will print o and 1 - for False and True respectively. For string data the function - will print the data as 8 characters long string with blank - padding on the right. - """ - if fmt is None: - fmt = self.str_fmt + "\n" - cfile = CFILE(file) - self._fprintf_data(fmt, cfile) - - - def fix_uninitialized(self, grid): - """ - Special case function for region code. - """ - dims = grid.getDims() - actnum = grid.exportACTNUM() - self._fix_uninitialized(dims[0], dims[1], dims[2], actnum.getDataPtr()) - - - def get_data_ptr(self): - if self.data_type.is_int(): - return self._int_ptr() - elif self.data_type.is_float(): - return self._float_ptr() - elif self.data_type.is_double(): - return self._double_ptr() - else: - raise ValueError("Only numeric types can export data pointer") - - - def first_different(self, other, offset=0, epsilon=0, abs_epsilon=None, rel_epsilon=None): - if len(self) != len(other): - raise ValueError("Keywords must have equal size") - - if offset >= len(self): - raise IndexError("Offset:%d invalid - size:%d" % (offset, len(self))) - - if self.getEclType() != other.getEclType(): - raise TypeError("The two keywords have different type") - - if abs_epsilon is None: - abs_epsilon = epsilon - - if rel_epsilon is None: - rel_epsilon = epsilon - - return self._first_different(other, offset, abs_epsilon, rel_epsilon) - -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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_npv.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_npv.py deleted file mode 100644 index df3860203e..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_npv.py +++ /dev/null @@ -1,220 +0,0 @@ -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'ecl_npv.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import re -import datetime -import numbers - -from ecl.util import monkey_the_camel -from ecl.ecl import EclSum - - -class NPVParseKey(object): - def __init__(self, eclNPV): - self.baseCase = eclNPV.baseCase - self.NPV = eclNPV - - - def __call__(self, matchObject): - key = matchObject.group(1) - smspecNode = self.baseCase.smspec_node(key) - if smspecNode.isTotal(): - var = key.replace(":", "_") - self.NPV.addKey(key, var) - return var + "[i]" - else: - raise ValueError("Sorry - the key: %s is not a total key - aborting" % key) - - -class NPVPriceVector(object): - def __init__(self, argList): - self.dateList = [] - if isinstance(argList, list): - for item in argList: - if isinstance(item, tuple) and len(item) == 2: - self.addItem(item) - else: - raise ValueError("Each element in list must be tuple with two elements") - else: - raise ValueError("Constructor argument must be list") - - - - def add_item(self, item): - dateItem = item[0] - try: - year = dateItem.year - month = dateItem.month - day = dateItem.day - date = datetime.date(year, month, day) - except AttributeError: - try: - tmp = re.split("[ .-/]", dateItem) - day = int(tmp[0]) - month = int(tmp[1]) - year = int(tmp[2]) - - date = datetime.date(year, month, day) - except Exception: - raise ValueError("First element was invalid date item") - - - if len(self.dateList): - prevItem = self.dateList[-1] - if prevItem[0] >= date: - raise ValueError("The dates must be in a strictly increasing order") - - value = item[1] - if isinstance(value, numbers.Real) or callable(value): - self.dateList.append((date, value)) - else: - raise ValueError("The value argument must be a scalar number or callable") - - @staticmethod - def assert_date(date): - try: - year = date.year - month = date.month - day = date.day - date = datetime.date(year, month, day) - - return date - except AttributeError: - return date.date() - - - - def eval_date(self, dateItem, date): - value = dateItem[1] - if callable(value): - td = date - dateItem[0] - return value(td.days) - else: - return value - - - def eval(self, date): - date = self.assertDate(date) - startDate = self.dateList[0][0] - if date >= startDate: - endDate = self.dateList[-1][0] - if date >= endDate: - return self.evalDate(self.dateList[-1], date) - else: - index1 = 0 - index2 = len(self.dateList) - 1 - while True: - if (index2 - index1) == 1: - index = index1 - break - - index = (index1 + index2) >> 1 - item = self.dateList[index] - if date >= item[0]: - index1 = index - else: - index2 = index - return self.evalDate(self.dateList[index], date) - else: - raise ValueError("Input date:%s before start of vector" % date) - - - - - -class EclNPV(object): - sumKeyRE = re.compile("[[]([\w:,]+)[]]") - - - def __init__(self, baseCase): - sum = EclSum(baseCase) - if sum: - self.baseCase = sum - else: - raise Error("Failed to open ECLIPSE sumamry case:%s" % baseCase) - self.expression = None - self.keyList = {} - self.start = None - self.end = None - self.interval = "1Y" - - - def eval(self): - if self.expression is None: - raise ValueError("Can not eval with an expression to evaluate") - pass - - - def get_expression(self): - return self.expression - - - def set_expression(self, expression): - self.compiled_expr = self.compile(expression) - self.expression = expression - - - def get_key_list(self): - return self.keyList.keys() - - - def add_key(self, key, var): - self.keyList[key] = var - - - def parse_expression(self, expression): - self.keyList = {} - if expression.count("[") != expression.count("]"): - raise ValueError("Expression:%s invalid - not matching [ and ]" % expression) - - replaceKey = NPVParseKey(self) - parsedExpression = self.sumKeyRE.sub(replaceKey, expression) - return parsedExpression - - - def compile(self, expression): - parsedExpression = self.parseExpression(expression) - self.code = "trange = self.baseCase.timeRange(self.start, self.end, self.interval)\n" - for (key,var) in self.keyList.items(): - self.code += "%s = self.baseCase.blockedProduction(\"%s\", trange)\n" % (var, key) - - self.code += "npv = 0\n" - self.code += """ -for i in range(len(trange) - 1): - npv += %s -varDict[\"npv\"] = npv -""" % parsedExpression - - - - def eval_npv(self): - byteCode = compile(self.code, "", 'exec') - varDict = {} - eval(byteCode) - return varDict["npv"] - - - -monkey_the_camel(NPVPriceVector, 'addItem', NPVPriceVector.add_item) -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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_region.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_region.py deleted file mode 100644 index 30cf71e9e4..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_region.py +++ /dev/null @@ -1,1054 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_region.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Module used to select cells based on many different criteria. - -This module implements the class EclRegion 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 -combined e.g. with logical &. - -When the selection process is complete the region instance can be -queried for the corresponding list of indices. -""" -import ctypes - -from cwrap import BaseCClass - -from ecl.util import monkey_the_camel -from ecl.util import IntVector - -from ecl.ecl.faults import Layer -from ecl.ecl import EclKW, EclDataType, EclPrototype -from ecl.geo import CPolyline - - -def select_method(select): - """ - The select_method method decorator is applied to all the - select_xxx() methods. The purpose of this decorator is to - allow the select_xxx() methods to have an optional argument - @intersect. If the @intersect argument is True the results of - the current select method will be and'ed with the current - selection, instead of or'ed which is the default. - - Consider this example: - - region = EclRegion( 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] - - When these two calls have completed selection will contain all - the cells which are either in i-interval [0:5] or in - j-interval [0:5]. If we supply the @intersect argument in the - second call the j selection will only be applied to the cells - in i:[0:5] interval: - - region = EclRegion( 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] AND i:[0:5] - """ - - def select_wrapper(self , *args , **kwargs): - intersect = kwargs.has_key('intersect') and kwargs['intersect'] - if intersect: - new_region = EclRegion( self.grid , False ) - select(new_region , *args ) - - self &= new_region - else: - select(self , *args ) - - 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 )") - - _set_kw_int = EclPrototype("void ecl_region_set_kw_int( ecl_region , ecl_kw , int, bool) ") - _set_kw_float = EclPrototype("void ecl_region_set_kw_float( ecl_region , ecl_kw , float, bool ) ") - _set_kw_double = EclPrototype("void ecl_region_set_kw_double( ecl_region , ecl_kw , double , bool) ") - _shift_kw_int = EclPrototype("void ecl_region_shift_kw_int( ecl_region , ecl_kw , int, bool) ") - _shift_kw_float = EclPrototype("void ecl_region_shift_kw_float( ecl_region , ecl_kw , float, bool ) ") - _shift_kw_double = EclPrototype("void ecl_region_shift_kw_double( ecl_region , ecl_kw , double , bool) ") - _scale_kw_int = EclPrototype("void ecl_region_scale_kw_int( ecl_region , ecl_kw , int, bool) ") - _scale_kw_float = EclPrototype("void ecl_region_scale_kw_float( ecl_region , ecl_kw , float, bool ) ") - _scale_kw_double = EclPrototype("void ecl_region_scale_kw_double( ecl_region , ecl_kw , double , bool) ") - _sum_kw_int = EclPrototype("int ecl_region_sum_kw_int( ecl_region , ecl_kw , bool) ") - _sum_kw_float = EclPrototype("float ecl_region_sum_kw_float( ecl_region , ecl_kw , bool ) ") - _sum_kw_double = EclPrototype("double ecl_region_sum_kw_double( ecl_region , ecl_kw , bool) ") - _sum_kw_bool = EclPrototype("int ecl_region_sum_kw_int( ecl_region , ecl_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 )") - _deselect_equal = EclPrototype("void ecl_region_deselect_equal( ecl_region , ecl_kw , int)") - _select_less = EclPrototype("void ecl_region_select_smaller( ecl_region , ecl_kw , float )") - _deselect_less = EclPrototype("void ecl_region_deselect_smaller( ecl_region , ecl_kw , float )") - _select_more = EclPrototype("void ecl_region_select_larger( ecl_region , ecl_kw , float )") - _deselect_more = EclPrototype("void ecl_region_deselect_larger( ecl_region , ecl_kw , float )") - _select_in_interval = EclPrototype("void ecl_region_select_in_interval( ecl_region, ecl_kw , float , float )") - _deselect_in_interval = EclPrototype("void ecl_region_deselect_in_interval( ecl_region, ecl_kw, float , float )") - _invert_selection = EclPrototype("void ecl_region_invert_selection( ecl_region )") - - _select_box = EclPrototype("void ecl_region_select_from_ijkbox(ecl_region , int , int , int , int , int , int)") - _deselect_box = EclPrototype("void ecl_region_deselect_from_ijkbox(ecl_region , int , int , int , int , int , int)") - _imul_kw = EclPrototype("void ecl_region_kw_imul( ecl_region , ecl_kw , ecl_kw , bool)") - _idiv_kw = EclPrototype("void ecl_region_kw_idiv( ecl_region , ecl_kw , ecl_kw , bool)") - _iadd_kw = EclPrototype("void ecl_region_kw_iadd( ecl_region , ecl_kw , ecl_kw , bool)") - _isub_kw = EclPrototype("void ecl_region_kw_isub( ecl_region , ecl_kw , ecl_kw , bool)") - _copy_kw = EclPrototype("void ecl_region_kw_copy( ecl_region , ecl_kw , ecl_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 )") - _get_active_list = EclPrototype("int_vector_ref ecl_region_get_active_list( ecl_region )") - _get_global_list = EclPrototype("int_vector_ref ecl_region_get_global_list( ecl_region )") - _get_active_global = EclPrototype("int_vector_ref ecl_region_get_global_active_list( ecl_region )") - _select_cmp_less = EclPrototype("void ecl_region_cmp_select_less( ecl_region , ecl_kw , ecl_kw)") - _select_cmp_more = EclPrototype("void ecl_region_cmp_select_more( ecl_region , ecl_kw , ecl_kw)") - _deselect_cmp_less = EclPrototype("void ecl_region_cmp_deselect_less( ecl_region , ecl_kw , ecl_kw)") - _deselect_cmp_more = EclPrototype("void ecl_region_cmp_deselect_more( ecl_region , ecl_kw , ecl_kw)") - _select_islice = EclPrototype("void ecl_region_select_i1i2( ecl_region , int , int )") - _deselect_islice = EclPrototype("void ecl_region_deselect_i1i2( ecl_region , int , int )") - _select_jslice = EclPrototype("void ecl_region_select_j1j2( ecl_region , int , int )") - _deselect_jslice = EclPrototype("void ecl_region_deselect_j1j2( ecl_region , int , int )") - _select_kslice = EclPrototype("void ecl_region_select_k1k2( ecl_region , int , int )") - _deselect_kslice = EclPrototype("void ecl_region_deselect_k1k2( ecl_region , int , int )") - _select_deep_cells = EclPrototype("void ecl_region_select_deep_cells( ecl_region , double )") - _deselect_deep_cells = EclPrototype("void ecl_region_select_deep_cells( ecl_region , double )") - _select_shallow_cells = EclPrototype("void ecl_region_select_shallow_cells( ecl_region , double )") - _deselect_shallow_cells = EclPrototype("void ecl_region_select_shallow_cells( ecl_region , double )") - _select_small = EclPrototype("void ecl_region_select_small_cells( ecl_region , double )") - _deselect_small = EclPrototype("void ecl_region_deselect_small_cells( ecl_region , double )") - _select_large = EclPrototype("void ecl_region_select_large_cells( ecl_region , double )") - _deselect_large = EclPrototype("void ecl_region_deselect_large_cells( ecl_region , double )") - _select_thin = EclPrototype("void ecl_region_select_thin_cells( ecl_region , double )") - _deselect_thin = EclPrototype("void ecl_region_deselect_thin_cells( ecl_region , double )") - _select_thick = EclPrototype("void ecl_region_select_thick_cells( ecl_region , double )") - _deselect_thick = EclPrototype("void ecl_region_deselect_thick_cells( ecl_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_active = EclPrototype("void ecl_region_deselect_active_cells( ecl_region )") - _deselect_inactive = EclPrototype("void ecl_region_deselect_inactive_cells( ecl_region )") - _select_above_plane = EclPrototype("void ecl_region_select_above_plane( ecl_region , double* , double* )") - _select_below_plane = EclPrototype("void ecl_region_select_below_plane( ecl_region , double* , double* )") - _deselect_above_plane = EclPrototype("void ecl_region_deselect_above_plane( ecl_region, double* , double* )") - _deselect_below_plane = EclPrototype("void ecl_region_deselect_below_plane( ecl_region, double* , double* )") - _select_inside_polygon = EclPrototype("void ecl_region_select_inside_polygon( ecl_region , geo_polygon)") - _select_outside_polygon = EclPrototype("void ecl_region_select_outside_polygon( ecl_region , geo_polygon)") - _deselect_inside_polygon = EclPrototype("void ecl_region_deselect_inside_polygon( ecl_region , geo_polygon)") - _deselect_outside_polygon = EclPrototype("void ecl_region_deselect_outside_polygon( ecl_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)") - _contains_global = EclPrototype("void ecl_region_contains_global( ecl_region, int )") - _contains_active = EclPrototype("void ecl_region_contains_active( ecl_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)") - _select_from_layer = EclPrototype("void ecl_region_select_from_layer( ecl_region , layer , int , int)") - _deselect_from_layer = EclPrototype("void ecl_region_deselect_from_layer( ecl_region , layer , int , int)") - - - def __init__(self , grid , preselect): - """ - Create a new region selector for cells in @grid. - - 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 - cells, or no cells, selected, depending on the value of - @preselect. - """ - - self.grid = grid - self.active_index = False - c_ptr = self._alloc( grid , preselect ) - super(EclRegion , self).__init__( c_ptr ) - - - def free(self): - self._free( ) - - - def __eq__(self , other): - return self._equal(other) - - def __hash__(self): - return hash(hash(self.grid) + hash(self.active_index)) - - - def __deep_copy__(self , memo): - """ - Creates a deep copy of the current region. - """ - return self._alloc_copy( ) - - - def __nonzero__(self): - global_list = self.get_global_list() - return len(global_list) > 0 - - - def __iand__(self , other): - """ - Will perform set intersection operation inplace. - - Will update the current region selection so that the elements - selected in self are also selected in @other. Bound to the - inplace & operator, i.e. - - reg1 &= reg2 - - will eventually call this method. - """ - if isinstance(other , EclRegion): - self._intersect( other) - else: - raise TypeError("Ecl region can only intersect with other EclRegion instances") - - return self - - - def __isub__(self , other): - """ - Inplace "subtract" one selection from another. - - Bound to reg -= reg2 - """ - if isinstance( other , EclRegion ): - self._subtract( other) - else: - raise TypeError("Ecl region can only subtract with other EclRegion instances") - - return self - - - def __ior__(self , other): - """ - Will perform set operation union in place. - - The current region selection will be updated to contain all - the elements which are selected either in the current region, - or in @other; bound to to inplace | operator, so you can write e.g. - - reg1 |= reg2 - - to update reg1 with the selections from reg2. - """ - if isinstance( other , EclRegion): - self._combine( other) - else: - raise TypeError("Ecl region can only be combined with other EclRegion instances") - - return self - - def __iadd__(self , other): - """ - Combines to regions - see __ior__(). - """ - return self.__ior__( other ) - - def __or__(self , other): - """ - Creates a new region which is the union of @self and other. - - The method will create a new region which selection status is - given by the logical or of regions @self and @other; the two - initial regions will not be modified. Bound to the unary | - operator: - - new_reg = reg1 | reg2 - - """ - new_region = self.copy() - new_region.__ior__( other ) - return new_region - - def __and__(self , other): - """ - Creates a new region which is the intersection of @self and other. - - The method will create a new region which selection status is - given by the logical and of regions @self and @other; the two - initial regions will not be modified. Bound to the unary & - operator: - - new_reg = reg1 & reg2 - """ - new_region = self.copy() - new_region.__iand__( other ) - return new_region - - def __add__(self , other): - """ - Unary add operator for two regions - implemented by __or__(). - """ - return self.__or__( other ) - - - def __sub__( self, other): - """ - Unary del operator for two regions. - """ - new_region = self.copy() - new_region.__isub__( other ) - return new_region - - - def union_with( self, other): - """ - Will update self with the union of @self and @other. - - See doscumentation of __ior__(). - """ - return self.__ior__( other ) - - def intersect_with( self, other): - """ - Will update self with the intersection of @self and @other. - - See doscumentation of __iand__(). - """ - return self.__iand__( other ) - - - def copy( self ): - return self.__deep_copy__( {} ) - - def reset(self): - """ - Clear selections according to constructor argument @preselect. - - Will clear all selections, depending on the value of the - constructor argument @preselect. If @preselect is true - everything will be selected after calling reset(), otherwise - no cells will be selected after calling reset(). - """ - self._reset( ) - - ################################################################## - - - @select_method - def select_more( self , ecl_kw , limit , intersect = False): - """ - Select all cells where keyword @ecl_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 - 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 - 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 ) - - region.select_more( swat_kw , 0.85 ) - - """ - self._select_more( ecl_kw , limit ) - - - - def deselect_more( self , ecl_kw , limit): - """ - Deselects cells with value above limit. - - See select_more() for further documentation. - """ - self._deselect_more( ecl_kw , limit ) - - @select_method - def select_less( self , ecl_kw , limit , intersect = False): - """ - Select all cells where keyword @ecl_kw is below @limit. - - See select_more() for further documentation. - """ - self._select_less( ecl_kw , limit ) - - def deselect_less( self , ecl_kw , limit): - """ - Deselect all cells where keyword @ecl_kw is below @limit. - - See select_more() for further documentation. - """ - self._deselect_less( ecl_kw , limit ) - - @select_method - def select_equal( self , ecl_kw , value , intersect = False): - """ - Select all cells where @ecl_kw is equal to @value. - - The EclKW instance @ecl_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 ) - - region.select_equal( pvtnum_kw , 2 ) - region.select_equal( pvtnum_kw , 4 ) - - """ - if not ecl_kw.data_type.is_int(): - raise ValueError("The select_equal method must have an integer valued keyword - got:%s" % ecl_kw.typeName( )) - self._select_equal( ecl_kw , value ) - - - def deselect_equal( self , ecl_kw , value ): - """ - Select all cells where @ecl_kw is equal to @value. - - See select_equal() for further documentation. - """ - if not ecl_kw.data_type.is_int(): - raise ValueError("The select_equal method must have an integer valued keyword - got:%s" % ecl_kw.typeName( )) - self._deselect_equal( ecl_kw , value ) - - @select_method - def select_in_range( self , ecl_kw , lower_limit , upper_limit , select = False): - """ - Select all cells where @ecl_kw is in the half-open interval [ , ). - - Will select all the cells where EclKW instance @ecl_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. - - 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 ) - - region.select_in_range( poro_kw , 0.15, 0.20 ) - - """ - self._select_in_interval( ecl_kw , lower_limit , upper_limit) - - def deselect_in_range( self , ecl_kw , lower_limit , upper_limit): - """ - Deselect all cells where @ecl_kw is in the half-open interval [ , ). - - See select_in_range() for further documentation. - """ - self._deselect_in_interval( ecl_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 - all the cells where the numerical value of @kw1 is less than - the numerical value of @kw2. The ECLIPSE 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 - 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) - - region.select_cmp_less( pressure2 , pressure1) - - """ - self._select_cmp_less( kw1 , kw2 ) - - def deselect_cmp_less( self , kw1 , kw2): - """ - Will deselect all cells where kw2 < kw1. - - See select_cmp_less() for further documentation. - """ - self._deselect_cmp_less( kw1 , kw2 ) - - @select_method - def select_cmp_more( self , kw1 , kw2 , intersect = False): - """ - Will select all cells where kw2 > kw1. - - See select_cmp_less() for further documentation. - """ - self._select_cmp_more( kw1 , kw2 ) - - def deselect_cmp_more( self , kw1 , kw2): - """ - Will deselect all cells where kw2 > kw1. - - See select_cmp_less() for further documentation. - """ - self._deselect_cmp_more( kw1 , kw2 ) - - @select_method - def select_active( self , intersect = False): - """ - Will select all the active grid cells. - """ - self._select_active( ) - - def deselect_active( self ): - """ - Will deselect all the active grid cells. - """ - self._deselect_active( ) - - @select_method - def select_inactive( self , intersect = False): - """ - Will select all the inactive grid cells. - """ - self._select_inactive( ) - - - def deselect_inactive( self ): - """ - Will deselect all the inactive grid cells. - """ - self._deselect_inactive( ) - - - def select_all( self ): - """ - Will select all the cells. - """ - self._select_all( ) - - def deselect_all( self ): - """ - Will deselect all the cells. - """ - self._deselect_all( ) - - def clear( self ): - """ - Will deselect all cells. - """ - self.deselect_all() - - @select_method - def select_deep( self , depth , intersect = False): - """ - Will select all cells below @depth. - """ - self._select_deep_cells(depth) - - def deselect_deep( self, depth): - """ - Will deselect all cells below @depth. - """ - self._deselect_deep_cells(depth) - - @select_method - def select_shallow( self, depth , intersect = False): - """ - Will select all cells above @depth. - """ - self._select_shallow_cells(depth) - - def deselect_shallow( self, depth): - """ - Will deselect all cells above @depth. - """ - self._deselect_shallow_cells(depth) - - @select_method - def select_small( self , size_limit , intersect = False): - """ - Will select all cells smaller than @size_limit. - """ - self._select_small( size_limit ) - - def deselect_small( self , size_limit ): - """ - Will deselect all cells smaller than @size_limit. - """ - self._deselect_small( size_limit ) - - @select_method - def select_large( self , size_limit , intersect = False): - """ - Will select all cells larger than @size_limit. - """ - self._select_large( size_limit ) - - def deselect_large( self , size_limit ): - """ - Will deselect all cells larger than @size_limit. - """ - self._deselect_large( size_limit ) - - @select_method - def select_thin( self , size_limit , intersect = False): - """ - Will select all cells thinner than @size_limit. - """ - self._select_thin( size_limit ) - - def deselect_thin( self , size_limit ): - """ - Will deselect all cells thinner than @size_limit. - """ - self._deselect_thin( size_limit ) - - @select_method - def select_thick( self , size_limit , intersect = False): - """ - Will select all cells thicker than @size_limit. - """ - self._select_thick( size_limit ) - - def deselect_thick( self , size_limit ): - """ - Will deselect all cells thicker than @size_limit. - """ - self._deselect_thick( size_limit ) - - @select_method - def select_box( self , ijk1 , ijk2 , intersect = False): - """ - Will select all cells in box. - - Will select all the the cells in the box given by @ijk1 and - @ijk2. The two arguments @ijk1 and @ijk2 are tuples (1,j,k) - representing two arbitrary - diagonally opposed corners - of a - box. All the elements in @ijk1 and @ijk2 are inclusive, i.e. - - select_box( (10,12,8) , (8 , 16,4) ) - - will select the box defined by [8,10] x [12,16] x [4,8]. - """ - self._select_box( ijk1[0] , ijk2[0] , ijk1[1] , ijk2[1] , ijk1[2] , ijk2[2]) - - def deselect_box( self , ijk1 , ijk2 ): - """ - Will deselect all elements in box. - - See select_box() for further documentation. - """ - self._deselect_box( ijk1[0] , ijk2[0] , ijk1[1] , ijk2[1] , ijk1[2] , ijk2[2]) - - @select_method - def select_islice( self , i1 , i2, intersect = False): - """ - Will select all cells with i in [@i1, @i2]. @i1 and @i2 are zero offset. - """ - self._select_islice( i1,i2) - - def deselect_islice( self , i1 , i2): - """ - Will deselect all cells with i in [@i1, @i2]. @i1 and @i2 are zero offset. - """ - self._deselect_islice( i1,i2) - - @select_method - def select_jslice( self , j1 , j2 , intersect = False): - """ - Will select all cells with j in [@j1, @j2]. @i1 and @i2 are zero offset. - """ - self._select_jslice( j1,j2) - - def deselect_jslice( self , j1 , j2): - """ - Will deselect all cells with j in [@j1, @j2]. @i1 and @i2 are zero offset. - """ - self._deselect_jslice( j1,j2) - - @select_method - def select_kslice( self , k1 , k2 , intersect = False): - """ - Will select all cells with k in [@k1, @k2]. @i1 and @i2 are zero offset. - """ - self._select_kslice( k1,k2) - - def deselect_kslice( self , k1 , k2): - """ - Will deselect all cells with k in [@k1, @k2]. @i1 and @i2 are zero offset. - """ - self._deselect_kslice( k1,k2) - - def invert( self ): - """ - Will invert the current selection. - """ - self._invert_selection( ) - - def __init_plane_select( self , n , p ): - n_vec = ctypes.cast( (ctypes.c_double * 3)() , ctypes.POINTER( ctypes.c_double )) - p_vec = ctypes.cast( (ctypes.c_double * 3)() , ctypes.POINTER( ctypes.c_double )) - for i in range(3): - n_vec[i] = n[i] - p_vec[i] = p[i] - return ( n_vec , p_vec ) - - @select_method - def select_above_plane( self , n , p , intersect = False): - """ - Will select all the cells 'above' the plane defined by n & p. - - @n is the surface normal vector of the plane in question and - @p is a point on the plane surface. The point @p should be - given in (utm_x , utm_y , tvd) coordinates. The term 'above' - means that the cell center has a positive distance to the - plain; correspondingly 'below' means that the cell center has - a negative disatnce to the plane. - """ - (n_vec , p_vec) = self.__init_plane_select( n , p ) - self._select_above_plane( n_vec , p_vec ) - - @select_method - def select_below_plane( self , n , p , interscet = False): - """ - Will select all the cells 'below' the plane defined by n & p. - - See method 'select_above_plane' for further documentation. - """ - (n_vec , p_vec) = self.__init_plane_select( n , p ) - self._select_below_plane( n_vec , p_vec ) - - def deselect_above_plane( self , n , p): - """ - Will deselect all the cells 'above' the plane defined by n & p. - - See method 'select_above_plane' for further documentation. - """ - (n_vec , p_vec) = self.__init_plane_select( n , p ) - self._deselect_above_plane( n_vec , p_vec ) - - def deselect_below_plane( self , n , p): - """ - Will deselect all the cells 'below' the plane defined by n & p. - - See method 'select_above_plane' for further documentation. - """ - (n_vec , p_vec) = self.__init_plane_select( n , p ) - self._deselect_below_plane( n_vec , p_vec ) - - @select_method - def select_inside_polygon( self , points , intersect = False): - """ - Will select all points inside polygon. - - Will select all points inside polygon specified by input - variable @points. Points should be a list of two-element - tuples (x,y). So to select all the points within the rectangle - bounded by the lower left rectangle (0,0) and upper right - (100,100) the @points list should be: - - points = [(0,0) , (0,100) , (100,100) , (100,0)] - - The elements in the points list should be (utm_x, utm_y) - values. These values will be compared with the centerpoints of - the cells in the grid. The selection is based the top k=0 - layer, and then extending this selection to all k values; this - implies that the selection polygon will effectively be - translated if the pillars are not vertical. - """ - self._select_inside_polygon( CPolyline( init_points = points )) - - @select_method - def select_outside_polygon( self , points , intersect = False): - """ - Will select all points outside polygon. - - See select_inside_polygon for more docuemntation. - """ - self._select_outside_polygon( CPolyline( init_points = points )) - - def deselect_inside_polygon( self , points ): - """ - Will select all points outside polygon. - - See select_inside_polygon for more docuemntation. - """ - self._deselect_inside_polygon( CPolyline( init_points = points )) - - def deselect_outside_polygon( self , points ): - """ - Will select all points outside polygon. - - See select_inside_polygon for more docuemntation. - """ - self._deselect_outside_polygon( CPolyline( init_points = points )) - - - @select_method - def select_true( self , ecl_kw , intersect = False): - """ - Assume that input ecl_kw is a boolean mask. - """ - self._select_true( ecl_kw ) - - - @select_method - def select_false( self , ecl_kw , intersect = False): - """ - Assume that input ecl_kw is a boolean mask. - """ - self._select_false( ecl_kw ) - - - @select_method - def select_from_layer(self , layer , k , value, intersect = False): - """Will select all the cells in in @layer with value @value - at - vertical coordinate @k. - - The input @layer should be of type Layer - from the - ecl.ecl.faults.layer module. The k value must in the range - [0,grid.nz) and the dimensions of the layer must correspond - exactly to nx,ny of the grid. - """ - grid = self.grid - if k < 0 or k >= grid.getNZ(): - raise ValueError("Invalid k value:%d - must be in range [0,%d)" % (k , grid.getNZ())) - - if grid.getNX() != layer.getNX(): - raise ValueError("NX dimension mismatch. Grid:%d layer:%d" % (grid.getNX() , layer.getNX())) - - if grid.getNY() != layer.getNY(): - raise ValueError("NY dimension mismatch. Grid:%d layer:%d" % (grid.getNY() , layer.getNY())) - - self._select_from_layer( layer , k , value ) - - - - ################################################################# - - def scalar_apply_kw( self , target_kw , scalar , func_dict , force_active = False): - - """ - Helper function to apply a function with one scalar arg on target_kw. - """ - data_type = target_kw.data_type - if func_dict.has_key( data_type ): - func = func_dict[ data_type ] - func( target_kw, scalar , force_active ) - else: - raise Exception("scalar_apply_kw() only supported for INT/FLOAT/DOUBLE") - - 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 - optional "mask" argument. - """ - if isinstance(delta_kw , EclKW): - if target_kw.assert_binary( delta_kw ): - self._iadd_kw( target_kw , delta_kw , force_active ) - else: - raise TypeError("Type mismatch") - else: - self.shift_kw( target_kw , delta_kw , force_active = force_active) - - - def shift_kw( self , ecl_kw , shift , force_active = False): - """ - See usage documentation on iadd_kw(). - """ - self.scalar_apply_kw( ecl_kw , shift , {EclDataType.ECL_INT : self._shift_kw_int, - EclDataType.ECL_FLOAT : self._shift_kw_float , - EclDataType.ECL_DOUBLE : self._shift_kw_double} , force_active) - - def isub_kw( self , target_kw , delta_kw , force_active = False): - if isinstance(delta_kw , EclKW): - if target_kw.assert_binary( delta_kw ): - self._isub_kw( target_kw , delta_kw , force_active ) - else: - raise TypeError("Type mismatch") - else: - self.shift_kw( target_kw , -delta_kw , force_active = force_active) - - - def scale_kw( self , ecl_kw , scale , force_active = False): - """ - See usage documentation on iadd_kw(). - """ - self.scalar_apply_kw( ecl_kw , scale , {EclDataType.ECL_INT : self._scale_kw_int, - EclDataType.ECL_FLOAT : self._scale_kw_float , - EclDataType.ECL_DOUBLE : self._scale_kw_double} , force_active) - - def imul_kw(self, target_kw , other , force_active = False): - if isinstance(other , EclKW): - if target_kw.assert_binary( other): - self._imul_kw( target_kw , other ) - else: - raise TypeError("Type mismatch") - else: - self.scale_kw( target_kw , other , force_active ) - - - def idiv_kw( self , target_kw , other , force_active = False): - if isinstance(other , EclKW): - if target_kw.assert_binary( other): - self._idiv_kw( target_kw , other ) - else: - raise TypeError("Type mismatch") - else: - self.scale_kw( target_kw , 1/other , force_active ) - - - def copy_kw( self , target_kw , src_kw , force_active = False): - """ - See usage documentation on iadd_kw(). - """ - if target_kw.assert_binary( src_kw ): - self._copy_kw( target_kw , src_kw , force_active ) - else: - raise TypeError("Type mismatch") - - def set_kw( self , ecl_kw , value , force_active = False): - """ - See usage documentation on iadd_kw(). - """ - self.scalar_apply_kw( ecl_kw , value , {EclDataType.ECL_INT : self._set_kw_int, - EclDataType.ECL_FLOAT : self._set_kw_float , - EclDataType.ECL_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: - return self._sum_kw_float( kw, force_active ) - - if data_type == EclDataType.ECL_INT: - return self._sum_kw_int( kw, force_active ) - - if data_type == EclDataType.ECL_DOUBLE: - return self._sum_kw_double( kw, force_active ) - - if data_type == EclDataType.ECL_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): - """ - Helper function (attribute) to support run-time typechecking. - """ - return True - - - def active_size(self): - return len(self._get_active_list()) - - - def global_size(self): - return len(self._get_global_list()) - - - def get_active_list(self): - """ - IntVector instance with active indices in the region. - """ - active_list = self._get_active_list() - active_list.setParent(self) - return active_list - - - def get_global_list(self): - """ - IntVector instance with global indices in the region. - """ - global_list = self._get_global_list() - global_list.setParent(self) - return global_list - - - def get_ijk_list(self): - """ - WIll return a Python list of (ij,k) tuples for the region. - """ - global_list = self.getGlobalList() - ijk_list = [] - for g in global_list: - ijk_list.append( self.grid.get_ijk( global_index = g ) ) - - return ijk_list - - def contains_ijk( self , i,j,k): - """ - Will check if the cell given by i,j,k is part of the region. - """ - return self._contains_ijk( i , j , k ) - - - def contains_global( self , global_index): - """ - Will check if the cell given by @global_index is part of the region. - """ - return self._contains_global( global_index ) - - - def contains_active( self , active_index): - """ - Will check if the cell given by @active_index is part of the region. - """ - 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) - index_list = IntVector.createCReference( c_ptr, self ) - return index_list - - @property - def name(self): - return self._get_name() - - def get_name(self): - return self._get_name( ) - - 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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_restart_file.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_restart_file.py deleted file mode 100644 index 749f1cd912..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_restart_file.py +++ /dev/null @@ -1,157 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'ecl_restart_file.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCClass - -from ecl.util import monkey_the_camel -from ecl.util import CTime -from ecl.ecl import EclPrototype , EclFile, Ecl3DKW , Ecl3DFile, EclFileEnum - -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) - _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)") - - 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!') - - if not kw_arg is None: - report_step , intehead_kw , doubhead_kw , logihead_kw = kw_arg - c_ptr = self._alloc_from_kw( report_step , intehead_kw , doubhead_kw , logihead_kw ) - else: - c_ptr = self._alloc( rst_view , -1 ) - - super(EclRestartHead, self).__init__(c_ptr) - - - def free(self): - self._free( ) - - def get_report_step(self): - return self._get_report_step( ) - - def get_sim_date(self): - ct = CTime( self._get_sim_time( ) ) - return ct.datetime( ) - - def get_sim_days(self): - return self._get_sim_days( ) - - def well_details(self): - return {"NXCONZ" : self._get_nxconz(), - "NCWMAX" : self._get_ncwmax()} - - - - -class EclRestartFile(Ecl3DFile): - - def __init__(self , grid , filename , flags = 0): - """Will open an Eclipse restart file. - - The EclRestartFile 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. - - The EclRestartFile will use a grid reference to create Ecl3DKw - instances for all the keyword elements which have either - 'nactive' or 'nx*ny*nz' elements. - """ - - file_type , report_step , fmt_file = EclFile.getFileType( filename ) - if not file_type in [EclFileEnum.ECL_RESTART_FILE, EclFileEnum.ECL_UNIFIED_RESTART_FILE]: - 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) - self.rst_headers = None - if file_type == EclFileEnum.ECL_RESTART_FILE: - self.is_unified = False - self.report_step = report_step - else: - self.is_unified = True - - - - def unified(self): - """ - Will return True if the file we have opened is unified. - """ - return self.is_unified - - - def assert_headers(self): - if self.rst_headers is None: - self.rst_headers = [] - if self.unified(): - for index in range(self.num_named_kw("SEQNUM")): - self.rst_headers.append( EclRestartHead( rst_view = self.restartView( seqnum_index = index ))) - else: - intehead_kw = self["INTEHEAD"][0] - doubhead_kw = self["DOUBHEAD"][0] - if "LOGIHEAD" in self: - logihead_kw = self["LOGIHEAD"][0] - else: - logihead_kw = None - - self.rst_headers.append( EclRestartHead( kw_arg = (self.report_step , intehead_kw , doubhead_kw , logihead_kw) )) - - - def time_list(self): - """Will return a list of report_step, simulation time and days. - - The return value will be a list tuples. For a unified restart - file with the three report steps {10,15,20} it can look like: - - [ (10, datetime.datetime( 2010 , 1 , 1 , 0 , 0 , 0 ) , 100.0), - (15, datetime.datetime( 2010 , 3 , 1 , 0 , 0 , 0 ) , 160.0), - (20, datetime.datetime( 2010 , 5 , 1 , 0 , 0 , 0 ) , 220.0) ] - - For a non-unified restart file the list will have only one element. - """ - - self.assertHeaders() - time_list = [] - for header in self.rst_headers: - time_list.append( (header.getReportStep() , header.getSimDate( ) , header.getSimDays( )) ) - - return time_list - - - def headers(self): - self.assertHeaders() - return self.rst_headers - - - def get_header(self, index): - self.assertHeaders() - 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(EclRestartFile, 'assertHeaders', EclRestartFile.assert_headers) -monkey_the_camel(EclRestartFile, 'timeList', EclRestartFile.time_list) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_rft.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_rft.py deleted file mode 100644 index 59dda841cc..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_rft.py +++ /dev/null @@ -1,355 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_rft.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Module for loading ECLIPSE RFT files. -""" - -from __future__ import absolute_import, division, print_function, unicode_literals - -from cwrap import BaseCClass - -from ecl.util import monkey_the_camel -from ecl.util import CTime -from ecl.ecl import EclRFTCell, EclPLTCell, EclPrototype - -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 - for such objects. The three different object types which can be - found in an RFT file are: - - RFT: This is old-fashioned RFT which contains measurements of - saturations for each of the completed cells. - - PLT: This contains production and flow rates for each phase in - each cell. - - SEGMENT: Not implemented. - - In addition to the measurements specific for RFT and PLT each cell - has coordinates, pressure and depth. - """ - TYPE_NAME = "ecl_rft" - _alloc = EclPrototype("void* ecl_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_cell_sorted = EclPrototype("void* ecl_rft_node_iget_cell_sorted( ecl_rft )") - _sort_cells = EclPrototype("void* ecl_rft_node_inplace_sort_cells( 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*)") - _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)") - _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 )") - - - def __init__(self , name , type_string , date , days): - c_ptr = self._alloc( name , type_string , CTime( date ) , days ) - super(EclRFT , self).__init__( c_ptr ) - - - def free(self): - self._free( ) - - def __repr__(self): - rs = [] - rs.append('completed_cells = %d' % len(self)) - rs.append('date = %s' % self.getDate()) - if self.is_RFT(): - rs.append('RFT') - if self.is_PLT(): - rs.append('PLT') - if self.is_SEGMENT(): - rs.append('SEGMENT') - if self.is_MSW(): - rs.append('MSW') - rstr = ', '.join(rs) - return self._create_repr(rstr) - - def __len__(self): - """ - The number of completed cells in this RFT. - """ - return self._get_size( ) - - def is_RFT(self): - """ - Is instance an RFT; in that case all the cells will be EclRFTCell instances. - """ - return self._is_RFT( ) - - def is_PLT(self): - """ - Is instance a PLT; in that case all the cells will be EclPLTCell instances. - """ - return self._is_PLT( ) - - def is_SEGMENT(self): - """ - Is this a SEGMENT - not implemented. - """ - return self._is_SEGMENT( ) - - def is_MSW(self): - """ - Is this well a MSW well. Observe that the test ONLY applies to PLTs. - """ - return self._is_MSW( ) - - - def get_well_name(self): - """ - The name of the well we are considering. - """ - return self._get_well( ) - - def get_date(self): - """ - The date when this RFT/PLT/... was recorded. - """ - ct = CTime(self._get_date( )) - return ct.date() - - def __cell_ref( self , cell_ptr ): - if self.is_RFT(): - return EclRFTCell.createCReference( cell_ptr , self ) - elif self.is_PLT(): - return EclPLTCell.createCReference( cell_ptr , self ) - else: - raise NotImplementedError("Only RFT and PLT cells are implemented") - - - def assert_cell_index( self , index ): - if isinstance( index , int): - length = self.__len__() - if index < 0 or index >= length: - raise IndexError - else: - raise TypeError("Index should be integer type") - - - def __getitem__(self , index): - """Implements the [] operator to return the cells. - - To get the object related to cell nr 5: - - cell = rft[4] - - The return value from the __getitem__() method is either an - EclRFTCell instance or a EclPLTCell instance, depending on the - type of this particular RFT object. - """ - self.assert_cell_index( index ) - cell_ptr = self._iget_cell( index ) - return self.__cell_ref( cell_ptr ) - - - def iget( self , index ): - return self[index] - - - def iget_sorted( self , index ): - """ - Will return the cell nr @index in the list of sorted cells. - - See method sort() for further documentation. - """ - self.assert_cell_index( index ) - cell_ptr = self._iget_cell_sorted( index ) - return self.__cell_ref( cell_ptr ) - - - def sort(self): - """ - Will sort cells in RFT; currently only applies to MSW wells. - - By default the cells in the RFT come in the order they are - specified in the ECLIPSE input file; that is not necessarily - in a suitable order. In the case of MSW wells it is possible - to sort the connections after distance along the wellpath. To - access the cells in sort order you have two options: - - 1. Sort the cells using the sort() method, and then - subsequently access them sequentially: - - rft.sort() - for cell in rft: - print cell - - 2. Let the rft object stay unsorted, but access the cells - using the iget_sorted() method: - - for i in range(len(rft)): - cell = rft.iget_sorted( i ) - - Currently only MSW/PLTs are sorted, based on the CONLENST - keyword; for other wells the sort() method does nothing. - """ - self._sort_cells( ) - - - # ijk are zero offset - def ijkget( self , ijk ): - """ - Will look up the cell based on (i,j,k). - - If the cell (i,j,k) is not part of this RFT/PLT None will be - returned. The (i,j,k) input values should be zero offset, - i.e. you must subtract 1 from the (i,j,k) values given in the ECLIPSE input. - """ - cell_ptr = self._lookup_ijk( ijk[0] , ijk[1] , ijk[2]) - if cell_ptr: - return self.__cell_ref( cell_ptr ) - else: - 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)") - _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)") - _get_num_wells = EclPrototype("int ecl_rft_file_get_num_wells( ecl_rft_file )") - - - """ - The EclRFTFile class is used to load an ECLIPSE 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 - contain data for several wells and several times in one large - container. The EclRFTClass 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 - measurements. The class does not really differentiate between - these. - """ - - def __init__(self , case): - c_ptr = self._load( case ) - super(EclRFTFile , self).__init__(c_ptr) - - - def __len__(self): - return self._get_size( None , CTime(-1)) - - - def __getitem__(self, index): - if isinstance(index, int): - if 0 <= index < len(self): - rft = self._iget(index) - rft.setParent( self ) - return rft - else: - raise IndexError("Index '%d' must be in range: [0, %d]" % (index, len(self) - 1)) - else: - raise TypeError("Index must be integer type") - - - def size(self, well=None, date=None): - """ - The number of elements in EclRFTFile container. - - By default the size() method will return the total number of - RFTs/PLTs in the container, but by specifying the optional - arguments date and/or well the function will only count the - 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 )) - - """ - if date: - cdate = CTime( date ) - else: - cdate = CTime( -1 ) - - return self._get_size( well , cdate) - - - def get_num_wells(self): - """ - Returns the total number of distinct wells in the RFT file. - """ - return self._get_num_wells( ) - - - def get_headers(self): - """ - Returns a list of two tuples (well_name , date) for the whole file. - """ - header_list = [] - for i in (range(self._get_size( None , CTime(-1)))): - rft = self.iget( i ) - header_list.append( (rft.getWellName() , rft.getDate()) ) - return header_list - - - def iget(self , index): - """ - Will lookup RFT @index - equivalent to [@index]. - """ - return self[index] - - - def get(self , well_name , date ): - """ - Will look up the RFT object corresponding to @well and @date. - - Raise Exception if not found. - """ - if self.size( well = well_name , date = date) == 0: - raise KeyError("No RFT for well:%s at %s" % (well_name , date)) - - rft = self._get_rft( well_name , CTime( date )) - rft.setParent( self ) - return rft - - def free(self): - self._free( ) - - def __repr__(self): - w = len(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(EclRFTFile, 'getNumWells', EclRFTFile.get_num_wells) -monkey_the_camel(EclRFTFile, 'getHeaders', EclRFTFile.get_headers) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_rft_cell.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_rft_cell.py deleted file mode 100644 index c875d1f52f..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_rft_cell.py +++ /dev/null @@ -1,171 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_rft_cell.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCClass -from ecl.ecl import EclPrototype - - -class RFTCell(BaseCClass): - """The RFTCell is a base class for the cells which are part of an RFT/PLT. - - 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. - - Observe that from june 2013 the properties i,j and k which return - offset 1 coordinate values are deprecated, and you should rather - use the methods get_i(), get_j() and get_k() which return offset 0 - coordinate values. - """ - 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)") - - - def free(self): - self._free() - - def get_i(self): - return self._get_i() - - def get_j(self): - return self._get_j() - - def get_k(self): - return self._get_k() - - def get_ijk(self): - return (self.get_i(), self.get_j(), self.get_k()) - - @property - def pressure(self): - return self._get_pressure() - - @property - def depth(self): - return self._get_depth() - - -################################################################# - - -class EclRFTCell(RFTCell): - TYPE_NAME = "ecl_rft_cell" - _alloc_RFT = EclPrototype("void* ecl_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)") - - 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) - - @property - def swat(self): - return self._get_swat() - - @property - def sgas(self): - return self._get_sgas() - - @property - def soil(self): - return 1 - (self._get_sgas() + self._get_swat()) - - -################################################################# - - -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)", 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_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_gas_flowrate = EclPrototype("double ecl_rft_cell_get_gas_flowrate(ecl_plt_cell)") - _get_water_flowrate = EclPrototype("double ecl_rft_cell_get_water_flowrate(ecl_plt_cell)") - - _get_conn_start = EclPrototype("double ecl_rft_cell_get_connection_start(ecl_plt_cell)") - _get_conn_end = EclPrototype("double ecl_rft_cell_get_connection_end(ecl_plt_cell)") - - - def __init__(self, i, j, k, depth, pressure, orat, grat, wrat, conn_start, - conn_end, flowrate, oil_flowrate, gas_flowrate, water_flowrate): - c_ptr = self._alloc_PLT(i, j, k, depth, pressure, orat, grat, wrat, - conn_start, conn_end, flowrate, oil_flowrate, - gas_flowrate, water_flowrate) - super(EclPLTCell, self).__init__(c_ptr) - - - @property - def orat(self): - return self._get_orat() - - @property - def grat(self): - return self._get_grat() - - @property - def wrat(self): - return self._get_wrat() - - @property - def conn_start(self): - """Will return the length from wellhead(?) to connection. - - For MSW wells this property will return the distance from a - fixed point (wellhead) to the current connection. This value - will be used to sort the completed cells along the well - path. In the case of non MSW wells this will just return a - fixed default value. - """ - return self._get_conn_start() - - @property - def conn_end(self): - """Will return the length from wellhead(?) to connection end. - - For MSW wells this property will return the distance from a - fixed point (wellhead) to the current connection end. This value - will be used to sort the completed cells along the well - path. In the case of non MSW wells this will just return a - fixed default value. - """ - return self._get_conn_end() - - @property - def flowrate(self): - return self._get_flowrate() - - @property - def oil_flowrate(self): - return self._get_oil_flowrate() - - @property - def gas_flowrate(self): - return self._get_gas_flowrate() - - @property - def water_flowrate(self): - return self._get_water_flowrate() diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_smspec_node.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_smspec_node.py deleted file mode 100644 index 2a903bc964..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_smspec_node.py +++ /dev/null @@ -1,196 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCClass -from ecl.util import monkey_the_camel -from ecl.ecl import EclPrototype - - -class EclSMSPECNode(BaseCClass): - """ - Small class with some meta information about a summary variable. - - The summary variables have different attributes, like if they - represent a total quantity, a rate or a historical quantity. These - quantities, in addition to the underlying values like WGNAMES, - KEYWORD and NUMS taken from the the SMSPEC file are stored in this - structure. - """ - 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)") - - def __init__(self): - super(EclSMSPECNode, self).__init__(0) # null pointer - raise NotImplementedError("Class can not be instantiated directly!") - - def cmp(self, other): - if isinstance(other, EclSMSPECNode): - return self._cmp( other ) - else: - raise TypeError("Other argument must be of type EclSMSPECNode") - - - def __lt__(self , other): - return self.cmp( other ) < 0 - - - def __gt__(self , other): - return self.cmp( other ) > 0 - - - def __eq__(self , other): - return self.cmp( other ) == 0 - - - def __hash__(self , other): - return hash(self._gen_key1( )) - - - @property - def unit(self): - """ - Returns the unit of this node as a string. - """ - return self._node_unit( ) - - @property - def wgname(self): - """ - Returns the WGNAME property for this node. - - 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: ":+:+:+:+". - """ - return self._node_wgname( ) - - - @property - 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 - read from the KEWYORD value; see table 3.4 in the ECLIPSE file - format reference manual. - """ - return self._node_keyword( ) - - @property - def num(self): - return self.getNum( ) - - def get_key1(self): - """ - Returns the primary composite key, i.e. like 'WOPR:OPX' for this - node. - """ - return self._gen_key1( ) - - - def get_key2(self): - """Returns the secondary composite key for this node. - - Most variables have only one composite key, but in particular - nodes which involve (i,j,k) coordinates will contain two - forms: - - getKey1() => "BPR:10,11,6" - getKey2() => "BPR:52423" - - Where the '52423' in getKey2() corresponds to i + j*nx + - k*nx*ny. - """ - return self._gen_key2( ) - - - def var_type(self): - return self._var_type( ) - - - def get_num(self): - """ - Returns the NUMS value for this keyword; or None. - - Many of the summary keywords have an integer stored in the - vector NUMS as an attribute, i.e. the block properties have - the global index of the cell in the nums vector. If the - variable in question makes use of the NUMS value this property - will return the value, otherwise it will return None: - - sum.smspec_node("FOPT").num => None - sum.smspec_node("BPR:1000").num => 1000 - - """ - if self._node_need_num( ): - return self._node_num( ) - else: - return None - - def is_rate(self): - """ - Will check if the variable in question is a rate variable. - - The conecpt of rate variabel is important (internally) when - interpolation values to arbitrary times. - """ - return self._node_is_rate() - - - def is_total(self): - """ - Will check if the node corresponds to a total quantity. - - The question of whether a variable corresponds to a 'total' - quantity or not can be interesting for e.g. interpolation - purposes. The actual question whether a quantity is total or - not is based on a hardcoded list in smspec_node_set_flags() in - smspec_node.c; this list again is based on the tables 2.7 - - 2.11 in the ECLIPSE fileformat documentation. - """ - return self._node_is_total( ) - - - def is_historical(self): - """ - Checks if the key corresponds to a historical variable. - - The check is only based on the last character; all variables - ending with 'H' are considered historical. - """ - 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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_subsidence.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_subsidence.py deleted file mode 100644 index 1299e4b781..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_subsidence.py +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_subsidence.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Calculate dynamic change in gravitational strength. - -The ecl_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. -""" -from cwrap import BaseCClass -from ecl.ecl import EclPrototype -from ecl.util import monkey_the_camel - -class EclSubsidence(BaseCClass): - """ - Holding ECLIPSE results for calculating subsidence changes. - - The EclSubsidence 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. - - Typical use of the EclSubsidence class involves the following steps: - - 1. Create the EclSubsidence 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) - _free = EclPrototype("void ecl_subsidence_free( ecl_subsidence )") - _add_survey_PRESSURE = EclPrototype("void* ecl_subsidence_add_survey_PRESSURE( ecl_subsidence , char* , ecl_file_view )") - _eval = EclPrototype("double ecl_subsidence_eval( ecl_subsidence , char* , char* , ecl_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)") - _has_survey = EclPrototype("bool ecl_subsidence_has_survey( ecl_subsidence , char*)") - - def __init__( self, grid, init_file ): - """ - Creates a new EclSubsidence instance. - - The input arguments @grid and @init_file should be instances - of EclGrid and EclFile 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 ) - - - def __contains__(self , survey_name): - return self._has_survey( survey_name ) - - - - 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 - 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 - 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 ) - - The pore volume is calculated from the initial pore volume and - the PRESSURE keyword from the restart file. - """ - self._add_survey_PRESSURE( survey_name, restart_file) - - - def eval_geertsma(self, base_survey, monitor_survey, pos, youngs_modulus, poisson_ratio, seabed, region=None): - if not base_survey in self: - raise KeyError("No such survey: %s" % base_survey) - - if monitor_survey is not None: - if not monitor_survey in self: - raise KeyError("No such survey: %s" % monitor_survey) - - return self._eval_geertsma(base_survey, monitor_survey, region, pos[0], pos[1], pos[2], youngs_modulus, poisson_ratio, seabed) - - def eval(self, base_survey, monitor_survey, pos, compressibility, poisson_ratio, region=None): - """ - Calculates the subsidence change between two surveys. - - This is the method everything is leading up to; will calculate - the change in subsidence, in centimeters, - between the two surveys named @base_survey and - @monitor_survey. - - The monitor survey can be 'None' - the resulting answer has - nothing whatsovever to do with subsidence, but can be - interesting to determine the numerical size of the quantities - which are subtracted in a 4D study. - - The @pos argument should be a tuple of three elements with the - (utm_x , utm_y , depth) position where we want to evaluate the - change in subsidence. - - If supplied the optional argument @region should be an - EclRegion() 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. - """ - if not base_survey in self: - raise KeyError("No such survey: %s" % base_survey) - - if not monitor_survey in self: - raise KeyError("No such survey: %s" % monitor_survey) - - return self._eval(base_survey, monitor_survey, region, pos[0], pos[1], pos[2], compressibility,poisson_ratio) - - - - def free(self): - self._free( ) - - -monkey_the_camel(EclSubsidence, 'evalGeertsma', EclSubsidence.eval_geertsma) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum.py deleted file mode 100644 index fe6ca681e2..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum.py +++ /dev/null @@ -1,1300 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_sum.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -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. -""" - - -import numpy -import datetime -import os.path - -# 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, CFILE - -from ecl.util import monkey_the_camel -from ecl.util import StringList, CTime, DoubleVector, TimeVector, IntVector - -from ecl.ecl import EclSumTStep -from ecl.ecl import EclSumVarType -from ecl.ecl.ecl_sum_vector import EclSumVector -from ecl.ecl.ecl_smspec_node import EclSMSPECNode -from ecl.ecl import EclPrototype -#, EclSumKeyWordVector - - - - -#import ecl.ecl_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 -# avoid importing the full matplotlib library. The date2num -# implementation could be replaced with: -# -# from matplotlib.dates import date2num - - -HOURS_PER_DAY = 24.0 -MINUTES_PER_DAY = 60 * HOURS_PER_DAY -SECONDS_PER_DAY = 60 * MINUTES_PER_DAY -MUSECONDS_PER_DAY = 1e6 * SECONDS_PER_DAY - -def date2num(dt): - """ - Convert a python datetime instance to UTC float days. - - Convert datetime to the Gregorian date as UTC float days, - preserving hours, minutes, seconds and microseconds, return value - is a float. The function is a verbatim copy of the _to_ordinalf() - function from the matplotlib.dates module. - """ - - if hasattr(dt, 'tzinfo') and dt.tzinfo is not None: - delta = dt.tzinfo.utcoffset(dt) - if delta is not None: - dt -= delta - - base = float(dt.toordinal()) - if hasattr(dt, 'hour'): - base += (dt.hour/HOURS_PER_DAY + - dt.minute/MINUTES_PER_DAY + - dt.second/SECONDS_PER_DAY + - dt.microsecond/MUSECONDS_PER_DAY) - return base - - -class EclSum(BaseCClass): - TYPE_NAME = "ecl_sum" - _fread_alloc_case = EclPrototype("void* ecl_sum_fread_alloc_case__(char*, char*, bool)", bind=False) - _fread_alloc = EclPrototype("void* ecl_sum_fread_alloc(char*, stringlist, char*, bool)", bind=False) - _create_restart_writer = EclPrototype("ecl_sum_obj ecl_sum_alloc_restart_writer(char*, char*, bool, bool, char*, time_t, bool, int, int, int)", bind = False) - _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)") - _scale_vector = EclPrototype("void ecl_sum_scale_vector(ecl_sum, int, double)") - _shift_vector = EclPrototype("void ecl_sum_shift_vector(ecl_sum, int, double)") - _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_mini_step = EclPrototype("int ecl_sum_iget_mini_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*)") - _get_general_var_index = EclPrototype("int ecl_sum_get_general_var_params_index(ecl_sum, char*)") - _get_general_var_from_sim_days = EclPrototype("double ecl_sum_get_general_var_from_sim_days(ecl_sum, double, char*)") - _get_general_var_from_sim_time = EclPrototype("double ecl_sum_get_general_var_from_sim_time(ecl_sum, time_t, char*)") - _solve_days = EclPrototype("double_vector_obj ecl_sum_alloc_days_solution(ecl_sum, char*, double, bool)") - _solve_dates = EclPrototype("time_t_vector_obj ecl_sum_alloc_time_solution(ecl_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)") - _get_first_report_step = EclPrototype("int ecl_sum_get_first_report_step(ecl_sum)") - _select_matching_keys = EclPrototype("void ecl_sum_select_matching_general_var_list(ecl_sum, char*, stringlist)") - _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_simcase = EclPrototype("char* ecl_sum_get_case(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_report_step_from_days = EclPrototype("int ecl_sum_get_report_step_from_days(ecl_sum, double)") - _get_report_time = EclPrototype("time_t ecl_sum_get_report_time(ecl_sum, int)") - _fwrite_sum = EclPrototype("void ecl_sum_fwrite(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)") - _alloc_data_vector = EclPrototype("double_vector_obj ecl_sum_alloc_data_vector(ecl_sum, int, bool)") - _get_var_node = EclPrototype("smspec_node_ref ecl_sum_get_general_var_node(ecl_sum, char*)") - _create_well_list = EclPrototype("stringlist_obj ecl_sum_alloc_well_list(ecl_sum, char*)") - _create_group_list = EclPrototype("stringlist_obj ecl_sum_alloc_group_list(ecl_sum, char*)") - _add_variable = EclPrototype("smspec_node_ref ecl_sum_add_var(ecl_sum, char*, char*, int, char*, double)") - _add_tstep = EclPrototype("ecl_sum_tstep_ref ecl_sum_add_tstep(ecl_sum, int, double)") - _export_csv = EclPrototype("void ecl_sum_export_csv(ecl_sum, char*, stringlist, char*, char*)") - _identify_var_type = EclPrototype("ecl_sum_var_type ecl_sum_identify_var_type(char*)", bind = False) - - - - def __init__(self, load_case, join_string=":", include_restart=True): - """ - Loads a new EclSum 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 - simulation you want to load. @load_case can contain a leading path - component, and also an extension - the latter will be ignored. - - The @join_string is the string used when combining elements - from the WGNAMES, KEYWORDS and NUMS vectors into a composit - key; with @join_string == ":" the water cut in well OP_1 will - be available as "WWCT:OP_1". - - If the @include_restart parameter is set to true the summary - loader will, in the case of a restarted ECLIPSE simulation, - try to load summary results also from the restarted case. - """ - if not load_case: - raise ValueError('load_case must be the basename of the simulation') - c_pointer = self._fread_alloc_case(load_case, join_string, include_restart) - if c_pointer is None: - raise IOError("Failed to create summary instance from argument:%s" % load_case) - - super(EclSum, self).__init__(c_pointer) - self.__private_init() - self._load_case = load_case - - - @classmethod - def load(cls, smspec_file, unsmry_file, key_join_string = ":", include_restart = True): - if not os.path.isfile( smspec_file ): - raise IOError("No such file: %s" % smspec_file) - - if not os.path.isfile( unsmry_file ): - raise IOError("No such file: %s" % unsmry_file ) - - data_files = StringList( ) - data_files.append( unsmry_file ) - c_ptr = cls._fread_alloc(smspec_file, data_files, key_join_string, include_restart) - 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 - - - @classmethod - def createCReference(cls, c_pointer, parent=None): - result = super(EclSum, cls).createCReference(c_pointer, parent) - if not result is None: - result.__private_init() - return result - - - @classmethod - def createPythonObject(cls, c_pointer): - result = super(EclSum, cls).createPythonObject(c_pointer) - result.__private_init() - return result - - - @classmethod - def var_type(cls, keyword): - return cls._identify_var_type(keyword) - - - @staticmethod - def writer(case, start_time, nx,ny,nz, fmt_output=False, unified=True, time_in_days=True, key_join_string=":"): - """ - The writer is not generally usable. - @rtype: EclSum - """ - return EclSum._create_restart_writer(case, None, fmt_output, unified, key_join_string, CTime(start_time), time_in_days, nx, ny, nz) - - @staticmethod - def restart_writer(case, restart_case, start_time, nx,ny,nz, fmt_output=False, unified=True, time_in_days=True, key_join_string=":"): - """ - The writer is not generally usable. - @rtype: EclSum - """ - return EclSum._create_restart_writer(case, restart_case, fmt_output, unified, key_join_string, CTime(start_time), time_in_days, nx, ny, nz) - - def add_variable(self, variable, wgname=None, num=0, unit="None", default_value=0): - return self._add_variable(variable, wgname, num, unit, default_value).setParent(parent=self) - - - def add_t_step(self, report_step, sim_days): - """ @rtype: EclSumTStep """ - sim_seconds = sim_days * 24 * 60 * 60 - return self._add_tstep(report_step, sim_seconds).setParent(parent=self) - - - - def __private_init(self): - # Initializing the time vectors - length = self.length - self.__dates = [0] * length - self.__report_step = numpy.zeros(length, dtype=numpy.int32) - self.__mini_step = numpy.zeros(length, dtype=numpy.int32) - self.__days = numpy.zeros(length) - self.__mpl_dates = numpy.zeros(length) - - for i in range(length): - self.__days[i] = self._iget_sim_days(i) - self.__dates[i] = self.iget_date(i) - self.__report_step[i] = self._iget_report_step(i) - self.__mini_step[i] = self._iget_mini_step(i) - self.__mpl_dates[i] = date2num(self.__dates[i]) - - index_list = self.report_index_list() - - length = len(index_list) - index_list.count(-1) - self.__datesR = [0] * length - self.__report_stepR = numpy.zeros(length, dtype=numpy.int32) - self.__mini_stepR = numpy.zeros(length, dtype=numpy.int32) - self.__daysR = numpy.zeros(length) - self.__mpl_datesR = numpy.zeros(length) - - # Slightly hysterical heuristics to accomoate for the - # situation where there are holes in the report steps series; - # when a report step is completely missing there will be -1 - # entries in the index_list. - i1 = 0 - for i0 in range(length): - while True: - time_index = index_list[i1] - if time_index >= 0: - break - i1 += 1 - - self.__daysR[i0] = self._iget_sim_days(time_index) - self.__datesR[i0] = self.iget_date(time_index) - self.__report_stepR[i0] = self._iget_report_step(time_index) - self.__mini_stepR[i0] = self._iget_mini_step(time_index) - self.__mpl_datesR[i0] = date2num(self.__datesR[i0]) - - - def get_vector(self, key, report_only=False): - """ - Will return EclSumVector according to @key. - - Will raise exception KeyError if the summary object does not - have @key. - """ - self.assertKeyValid(key) - if report_only: - return EclSumVector(self, key, report_only=True) - else: - return EclSumVector(self, key) - - - def report_index_list(self): - """ - Internal function for working with report_steps. - """ - first_report = self.first_report - last_report = self.last_report - index_list = IntVector() - for report_step in range(first_report, last_report + 1): - time_index = self._get_report_end(report_step) - index_list.append(time_index) - return index_list - - - - def wells(self, pattern=None): - """ - Will return a list of all the well names in case. - - If the pattern variable is different from None only wells - matching the pattern will be returned; the matching is based - on fnmatch(), i.e. shell style wildcards. - """ - return self._create_well_list(pattern) - - - def groups(self, pattern=None): - """ - Will return a list of all the group names in case. - - If the pattern variable is different from None only groups - matching the pattern will be returned; the matching is based - on fnmatch(), i.e. shell style wildcards. - """ - return self._create_group_list(pattern) - - - def get_values(self, key, report_only=False): - """ - Will return numpy vector of all values according to @key. - - 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 - instance. - """ - if self.has_key(key): - key_index = self._get_general_var_index(key) - if report_only: - index_list = self.report_index_list() - values = numpy.zeros(len(index_list)) - for i in range(len(index_list)): - time_index = index_list[i] - values[i] = self._iiget(time_index, key_index) - else: - length = self._data_length() - values = numpy.zeros(length) - for i in range(length): - values[i] = self._iiget(i, key_index) - - return values - else: - raise KeyError("Summary object does not have key:%s" % key) - - - def get_key_index(self, key): - """ - Lookup parameter index of @key. - - All the summary keys identified in the SMSPEC file have a - corresponding index which is used internally. This function - will return that index for input key @key, this can then be - used in subsequent calls to e.g. the iiget() method. This is a - 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) - - Quite low-level function, should probably rather use a - EclSumVector based function? - """ - index = self._get_general_var_index(key) - if index >= 0: - return index - else: - return None - - - def get_last_value(self, key): - """ - Will return the last value corresponding to @key. - - Typically useful to get the total production at end of - simulation: - - total_production = sum.last_value("FOPT") - - The alternative method 'last' will return a EclSumNode - instance with some extra time related information. - """ - return self[key].last_value - - def get_last(self, key): - """ - Will return the last EclSumNode corresponding to @key. - - If you are only interested in the final value, you can use the - get_last_value() method. - """ - return self[key].last - - - def iiget(self, time_index, key_index): - """ - Lookup a summary value based on naive @time_index and - @key_index. - - The iiget() method will lookup a summary value based on the - 'time' value give by @time_index (i.e. naive counting of - time steps starting at zero), and a key index given by - @key_index. The @key_index value will typically be obtained - 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. - """ - return self._iiget(time_index, key_index) - - - def iget(self, key, time_index): - """ - Lookup summary value based on @time_index and key. - - The @time_index value should be an integer [0,num_steps) and - @key should be string key. To get all the water cut values - from a well: - - for time_index in range(sum.length): - wwct = sum.iget(time_index, "WWCT:W5") - - This is a quite low level function, in most cases it will be - natural to go via e.g. an EclSumVector instance. - """ - return self._get_general_var(time_index, key) - - - def __len__(self): - """ - The number of timesteps in the dataset; the return when evaluating - len(case). - - """ - return self._data_length() - - - def __contains__(self, key): - if self._has_key(key): - return True - else: - return False - - def assert_key_valid(self, key): - if not key in self: - raise KeyError("The summary key:%s was not recognized" % key) - - def __iter__(self): - return iter(self.keys()) - - def __getitem__(self, key): - """ - Implements [] operator - @key should be a summary key. - - The returned value will be a EclSumVector instance. - """ - return self.get_vector(key) - - def scale_vector(self, key, scalar): - """ecl_sum.scaleVector("WOPR:OPX", 0.78) - will scale all the elements in the 'WOPR:OPX' vector with 0.78. - """ - if not key in self: - raise KeyError("Summary object does not have key:%s" % key) - - key_index = self._get_general_var_index(key) - self._scale_vector(key_index, float(scalar)) - - def shift_vector(self, key, addend): - """ecl_sum.shiftVector("WOPR:OPX", 0.78) - will shift (add) all the elements in the 'WOPR:OPX' vector with 0.78. - """ - if not key in self: - raise KeyError("Summary object does not have key:%s" % key) - key_index = self._get_general_var_index(key) - self._shift_vector(key_index, float(addend)) - - def check_sim_time(self, date): - """ - Will check if the input date is in the time span [sim_start, sim_end]. - """ - if not isinstance(date, CTime): - date = CTime(date) - return self._check_sim_time(date) - - def get_interp_direct(self,key, date): - - if not isinstance(date, CTime): - date = CTime(date) - return self._get_general_var_from_sim_time(date, key) - - def get_interp(self, key, days=None, date=None): - """ - Will lookup vector @key at time given by @days or @date. - - Requiers exactly one input argument @days or @date; will raise - exception ValueError if this is not satisfied. - - The method will check that the time argument is within the - time limits of the simulation; if else the method will raise - exception ValueError. - - Also available as method get_interp() on the EclSumVector - class. - """ - self.assertKeyValid(key) - if days is None and date is None: - raise ValueError("Must supply either days or date") - - if days is None: - t = CTime(date) - if self.check_sim_time(t): - return self._get_general_var_from_sim_time(t, key) - else: - - raise ValueError("date:%s is outside range of simulation data" % date) - elif date is None: - if self._check_sim_days(days): - return self._get_general_var_from_sim_days(days, key) - else: - raise ValueError("days:%s is outside range of simulation: [%g,%g]" % (days, self.first_day, self.sim_length)) - else: - raise ValueError("Must supply either days or date") - - - def get_interp_row(self, key_list, sim_time): - ctime = CTime(sim_time) - data = DoubleVector( initial_size = len(key_list) ) - EclSum._get_interp_vector(self, ctime, key_list, data) - return data - - - def time_range(self, start=None, end=None, interval="1Y", extend_end=True): - (num, timeUnit) = TimeVector.parseTimeUnit(interval) - - if start is None: - start = self.getDataStartTime() - else: - if isinstance(start, datetime.date): - start = datetime.datetime(start.year, start.month, start.day, 0, 0, 0) - - if start < self.getDataStartTime(): - start = self.getDataStartTime() - - - if end is None: - end = self.getEndTime() - else: - if isinstance(end, datetime.date): - end = datetime.datetime(end.year, end.month, end.day, 0, 0, 0) - - if end > self.getEndTime(): - end = self.getEndTime() - - if end < start: - raise ValueError("Invalid time interval start after end") - - - range_start = start - range_end = end - if not timeUnit == "d": - year1 = start.year - year2 = end.year - month1 = start.month - month2 = end.month - day1 = start.day - day2 = end.day - if extend_end: - if timeUnit == 'm': - if day2 > 1: - month2 += 1 - if month2 == 13: - year2 += 1 - month2 = 1 - elif timeUnit == "y": - month1 = 1 - if year2 > 1 or day2 > 1: - year2 += 1 - month2 = 1 - day1 = 1 - day2 = 1 - - range_start = datetime.date(year1, month1, day1) - range_end = datetime.date(year2, month2, day2) - - trange = TimeVector.createRegular(range_start, range_end, interval) - - # If the simulation does not start at the first of the month - # the start value will be before the simulation start; we - # manually shift the first element in the trange to the start - # value; the same for the end of list. - - if trange[-1] < end: - if extend_end: - trange.appendTime(num, timeUnit) - else: - trange.append(end) - - data_start = self.getDataStartTime() - if trange[0] < data_start: - trange[0] = CTime(data_start) - - return trange - - - - def blocked_production(self, totalKey, timeRange): - node = self.smspec_node(totalKey) - if node.isTotal(): - total = DoubleVector() - for t in timeRange: - if t < CTime(self.start_time): - total.append(0) - elif t >= CTime(self.end_time): - total.append(self.get_last_value(totalKey)) - else: - total.append(self.get_interp(totalKey, date=t)) - tmp = total << 1 - total.pop() - return tmp - total - else: - raise TypeError("The blockedProduction method must be called with one of the TOTAL keys like e.g. FOPT or GWIT") - - - def get_report(self, date=None, days=None): - """ - Will return the report step corresponding to input @date or @days. - - If the input argument does not correspond to any report steps - the function will return -1. Observe that the function - requires strict equality. - """ - if date: - if days: - raise ValueError("Must supply either days or date") - step = self._get_report_step_from_time(CTime(date)) - elif days: - step = self._get_report_step_from_days(days) - - return step - - - def get_report_time(self, report): - """ - Will return the datetime corresponding to the report_step @report. - """ - return CTime(self._get_report_time(report)).date() - - - def get_interp_vector(self, key, days_list=None, date_list=None): - """ - Will return numpy vector with interpolated values. - - Requiers exactly one input argument @days or @date; will raise - exception ValueError if this is not satisfied. - - The method will check that the time arguments are within the - time limits of the simulation; if else the method will raise - exception ValueError. - - Also available as method get_interp_vector() on the - EclSumVector class. - """ - self.assertKeyValid(key) - if days_list: - if date_list: - raise ValueError("Must supply either days_list or date_list") - else: - vector = numpy.zeros(len(days_list)) - sim_length = self.sim_length - sim_start = self.first_day - index = 0 - for days in days_list: - if (days >= sim_start) and (days <= sim_length): - vector[index] = self._get_general_var_from_sim_days(days, key) - else: - raise ValueError("Invalid days value") - index += 1 - elif date_list: - start_time = self.data_start - end_time = self.end_date - vector = numpy.zeros(len(date_list)) - index = 0 - - for date in date_list: - ct = CTime(date) - if start_time <= ct <= end_time: - vector[index] = self._get_general_var_from_sim_time(ct, key) - else: - raise ValueError("Invalid date value") - index += 1 - else: - raise ValueError("Must supply either days_list or date_list") - return vector - - - def get_from_report(self, key, report_step): - """ - Return summary value of @key at time @report_step. - """ - time_index = self._get_report_end(report_step) - return self._get_general_var(time_index, key) - - - def has_key(self, key): - """ - Check if summary object has key @key. - """ - return key in self - - - def smspec_node(self, key): - """ - Will return a EclSMSPECNode instance corresponding to @key. - - The returned EclSMPECNode 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. - """ - if self.has_key(key): - node = self._get_var_node(key).setParent(self) - return node - else: - raise KeyError("Summary case does not have key:%s" % key) - - - def unit(self, key): - """ - Will return the unit of @key. - """ - node = self.smspec_node(key) - return node.unit - - - @property - def case(self): - """ - Will return the case name of the current instance - optionally including path. - """ - return self._get_simcase() - - - @property - def path(self): - """ - Will return the path to the current case. Will be None for - case in CWD. See also abs_path. - """ - return self._get_path() - - @property - def base(self): - """ - Will return the basename of the current case - no path. - """ - return self._get_base() - - @property - def abs_path(self): - """ - Will return the absolute path to the current case. - """ - return self._get_abs_path() - - #----------------------------------------------------------------- - # Here comes functions for getting vectors of the time - # dimension. All the get_xxx() functions have an optional boolean - # argument @report_only. If this argument is set to True the - # functions will return time vectors only corresponding to the - # report times. - # - # In addition to the get_xxx() methods there are properties with - # the same name (excluding the 'get'); these properties correspond - # to an get_xxx() invocation with optional argument report_only - # set to False (i.e. the defualt). - - @property - def days(self): - """ - Will return a numpy vector of simulations days. - """ - return self.get_days(False) - - def get_days(self, report_only=False): - """ - Will return a numpy vector of simulations days. - - If the optional argument @report_only is set to True, only - 'days' values corresponding to report steps will be included. - """ - if report_only: - return self.__daysR - else: - return self.__days - - @property - def dates(self): - """ - Will return a list of simulation dates. - - The list will be an ordinary Python list, and the dates will - be in terms ordinary Python datetime values. - """ - return self.get_dates(False) - - def get_dates(self, report_only=False): - """ - Will return a list of simulation dates. - - The list will be an ordinary Python list, and the dates will - be in terms ordinary Python datetime values. If the optional - argument @report_only is set to True, only dates corresponding - to report steps will be included. - """ - if report_only: - return self.__datesR - else: - return self.__dates - - @property - def mpl_dates(self): - """ - Will return a numpy vector of dates ready for matplotlib - - The content of the vector are dates in matplotlib format, - i.e. floats - generated by the date2num() function at the top - of this file. - """ - return self.get_mpl_dates(False) - - def get_mpl_dates(self, report_only=False): - """ - Will return a numpy vector of dates ready for matplotlib - - If the optional argument @report_only is set to True, only - dates values corresponding to report steps will be - included. The content of the vector are dates in matplotlib - format, i.e. floats - generated by the date2num() function at - the top of this file. - """ - if report_only: - return self.__mpl_datesR - else: - return self.__mpl_dates - - @property - def mini_step(self): - """ - Will return a a python list of ministep values. - - Will return a Python list of ministep values from this summary - case; the ministep values are the internal indexing of - timesteps provided by the reservoir simulator. In normal cases - this will be: [0,1,2,3,4,5,....], but in the case of restarted - simulations it can start at a higher value, and there can also - be 'holes' in the series if 'RPTONLY' has been used in THE - ECLIPSE datafile. - """ - return self.get_mini_step(False) - - def get_mini_step(self, report_only=False): - """ - Will return a a python list of ministep values. - - If the optional argument @report_only is set to True, only - dates values corresponding to report steps will be - included. See documentation of property: 'mini_step' for - further documentation. - """ - if report_only: - return self.__mini_stepR - else: - return self.__mini_step - - - @property - def report_step(self): - """ - Will return a list of report steps. - - The simulator will typically use several simulation timesteps - for each report step, and the number will change between - different report steps. So - assuming that the first report - step one has five simulations timesteps and the next two have - three the report_step vector can look like: - - [...,1,1,1,1,1,2,2,2,3,3,3,....] - - """ - return self.get_report_step(False) - - def get_report_step(self, report_only=False): - if report_only: - return self.__report_stepR - else: - return self.__report_step - - #----------------------------------------------------------------- - - def iget_days(self, time_index): - """ - Returns the number of simulation days for element nr @time_index. - """ - return self._iget_sim_days(time_index) - - def iget_date(self, time_index): - """ - Returns the simulation date for element nr @time_index. - """ - long_time = self._iget_sim_time(time_index) - ct = CTime(long_time) - return ct.datetime() - - - def iget_report(self, time_index): - """ - Returns the report step corresponding to @time_index. - - One report step will in general contain many ministeps. - """ - return self._iget_report_step(time_index) - - - @property - def length(self): - """ - The number of timesteps in the dataset. - """ - return self._data_length() - - @property - def first_day(self): - """ - The first day we have simulation data for; normally 0. - """ - return self._get_first_day() - - @property - def sim_length(self): - return self.getSimulationLength() - - @property - def start_date(self): - """ - A Python date instance with the start date. - - The start time is taken from the SMSPEC file, and in case not - all timesteps have been loaded, e.g. for a restarted case, the - returned start_date might be different from the datetime of - the first (loaded) timestep. - """ - ct = self._get_start_date() - return CTime(ct).date() - - - @property - def end_date(self): - """ - The date of the last (loaded) time step. - """ - return CTime(self._get_end_date()).date() - - - - @property - def data_start(self): - return self.getDataStartTime() - - - - @property - def end_time(self): - """ - The time of the last (loaded) time step. - """ - return self.getEndTime() - - - @property - def start_time(self): - return self.getStartTime() - - - def get_data_start_time(self): - """The first date we have data for. - - Thiw will mostly be equal to getStartTime(), but in the case - of restarts, where the case we have restarted from is not - found, this time will be later than the true start of the - field. - """ - return CTime(self._get_data_start()).datetime() - - - - def get_start_time(self): - """ - A Python datetime instance with the start time. - - See start_date() for further details. - """ - return CTime(self._get_start_date()).datetime() - - - def get_end_time(self): - """ - A Python datetime instance with the last loaded time. - """ - return CTime(self._get_end_date()).datetime() - - def getSimulationLength(self): - """ - The length of the current dataset in simulation days. - - Will include the length of a leading restart section, - irrespective of whether we have data for this or not. - """ - return self._sim_length() - - - - @property - def last_report(self): - """ - The number of the last report step in the dataset. - """ - return self._get_last_report_step() - - @property - def first_report(self): - """ - The number of the first report step in the dataset. - """ - return self._get_first_report_step() - - def first_gt_index(self, key, limit): - """ - Returns the first index where @key is above @limit. - """ - key_index = self._get_general_var_index(key) - time_index = self._get_first_gt(key_index, limit) - return time_index - - def first_lt_index(self, key, limit): - """ - Returns the first index where @key is below @limit. - """ - key_index = self._get_general_var_index(key) - time_index = self._get_first_lt(key_index, limit) - return time_index - - def first_gt(self, key, limit): - """ - First EclSumNode 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. - """ - vector = self[key] - return vector.first_lt(limit) - - def solve_dates(self, key, value, rates_clamp_lower=True): - """Will solve the equation vector[@key] == value for dates. - - See solveDays() for further details. - """ - if not key in self: - raise KeyError("Unrecognized key:%s" % key) - - if len(self) < 2: - raise ValueError("Must have at least two elements to start solving") - - return [ x.datetime() for x in self._solve_dates(key, value, rates_clamp_lower)] - - - def solve_days(self, key, value, rates_clamp_lower=True): - """Will solve the equation vector[@key] == value. - - This method will solve find tha approximate simulation days - 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") - days = case.solveDays("RPR:2", 200) - - if len(days) == 0: - print("Pressure was never equal to 200 BARSA") - elif len(days) == 1: - print("Pressure equal to 200 BARSA after %s simulation days" % days[0]) - else: - print("Pressure equal to 200 BARSA multiple times") - for index,day in enumerate(days): - print("Solution[%d] : %s days" % (index, day)) - - For variables like pressure and total volumes the solution is - based on straightforward linear interpolation between the - simulated values; that is quite intuitive. However - rates is - less intuitive, and how a rate like FOPR is handled can be - surprising: - - Fundamentally the simulator works with *volumes*. Assume that - the simulator calculates that between the times t1 and t2 the - total volume of oil produced is V, then the oil production - rate is given as: - - FOPR = V / (t2 - t1) - - This is the average production rate in the timespan (t1,t2]; - the simulator does not have any information on a finer time - scale than this - so the natural assumption is that the - production is constant at this value for the whole time - period. The logical consequence of this is that production - rates should be visualized as a piecewise constant function: - - - - A B - | | - /|\ OPR | | - | \|/ \|/ - | - | +============X - | | | - |-------------------------------------------------- X - | | | - | +=============X - | | - | | +===========X - |=========X | - | - +---------+-------------+------------+-----------+--> - t0 t1 t2 t3 t4 time - - - This figure shows a plot of the OPR as a piecewise constant - function. In a strict mathematical sense the equation: - - OPR = X - - Does not have a solution at all, but since this inequality: - - OPR(t2) < X < OPR(t3) - - it is natural to say that the equation has a solution. The - default behaviour is to say that the (first) solution in this - case is: - - tx = t2 + epsilon - - corresponding to the arrow 'A' on the figure. Alternatively if - you set the optional argument 'rates_clamp_lower' to false the - method will find the solution: - - tx = t3 - - corresponding to the arrow 'B* in the figure. - - """ - if not key in self: - raise KeyError("Unrecognized key:%s" % key) - - if len(self) < 2: - raise ValueError("Must have at least two elements to start solving") - - return self._solve_days(key, value, rates_clamp_lower) - - - def keys(self, pattern=None): - """ - Return a StringList of summary keys matching @pattern. - - The matching algorithm is ultimately based on the fnmatch() - function, i.e. normal shell-character syntax is used. With - @pattern == "WWCT:*" you will get a list of watercut keys for - all wells. - - If pattern is None you will get all the keys of summary - object. - """ - s = StringList() - self._select_matching_keys(pattern, s) - return s - - - - - def fwrite(self, ecl_case=None): - if ecl_case: - self._set_case(ecl_case) - - self._fwrite_sum() - - - def alloc_time_vector(self, report_only): - return self._alloc_time_vector(report_only) - - def alloc_data_vector(self, data_index, report_only): - return self._alloc_data_vector(data_index, report_only) - - def get_general_var_index(self, key): - return self._get_general_var_index(key) - - def free(self): - self._free() - - def _nicename(self): - """load_case is often full path to summary file, - if so, output basename, else name - """ - name = self._load_case - if name and os.path.isfile(name): - name = os.path.basename(name) - return name - - 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 - """ - name = self._nicename() - s_time = self.getStartTime() - e_time = self.getEndTime() - num_keys = len(self.keys()) - content = 'name="%s", time=[%s, %s], keys=%d' % (name, s_time, e_time, num_keys) - return self._create_repr(content) - - def dump_csv_line(self, time, keywords, pfile): - """ - Will dump a csv formatted line of the keywords in @keywords, - evaluated at the intertpolated time @time. @pfile should point to an open Python file handle. - """ - cfile = CFILE(pfile) - ctime = CTime(time) - EclSum._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. - - By default all the vectors in the summary case will be - 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"]) - - Will export all well related variables for wells 'OP1' and - 'OP2' and all total field vectors. - """ - - if keys is None: - var_list = self.keys() - else: - var_list = StringList() - for key in keys: - var_list |= self.keys(pattern=key) - self._export_csv(filename, var_list, date_format, sep) - - - - -import ecl.ecl.ecl_sum_keyword_vector -EclSum._dump_csv_line = EclPrototype("void ecl_sum_fwrite_interp_csv_line(ecl_sum, time_t, ecl_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)", 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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_keyword_vector.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_keyword_vector.py deleted file mode 100644 index 1dea8aaa7a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_keyword_vector.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_sum_keyword_vector.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -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 import monkey_the_camel -from ecl.ecl import EclPrototype - - - -class EclSumKeyWordVector(BaseCClass): - TYPE_NAME = "ecl_sum_vector" - _alloc = EclPrototype("void* ecl_sum_vector_alloc(ecl_sum)", bind=False) - _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): - c_pointer = self._alloc(ecl_sum) - 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)) - -monkey_the_camel(EclSumKeyWordVector, 'addKeyword', EclSumKeyWordVector.add_keyword) -monkey_the_camel(EclSumKeyWordVector, 'addKeywords', EclSumKeyWordVector.add_keywords) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_node.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_node.py deleted file mode 100644 index ed4ccfc680..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_node.py +++ /dev/null @@ -1,28 +0,0 @@ -class EclSumNode(object): - - def __init__(self, mini_step, report_step, days, date, mpl_date, value): - """ - EclSumNode 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: - - value : The actual value - report_step : The report step - mini_step : The ministep - days : Days since simulation start - date : The simulation date - mpl_date : A date format suitable for matplotlib - - """ - self.value = value - self.report_step = report_step - self.mini_step = mini_step - self.days = days - self.date = date - self.mpl_date = mpl_date - - def __repr__(self): - return "EclSumNode(days=%d, value=%g)" % (self.days, self.value) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_tstep.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_tstep.py deleted file mode 100644 index 3a759ae9c5..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_tstep.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCClass - -from ecl.util import monkey_the_camel -from ecl.util import CTime -from ecl.ecl import EclPrototype - - - -class EclSumTStep(BaseCClass): - TYPE_NAME = "ecl_sum_tstep" - _alloc = EclPrototype("void* ecl_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)") - _get_from_key = EclPrototype("double ecl_sum_tstep_get_from_key(ecl_sum_tstep, char*)") - _has_key = EclPrototype("bool ecl_sum_tstep_has_key(ecl_sum_tstep)") - - - - 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) - - - def get_sim_days(self): - """ @rtype: double """ - return self._get_sim_days() - - def get_report(self): - """ @rtype: int """ - return self._get_report() - - def get_mini_step(self): - """ @rtype: int """ - return self._get_ministep() - - def get_sim_time(self): - """ @rtype: CTime """ - return self._get_sim_time() - - def __getitem__(self, key): - """ @rtype: double """ - if not key in self: - raise KeyError("Key '%s' is not available." % key) - - return self._get_from_key(key) - - def __setitem__(self, key, value): - if not key in self: - raise KeyError("Key '%s' is not available." % key) - - self._set_from_key(key, value) - - def __contains__(self, key): - return self._has_key(key) - - def free(self): - self._free(self) - -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) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_var_type.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_var_type.py deleted file mode 100644 index d9f9e8cf99..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_var_type.py +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# The file 'ecl_sum_var_type.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCEnum -from ecl.ecl import ECL_LIB - - -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/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_vector.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_vector.py deleted file mode 100644 index 5cde9f119a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_sum_vector.py +++ /dev/null @@ -1,304 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import print_function -import warnings -from ecl.ecl.ecl_sum_node import EclSumNode - - -class EclSumVector(object): - def __init__(self, parent, key, report_only = False): - """ - A summary vector with a vector of values and time. - - 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 time values, or only those corresponding to report_steps. - - The EclSumVector contains a reference to the parent EclSum - structure and this is used to implement several of the - properties and methods of the object; the EclSum vector - instances should therefor only be instantiated through the - EclSum.get_vector() method, and not manually with the - EclSumVector() constructor. - """ - self.parent = parent - self.key = key - self.report_only = report_only - - if report_only: - warnings.warn("The report_only flag to the EclSumVector will be removed", DeprecationWarning) - - self.__dates = parent.get_dates(report_only) - self.__days = parent.get_days(report_only) - self.__mpl_dates = parent.get_mpl_dates(report_only) - self.__mini_step = parent.get_mini_step(report_only) - self.__report_step = parent.get_report_step(report_only) - self.__values = None - - - def __str__(self): - return "" % self.key - - def __repr__(self): - return 'EclSumVector(key = %s, size = %d, unit = %s)' % (self.key, len(self), self.unit) - - @property - def unit(self): - """ - The unit of this vector. - """ - return self.parent.unit(self.key) - - def assert_values(self): - """ - This function will load and internalize all the values. - """ - if self.__values is None: - self.__values = self.parent.get_values(self.key, self.report_only) - - @property - def values(self): - """ - All the summary values of the vector, as a numpy vector. - """ - self.assert_values() - return self.__values - - @property - def dates(self): - """ - All the dates of the vector, list of datetime() instances. - """ - return self.__dates - - @property - def days(self): - """ - The time in days as a numpy vector. - - In the case of lab unit this will be hours. - """ - return self.__days - - @property - def mpl_dates(self): - """ - All the dates as numpy vector of dates in matplotlib format. - """ - return self.__mpl_dates - - @property - def mini_step(self): - """ - All the ministeps of the vector. - - Ministeps is the ECLIPSE notion of timesteps. The ministeps - are numbered sequentially starting at zero; if you have loaded - the entire simulation the ministep number will correspond to - the natural indexing. The length of each ministep is - determined by the convergence properties of the ECLIPSE - simulation. - """ - return self.__mini_step - - @property - def report_step(self): - """ - All the report_step of the vector. - """ - return self.__report_step - - - def __iget(self, index): - """ - Will return an EclSumNode for element @index; should be called - through the [] operator, otherwise you can come across - unitialized data. - """ - return EclSumNode(self.__mini_step[index], - self.__report_step[index], - self.__days[index], - self.__dates[index], - self.__mpl_dates[index], - self.__values[index]) - - - def __len__(self): - """ - The length of the vector - used for the len() builtin. - """ - return len(self.__days) - - - def __getitem__(self, index): - """ - Implements the [] operator. - - Will return EclSumNode 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. - """ - self.assert_values() - length = len(self.values) - if isinstance(index, int): - if index < 0: - index += len(self.__values) - if index < 0 or index > length: - raise KeyError("Invalid index:%d out of range [0:%d)" % (index, length)) - else: - 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. - (start, stop, step) = index.indices(length) - index = start - sub_vector = [] - while index < stop: - sub_vector.append(self.__iget(index)) - index += step - return sub_vector - - raise KeyError("Invalid index:%s - must have integer or slice." % index) - - @property - def first(self): - """ - Will return the first EclSumNode in this vector. - """ - self.assert_values() - return self.__iget(0) - - @property - def last(self): - """ - Will return the last EclSumNode in this vector. - """ - self.assert_values() - - index = len(self.__values) - 1 - return self.__iget(index) - - @property - def last_value(self): - """ - Will return the last value in this vector. - """ - self.assert_values() - - index = len(self.__values) - 1 - return self.__iget(index).value - - - def get_interp(self, days=None, date=None): - """ - Will lookup value interpolated to @days or @date. - - The function requires one, and only one, time indicator in - terms of @days or @date. If the @date variable is given that - should be Python datetime instance. - - vec = sum["WWCT:A-3"] - vec.get_interp(days = 100) - vec.get_interp(date = datetime.date(year, month, day)) - - This function will crash and burn if the time arguments are - invalid; if in doubt you should check first. - """ - return self.parent.get_interp(self.key, days, date) - - - def get_interp_vector(self, days_list=None, date_list=None): - """ - Will return Python list of interpolated values. - - See get_interp() for further details. - """ - return self.parent.get_interp_vector(self.key, days_list, date_list) - - - def get_from_report(self, report_step): - """ - Will lookup the value based on @report_step. - """ - return self.parent.get_from_report(self.key, report_step) - - ################################################################# - - def first_gt_index(self, limit): - """ - Locates first index where the value is above @limit. - - Observe that this method will raise an exception if it is - called from a vector instance with report_only = True. - """ - if not self.report_only: - key_index = self.parent._get_general_var_index(self.key) - time_index = self.parent._get_first_gt(key_index, limit) - return time_index - else: - raise Exception("Sorry - first_gt_index() can not be called for vectors with report_only=True") - - def first_gt(self, limit): - """ - Locate the first EclSumNode where value is above @limit. - - vec = sum["WWCT:A-3"] - w = vec.first_gt(0.50) - print('Water cut above 0.50 in well A-3 at: %s' % w.date) - - Uses first_gt_index() internally and can not be called for - vectors with report_only = True. - """ - time_index = self.first_gt_index(limit) - print(time_index) - if time_index >= 0: - return self.__iget(time_index) - else: - return None - - def first_lt_index(self, limit): - """ - Locates first index where the value is below @limit. - - See first_gt_index() for further details. - """ - if not self.report_only: - key_index = self.parent._get_general_var_index(self.key) - time_index = self.parent._get_first_lt(key_index, limit) - return time_index - else: - raise Exception("Sorry - first_lt_index() can not be called for vectors with report_only=True") - - def first_lt(self, limit): - """ - Locates first element where the value is below @limit. - - See first_gt() for further details. - """ - time_index = self.first_lt_index(limit) - if time_index >= 0: - return self.__iget(time_index) - else: - return None diff --git a/ThirdParty/Ert/python/python/ecl/ecl/ecl_type.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_type.py deleted file mode 100644 index 1ac3cc6556..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_type.py +++ /dev/null @@ -1,184 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# The file 'ecl_type.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCClass, BaseCEnum -from ecl.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_ctype_fortio_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/ThirdParty/Ert/python/python/ecl/ecl/ecl_util.py b/ThirdParty/Ert/python/python/ecl/ecl/ecl_util.py deleted file mode 100644 index b7f4f19b05..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/ecl_util.py +++ /dev/null @@ -1,166 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ecl_util.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -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. -""" - -import ctypes - -from cwrap import BaseCEnum -from ecl.util import monkey_the_camel -from ecl.ecl import EclPrototype, ECL_LIB - -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_CLOSE_STREAM = None - ECL_FILE_WRITABLE = None - -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/ThirdParty/Ert/python/python/ecl/ecl/faults/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/ecl/faults/CMakeLists.txt deleted file mode 100644 index d7955a8c6e..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - fault_block.py - fault_block_layer.py - fault_collection.py - fault.py - fault_line.py - fault_segments.py - layer.py -) - -add_python_package("python.ecl.ecl.faults" ${PYTHON_INSTALL_PREFIX}/ecl/ecl/faults "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/__init__.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/__init__.py deleted file mode 100644 index cc9670e15c..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from .layer import Layer -from .fault_collection import FaultCollection -from .fault import Fault -from .fault_line import FaultLine -from .fault_segments import FaultSegment , SegmentMap -from .fault_block import FaultBlock , FaultBlockCell -from .fault_block_layer import FaultBlockLayer diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/fault.py deleted file mode 100644 index ae62f8b582..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault.py +++ /dev/null @@ -1,654 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'fault.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.util import monkey_the_camel -from ecl.util import stat -from ecl.util import Matrix -from ecl.geo import Polyline, CPolyline, GeometryTools - -from .fault_line import FaultLine -from .fault_segments import FaultSegment, SegmentMap - - -class FaultLayer(object): - def __init__(self, grid, K): - assert(isinstance(K, int)) - self.__grid = grid - self.__K = K - self.__fault_lines = [] - self.__segment_map = SegmentMap() - self.__processed = False - - - def add_segment(self, segment): - self.__segment_map.addSegment(segment) - self.__processed = False - - def __len__(self): - self.processSegments() - return len(self.__fault_lines) - - def __iter__(self): - self.processSegments() - return iter(self.__fault_lines) - - def __getitem__(self, index): - self.processSegments() - return self.__fault_lines[index] - - def get_k(self): - return self.__K - - @property - def k(self): - return self.__K - - - def get_neighbor_cells(self): - neighbor_cells = [] - for fl in self: - neighbor_cells += fl.getNeighborCells() - return neighbor_cells - - def get_polyline(self, name=None): - polyline = CPolyline(name=name) - for fl in self: - polyline += fl.getPolyline() - return polyline - - - def get_ij_polyline(self): - """ - Will return a python list of (int,int) tuple. - """ - polyline = [] - for fl in self: - polyline += fl.getIJPolyline() - return polyline - - - def num_lines(self): - return len(self) - - def __sort_fault_lines(self): - """A fault can typically consist of several non connected fault - segments; right after reading the fault input these can be in - a complete mess: - - 1. The different part of the fault can be in random order. - - 2. Within each fault line the micro segments can be ordered in - reverse. - - This method goes through some desparate heuristics trying to sort - things out. - - """ - - N = len(self.__fault_lines) - x = Matrix(N, 1) - y = Matrix(N, 1) - - for index,line in enumerate(self.__fault_lines): - xc,yc = line.center() - - x[index,0] = xc - y[index,0] = yc - - # y = beta[0] + beta[1] * x - # = a + b * x - beta = stat.polyfit(2, x, y) - a = beta[0] - b = beta[1] - - perm_list = [] - for index,line in enumerate(self.__fault_lines): - x0, y0 = line.center() - d = x0 + b*(y0 - a) - perm_list.append((index, d)) - perm_list.sort(key=lambda x: x[1]) - - fault_lines = [] - for (index,d) in perm_list: - fault_lines.append(self.__fault_lines[ index ]) - self.__fault_lines = fault_lines - - - for line in self.__fault_lines: - x1,y1 = line.startPoint() - x2,y2 = line.endPoint() - d1 = x1 + b*(y1 - a) - d2 = x2 + b*(y2 - a) - - if d1 > d2: - line.reverse() - - - - - def process_segments(self): - if self.__processed: - return - - while self.__segment_map: - fault_line = FaultLine(self.__grid, self.__K) - self.__fault_lines.append(fault_line) - - current_segment = self.__segment_map.popStart() - while current_segment: - append = fault_line.tryAppend(current_segment) - if not append: - fault_line = FaultLine(self.__grid, self.__K) - self.__fault_lines.append(fault_line) - fault_line.tryAppend(current_segment) - - current_segment.next_segment = self.__segment_map.popNext(current_segment) - current_segment = current_segment.next_segment - - if len(self.__fault_lines) > 1: - self.__sort_fault_lines() - - self.__processed = True - - -################################################################# - - -class Fault(object): - allowed_faces = ["X","Y","Z","I","J","K","X-","Y-","Z-","I-","J-","K-"] - - def __init__(self, grid, name): - self.__grid = grid - self.__name = name - self.__layer_map = {} - self.__layer_list = [] - (self.nx, self.ny, self.nz, nactive) = grid.getDims() - - - def __str__(self): - return "Fault:%s" % self.__name - - def __getitem__(self, K): - if not self.hasLayer(K): - self.addLayer(K) - layer = self.__layer_map[K] - return layer - - def __len__(self): - return len(self.__layer_map) - - - def __iter__(self): - for layer in self.__layer_list: - yield layer - - - def has_layer(self, K): - return self.__layer_map.has_key(K) - - - def add_layer(self, K): - layer = FaultLayer(self.__grid, K) - self.__layer_map[K] = layer - self.__layer_list.append(layer) - - - def create_segment(self, I1, I2, J1, J2, face): - if face in ["X", "I"]: - C1 = I1 + 1 + J1*(self.nx + 1) - C2 = C1 + (1 + J2 - J1) * (self.nx + 1) - elif face in ["X-", "I-"]: - C1 = I1 + J1*(self.nx + 1) - C2 = C1 + (1 + J2 - J1) * (self.nx + 1) - elif face in ["Y", "J"]: - C1 = I1 + (J1 + 1) * (self.nx + 1) - C2 = C1 + (1 + I2 - I1) - elif face in ["Y-", "J-"]: - C1 = I1 + J1 * (self.nx + 1) - C2 = C1 + (1 + I2 - I1) - else: - return None - - return FaultSegment(C1,C2) - - - - def add_record(self, I1, I2, J1, J2, K1, K2, face): - if not face in Fault.allowed_faces: - raise ValueError("Invalid face:%s" % face) - - if I1 > I2: - raise ValueError("Invalid I1 I2 indices") - - if J1 > J2: - raise ValueError("Invalid J1 J2 indices") - - if K1 > K2: - raise ValueError("Invalid K1 K2 indices") - - if I1 < 0 or I1 >= self.nx: - raise ValueError("Invalid I1:%d" % I1) - if I2 < 0 or I2 >= self.nx: - raise ValueError("Invalid I2:%d" % I2) - - if J1 < 0 or J1 >= self.ny: - raise ValueError("Invalid J1:%d" % J1) - if J2 < 0 or J2 >= self.ny: - raise ValueError("Invalid J2:%d" % J2) - - if K1 < 0 or K1 >= self.nz: - raise ValueError("Invalid K1:%d" % K1) - if K2 < 0 or K2 >= self.nz: - raise ValueError("Invalid K2:%d" % K2) - - if face in ["X","I"]: - if I1 != I2: - raise ValueError("For face:%s we must have I1 == I2" % face) - - if face in ["Y","J"]: - if J1 != J2: - raise ValueError("For face:%s we must have J1 == J2" % face) - - if face in ["Z","K"]: - if K1 != K2: - raise ValueError("For face:%s we must have K1 == K2" % face) - - #----------------------------------------------------------------- - - for K in range(K1,K2+1): - if not self.hasLayer(K): - self.addLayer(K) - layer = self.__layer_map[K] - segment = self.createSegment(I1,I2,J1,J2,face) - if segment: - layer.addSegment(segment) - - - - @property - def name(self): - return self.__name - - def get_name(self): - return self.__name - - - def get_neighbor_cells(self): - neighbor_cells = [] - for layer in self: - neighbor_cells += layer.getNeighborCells() - return neighbor_cells - - - def get_polyline(self, k): - layer = self[k] - return layer.getPolyline(name="Polyline[%s]" % self.getName()) - - - def get_ij_polyline(self, k): - layer = self[k] - return layer.getIJPolyline() - - - def num_lines(self, k): - layer = self[k] - return layer.numLines() - - - @staticmethod - def __ray_intersect(p0, p1, polyline): - ray_dir = GeometryTools.lineToRay(p0, p1) - intersections = GeometryTools.rayPolygonIntersections(p1, ray_dir, polyline) - if intersections: - if len(intersections) > 1: - d_list = [ GeometryTools.distance(p1, p[1]) for p in intersections ] - index = d_list.index(min(d_list)) - else: - index = 0 - p2 = intersections[index][1] - return [p1, p2] - else: - return None - - - def connect_with_polyline(self, polyline, k): - """ - """ - if self.intersectsPolyline(polyline, k): - return None - else: - self_polyline = self.getPolyline(k) - if len(self_polyline) > 0: - return self_polyline.connect(polyline) - else: - return None - - - def connect(self, target, k): - if isinstance(target, Fault): - polyline = target.getPolyline(k) - else: - polyline = target - return self.connectWithPolyline(polyline, k) - - - - def extend_to_polyline(self, polyline, k): - """Extends the fault until it intersects @polyline in layer @k. - - The return value is a list [(x1,y1), (x2,y2)] where (x1,y1) - is on the tip of the fault, and (x2,y2) is on the polyline. If - the fault already intersects polyline None is returned, if no - intersection is found a ValueError exception is raised. - - The method will try four different strategies for finding an - intersection between the extension of the fault and the - polyline. Assume the fault and the polyline looks like: - - - Polyline: ---------------------------------------------- - - +------------+ D - | | | - | +-------C - B-----+ - | - A - - The algorithm will then try to intersect the following rays - with the polyline, the first match will return: - - 1. (Pc, Pd) - 2. (Pb, Pa) - 3. (Pa, Pd) - 4. (Pd, Pa) - - The fault object is not directed in any way; i.e. in the case - both (Pc,Pd) and (Pb,Pa) intersects the polyline it is - impossible to know which intersection is returned, without - actually consulting the construction of the fault object. - """ - if self.intersectsPolyline(polyline, k): - return None - - fault_polyline = self.getPolyline(k) - p0 = fault_polyline[-2] - p1 = fault_polyline[-1] - extension = self.__ray_intersect(p0, p1, polyline) - if extension: - return extension - - p0 = fault_polyline[1] - p1 = fault_polyline[0] - extension = self.__ray_intersect(p0, p1, polyline) - if extension: - return extension - - p0 = fault_polyline[0] - p1 = fault_polyline[-1] - extension = self.__ray_intersect(p0, p1, polyline) - if extension: - return extension - - p0 = fault_polyline[-1] - p1 = fault_polyline[0] - extension = self.__ray_intersect(p0, p1, polyline) - if extension: - return extension - - raise ValueError("The fault %s can not be extended to intersect with polyline:%s in layer:%d" % (self.getName(), polyline.getName(), k+1)) - - - - def intersects_polyline(self, polyline, k): - fault_line = self.getPolyline(k) - return fault_line.intersects(polyline) - - - def intersects_fault(self, other_fault, k): - fault_line = other_fault.getPolyline(k) - return self.intersectsPolyline(fault_line, k) - - def extend_to_fault(self, fault, k): - fault_line = fault.getPolyline(k) - return self.extendToPolyline(fault_line, k) - - def extend_to_edge(self, edge, k): - if isinstance(edge, Fault): - return self.extendToFault(edge, k) - else: - return self.extendToPolyline(edge, k) - - - def extend_to_b_box(self, bbox, k, start=True): - fault_polyline = self.getPolyline(k) - if start: - p0 = fault_polyline[1] - p1 = fault_polyline[0] - else: - p0 = fault_polyline[-2] - p1 = fault_polyline[-1] - - ray_dir = GeometryTools.lineToRay(p0,p1) - intersections = GeometryTools.rayPolygonIntersections(p1, ray_dir, bbox) - if intersections: - p2 = intersections[0][1] - if self.getName(): - name = "Extend:%s" % self.getName() - else: - name = None - - return CPolyline(name=name, init_points=[(p1[0], p1[1]), p2]) - else: - raise Exception("Logical error - must intersect with bounding box") - - - def end_join(self, other, k): - fault_polyline = self.getPolyline(k) - - if isinstance(other, Fault): - other_polyline = other.getPolyline(k) - else: - other_polyline = other - - return GeometryTools.joinPolylines(fault_polyline, other_polyline) - - - - def connect_polyline_onto(self, polyline, k): - if self.intersectsPolyline(polyline, k): - return None - - self_polyline = self.getPolyline(k) - return polyline.connect(self_polyline) - - - - def extend_polyline_onto(self, polyline, k): - if self.intersectsPolyline(polyline, k): - return None - - if len(polyline) > 1: - fault_polyline = self.getPolyline(k) - ext1 = self.__ray_intersect(polyline[-2], polyline[-1], fault_polyline) - ext2 = self.__ray_intersect(polyline[0] , polyline[1] , fault_polyline) - - if ext1 and ext2: - d1 = GeometryTools.distance(ext1[0], ext1[1]) - d2 = GeometryTools.distance(ext2[0], ext2[1]) - - if d1 < d2: - return ext1 - else: - return ext2 - - if ext1: - return ext1 - else: - return ext2 - else: - raise ValueError("Polyline must have length >= 2") - - - - @staticmethod - def intersect_fault_rays(ray1, ray2): - p1,dir1 = ray1 - p2,dir2 = ray2 - if p1 == p2: - return [] - - dx = p2[0] - p1[0] - dy = p2[1] - p1[1] - if dx != 0: - if dir1[0] * dx <= 0 and dir2[0] * dx >= 0: - raise ValueError("Rays will never intersect") - - if dy != 0: - if dir1[1] * dy <= 0 and dir2[1] * dy >= 0: - raise ValueError("Rays will never intersect") - - if dx*dy != 0: - if dir1[0] != 0: - xc = p2[0] - yc = p1[1] - else: - xc = p1[0] - yc = p2[1] - - coord_list = [p1, (xc,yc), p2] - else: - coord_list = [p1,p2] - - return coord_list - - - @staticmethod - def int_ray(p1,p2): - if p1 == p2: - raise Exception("Can not form ray from coincident points") - - if p1[0] == p2[0]: - # Vertical line - dx = 0 - if p2[1] > p1[1]: - dy = 1 - elif p2[1] < p1[1]: - dy = -1 - else: - # Horizontal line - if p2[1] != p1[1]: - raise Exception("Invalid direction") - - dy = 0 - if p2[0] > p1[0]: - dx = 1 - else: - dx = -1 - - return [p2, (dx,dy)] - - - - def get_end_rays(self, k): - polyline = self.getIJPolyline(k) - - p0 = polyline[0] - p1 = polyline[1] - p2 = polyline[-2] - p3 = polyline[-1] - - return (Fault.intRay(p1,p0), Fault.intRay(p2,p3)) - - - - - @staticmethod - def join_faults(fault1, fault2, k): - fault1_rays = fault1.getEndRays(k) - fault2_rays = fault2.getEndRays(k) - - if fault1.intersectsFault(fault2, k): - return None - - count = 0 - join = None - try: - join = Fault.intersectFaultRays(fault1_rays[0], fault2_rays[0]) - count += 1 - except ValueError: - pass - - try: - join = Fault.intersectFaultRays(fault1_rays[0], fault2_rays[1]) - count += 1 - except ValueError: - pass - - try: - join = Fault.intersectFaultRays(fault1_rays[1], fault2_rays[0]) - count += 1 - except ValueError: - pass - - try: - join = Fault.intersectFaultRays(fault1_rays[1], fault2_rays[1]) - count += 1 - except ValueError: - pass - - if count == 1: - xy_list = [] - for ij in join: - xyz = fault1.__grid.getNodeXYZ(ij[0], ij[1], k) - xy_list.append((xyz[0], xyz[1])) - - return xy_list - else: - return fault1.endJoin(fault2, k) - - -monkey_the_camel(FaultLayer, 'addSegment', FaultLayer.add_segment) -monkey_the_camel(FaultLayer, 'getK', FaultLayer.get_k) -monkey_the_camel(FaultLayer, 'getNeighborCells', FaultLayer.get_neighbor_cells) -monkey_the_camel(FaultLayer, 'getPolyline', FaultLayer.get_polyline) -monkey_the_camel(FaultLayer, 'getIJPolyline', FaultLayer.get_ij_polyline) -monkey_the_camel(FaultLayer, 'numLines', FaultLayer.num_lines) -monkey_the_camel(FaultLayer, 'processSegments', FaultLayer.process_segments) - -monkey_the_camel(Fault, 'hasLayer', Fault.has_layer) -monkey_the_camel(Fault, 'addLayer', Fault.add_layer) -monkey_the_camel(Fault, 'createSegment', Fault.create_segment) -monkey_the_camel(Fault, 'addRecord', Fault.add_record) -monkey_the_camel(Fault, 'getName', Fault.get_name) -monkey_the_camel(Fault, 'getNeighborCells', Fault.get_neighbor_cells) -monkey_the_camel(Fault, 'getPolyline', Fault.get_polyline) -monkey_the_camel(Fault, 'getIJPolyline', Fault.get_ij_polyline) -monkey_the_camel(Fault, 'numLines', Fault.num_lines) -monkey_the_camel(Fault, 'connectWithPolyline', Fault.connect_with_polyline) -monkey_the_camel(Fault, 'extendToPolyline', Fault.extend_to_polyline) -monkey_the_camel(Fault, 'intersectsPolyline', Fault.intersects_polyline) -monkey_the_camel(Fault, 'intersectsFault', Fault.intersects_fault) -monkey_the_camel(Fault, 'extendToFault', Fault.extend_to_fault) -monkey_the_camel(Fault, 'extendToEdge', Fault.extend_to_edge) -monkey_the_camel(Fault, 'extendToBBox', Fault.extend_to_b_box) -monkey_the_camel(Fault, 'endJoin', Fault.end_join) -monkey_the_camel(Fault, 'connectPolylineOnto', Fault.connect_polyline_onto) -monkey_the_camel(Fault, 'extendPolylineOnto', Fault.extend_polyline_onto) -monkey_the_camel(Fault, 'intersectFaultRays', Fault.intersect_fault_rays, staticmethod) -monkey_the_camel(Fault, 'intRay', Fault.int_ray, staticmethod) -monkey_the_camel(Fault, 'getEndRays', Fault.get_end_rays) -monkey_the_camel(Fault, 'joinFaults', Fault.join_faults, staticmethod) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block.py deleted file mode 100644 index c4d03db926..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block.py +++ /dev/null @@ -1,190 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'fault_block.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import ctypes -from cwrap import BaseCClass - -from ecl.util import monkey_the_camel -from ecl.util import DoubleVector, IntVector -from ecl.ecl import EclPrototype -from ecl.geo import Polyline, GeometryTools, CPolylineCollection - -class FaultBlockCell(object): - - def __init__(self, i, j, k, x, y, z): - self.i = i - self.j = j - self.k = k - - self.x = x - self.y = y - self.z = z - - - def __str__(self): - return "(%d,%d)" % (self.i, self.j) - - - -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("void fault_block_export_cell(fault_block, int, int*, int*, int*, double*, double*, double*)") - _assign_to_region = EclPrototype("void fault_block_assign_to_region(fault_block, int)") - _get_region_list = EclPrototype("int_vector_ref fault_block_get_region_list(fault_block)") - _add_cell = EclPrototype("void fault_block_add_cell(fault_block, int, int)") - _get_global_index_list = EclPrototype("int_vector_ref fault_block_get_global_index_list(fault_block)") - _trace_edge = EclPrototype("void fault_block_trace_edge(fault_block, double_vector, double_vector, int_vector)") - _get_neighbours = EclPrototype("void fault_block_list_neighbours(fault_block, bool, geo_polygon_collection, int_vector)") - _free = EclPrototype("void fault_block_free__(fault_block)") - - - def __init__(self, *args, **kwargs): - raise NotImplementedError("Class can not be instantiated directly!") - - - def __getitem__(self, index): - if isinstance(index, int): - if index < 0: - index += len(self) - - if 0 <= index < len(self): - x = ctypes.c_double() - y = ctypes.c_double() - z = ctypes.c_double() - - i = ctypes.c_int() - j = ctypes.c_int() - k = ctypes.c_int() - - self._export_cell(index, - ctypes.byref(i), ctypes.byref(j), ctypes.byref(k), - ctypes.byref(x), ctypes.byref(y), ctypes.byref(z)) - return FaultBlockCell(i.value, j.value, k.value, x.value, y.value, z.value) - else: - raise IndexError("Index:%d out of range: [0,%d)" % (index, len(self))) - else: - raise TypeError("Index:%s wrong type - integer expected") - - def __str__(self): - return "Block ID: %d" % self.getBlockID() - - - def __len__(self): - return self._get_size() - - def free(self): - self._free() - - def get_centroid(self): - xc = self._get_xc() - yc = self._get_yc() - return (xc,yc) - - - def count_inside(self, polygon): - """ - Will count the number of points in block which are inside polygon. - """ - inside = 0 - for p in self: - if GeometryTools.pointInPolygon((p.x, p.y), polygon): - inside += 1 - - return inside - - - def get_block_id(self): - return self._get_block_id() - - - def assign_to_region(self, region_id): - self._assign_to_region(region_id) - - - def get_region_list(self): - regionList = self._get_region_list() - return regionList.copy() - - def add_cell(self, i, j): - self._add_cell(i, j) - - def get_global_index_list(self): - return self._get_global_index_list() - - - def get_edge_polygon(self): - x_list = DoubleVector() - y_list = DoubleVector() - cell_list = IntVector() - - self._trace_edge(x_list, y_list, cell_list) - p = Polyline() - for (x,y) in zip(x_list, y_list): - p.addPoint(x,y) - return p - - - def contains_polyline(self, polyline): - """ - Will return true if at least one point from the polyline is inside the block. - """ - edge_polyline = self.getEdgePolygon() - for p in polyline: - if GeometryTools.pointInPolygon(p, edge_polyline): - return True - else: - edge_polyline.assertClosed() - return GeometryTools.polylinesIntersect(edge_polyline, polyline) - - - def get_neighbours(self, polylines=None, connected_only=True): - """ - Will return a list of FaultBlock instances which are in direct - contact with this block. - """ - neighbour_id_list = IntVector() - if polylines is None: - polylines = CPolylineCollection() - - self._get_neighbours(connected_only, polylines, neighbour_id_list) - - parent_layer = self.getParentLayer() - neighbour_list = [] - for id in neighbour_id_list: - neighbour_list.append(parent_layer.getBlock(id)) - return neighbour_list - - - def get_parent_layer(self): - return self.parent() - - -monkey_the_camel(FaultBlock, 'getCentroid', FaultBlock.get_centroid) -monkey_the_camel(FaultBlock, 'countInside', FaultBlock.count_inside) -monkey_the_camel(FaultBlock, 'getBlockID', FaultBlock.get_block_id) -monkey_the_camel(FaultBlock, 'assignToRegion', FaultBlock.assign_to_region) -monkey_the_camel(FaultBlock, 'getRegionList', FaultBlock.get_region_list) -monkey_the_camel(FaultBlock, 'addCell', FaultBlock.add_cell) -monkey_the_camel(FaultBlock, 'getGlobalIndexList', FaultBlock.get_global_index_list) -monkey_the_camel(FaultBlock, 'getEdgePolygon', FaultBlock.get_edge_polygon) -monkey_the_camel(FaultBlock, 'containsPolyline', FaultBlock.contains_polyline) -monkey_the_camel(FaultBlock, 'getNeighbours', FaultBlock.get_neighbours) -monkey_the_camel(FaultBlock, 'getParentLayer', FaultBlock.get_parent_layer) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block_collection.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block_collection.py deleted file mode 100644 index 88333268fe..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block_collection.py +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'fault_block_collection.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -from cwrap import BaseCClass - -from ecl.util import monkey_the_camel -from ecl.ecl import EclPrototype - - -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("int fault_block_collection_num_layers(fault_block_collection)") - _scan_keyword = EclPrototype("bool fault_block_collection_scan_kw(fault_block_collection, ecl_kw)") - _get_layer = EclPrototype("fault_block_layer_ref fault_block_collection_get_layer(fault_block_collection, int)") - - def __init__(self, grid): - c_ptr = self._alloc(grid) - if c_ptr: - super(FaultBlockCollection, self).__init__(c_ptr) - else: - raise ValueError("Invalid input - failed to create FaultBlockCollection") - - # The underlying C implementation uses lazy evaluation and - # needs to hold on to the grid reference. We therefor take - # references to it here, to protect against premature garbage - # collection. - self.grid_ref = grid - - - def __len__(self): - return self._num_layers() - - - def __repr__(self): - return self._create_repr('len=%s' % len(self)) - - - def __getitem__(self, index): - """ - @rtype: FaultBlockLayer - """ - if isinstance(index, int): - if 0 <= index < len(self): - return self._get_layer(index).setParent(self) - else: - raise IndexError("Index:%d out of range [0,%d)" % (index, len(self))) - else: - raise TypeError("Index should be integer type") - - - def get_layer(self, k): - """ - @rtype: FaultBlockLayer - """ - return self[k] - - def free(self): - self._free() - - - def scan_keyword(self, fault_block_kw): - ok = self._scan_keyword(fault_block_kw) - if not ok: - raise ValueError("The fault block keyword had wrong type/size") - - -monkey_the_camel(FaultBlockCollection, 'getLayer', FaultBlockCollection.get_layer) -monkey_the_camel(FaultBlockCollection, 'scanKeyword', FaultBlockCollection.scan_keyword) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block_layer.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block_layer.py deleted file mode 100644 index 7bffe6a608..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_block_layer.py +++ /dev/null @@ -1,235 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'fault_block_layer.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import print_function -from cwrap import BaseCClass - -from ecl.util import monkey_the_camel -from ecl.ecl import EclDataType, EclPrototype -from ecl.ecl.faults import Fault - -class FaultBlockLayer(BaseCClass): - TYPE_NAME = "fault_block_layer" - _alloc = EclPrototype("void* fault_block_layer_alloc(ecl_grid, int)", bind = False) - _free = EclPrototype("void fault_block_layer_free(fault_block_layer)") - _size = EclPrototype("int fault_block_layer_get_size(fault_block_layer)") - _iget_block = EclPrototype("fault_block_ref fault_block_layer_iget_block(fault_block_layer, int)") - _add_block = EclPrototype("fault_block_ref fault_block_layer_add_block(fault_block_layer, int)") - _get_block = EclPrototype("fault_block_ref fault_block_layer_get_block(fault_block_layer, int)") - _del_block = EclPrototype("void fault_block_layer_del_block(fault_block_layer, int)") - _has_block = EclPrototype("bool fault_block_layer_has_block(fault_block_layer, int)") - _scan_keyword = EclPrototype("bool fault_block_layer_scan_kw(fault_block_layer, ecl_kw)") - _load_keyword = EclPrototype("bool fault_block_layer_load_kw(fault_block_layer, ecl_kw)") - _getK = EclPrototype("int fault_block_layer_get_k(fault_block_layer)") - _get_next_id = EclPrototype("int fault_block_layer_get_next_id(fault_block_layer)") - _scan_layer = EclPrototype("void fault_block_layer_scan_layer(fault_block_layer, layer)") - _insert_block_content = EclPrototype("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)") - _get_layer = EclPrototype("layer_ref fault_block_layer_get_layer(fault_block_layer)") - - - def __init__(self, grid, k): - c_ptr = self._alloc(grid, k) - if c_ptr: - super(FaultBlockLayer, self).__init__(c_ptr) - else: - raise ValueError("Invalid input - failed to create FaultBlockLayer") - - # The underlying C implementation uses lazy evaluation and - # needs to hold on to the grid reference. We therefor take - # references to it here, to protect against premature garbage - # collection. - self.grid_ref = grid - - - def __len__(self): - return self._size() - - - def __repr__(self): - return self._create_repr('size=%d, k=%d' % (len(self), self.get_k())) - - def __getitem__(self, index): - """ - @rtype: FaultBlock - """ - if isinstance(index, int): - if index < 0: - index += len(self) - - if 0 <= index < len(self): - return self._iget_block(index).setParent(self) - else: - raise IndexError("Index:%d out of range: [0,%d)" % (index, len(self))) - elif isinstance(index,tuple): - i,j = index - if 0 <= i < self.grid_ref.getNX() and 0 <= j < self.grid_ref.getNY(): - geo_layer = self.getGeoLayer() - block_id = geo_layer[i,j] - if block_id == 0: - raise ValueError("No fault block defined for location (%d,%d)" % (i,j)) - else: - return self.getBlock(block_id) - else: - raise IndexError("Invalid i,j : (%d,%d)" % (i,j)) - else: - raise TypeError("Index should be integer type") - - def __contains__(self, block_id): - return self._has_block(block_id) - - - def scan_keyword(self, fault_block_kw): - """ - Will reorder the block ids, and ensure single connectedness. Assign block_id to zero blocks. - """ - ok = self._scan_keyword(fault_block_kw) - if not ok: - raise ValueError("The fault block keyword had wrong type/size: type:%s size:%d grid_size:%d" % (fault_block_kw.type_name, len(fault_block_kw), self.grid_ref.getGlobalSize())) - - - def load_keyword(self, fault_block_kw): - """ - Will load directly from keyword - without reorder; ignoring zero. - """ - ok = self._load_keyword(fault_block_kw) - if not ok: - raise ValueError("The fault block keyword had wrong type/size: type:%s size:%d grid_size:%d" % (fault_block_kw.typeName(), len(fault_block_kw), self.grid_ref.getGlobalSize())) - - - def get_block(self, block_id): - """ - @rtype: FaultBlock - """ - if block_id in self: - return self._get_block(block_id).setParent(self) - else: - raise KeyError("No blocks with ID:%d in this layer" % block_id) - - - def delete_block(self, block_id): - if block_id in self: - self._del_block(block_id) - else: - raise KeyError("No blocks with ID:%d in this layer" % block_id) - - def add_block(self, block_id=None): - if block_id is None: - block_id = self.getNextID() - - if block_id in self: - raise KeyError("Layer already contains block with ID:%s" % block_id) - else: - return self._add_block(block_id).setParent(self) - - def get_next_id(self): - return self._get_next_id() - - - def get_k(self): - return self._getK() - - @property - def k(self): - return self._getK() - - def free(self): - self._free() - - - def scan_layer(self, layer): - self._scan_layer(layer) - - - def insert_block_content(self, block): - self._insert_block_content(block) - - def export_keyword(self, kw): - if len(kw) != self.grid_ref.getGlobalSize(): - msg = 'The size of the target keyword must be equal to the size of the grid.' - msg += ' Got:%d Expected:%d.' - raise ValueError(msg % (len(kw), self.grid_ref.getGlobalSize())) - - if not kw.data_type.is_int(): - raise TypeError("The target kewyord must be of integer type") - - self._export_kw(kw) - - - def add_fault_barrier(self, fault, link_segments=False): - layer = self.getGeoLayer() - layer.addFaultBarrier(fault, self.getK(), link_segments) - - - def add_fault_link(self, fault1, fault2): - if not fault1.intersectsFault(fault2, self.getK()): - layer = self.getGeoLayer() - layer.addIJBarrier(fault1.extendToFault(fault2, self.getK())) - - - def join_faults(self, fault1, fault2): - if not fault1.intersectsFault(fault2, self.getK()): - layer = self.getGeoLayer() - try: - layer.addIJBarrier(Fault.joinFaults(fault1, fault2, self.getK())) - except ValueError: - err = 'Failed to join faults %s and %s' - names = (fault1.getName(), fault2.getName()) - print(err % names) - raise ValueError(err % names) - - - def add_polyline_barrier(self, polyline): - layer = self.getGeoLayer() - p0 = polyline[0] - c0 = self.grid_ref.findCellCornerXY(p0[0], p0[1], self.getK()) - i,j = self.grid_ref.findCellXY(p0[0], p0[1], self.getK()) - print('%g,%g -> %d,%d %d' % (p0[0], p0[1], i,j,c0)) - for index in range(1,len(polyline)): - p1 = polyline[index] - c1 = self.grid_ref.findCellCornerXY(p1[0], p1[1], self.getK()) - i,j = self.grid_ref.findCellXY(p1[0], p1[1], self.getK()) - layer.addInterpBarrier(c0, c1) - print('%g,%g -> %d,%d %d' % (p1[0], p1[1], i,j,c1)) - print('Adding barrier %d -> %d' % (c0, c1)) - c0 = c1 - - - def get_geo_layer(self): - """Returns the underlying geometric layer.""" - return self._get_layer() - - - def cell_contact(self, p1, p2): - layer = self.getGeoLayer() - return layer.cellContact(p1,p2) - -monkey_the_camel(FaultBlockLayer, 'scanKeyword', FaultBlockLayer.scan_keyword) -monkey_the_camel(FaultBlockLayer, 'loadKeyword', FaultBlockLayer.load_keyword) -monkey_the_camel(FaultBlockLayer, 'getBlock', FaultBlockLayer.get_block) -monkey_the_camel(FaultBlockLayer, 'deleteBlock', FaultBlockLayer.delete_block) -monkey_the_camel(FaultBlockLayer, 'addBlock', FaultBlockLayer.add_block) -monkey_the_camel(FaultBlockLayer, 'getNextID', FaultBlockLayer.get_next_id) -monkey_the_camel(FaultBlockLayer, 'getK', FaultBlockLayer.get_k) -monkey_the_camel(FaultBlockLayer, 'scanLayer', FaultBlockLayer.scan_layer) -monkey_the_camel(FaultBlockLayer, 'insertBlockContent', FaultBlockLayer.insert_block_content) -monkey_the_camel(FaultBlockLayer, 'exportKeyword', FaultBlockLayer.export_keyword) -monkey_the_camel(FaultBlockLayer, 'addFaultBarrier', FaultBlockLayer.add_fault_barrier) -monkey_the_camel(FaultBlockLayer, 'addFaultLink', FaultBlockLayer.add_fault_link) -monkey_the_camel(FaultBlockLayer, 'joinFaults', FaultBlockLayer.join_faults) -monkey_the_camel(FaultBlockLayer, 'addPolylineBarrier', FaultBlockLayer.add_polyline_barrier) -monkey_the_camel(FaultBlockLayer, 'getGeoLayer', FaultBlockLayer.get_geo_layer) -monkey_the_camel(FaultBlockLayer, 'cellContact', FaultBlockLayer.cell_contact) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_collection.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_collection.py deleted file mode 100644 index 7daf0fce44..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_collection.py +++ /dev/null @@ -1,135 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'fault_collection.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import re - -from ecl.util import monkey_the_camel -from ecl.ecl import EclGrid -from .fault import Fault - -comment_regexp = re.compile("--.*") - -def dequote(s): - if s[0] in ["'", '"']: - if s[0] == s[-1]: - return s[1:-1] - else: - raise ValueError("Quote fuckup") - else: - return s - - -class FaultCollection(object): - def __init__(self, grid=None, *file_list): - self.__fault_list = [] - self.__fault_map = {} - self.__grid = grid - - if self.__grid is not None: - if not isinstance(self.__grid, EclGrid): - raise ValueError("When supplying a list of files to load - you must have a grid") - for file in file_list: - self.load(self.__grid, file) - - - def __contains__(self, fault_name): - return self.__fault_map.has_key(fault_name) - - - def __len__(self): - return len(self.__fault_list) - - - def __getitem__(self, index): - if isinstance(index, str): - return self.__fault_map[index] - elif isinstance(index, int): - return self.__fault_list[index] - else: - raise TypeError("Argument must be fault name or number") - - def __iter__(self): - return iter(self.__fault_list) - - - def get_grid(self): - return self.__grid - - - def get_fault(self, name): - return self[name] - - - def has_fault(self, fault_name): - return fault_name in self - - - def add_fault(self, fault): - self.__fault_map[fault.getName()] = fault - self.__fault_list.append(fault) - - - def split_line(self, line): - tmp = line.split() - if not tmp[-1] == "/": - raise ValueError("Line:%s does not end with /" % line) - - if len(tmp) != 9: - raise ValueError("Line:%s not correct number of items" % line) - - fault_name = dequote(tmp[0]) - I1 = int(tmp[1]) - 1 - I2 = int(tmp[2]) - 1 - J1 = int(tmp[3]) - 1 - J2 = int(tmp[4]) - 1 - K1 = int(tmp[5]) - 1 - K2 = int(tmp[6]) - 1 - face = dequote(tmp[7]) - - return (fault_name, I1,I2,J1,J2,K1,K2, face) - - - - def load_faults(self, grid, fileH): - for line in fileH: - line = comment_regexp.sub("", line) - line = line.strip() - if line == "/": - break - - if line: - (name, I1, I2, J1, J2, K1, K2, face) = self.splitLine(line) - if not self.hasFault(name): - fault = Fault(grid, name) - self.addFault(fault) - else: - fault = self.getFault(name) - - fault.addRecord(I1, I2, J1, J2, K1, K2, face) - - - def load(self, grid, file_name): - with open(file_name) as fileH: - for line in fileH: - if line.startswith("FAULTS"): - self.loadFaults(grid, fileH) - - -monkey_the_camel(FaultCollection, 'getGrid', FaultCollection.get_grid) -monkey_the_camel(FaultCollection, 'getFault', FaultCollection.get_fault) -monkey_the_camel(FaultCollection, 'hasFault', FaultCollection.has_fault) -monkey_the_camel(FaultCollection, 'addFault', FaultCollection.add_fault) -monkey_the_camel(FaultCollection, 'splitLine', FaultCollection.split_line) -monkey_the_camel(FaultCollection, 'loadFaults', FaultCollection.load_faults) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_line.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_line.py deleted file mode 100644 index 3436d7454d..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_line.py +++ /dev/null @@ -1,253 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'fault_line.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import print_function -import sys - -from ecl.util import monkey_the_camel -from ecl.util import DoubleVector,stat -from ecl.geo import CPolyline - -from .fault_segments import FaultSegment - - -def cmp_index_pair(p1, p2): - if p1[0] == p2[0]: - return cmp(p1[1], p2[1]) - else: - return cmp(p1[0], p2[0]) - - -class FaultLine(object): - def __init__(self, grid, k): - self.__grid = grid - self.__k = k - self.__segment_list = [] - self.__polyline = None - self.__ijpolyline = None - self.__neighborCells = None - - def __len__(self): - return len(self.__segment_list) - - - def __getitem__(self, index): - return self.__segment_list[index] - - def __iter__(self): - return iter(self.__segment_list) - - - def verify(self): - if len(self.__segment_list) > 1: - current = self.__segment_list[0] - for next_segment in self.__segment_list[1:]: - if not current.getC2() == next_segment.getC1(): - sys.stdout.write("Current: %d ---- %d \n" % (current.getC1() , current.getC2())) - sys.stdout.write("Next : %d ---- %d \n" % (next_segment.getC1(), next_segment.getC2())) - assert current.getC2() == next_segment.getC1() - current = next_segment - - - def try_append(self, segment): - if len(self.__segment_list) > 0: - tail = self.__segment_list[-1] - if tail.getC2() != segment.getC1(): - if len(self.__segment_list) == 1: - if tail.getC2() == segment.getC2(): - segment.swap() - else: - tail.swap() - if tail.getC2() == segment.getC2(): - segment.swap() - else: - segment.swap() - - if not tail.getC2() == segment.getC1(): - return False - - self.__segment_list.append(segment) - self.__polyline = None - self.__ijpolyline = None - return True - - - def get_k(self): - return self.__k - - @property - def k(self): - return self.__k - - - def __init_ij_polyline(self): - pl = [] - nx = self.__grid.getNX() - ny = self.__grid.getNY() - for segment in self: - corner = segment.getC1() - i = corner % (nx + 1) - j = corner / (nx + 1) - pl.append((i,j)) - - segment = self[-1] - corner = segment.getC2() - i = corner % (nx + 1) - j = corner / (nx + 1) - pl.append((i,j)) - - self.__ijpolyline = pl - - - - def __init_polyline(self): - pl = CPolyline() - for (i,j) in self.getIJPolyline(): - x,y,z = self.__grid.getNodeXYZ(i, j, self.__k) - pl.addPoint(x, y) - self.__polyline = pl - - - - def get_polyline(self): - if self.__polyline is None: - self.__init_polyline() - return self.__polyline - - - def get_ij_polyline(self): - if self.__ijpolyline is None: - self.__init_ij_polyline() - return self.__ijpolyline - - - - def __init_neighbor_cells(self): - self.__neighborCells = [] - nx = self.__grid.getNX() - ny = self.__grid.getNY() - k = self.__k - - for segment in self: - (j1,i1) = divmod(segment.getC1(), (nx + 1)) - (j2,i2) = divmod(segment.getC2(), (nx + 1)) - - if j1 > j2: - j1,j2 = j2,j1 - - if i1 > i2: - i1,i2 = i2,i1 - - - if i1 == i2: - i = i1 - for j in range(j1, j2): - g2 = i + j * nx + k * nx*ny - if i == 0: - g1 = -1 - else: - g1 = g2 - 1 - - if i == nx: - g2 = -1 - - self.__neighborCells.append((g1,g2)) - elif j1 == j2: - j = j1 - for i in range(i1,i2): - g2 = i + j * nx + k * nx*ny - if j == 0: - g1 = -1 - else: - g1 = g2 - nx - - if j == ny: - g2 = -1 - - self.__neighborCells.append((g1,g2)) - else: - raise Exception("Internal error: found fault segment with variation in two directions") - self.__neighborCells.sort(cmp_index_pair) - - - def get_neighbor_cells(self): - if self.__neighborCells is None: - self.__init_neighbor_cells() - - return self.__neighborCells - - - def center(self): - xlist = DoubleVector() - ylist = DoubleVector() - for segment in self: - C1 = segment.getC1() - C2 = segment.getC2() - (J1, I1) = divmod(C1, self.__grid.getNX() + 1) - (J2, I2) = divmod(C2, self.__grid.getNX() + 1) - - (x1,y1,z) = self.__grid.getNodePos(I1, J1, self.__k) - (x2,y2,z) = self.__grid.getNodePos(I2, J2, self.__k) - - xlist.append(x1) - xlist.append(x2) - - ylist.append(y1) - ylist.append(y2) - - - N = len(xlist) - return (xlist.elementSum()/N, ylist.elementSum()/N) - - - - def reverse(self): - reverse_list = reversed(self.__segment_list) - self.__segment_list = [] - for segment in reverse_list: - C1 = segment.getC1() - C2 = segment.getC2() - - rseg = FaultSegment(C2, C1) - self.tryAppend(rseg) - - - def start_point(self): - pl = self.getPolyline() - return pl[0] - - def end_point(self): - pl = self.getPolyline() - return pl[-1] - - def dump(self): - print('-----------------------------------------------------------------') - for segment in self: - C1 = segment.getC1() - C2 = segment.getC2() - (J1, I1) = divmod(C1, self.__grid.getNX() + 1) - (J2, I2) = divmod(C2, self.__grid.getNX() + 1) - print('[Corner:%5d IJ:(%3d,%d)] -> [Corner:%5d IJ:(%3d,%d)]' - % (C1, I1, J1, C2, I2, J2)) - - -monkey_the_camel(FaultLine, 'tryAppend', FaultLine.try_append) -monkey_the_camel(FaultLine, 'getK', FaultLine.get_k) -monkey_the_camel(FaultLine, 'getPolyline', FaultLine.get_polyline) -monkey_the_camel(FaultLine, 'getIJPolyline', FaultLine.get_ij_polyline) -monkey_the_camel(FaultLine, 'getNeighborCells', FaultLine.get_neighbor_cells) -monkey_the_camel(FaultLine, 'startPoint', FaultLine.start_point) -monkey_the_camel(FaultLine, 'endPoint', FaultLine.end_point) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_segments.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_segments.py deleted file mode 100644 index 9b579a57d9..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/fault_segments.py +++ /dev/null @@ -1,174 +0,0 @@ -# Copyright (C) 2014. Statoil ASA, Norway. -# -# This file 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 the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import print_function - -from ecl.util import monkey_the_camel - - -class FaultSegment(object): - - def __init__(self, C1, C2): - self.__C1 = C1 - self.__C2 = C2 - self.__next_segment = None - - - def __eq__(self, other): - s = self.c1, self.c2 - o = other.c1, other.c2 - o_flipped = other.c2, other.c1 - return s == o or s == o_flipped - - def __hash__(self): - return hash(hash(self.__C1) + hash(self.__C2) + hash(self.__next_segment)) - - def get_corners(self): - return (self.__C1, self.__C2) - - def joins(self, other): - if self.__C1 == other.__C1: - return True - if self.__C1 == other.__C2: - return True - if self.__C2 == other.__C1: - return True - if self.__C2 == other.__C2: - return True - - return False - - def get_c1(self): - return self.__C1 - - @property - def c1(self): - return self.__C1 - - def get_c2(self): - return self.__C2 - - @property - def c2(self): - return self.__C2 - - def swap(self): - C1 = self.__C1 - self.__C1 = self.__C2 - self.__C2 = C1 - - - def __repr__(self): - return "%d -> %d" % (self.__C1, self.__C2) - - - -class SegmentMap(object): - - def __init__(self): - self.__segment_map = {} - self.__count_map = {} - - def __len__(self): - return len(self.__segment_map) - - def __str__(self): - return self.__segment_map.__str__() - - def verify(self): - for (C, count) in self.__count_map.iteritems(): - if count > 0: - d = self.__segment_map[C] - if len(d) != count: - print('CornerPoint:%d count:%d len(d):%d map:%s' % (C, count, len(d), d)) - assert len(d) == count - else: - assert self.__segment_map.get(C) is None - - - def add_segment(self, segment): - (C1,C2) = segment.getCorners() - if not self.__segment_map.has_key(C1): - self.__segment_map[C1] = {} - self.__count_map[C1] = 0 - if not self.__segment_map.has_key(C2): - self.__segment_map[C2] = {} - self.__count_map[C2] = 0 - - if not self.__segment_map[C1].has_key(C2): - self.__segment_map[C1][C2] = segment - self.__count_map[C1] += 1 - - if not self.__segment_map[C2].has_key(C1): - self.__segment_map[C2][C1] = segment - self.__count_map[C2] += 1 - - - - def del_segment(self, segment): - (C1,C2) = segment.getCorners() - self.__count_map[C1] -= 1 - self.__count_map[C2] -= 1 - del self.__segment_map[C1][C2] - del self.__segment_map[C2][C1] - - if len(self.__segment_map[C1]) == 0: - del self.__segment_map[C1] - - if len(self.__segment_map[C2]) == 0: - del self.__segment_map[C2] - - - def pop_start(self): - end_segments = [] - for (C, count) in self.__count_map.iteritems(): - if count == 1: - end_segments.append(self.__segment_map[C].values()[0]) - - start_segment = end_segments[0] - self.delSegment(start_segment) - return start_segment - - def pop_next(self, segment): - (C1,C2) = segment.getCorners() - if self.__count_map[C1] >= 1: - next_segment = self.__segment_map[C1].values()[0] - elif self.__count_map[C2] >= 1: - next_segment = self.__segment_map[C2].values()[0] - else: - next_segment = None - - if next_segment: - self.delSegment(next_segment) - return next_segment - - - def print_content(self): - for d in self.__segment_map.values(): - for (C,S) in d.iteritems(): - print(S) - - - -monkey_the_camel(FaultSegment, 'getCorners', FaultSegment.get_corners) -monkey_the_camel(FaultSegment, 'getC1', FaultSegment.get_c1) -monkey_the_camel(FaultSegment, 'getC2', FaultSegment.get_c2) - -monkey_the_camel(SegmentMap, 'addSegment', SegmentMap.add_segment) -monkey_the_camel(SegmentMap, 'delSegment', SegmentMap.del_segment) -monkey_the_camel(SegmentMap, 'popStart', SegmentMap.pop_start) -monkey_the_camel(SegmentMap, 'popNext', SegmentMap.pop_next) -monkey_the_camel(SegmentMap, 'printContent', SegmentMap.print_content) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/faults/layer.py b/ThirdParty/Ert/python/python/ecl/ecl/faults/layer.py deleted file mode 100644 index 464fd891df..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/faults/layer.py +++ /dev/null @@ -1,274 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'layer.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import ctypes - -from cwrap import BaseCClass -from ecl.util import monkey_the_camel -from ecl.util import IntVector -from ecl.ecl import EclPrototype - - -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("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("void layer_add_ijbarrier(layer, int, int, int, int)") - _add_interp_barrier = EclPrototype("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("void layer_update_connected_cells(layer,int,int,int,int)") - _cells_equal = EclPrototype("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)") - - def __init__(self, nx, ny): - c_ptr = self._alloc(nx, ny) - if c_ptr: - super(Layer, self).__init__(c_ptr) - else: - raise ValueError("Invalid input - no Layer object created") - - @classmethod - def copy(cls, src): - layer = Layer(src.getNX(), src.getNY()) - layer._copy(layer, src) - return layer - - - def _assert_ij(self, i,j): - if i < 0 or i >= self.getNX(): - raise ValueError("Invalid layer i:%d" % i) - - if j < 0 or j >= self.getNY(): - raise ValueError("Invalid layer j:%d" % j) - - - def __unpack_index(self, index): - try: - (i,j) = index - except TypeError: - raise ValueError("Index:%s is invalid - must have two integers" % str(index)) - - self._assert_ij(i,j) - - return (i,j) - - - def __setitem__(self, index, value): - (i,j) = self.__unpack_index(index) - self._set_cell(i, j, value) - - def active_cell(self, i,j): - self._assert_ij(i,j) - return self._active_cell(i, j) - - - def update_active(self, grid, k): - if grid.getNX() != self.getNX(): - raise ValueError("NX dimension mismatch. Grid:%d layer:%d" % (grid.getNX(), self.getNX())) - - if grid.getNY() != self.getNY(): - raise ValueError("NY dimension mismatch. Grid:%d layer:%d" % (grid.getNY(), self.getNY())) - - if k >= grid.getNZ(): - raise ValueError("K value invalid: Grid range [0,%d)" % grid.getNZ()) - - self._update_active(grid, k) - - - def __getitem__(self, index): - (i,j) = self.__unpack_index(index) - return self._get_cell(i, j) - - def bottom_barrier(self, i,j): - self._assert_ij(i,j) - return self._get_bottom_barrier(i, j) - - def left_barrier(self, i,j): - self._assert_ij(i,j) - return self._get_left_barrier(i, j) - - def get_nx(self): - return self._get_nx() - - @property - def nx(self): - return self._get_nx() - - def get_ny(self): - return self._get_ny() - - @property - def ny(self): - return self._get_ny() - - def free(self): - self._free() - - def cell_contact(self, p1, p2): - i1,j1 = p1 - i2,j2 = p2 - - if not 0 <= i1 < self.getNX(): - raise IndexError("Invalid i1:%d" % i1) - - if not 0 <= i2 < self.getNX(): - raise IndexError("Invalid i2:%d" % i2) - - if not 0 <= j1 < self.getNY(): - raise IndexError("Invalid i1:%d" % j1) - - if not 0 <= j2 < self.getNY(): - raise IndexError("Invalid i2:%d" % j2) - - return self._cell_contact(i1, j1, i2, j2) - - - def add_interp_barrier(self, c1, c2): - self._add_interp_barrier(c1, c2) - - - def add_polyline_barrier(self, polyline, grid, k): - if len(polyline) > 1: - for i in range(len(polyline) - 1): - x1,y1 = polyline[i] - x2,y2 = polyline[i + 1] - - c1 = grid.findCellCornerXY(x1, y1, k) - c2 = grid.findCellCornerXY(x2, y2, k) - - self.addInterpBarrier(c1, c2) - - - def add_fault_barrier(self, fault, K, link_segments=True): - fault_layer = fault[K] - num_lines = len(fault_layer) - for index, fault_line in enumerate(fault_layer): - for segment in fault_line: - c1, c2 = segment.getCorners() - self._add_barrier(c1, c2) - - if index < num_lines - 1: - next_line = fault_layer[index + 1] - next_segment = next_line[0] - next_c1, next_c2 = next_segment.getCorners() - - if link_segments: - self.addInterpBarrier(c2, next_c1) - - - def add_ij_barrier(self, ij_list): - if len(ij_list) < 2: - raise ValueError("Must have at least two (i,j) points") - - nx = self.getNX() - ny = self.getNY() - p1 = ij_list[0] - i1,j1 = p1 - for p2 in ij_list[1:]: - i2,j2 = p2 - if i1 == i2 or j1 == j2: - if not 0 <= i2 <= nx: - raise ValueError("i value:%d invalid. Valid range: [0,%d] " % (i1, i2)) - - if not 0 <= j2 <= ny: - raise ValueError("i value:%d invalid. Valid range: [0,%d] " % (j1, j2)) - - self._add_ijbarrier(i1, j1, i2, j2) - p1 = p2 - i1,j1 = p1 - else: - raise ValueError("Must have i1 == i2 or j1 == j2") - - - def cell_sum(self): - return self._cell_sum() - - def clear_cells(self): - """ - Will reset all cell and edge values to zero. Barriers will be left - unchanged. - """ - self._clear_cells() - - - def assign(self, value): - """ - Will set the cell value to @value in all cells. Barriers will not be changed - """ - self._assign(value) - - def update_connected(self, ij, new_value, org_value=None): - """ - Will update cell value of all cells in contact with cell ij to the - value @new_value. If org_value is not supplied, the current - value in cell ij is used. - """ - if org_value is None: - org_value = self[ij] - - if self[ij] == org_value: - self._update_connected(ij[0], ij[1], org_value, new_value) - else: - raise ValueError("Cell %s is not equal to %d \n" % (ij, org_value)) - - - def cells_equal(self, value): - """ - Will return a list [(i1,j1),(i2,j2), ...(in,jn)] of all cells with value @value. - """ - i_list = IntVector() - j_list = IntVector() - self._cells_equal(value, i_list, j_list) - ij_list= [] - for (i,j) in zip(i_list, j_list): - ij_list.append((i,j)) - return ij_list - - - def count_equal(self, value): - return self._count_equal(value) - - - -monkey_the_camel(Layer, 'activeCell', Layer.active_cell) -monkey_the_camel(Layer, 'updateActive', Layer.update_active) -monkey_the_camel(Layer, 'bottomBarrier', Layer.bottom_barrier) -monkey_the_camel(Layer, 'leftBarrier', Layer.left_barrier) -monkey_the_camel(Layer, 'getNX', Layer.get_nx) -monkey_the_camel(Layer, 'getNY', Layer.get_ny) -monkey_the_camel(Layer, 'cellContact', Layer.cell_contact) -monkey_the_camel(Layer, 'addInterpBarrier', Layer.add_interp_barrier) -monkey_the_camel(Layer, 'addPolylineBarrier', Layer.add_polyline_barrier) -monkey_the_camel(Layer, 'addFaultBarrier', Layer.add_fault_barrier) -monkey_the_camel(Layer, 'addIJBarrier', Layer.add_ij_barrier) -monkey_the_camel(Layer, 'cellSum', Layer.cell_sum) -monkey_the_camel(Layer, 'clearCells', Layer.clear_cells) -monkey_the_camel(Layer, 'updateConnected', Layer.update_connected) -monkey_the_camel(Layer, 'cellsEqual', Layer.cells_equal) -monkey_the_camel(Layer, 'countEqual', Layer.count_equal) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/fortio.py b/ThirdParty/Ert/python/python/ecl/ecl/fortio.py deleted file mode 100644 index 75d7b917fd..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/fortio.py +++ /dev/null @@ -1,211 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'fortio.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Module to support transparent binary IO of Fortran created files. - -Fortran is a a funny language; when writing binary blobs of data to -file the Fortran runtime will silently add a header and footer around -the date. The Fortran code: - - integer array(100) - write(unit) array - -it actually writes a head and tail in addition to the actual -data. The header and tail is a 4 byte integer, which value is the -number of bytes in the immediately following record. I.e. what is -actually found on disk after the Fortran code above is: - - | 400 | array ...... | 400 | - -The fortio.c file implements the fortio_type C structure which can be -used to read and write these structures transparently. The current -python module is a minimal wrapping of this datastructure; mainly to -support passing of FortIO handles to the underlying C functions. A -more extensive wrapping of the fortio implementation would be easy. -""" -import ctypes -import os - -from cwrap import BaseCClass -from ecl.util import monkey_the_camel -from ecl.ecl import EclPrototype - - -class FortIO(BaseCClass): - TYPE_NAME = "fortio" - - READ_MODE = 1 - WRITE_MODE = 2 - READ_AND_WRITE_MODE = 3 - APPEND_MODE = 4 - - _open_reader = EclPrototype("void* fortio_open_reader(char*, bool, bool)", bind=False) - _open_writer = EclPrototype("void* fortio_open_writer(char*, bool, bool)", bind=False) - _open_readwrite = EclPrototype("void* fortio_open_readwrite(char*, bool, bool)", bind=False) - _open_append = EclPrototype("void* fortio_open_append(char*, bool, bool)", bind=False) - _guess_fortran = EclPrototype("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)") - - - def __init__(self, file_name, mode=READ_MODE, fmt_file=False, endian_flip_header=True): - """Will open a new FortIO handle to @file_name - default for reading. - - The newly created FortIO handle will open the underlying FILE* - for reading, but if you pass the flag mode=FortIO.WRITE_MODE - the file will be opened for writing. - - Observe that the flag @endian_flip_header will only affect the - interpretation of the block size markers in the file, endian - flipping of the actual data blocks must be handled at a higher - level. - - When you are finished working with the FortIO instance you can - manually close it with the close() method, alternatively that - will happen automagically when it goes out of scope. - - Small example script opening a restart file, and then writing - all the pressure keywords to another file: - - import sys - from ecl.ecl import FortIO, EclFile - - rst_file = EclFile(sys.argv[1]) - fortio = FortIO("PRESSURE", mode=FortIO.WRITE_MODE) - - for kw in rst_file: - if kw.name() == "PRESSURE": - kw.write(fortio) - - fortio.close() - - See the documentation of openFortIO() for an alternative - method based on a context manager and the with statement. - - """ - read_modes = (FortIO.READ_MODE, FortIO.APPEND_MODE, FortIO.READ_AND_WRITE_MODE) - if mode in read_modes and not os.path.exists(file_name): - raise IOError('No such file "%s".' % file_name) - if mode == FortIO.READ_MODE: - c_pointer = self._open_reader(file_name, fmt_file, endian_flip_header) - elif mode == FortIO.WRITE_MODE: - c_pointer = self._open_writer(file_name, fmt_file, endian_flip_header) - elif mode == FortIO.READ_AND_WRITE_MODE: - c_pointer = self._open_readwrite(file_name, fmt_file, endian_flip_header) - elif mode == FortIO.APPEND_MODE: - c_pointer = self._open_append(file_name, fmt_file, endian_flip_header) - else: - raise UserWarning("Unknown mode: %d" % mode) - - self.__mode = mode - if not c_pointer: - raise IOError('Failed to open FortIO file "%s".' % file_name) - super(FortIO, self).__init__(c_pointer) - - - - def close(self): - if self: - self._close() - self._invalidateCPointer() - - - def get_position(self): - """ @rtype: long """ - return self._get_position() - - - def truncate(self, size=None): - """Will truncate the file to new size. - - If the method is called without a size argument the stream - will be truncated to the current position. - """ - if size is None: - size = self.getPosition() - - if not self._truncate(size): - raise IOError("Truncate of fortran filehandle:%s failed" % self.filename()) - - - def filename(self): - return self._filename() - - - def seek(self, position, whence=0): - # SEEK_SET = 0 - # SEEK_CUR = 1 - # SEEK_END = 2 - self._seek(position, whence) - - - @classmethod - def is_fortran_file(cls, filename, endian_flip=True): - - """@rtype: bool - @type filename: str - - - Will use heuristics to try to guess if @filename is a binary - file written in fortran style. ASCII files will return false, - even if they are structured as ECLIPSE keywords. - """ - return cls._guess_fortran(filename, endian_flip) - - - def free(self): - self.close() - - -class FortIOContextManager(object): - - def __init__(self, fortio): - self.__fortio = fortio - - def __enter__(self): - return self.__fortio - - def __exit__(self, exc_type, exc_val, exc_tb): - self.__fortio.close() - return exc_type is not None - - -def openFortIO(file_name, mode=FortIO.READ_MODE, fmt_file=False, endian_flip_header=True): - """Will create FortIO based context manager for use with with. - - The with: statement and context managers is a good alternative in - the situation where you need to ensure resource cleanup. - - import sys - from ecl.ecl import FortIO, EclFile - - rst_file = EclFile(sys.argv[1]) - with openFortIO("PRESSURE", mode=FortIO.WRITE_MODE) as fortio: - for kw in rst_file: - if kw.name() == "PRESSURE": - kw.write(fortio) - - """ - return FortIOContextManager(FortIO(file_name, mode=mode, fmt_file=fmt_file, - endian_flip_header=endian_flip_header)) - -monkey_the_camel(FortIO, 'getPosition', FortIO.get_position) -monkey_the_camel(FortIO, 'isFortranFile', FortIO.is_fortran_file, classmethod) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/local.cmake b/ThirdParty/Ert/python/python/ecl/ecl/local.cmake deleted file mode 100644 index f2431a2a7a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/local.cmake +++ /dev/null @@ -1,13 +0,0 @@ -set( ECL_LOCAL_TARGET "" CACHE FILE "Name of optional external ecl_local module") - -if (EXISTS ${ECL_LOCAL_TARGET}) - if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") - EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") - endif() - - EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E create_symlink "${ECL_LOCAL_TARGET}" "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") -endif() - -if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") - add_python_package( "Python ecl.ecl.ecl_local" ${PYTHON_INSTALL_PREFIX}/ecl/ecl "ecl_local.py" True) -endif() diff --git a/ThirdParty/Ert/python/python/ecl/ecl/rft/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/ecl/rft/CMakeLists.txt deleted file mode 100644 index d41bccb489..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/rft/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - well_trajectory.py -) - -add_python_package("python.ecl.ecl.rft" ${PYTHON_INSTALL_PREFIX}/ecl/ecl/rft "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/python/python/ecl/ecl/rft/__init__.py b/ThirdParty/Ert/python/python/ecl/ecl/rft/__init__.py deleted file mode 100644 index d5a91dfba7..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/rft/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .well_trajectory import WellTrajectory diff --git a/ThirdParty/Ert/python/python/ecl/ecl/rft/well_trajectory.py b/ThirdParty/Ert/python/python/ecl/ecl/rft/well_trajectory.py deleted file mode 100644 index abe0cadcd5..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl/rft/well_trajectory.py +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'well_trajectory.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import sys -from os.path import isfile -from collections import namedtuple - -TrajectoryPoint = namedtuple('TrajectoryPoint', - ['utm_x', 'utm_y', - 'measured_depth', 'true_vertical_depth', - 'zone']) - -def _read_point(line): - line = line.partition("--")[0] - line = line.strip() - if not line: - return None - - point = line.split() - if len(point) not in (4, 5): - fmt = 'utm_x utm_y md tvd [zone]' - err = 'Trajectory data file not on correct format: "%s".' - err += ' zone is optional.' - raise UserWarning(err % fmt) - return point - -def _parse_point(point): - try: - utm_x = float(point[0]) - utm_y = float(point[1]) - md = float(point[2]) - tvd = float(point[3]) - except ValueError: - raise UserWarning("Error: Failed to extract data from line %s\n" % str(point)) - zone = None - if len(point) > 4: - zone = point[4] - return TrajectoryPoint(utm_x, utm_y, md, tvd, zone) - - -class WellTrajectory: - - def __init__(self, filename): - self._points = [] - if not isfile(filename): - raise IOError('No such file "%s"' % filename) - - with open(filename) as fileH: - for line in fileH.readlines(): - point = _read_point(line) - if not point: - continue - traj = _parse_point(point) - self._points.append(traj) - - def __len__(self): - return len(self._points) - - - def __getitem__(self, index): - if index < 0: - index += len(self) - - return self._points[index] - - - def __repr__(self): - return 'WellTrajectory(len=%d)' % len(self) - - def __str__(self): - return 'WellTrajectory(%s)' % str(self._points) diff --git a/ThirdParty/Ert/python/python/ecl/ecl_lib_info_build.py.in b/ThirdParty/Ert/python/python/ecl/ecl_lib_info_build.py.in deleted file mode 100644 index eaf570f7ca..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl_lib_info_build.py.in +++ /dev/null @@ -1,3 +0,0 @@ -lib_path = "${LIBRARY_OUTPUT_PATH}" -so_version = "${ECL_BINARY_POSTFIX}" -__version__ = "${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" diff --git a/ThirdParty/Ert/python/python/ecl/ecl_lib_info_install.py.in b/ThirdParty/Ert/python/python/ecl/ecl_lib_info_install.py.in deleted file mode 100644 index fc3e9a08d5..0000000000 --- a/ThirdParty/Ert/python/python/ecl/ecl_lib_info_install.py.in +++ /dev/null @@ -1,3 +0,0 @@ -lib_path = "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" -so_version = "${ECL_BINARY_POSTFIX}" -__version__ = "${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" diff --git a/ThirdParty/Ert/python/python/ecl/geo/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/geo/CMakeLists.txt deleted file mode 100644 index 563a73db75..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - cpolyline.py - cpolyline_collection.py - geometry_tools.py - geo_pointset.py - geo_region.py - polyline.py - xyz_io.py - surface.py -) - -add_python_package("python.ecl.geo" ${PYTHON_INSTALL_PREFIX}/ecl/geo "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/python/python/ecl/geo/__init__.py b/ThirdParty/Ert/python/python/ecl/geo/__init__.py deleted file mode 100644 index b2d982a580..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/__init__.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file '__init__.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Simple package for working with 2D geometry. - -""" -import ecl -from cwrap import Prototype - -class GeoPrototype(Prototype): - lib = ecl.load("libecl") - - def __init__(self, prototype, bind=True): - super(GeoPrototype, self).__init__(GeoPrototype.lib, prototype, bind=bind) - - -from .geo_pointset import GeoPointset -from .geo_region import GeoRegion -from .cpolyline import CPolyline -from .cpolyline_collection import CPolylineCollection -from .polyline import Polyline -from .xyz_io import XYZIo -from .geometry_tools import GeometryTools -from .surface import Surface diff --git a/ThirdParty/Ert/python/python/ecl/geo/cpolyline.py b/ThirdParty/Ert/python/python/ecl/geo/cpolyline.py deleted file mode 100644 index 4014059ed8..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/cpolyline.py +++ /dev/null @@ -1,210 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# This file 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 the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Create a polygon -""" -import ctypes -import os.path - -from cwrap import BaseCClass -from ecl.geo import GeoPrototype -from .geometry_tools import GeometryTools - - -class CPolyline(BaseCClass): - TYPE_NAME = "geo_polygon" - - _alloc_new = GeoPrototype("void* geo_polygon_alloc( char* )" , bind = False) - _fread_alloc_irap = GeoPrototype("geo_polygon_obj geo_polygon_fload_alloc_irap( char* )" , bind = False) - _add_point = GeoPrototype("void geo_polygon_add_point( geo_polygon , double , double )") - _add_point_front = GeoPrototype("void geo_polygon_add_point_front( geo_polygon , double , double )") - _free = GeoPrototype("void geo_polygon_free( geo_polygon )") - _size = GeoPrototype("int geo_polygon_get_size( geo_polygon )") - _iget_xy = GeoPrototype("void geo_polygon_iget_xy( geo_polygon , int , double* , double* )") - _segment_intersects = GeoPrototype("bool geo_polygon_segment_intersects( geo_polygon , double , double, double , double)") - _get_name = GeoPrototype("char* geo_polygon_get_name( geo_polygon )") - _set_name = GeoPrototype("void geo_polygon_set_name( geo_polygon , char* )") - _segment_length = GeoPrototype("double geo_polygon_get_length( geo_polygon)") - _equal = GeoPrototype("bool geo_polygon_equal( geo_polygon , geo_polygon )") - - - def __init__(self, name = None , init_points = ()): - c_ptr = self._alloc_new( name ) - super(CPolyline , self).__init__( c_ptr ) - for (xc, yc) in init_points: - self.addPoint(xc, yc) - - - @classmethod - def createFromXYZFile(cls , filename , name = None): - if not os.path.isfile(filename): - raise IOError("No such file:%s" % filename) - - polyline = cls._fread_alloc_irap( filename ) - if not name is None: - polyline._set_name( name ) - return polyline - - def __str__(self): - name = self.getName() - if name: - str = "%s [" % name - else: - str = "[" - - for index,p in enumerate(self): - str += "(%g,%g)" % p - if index < len(self) - 1: - str += "," - str += "]" - return str - - def __repr__(self): - return str(self) - - - def __len__(self): - return self._size() - - - def __getitem__(self , index): - if not isinstance(index,int): - raise TypeError("Index argument must be integer. Index:%s invalid" % index) - - if index < 0: - index += len(self) - - if 0 <= index < len(self): - x = ctypes.c_double() - y = ctypes.c_double() - self._iget_xy( index , ctypes.byref(x) , ctypes.byref(y) ) - - return (x.value , y.value) - else: - raise IndexError("Invalid index:%d valid range: [0,%d)" % (index , len(self))) - - - def segmentIntersects(self, p1 , p2): - return self._segment_intersects(p1[0] , p1[1] , p2[0] , p2[1]) - - - def intersects(self , polyline): - if len(self) > 1: - for index,p2 in enumerate(polyline): - if index == 0: - continue - - p1 = polyline[index - 1] - if self.segmentIntersects(p1 , p2): - return True - return False - - - def __iadd__(self , other ): - for p in other: - self.addPoint( p[0] , p[1] ) - return self - - - def __add__(self , other ): - copy = CPolyline( init_points = self) - copy.__iadd__(other) - return copy - - - def __radd__(self , other ): - copy = CPolyline( init_points = other ) - copy.__iadd__(self) - return copy - - def __eq__(self , other): - if super(CPolyline , self).__eq__( other ): - return True - else: - return self._equal( other ) - - - def segmentLength(self): - if len(self) == 0: - raise ValueError("Can not measure length of zero point polyline") - - return self._segment_length( ) - - def extendToBBox(self , bbox , start = True): - if start: - p0 = self[1] - p1 = self[0] - else: - p0 = self[-2] - p1 = self[-1] - - ray_dir = GeometryTools.lineToRay(p0,p1) - intersections = GeometryTools.rayPolygonIntersections( p1 , ray_dir , bbox) - if intersections: - p2 = intersections[0][1] - if self.getName(): - name = "Extend:%s" % self.getName() - else: - name = None - - return CPolyline( name = name , init_points = [(p1[0] , p1[1]) , p2]) - else: - raise ValueError("Logical error - must intersect with bounding box") - - - def addPoint( self, xc, yc , front = False): - if front: - self._add_point_front(xc, yc) - else: - self._add_point(xc, yc) - - - def getName(self): - return self._get_name( ) - - - def free(self): - self._free( ) - - - def unzip(self): - x_list = [ ] - y_list = [ ] - for x,y in self: - x_list.append(x) - y_list.append(y) - - return (x_list , y_list) - - - def unzip2(self): - return self.unzip() - - - def connect(self , target): - end1 = self[0] - end2 = self[-1] - - p1 = GeometryTools.nearestPointOnPolyline( end1 , target ) - p2 = GeometryTools.nearestPointOnPolyline( end2 , target ) - - d1 = GeometryTools.distance( p1 , end1 ) - d2 = GeometryTools.distance( p2 , end2 ) - - if d1 < d2: - return [end1 , p1] - else: - return [end2 , p2] diff --git a/ThirdParty/Ert/python/python/ecl/geo/cpolyline_collection.py b/ThirdParty/Ert/python/python/ecl/geo/cpolyline_collection.py deleted file mode 100644 index b93f5596d9..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/cpolyline_collection.py +++ /dev/null @@ -1,120 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'cpolyline_collection.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Create a polygon -""" -import ctypes - -from cwrap import BaseCClass -from ecl.geo import GeoPrototype, CPolyline - - -class CPolylineCollection(BaseCClass): - TYPE_NAME = "geo_polygon_collection" - - _alloc_new = GeoPrototype("void* geo_polygon_collection_alloc( )" , bind = False) - _free = GeoPrototype("void geo_polygon_collection_free( geo_polygon_collection )" ) - _size = GeoPrototype("int geo_polygon_collection_size( geo_polygon_collection)" ) - _create_polyline = GeoPrototype("geo_polygon_ref geo_polygon_collection_create_polygon(geo_polygon_collection , char*)" ) - _has_polyline = GeoPrototype("bool geo_polygon_collection_has_polygon(geo_polygon_collection , char*)" ) - _iget = GeoPrototype("geo_polygon_ref geo_polygon_collection_iget_polygon(geo_polygon_collection , int)" ) - _get = GeoPrototype("geo_polygon_ref geo_polygon_collection_get_polygon(geo_polygon_collection , char*)" ) - _add_polyline = GeoPrototype("void geo_polygon_collection_add_polygon(geo_polygon_collection , geo_polygon , bool)") - - - - def __init__(self): - c_ptr = self._alloc_new( ) - super(CPolylineCollection , self).__init__( c_ptr ) - self.parent_ref = None - - - def __contains__(self , name): - return self._has_polyline(name) - - - def __len__(self): - return self._size( ) - - - def __iter__(self): - index = 0 - - while index < len(self): - yield self[index] - index += 1 - - - def __getitem__(self , index): - if isinstance(index , int): - if index < 0: - index += len(self) - - if 0 <= index < len(self): - return self._iget( index).setParent( self ) - else: - raise IndexError("Invalid index:%d - valid range: [0,%d)" % (index , len(self))) - elif isinstance(index , str): - if index in self: - return self._get(index) - else: - raise KeyError("No polyline named:%s" % index) - else: - raise TypeError("The index argument must be string or integer") - - - def shallowCopy(self): - copy = CPolylineCollection() - for pl in self: - copy._add_polyline(pl , False) - - # If we make a shallow copy we must ensure that source, owning - # all the polyline objects does not go out of scope. - copy.parent_ref = self - return copy - - - - def addPolyline(self , polyline , name = None): - if not isinstance(polyline , CPolyline): - polyline = CPolyline( init_points = polyline , name = name) - else: - if not name is None: - raise ValueError("The name keyword argument can only be supplied when add not CPOlyline object") - - name = polyline.getName() - if name and name in self: - raise KeyError("The polyline collection already has an object:%s" % name) - - if polyline.isReference(): - self._add_polyline( polyline , False) - else: - polyline.convertToCReference( self ) - self._add_polyline( polyline , True) - - - - def createPolyline(self , name = None): - if name and name in self: - raise KeyError("The polyline collection already has an object:%s" % name) - - polyline = self._create_polyline(name) - polyline.setParent( parent = self ) - return polyline - - - def free(self): - self._free( ) diff --git a/ThirdParty/Ert/python/python/ecl/geo/geo_pointset.py b/ThirdParty/Ert/python/python/ecl/geo/geo_pointset.py deleted file mode 100644 index ff9fa3b2ec..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/geo_pointset.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -from cwrap import BaseCClass -from ecl.geo import GeoPrototype - -class GeoPointset(BaseCClass): - TYPE_NAME = "geo_pointset" - - _alloc = GeoPrototype("void* geo_pointset_alloc(bool)", bind=False) - _free = GeoPrototype("void geo_pointset_free(geo_pointset)") - #_add_xyz = GeoPrototype("void geo_pointset_add_xyz(geo_pointset, double, double, double)") - _get_size = GeoPrototype("int geo_pointset_get_size(geo_pointset)") - #_iget_xy = GeoPrototype("void geo_pointset_iget_xy(geo_pointset, int, double*, double*)") - #_get_zcoord = GeoPrototype("double* geo_pointset_get_zcoord(geo_pointset)") - _equal = GeoPrototype("bool geo_pointset_equal(geo_pointset, geo_pointset)") - _iget_z = GeoPrototype("double geo_pointset_iget_z(geo_pointset, int)") - #_iset_z = GeoPrototype("void geo_pointset_iset_z(geo_pointset, int, double)") - #_memcpy = GeoPrototype("void geo_pointset_memcpy(geo_pointset, geo_pointset, bool)") - #_shift_z = GeoPrototype("void geo_pointset_shift_z(geo_pointset, double)") - #_assign_z = GeoPrototype("void geo_pointset_assign_z(geo_pointset, double)") - #_scale_z = GeoPrototype("void geo_pointset_scale_z(geo_pointset, double)") - #_imul = GeoPrototype("void geo_pointset_imul(geo_pointset, geo_pointset)") - #_iadd = GeoPrototype("void geo_pointset_iadd(geo_pointset, geo_pointset)") - #_isub = GeoPrototype("void geo_pointset_isub(geo_pointset, geo_pointset)") - #_isqrt = GeoPrototype("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/ThirdParty/Ert/python/python/ecl/geo/geo_region.py b/ThirdParty/Ert/python/python/ecl/geo/geo_region.py deleted file mode 100644 index a4238d8650..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/geo_region.py +++ /dev/null @@ -1,121 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -from cwrap import BaseCClass -from ecl.util import IntVector -from ecl.geo import GeoPrototype -from .cpolyline import CPolyline -from ctypes import c_double - -cpair = c_double * 2 # this is a function that maps two doubles to a double* - -class GeoRegion(BaseCClass): - TYPE_NAME = "geo_region" - - _alloc = GeoPrototype("void* geo_region_alloc(geo_pointset, bool)", bind=False) - _free = GeoPrototype("void geo_region_free(geo_region)") - _reset = GeoPrototype("void geo_region_reset(geo_region)") - _get_index_list = GeoPrototype("int_vector_ref geo_region_get_index_list(geo_region)") - _select_inside_polygon = GeoPrototype("void geo_region_select_inside_polygon(geo_region, geo_polygon)") - _select_outside_polygon = GeoPrototype("void geo_region_select_outside_polygon(geo_region, geo_polygon)") - _deselect_inside_polygon = GeoPrototype("void geo_region_deselect_inside_polygon(geo_region, geo_polygon)") - _deselect_outside_polygon = GeoPrototype("void geo_region_deselect_outside_polygon(geo_region, geo_polygon)") - _select_above_line = GeoPrototype("void geo_region_select_above_line(geo_region, double*, double*)") - _select_below_line = GeoPrototype("void geo_region_select_below_line(geo_region, double*, double*)") - _deselect_above_line = GeoPrototype("void geo_region_deselect_above_line(geo_region, double*, double*)") - _deselect_below_line = GeoPrototype("void geo_region_deselect_below_line(geo_region, double*, double*)") - - - def __init__(self, pointset, preselect=False): - self._preselect = True if preselect else False - c_ptr = self._alloc(pointset, self._preselect) - if c_ptr: - super(GeoRegion, self).__init__(c_ptr) - else: - raise ValueError('Could not construct GeoRegion from pointset %s.' % pointset) - - - def getActiveList(self): - return self._get_index_list() - - def _assert_polygon(self, polygon): - if not isinstance(polygon, CPolyline): - raise ValueError('Need to select with a CPolyline, not %s.' - % type(polygon)) - - - def _construct_cline(self, line): - """Takes a line ((x1,y1), (x2,y2)) and returns two double[2]* but - reordered to (x1x2, y1y2). - """ - try: - p1, p2 = line - x1, y1 = map(float, p1) - x2, y2 = map(float, p2) - except Exception as err: - err_msg = 'Select with pair ((x1,y1), (x2,y2)), not %s (%s).' - raise ValueError(err_msg % (line, err)) - x1x2_ptr = cpair(x1, x2) - y1y2_ptr = cpair(y1, y2) - return x1x2_ptr, y1y2_ptr - - - def select_inside(self, polygon): - self._assert_polygon(polygon) - self._select_inside_polygon(polygon) - - def select_outside(self, polygon): - self._assert_polygon(polygon) - self._select_outside_polygon(polygon) - - def deselect_inside(self, polygon): - self._assert_polygon(polygon) - self._deselect_inside_polygon(polygon) - - def deselect_outside(self, polygon): - self._assert_polygon(polygon) - self._deselect_outside_polygon(polygon) - - - def select_above(self, line): - x_ptr, y_ptr = self._construct_cline(line) - self._select_above_line(x_ptr, y_ptr) - - def select_below(self, line): - x_ptr, y_ptr = self._construct_cline(line) - self._select_below_line(x_ptr, y_ptr) - - def deselect_above(self, line): - x_ptr, y_ptr = self._construct_cline(line) - self._deselect_above_line(x_ptr, y_ptr) - - def deselect_below(self, line): - x_ptr, y_ptr = self._construct_cline(line) - self._deselect_below_line(x_ptr, y_ptr) - - - def __len__(self): - """Returns the size of the active list, not the size of the - underlying pointset""" - return len(self._get_index_list()) - - def __repr__(self): - ls = len(self) - il = repr(self.getActiveList()) - pres = 'preselected' if self._preselect else 'not preselected' - return self._create_repr('size=%d, active_list=<%s>, %s' % (ls, il, pres)) - - def free(self): - self._free() diff --git a/ThirdParty/Ert/python/python/ecl/geo/geometry_tools.py b/ThirdParty/Ert/python/python/ecl/geo/geometry_tools.py deleted file mode 100644 index 9c33b89010..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/geometry_tools.py +++ /dev/null @@ -1,448 +0,0 @@ -from math import sqrt -import sys - -class GeometryTools(object): - EPSILON = 0.000001 - - @staticmethod - def lineIntersection(p1, p2, p3, p4): - """ - Finds intersection between line segments. Returns None if no intersection found. - Algorithm provided by Paul Bourke - - @type p1: tuple of (float, float) - @type p2: tuple of (float, float) - @type p3: tuple of (float, float) - @type p4: tuple of (float, float) - @rtype: tuple of (float, float) - """ - - denominator = (p4[1] - p3[1]) * (p2[0] - p1[0]) - (p4[0] - p3[0]) * (p2[1] - p1[1]) - numerator_a = (p4[0] - p3[0]) * (p1[1] - p3[1]) - (p4[1] - p3[1]) * (p1[0] - p3[0]) - numerator_b = (p2[0] - p1[0]) * (p1[1] - p3[1]) - (p2[1] - p1[1]) * (p1[0] - p3[0]) - - # coincident? - if abs(numerator_a) < GeometryTools.EPSILON and abs(numerator_b) < GeometryTools.EPSILON and abs(denominator) < GeometryTools.EPSILON: - return None - - # parallel? - if abs(denominator) < GeometryTools.EPSILON: - return None - - - # intersection along the segments? - mua = numerator_a / denominator - mub = numerator_b / denominator - - if mua < 0.0 or mua > 1.0 or mub < 0.0 or mub > 1.0: - return None - - x = p1[0] + mua * (p2[0] - p1[0]) - y = p1[1] + mua * (p2[1] - p1[1]) - return x, y - - @staticmethod - def polylinesIntersect(polyline1 , polyline2): - """Test if the polylines polyline1 and polyline2 intersect. - - The input arguments must be either Polyline instances[1], or a - list of (float,float) tuples. The method performs a super - naive n^2 check and should not be used for large polyline objects. - - @type polyline1: Polyline or list of tuple of (float, float) - @type polyline2: Polyline or list of tuple of (float, float) - - [1]: The z - coordinate will be ignored. - - """ - - for index1 in range(len(polyline1) - 1): - p1 = polyline1[index1] - p2 = polyline1[index1 + 1] - for index2 in range(len(polyline2) - 1): - p3 = polyline2[index2] - p4 = polyline2[index2 + 1] - - if GeometryTools.lineIntersection(p1,p2,p3,p4): - return True - - return False - - - - - @staticmethod - def ccw(p1, p2, p3): - """ - Three points are a counter-clockwise turn if ccw > 0, clockwise if - ccw < 0, and collinear if ccw = 0 because ccw is a determinant that - gives the signed area of the triangle formed by p1, p2 and p3. - - @type p1: tuple of (float, float) - @type p2: tuple of (float, float) - @type p3: tuple of (float, float) - @rtype: float - """ - return (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0]) - - - @staticmethod - def convexHull(points): - """ - Given a list of points finds the convex hull - @type points: list of tuple of (float, float) - @rtype: list of tuple of (float, float) - """ - points = sorted(points) - - def keepLeft(hull, r): - while len(hull) > 1 and GeometryTools.ccw(hull[-2], hull[-1], r) > 0: - hull.pop() - - if len(hull) == 0 or hull[-1] != r: - hull.append(r) - - return hull - - l = reduce(keepLeft, points, []) - u = reduce(keepLeft, reversed(points), []) - l.extend([u[i] for i in xrange(1, len(u) - 1)]) - - return l - - - @staticmethod - def pointInPolygon(p, polygon): - """ - Finds out if a point is inside a polygon or not - @type p: tuple of (float, float) - @type polygon: Polyline or list of tuple of (float, float) - @rtype: bool - """ - x = p[0] - y = p[1] - n = len(polygon) - - inside = False - - p1x, p1y = polygon[0][0:2] - for index in range(n + 1): - p2x, p2y = polygon[index % n][0:2] - - if min(p1y, p2y) < y <= max(p1y, p2y): - if x <= max(p1x, p2x): - if p1y != p2y: - xints = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x - - if p1x == p2x or x <= xints: - inside = not inside - - p1x, p1y = p2x, p2y - - return inside - - - @staticmethod - def extendToEdge(bounding_polygon, poly_line): - """ - """ - assert(bounding_polygon.isClosed()) - for p in poly_line: - if not GeometryTools.pointInPolygon( p , bounding_polygon): - raise ValueError("The point:%s was not inside bounding polygon") - - p1 = poly_line[0] - ray1 = GeometryTools.lineToRay(poly_line[1], poly_line[0]) - intersection1 = GeometryTools.rayPolygonIntersections(p1, ray1, bounding_polygon)[0] # assume convex - - - p2 = poly_line[-1] - assert(GeometryTools.pointInPolygon(p2 , bounding_polygon)) - - ray2 = GeometryTools.lineToRay(poly_line[-2], poly_line[-1]) - intersection2 = GeometryTools.rayPolygonIntersections(p2, ray2, bounding_polygon) - intersection2 = GeometryTools.rayPolygonIntersections(p2, ray2, bounding_polygon)[0] # assume convex - - return [intersection1[1]] + poly_line + [intersection2[1]] - - - @staticmethod - def slicePolygon(bounding_polygon, poly_line): - """ - This algorithm extends the end-points of the line and find intersections between the line - and the enclosing polygon. The result is a polygon sliced by the extended line. - - The enclosing polygon must be convex, closed and completely enclose the line. - - @type bounding_polygon: Polyline or list of tuple of (float, float) - @type poly_line: Polyline or list of tuple of (float, float) - @rtype: list of tuple of (float, float) - """ - - p1 = poly_line[0] - ray1 = GeometryTools.lineToRay(poly_line[1], poly_line[0]) - tmp = GeometryTools.rayPolygonIntersections(p1, ray1, bounding_polygon) - intersection1 = GeometryTools.rayPolygonIntersections(p1, ray1, bounding_polygon)[0] # assume convex - - p2 = poly_line[-1] - ray2 = GeometryTools.lineToRay(poly_line[-2], poly_line[-1]) - intersection2 = GeometryTools.rayPolygonIntersections(p2, ray2, bounding_polygon)[0] # assume convex - - - # Check for intersection between the polyline extensions on the inside of the bounadary - internal_intersection = GeometryTools.lineIntersection( p1 , intersection1[1] , p2 , intersection2[1]) - if internal_intersection: - start_point = poly_line[0] - return poly_line + [ internal_intersection , start_point] - - - - if intersection2[0] < intersection1[0]: - intersection1, intersection2 = intersection2, intersection1 - poly_line = list(reversed(poly_line)) - - result = [intersection1[1]] - - for index in range(intersection1[0] + 1, intersection2[0] + 1): - result.append(bounding_polygon[index]) - - result.append(intersection2[1]) - - for point in reversed(poly_line): - result.append(point) - - result.append(intersection1[1]) - - return result - - - - - @staticmethod - def lineToRay(p0, p1): - """ - Converts a line segment to a unit vector starting at p0 pointing towards p1. - @type p0: tuple of (float, float) - @type p1: tuple of (float, float) - @rtype: tuple of (float, float) - """ - - x = p1[0] - p0[0] - y = p1[1] - p0[1] - - length = sqrt(x * x + y * y) - - return x / length, y / length - - - @staticmethod - def rayLineIntersection(point, ray, p1, p2 , flip_ray = False): - """ - Finds the intersection between the ray starting at point and the line [p1, p2]. - @type point: tuple of (float, float) - @type ray: tuple of (float, float) - @type p1: tuple of (float, float) - @type p2: tuple of (float, float) - @rtype: tuple of (float, float) or None - - stackoverflow: 563198 - """ - s = (p2[0] - p1[0] , p2[1] - p1[1]) - q = p1 - r = ray - p = point - - p_m_q = (p[0] - q[0] , p[1] - q[1]) - q_m_p = (q[0] - p[0] , q[1] - p[1]) - r_x_s = r[0] * s[1] - r[1]*s[0] - - q_m_p_x_r = q_m_p[0] * r[1] - q_m_p[1] * r[0] - q_m_p_x_s = q_m_p[0] * s[1] - q_m_p[1] * s[0] - - if abs(r_x_s) < GeometryTools.EPSILON and abs(q_m_p_x_r) < GeometryTools.EPSILON: - q_m_p_dot_r = q_m_p[0] * r[0] + q_m_p[1] * r[1] - r_dot_r = r[0] * r[0] + r[1] * r[1] - - p_m_q_dot_s = p_m_q[0] * s[0] + p_m_q[1] * s[1] - s_dot_s = s[0] * s[0] + s[1] * s[1] - - # Coincident - if 0 <= q_m_p_dot_r <= r_dot_r: - return ((p1[0] + p2[0]) / 2 , (p1[1] + p2[1]) / 2) - - # Coincident - if 0 <= p_m_q_dot_s <= s_dot_s: - return ((p1[0] + p2[0]) / 2 , (p1[1] + p2[1]) / 2) - - return None - - - if abs(r_x_s) < GeometryTools.EPSILON: - # Parallell - return None - - - t = 1.0 * q_m_p_x_s / r_x_s - u = 1.0 * q_m_p_x_r / r_x_s - - if t >= 0 and 0 <= u <= 1: - x = p[0] + t*r[0] - y = p[1] + t*r[1] - - return x,y - - if flip_ray: - return GeometryTools.rayLineIntersection( point , (-ray[0] , -ray[1]) , p1 , p2 , False) - else: - return None - - - - - @staticmethod - def rayPolygonIntersections(point, ray, polygon): - """ - Finds all intersections along the ray with the polygon. - The returned value is a tuple containing the line segment in the polygon and the intersection coordinate. - - @type point: tuple of (float, float) - @type ray: tuple of (float, float) - @type polygon: Polyline or [tuple of (float, float)] - @rtype: list of tuple of (int, tuple of (float, float)) - """ - results = [] - for index in range(len(polygon) - 1): - lp1 = polygon[index] - lp2 = polygon[index + 1] - - intersection = GeometryTools.rayLineIntersection(point, ray, lp1, lp2) - if intersection is not None: - results.append((index, intersection)) - - return results - - - @staticmethod - def distance(p1,p2): - if len(p1) != len(p2): - raise ValueError("Different lenght of objects") - - sqr_distance = 0 - for x1,x2 in zip(p1,p2): - sqr_distance += (x1 - x2) * (x1 - x2) - - return sqrt( sqr_distance ) - - - @staticmethod - def joinPolylines(polyline1 , polyline2): - """The shortest straight line connecting polyline1 and polyline2. - - The joinPolylines function does not extend the polylines with - a ray from the end, only the length of the straight line - connecting the various endpoints is considered. If the two - polylines already intersect the function returns None. - """ - - - if len(polyline1) < 1: - raise ValueError("Length of polyline must be >= 1") - - if len(polyline2) < 1: - raise ValueError("Length of polyline must be >= 1") - - if GeometryTools.polylinesIntersect( polyline1 , polyline2): - return None - - p0 = polyline1[0] - p1 = polyline1[-1] - pa = polyline2[0] - pb = polyline2[-1] - - d_list = [ (GeometryTools.distance( p0 , pa ), [p0 , pa]), - (GeometryTools.distance( p0 , pb ), [p0 , pb]), - (GeometryTools.distance( p1 , pa ), [p1 , pa]), - (GeometryTools.distance( p1 , pb ), [p1 , pb]) ] - - d_list.sort( key = lambda x: x[0]) - return d_list[0][1] - - - @staticmethod - def connectPolylines( polyline , target_polyline): - if GeometryTools.polylinesIntersect( polyline , target_polyline ): - return None - - if len(polyline) < 2: - raise ValueError("Polyline must have at least two points") - - d_list = [] - - p0 = polyline[-1] - p1 = polyline[-2] - ray = GeometryTools.lineToRay( p1 , p0 ) - for (index , p) in GeometryTools.rayPolygonIntersections( p0 , ray , target_polyline): - d_list.append( (GeometryTools.distance( p0 , p) , [p0 , p]) ) - - p0 = polyline[0] - p1 = polyline[1] - ray = GeometryTools.lineToRay( p1 , p0 ) - for (index , p) in GeometryTools.rayPolygonIntersections( p0 , ray , target_polyline): - d_list.append( (GeometryTools.distance( p0 , p) , [p0 , p]) ) - - if len(d_list) == 0: - raise ValueError("Polyline %s can not be extended to %s" % (polyline.getName() , target_polyline.getName())) - - d_list.sort( key = lambda x: x[0]) - return d_list[0][1] - - - - @staticmethod - def nearestPointOnPolyline( p , polyline ): - if len(polyline) > 1: - d_list = [ GeometryTools.distance( p , pi ) for pi in polyline ] - index0 = d_list.index( min(d_list) ) - p0 = polyline[index0] - dist0 = d_list[index0] - - dist1 = sys.float_info.max - dist2 = sys.float_info.max - intercept1 = None - intercept2 = None - - index1 = None - index2 = None - if index0 > 0: - index1 = index0 - 1 - - if index0 < len(polyline) - 1: - index2 = index0 + 1 - - if not index1 is None: - p1 = polyline[index1] - dy1 = p1[1] - p0[1] - dx1 = p1[0] - p0[0] - intercept1 = GeometryTools.rayLineIntersection( p , (dy1 , -dx1) , p0 , p1 , True) - if intercept1: - dist1 = GeometryTools.distance( intercept1 , p ) - - - if not index2 is None: - p2 = polyline[index2] - dy2 = p2[1] - p0[1] - dx2 = p2[0] - p0[0] - intercept2 = GeometryTools.rayLineIntersection( p , (dy2 , -dx2) , p0 , p2 , True) - if intercept2: - dist2 = GeometryTools.distance( intercept2 , p ) - - - point_list = [ p0 , intercept1 , intercept2 ] - d_list = [ dist0 , dist1 , dist2 ] - index = d_list.index( min(d_list) ) - - - return point_list[index] - else: - raise ValueError("Polyline must have len() >= 2") - diff --git a/ThirdParty/Ert/python/python/ecl/geo/polyline.py b/ThirdParty/Ert/python/python/ecl/geo/polyline.py deleted file mode 100644 index 8a11571a31..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/polyline.py +++ /dev/null @@ -1,171 +0,0 @@ -import collections -from .geometry_tools import GeometryTools - -class Polyline(object): - def __init__(self, name=None , init_points = None): - super(Polyline, self).__init__() - self.__name = name - self.__points = [] - if init_points: - self.loadPoints( init_points ) - - def __str__(self): - s = "Polyline:[ " - for p in self: - s += "(%s,%s) " % (p[0],p[1]) - s += "]" - return s - - def getName(self): - """ @rtype: str """ - return self.__name - - - def __iadd__(self , other ): - for p in other: - self.__points.append( p ) - return self - - - def __add__(self , other ): - copy = Polyline( init_points = self) - copy.__iadd__(other) - return copy - - - def __radd__(self , other ): - copy = Polyline( init_points = other ) - copy.__iadd__(self) - return copy - - - def __eq__(self, other): - if len(self) != len(other): - return False - - for (p1,p2) in zip(self , other): - if p1 != p2: - return False - - return True - - - - def __len__(self): - return len(self.__points) - - def addPoint(self, x, y, z=None): - if z is None: - p = (x, y) - else: - p = (x, y, z) - self.__points.append(p) - - def __getitem__(self, index): - """ @rtype: tuple of (float, float, float) """ - if index < 0: - index += len(self) - - if not 0 <= index < len(self): - raise IndexError("Index:%d invalid must be in range: [0, %d]" % (index, (len(self) - 1))) - return self.__points[index] - - def isClosed(self): - first = self[0] - last = self[-1] - - return first == last - - - def assertClosed(self): - if not self.isClosed(): - first_point = self[0] - - x = first_point[0] - y = first_point[1] - try: - z = first_point[2] - self.addPoint(x,y,z) - except IndexError: - self.addPoint(x,y) - - - - - - def loadPoints(self , points): - for point in points: - x = point[0] - y = point[1] - try: - z = point[2] - except IndexError: - z = None - - self.addPoint(x,y,z) - - def intersects(self, other_polyline): - """ - Test if instances intersects with other polyline. - - @type other_polyline: Polyline or list of tuple of (float, float) - @rtype: bool - """ - return GeometryTools.polylinesIntersect( self , other_polyline ) - - - def __iter__(self): - index = 0 - - while index < len(self): - yield self[index] - index += 1 - - - def unzip2(self): - x = [] - y = [] - for p in self: - x.append(p[0]) - y.append(p[1]) - - return (x,y) - - - def unzip(self): - first_point = self[0] - x = [] - y = [] - - try: - z = first_point[2] - z = [] - for p in self: - x.append(p[0]) - y.append(p[1]) - z.append(p[2]) - - return (x,y,z) - except IndexError: - for p in self: - x.append(p[0]) - y.append(p[1]) - - return (x,y) - - - def connect(self , target): - end1 = self[0] - end2 = self[-1] - - p1 = GeometryTools.nearestPointOnPolyline( end1 , target ) - p2 = GeometryTools.nearestPointOnPolyline( end2 , target ) - - d1 = GeometryTools.distance( p1 , end1 ) - d2 = GeometryTools.distance( p2 , end2 ) - - if d1 < d2: - return [end1 , p1] - else: - return [end2 , p2] - diff --git a/ThirdParty/Ert/python/python/ecl/geo/surface.py b/ThirdParty/Ert/python/python/ecl/geo/surface.py deleted file mode 100644 index 6dfeae9b9a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/surface.py +++ /dev/null @@ -1,285 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# The file 'surface' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Create a polygon -""" -import os.path -import ctypes -from numpy import zeros - -from cwrap import BaseCClass -from ecl.geo import GeoPrototype -from ecl.geo import GeoPointset - -class Surface(BaseCClass): - TYPE_NAME = "surface" - - _alloc = GeoPrototype("void* geo_surface_fload_alloc_irap( char* , bool )" , bind = False) - _free = GeoPrototype("void geo_surface_free( surface )") - _new = GeoPrototype("void* geo_surface_alloc_new( int, int, double, double, double, double, double )", bind = False) - _get_nx = GeoPrototype("int geo_surface_get_nx( surface )") - _get_ny = GeoPrototype("int geo_surface_get_ny( surface )") - _iget_zvalue = GeoPrototype("double geo_surface_iget_zvalue( surface , int)") - _iset_zvalue = GeoPrototype("void geo_surface_iset_zvalue( surface , int , double)") - _write = GeoPrototype("void geo_surface_fprintf_irap( surface , char* )") - _equal = GeoPrototype("bool geo_surface_equal( surface , surface )") - _header_equal = GeoPrototype("bool geo_surface_equal_header( surface , surface )") - _copy = GeoPrototype("surface_obj geo_surface_alloc_copy( surface , bool )") - _assign = GeoPrototype("void geo_surface_assign_value( surface , double )") - _scale = GeoPrototype("void geo_surface_scale( surface , double )") - _shift = GeoPrototype("void geo_surface_shift( surface , double )") - _iadd = GeoPrototype("void geo_surface_iadd( surface , surface )") - _imul = GeoPrototype("void geo_surface_imul( surface , surface )") - _isub = GeoPrototype("void geo_surface_isub( surface , surface )") - _isqrt = GeoPrototype("void geo_surface_isqrt( surface )") - _iget_xy = GeoPrototype("void geo_surface_iget_xy(surface, int, double*, double*)") - _get_pointset = GeoPrototype("geo_pointset_ref geo_surface_get_pointset(surface)") - - - def __init__(self, filename=None, nx=None, ny=None, xinc=None, yinc=None, - xstart=None, ystart=None, angle=None): - """ - This will load a irap surface from file. The surface should - consist of a header and a set z values. - """ - if filename is not None: - filename = str(filename) - if os.path.isfile( filename ): - c_ptr = self._alloc(filename , True) - super(Surface , self).__init__(c_ptr) - else: - raise IOError('No such file "%s".' % filename) - else: - s_args = [nx, ny, xinc, yinc, xstart, ystart, angle] - if None in s_args: - raise ValueError('Missing argument for creating surface, all values must be set, was: %s' % str(s_args)) - c_ptr = self._new(*s_args) - super(Surface , self).__init__(c_ptr) - - def __eq__(self , other): - """ - Compares two Surface instances, both header and data must be equal - to compare as equal. - """ - if isinstance( other , Surface): - return self._equal(other) - else: - return False - - - def headerEqual(self , other): - return self._header_equal( other) - - - def __iadd__(self , other): - if isinstance(other , Surface): - if self.headerEqual(other): - self._iadd(other) - else: - raise ValueError("Tried to add incompatible surfaces") - else: - self._shift(other) - return self - - - def __isub__(self , other): - if isinstance(other , Surface): - if self.headerEqual(other): - self._isub(other) - else: - raise ValueError("Tried to subtract incompatible surfaces") - else: - self._shift( -other) - return self - - - def __imul__(self , other): - if isinstance(other , Surface): - if self.headerEqual(other): - self._imul( other) - else: - raise ValueError("Tried to add multiply ncompatible surfaces") - else: - self._scale( other) - return self - - - def __idiv__(self , other): - self._scale( 1.0/other) - return self - - - def __add__(self , other): - copy = self.copy() - copy += other - return copy - - - def __mul__(self , other): - copy = self.copy() - copy *= other - return copy - - - def __sub__(self , other): - copy = self.copy() - copy -= other - return copy - - - def __div__(self , other): - copy = self.copy() - copy /= other - return copy - - - def __len__(self): - """ - The number of values in the surface. - """ - return self.getNX() * self.getNY() - - - def inplaceSqrt(self): - """ - Will do an inplace sqrt operation. - """ - self._isqrt( ) - return self - - - def sqrt(self): - """ - Will return a new surface where all elements have been sqrt{ .. }. - """ - copy = self.copy( ) - copy.inplaceSqrt( ) - return copy - - - def copy(self , copy_data = True): - """Will create a deep copy of self, if copy_data is set to False the - copy will have all z-values set to zero. - """ - return self._copy( copy_data) - - - def write(self , filename): - - """ - Will write the surface as an ascii formatted file to @filename. - """ - self._write( filename ) - - - - def assign(self , value): - """ - Will set all the values in the surface to @value" - """ - self._assign(value) - - - def __setitem__(self , index , value): - if isinstance(index , int): - if index >= len(self): - raise IndexError("Invalid index:%d - valid range [0,%d)" % (index , len(self))) - if index < 0: - index += len(self) - - self._iset_zvalue(index , value) - else: - raise TypeError("Invalid index type:%s - must be integer" % index) - - - def __getitem__(self , index): - if isinstance(index , int): - idx = index - ls = len(self) - if idx < 0: - idx += ls - if 0 <= idx < ls: - return self._iget_zvalue(idx) - else: - raise IndexError("Invalid index:%d - valid range [0,%d)" % (index , len(self))) - else: - raise TypeError("Invalid index type:%s - must be integer" % index) - - - def getXY(self, index): - """Gets the index'th (x,y) coordinate""" - if isinstance(index, int): - idx = index - if idx < 0: - idx += len(self) - if not 0 <= idx < len(self): - raise IndexError("Invalid index:%d - valid range [0,%d)" % (index, len(self))) - index = idx - else: - raise TypeError("Invalid index type:%s - must be integer" % index) - - x = ctypes.c_double() - y = ctypes.c_double() - self._iget_xy(index, ctypes.byref(x), ctypes.byref(y)) - - return x.value, y.value - - - def getNX(self): - return self._get_nx() - - - def getNY(self): - return self._get_ny() - - def getPointset(self): - return self._get_pointset() - - def _assert_idx_or_i_and_j(self, idx, i, j): - if idx is None: - if i is None or j is None: - raise ValueError('idx is None, i and j must be ints, was %s and %s.' % (i, j)) - else: - if i is not None or j is not None: - raise ValueError('idx is set, i and j must be None, was %s and %s.' % (i, j)) - - - def getXYZ(self, idx=None, i=None, j=None): - """Returns a tuple of 3 floats, (x,y,z) for given global index, or i and j.""" - self._assert_idx_or_i_and_j(idx, i, j) - if idx is None: - nx, ny = self.getNX(), self.getNY() - i_idx, j_idx = i,j - if i_idx < 0: - i_idx += self.getNX() - if j_idx < 0: - j_idx += self.getNY() - if 0 <= i_idx < self.getNX() and 0 <= j_idx < self.getNY(): - idx = j_idx * self.getNX() + i_idx - else: - fmt = 'Index error: i=%d not in [0,nx=%d) or j=%d not in [0,ny=%d).' - raise IndexError(fmt % (i, nx, j, ny)) - x,y = self.getXY(idx) - z = self[idx] - return (x,y,z) - - - def free(self): - self._free() - - def __repr__(self): - cnt = 'nx=%d, ny=%d' % (self.getNX(), self.getNY()) - return self._create_repr(cnt) diff --git a/ThirdParty/Ert/python/python/ecl/geo/xyz_io.py b/ThirdParty/Ert/python/python/ecl/geo/xyz_io.py deleted file mode 100644 index 9f349b339f..0000000000 --- a/ThirdParty/Ert/python/python/ecl/geo/xyz_io.py +++ /dev/null @@ -1,62 +0,0 @@ -import os -from .polyline import Polyline - -class XYZIo(object): - - @staticmethod - def readXYZFile(path): - """ @rtype: Polyline """ - - if not os.path.exists(path): - raise IOError("Path does not exist '%s'!" % path) - - name = os.path.basename(path) - - polyline = Polyline(name=name) - - with open(path, "r") as f: - for line in f: - line = line.strip() - if line: - x, y, z = map(float, line.split()) - - if x != 999.000000 and y != 999.000000 and z != 999.000000: - polyline.addPoint(x, y, z) - else: - break - else: - break - - return polyline - - - @staticmethod - def readXYFile(path): - """ @rtype: Polyline """ - - if not os.path.exists(path): - raise IOError("Path does not exist '%s'!" % path) - - name = os.path.basename(path) - - polyline = Polyline(name=name) - - with open(path, "r") as f: - for line in f: - x, y= map(float, line.split()) - polyline.addPoint(x, y) - - return polyline - - - @staticmethod - def saveXYFile(polyline , filename): - """ - @type polyline: Polyline or list of tuple of (float, float) - """ - with open(filename , "w") as fileH: - for p in polyline: - fileH.write("%g %g\n" % (p[0] , p[1])) - - - diff --git a/ThirdParty/Ert/python/python/ecl/test/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/test/CMakeLists.txt deleted file mode 100644 index 9e4bec490d..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - ert_test_context.py - ert_test_runner.py - extended_testcase.py - test_run.py - source_enumerator.py - test_area.py - temp_area.py - path_context.py - lint_test_case.py - import_test_case.py - debug_msg.py -) - -add_python_package("python.ecl.test" ${PYTHON_INSTALL_PREFIX}/ecl/test "${PYTHON_SOURCES}" True) - -add_subdirectory(ecl_mock) diff --git a/ThirdParty/Ert/python/python/ecl/test/__init__.py b/ThirdParty/Ert/python/python/ecl/test/__init__.py deleted file mode 100644 index 1cc89f8d32..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -from .test_run import TestRun -from .test_run import path_exists -from .extended_testcase import ExtendedTestCase -from .source_enumerator import SourceEnumerator -from .test_area import TestArea , TestAreaContext -from .temp_area import TempArea , TempAreaContext -from .ert_test_runner import ErtTestRunner -from .path_context import PathContext -from .lint_test_case import LintTestCase -from .import_test_case import ImportTestCase -from .debug_msg import debug_msg diff --git a/ThirdParty/Ert/python/python/ecl/test/debug_msg.py b/ThirdParty/Ert/python/python/ecl/test/debug_msg.py deleted file mode 100644 index 4f479b9b74..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/debug_msg.py +++ /dev/null @@ -1,7 +0,0 @@ -import inspect - -def debug_msg(msg): - record = inspect.stack()[1] - frame = record[0] - info = inspect.getframeinfo( frame ) - return "FILE: %s LINE: %s Msg: %s" % (info.filename, info.lineno, msg) diff --git a/ThirdParty/Ert/python/python/ecl/test/ecl_mock/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/test/ecl_mock/CMakeLists.txt deleted file mode 100644 index bfa1896cd5..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/ecl_mock/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - ecl_sum_mock.py -) - -add_python_package("python.ecl.test.ecl_mock" ${PYTHON_INSTALL_PREFIX}/ecl/test/ecl_mock "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/python/python/ecl/test/ecl_mock/__init__.py b/ThirdParty/Ert/python/python/ecl/test/ecl_mock/__init__.py deleted file mode 100644 index eb49177fc0..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/ecl_mock/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .ecl_sum_mock import createEclSum diff --git a/ThirdParty/Ert/python/python/ecl/test/ecl_mock/ecl_sum_mock.py b/ThirdParty/Ert/python/python/ecl/test/ecl_mock/ecl_sum_mock.py deleted file mode 100644 index eb2b779229..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/ecl_mock/ecl_sum_mock.py +++ /dev/null @@ -1,30 +0,0 @@ -import datetime -from ecl.ecl import EclSum - - -def mock_func(ecl_sum , key , days): - return days * 10 - - -def createEclSum( case , keys , start = datetime.date(2010 , 1, 1) , sim_length_days = 5 * 365 , num_report_step = 5, num_mini_step = 10, dims = (20,10,5) , func_table = {}): - ecl_sum = EclSum.writer(case , start , dims[0] , dims[1] , dims[2]) - var_list = [] - for (kw,wgname,num) in keys: - var_list.append( ecl_sum.addVariable( kw , wgname = wgname , num = num) ) - - report_step_length = sim_length_days / num_report_step - mini_step_length = report_step_length / num_mini_step - for report_step in range(num_report_step): - for mini_step in range(num_mini_step): - days = report_step * report_step_length + mini_step * mini_step_length - t_step = ecl_sum.addTStep( report_step + 1 , sim_days = days ) - - for var in var_list: - key = var.getKey1( ) - if key in func_table: - func = func_table[key] - t_step[key] = func( days ) - else: - t_step[key] = mock_func( ecl_sum , key , days) - - return ecl_sum diff --git a/ThirdParty/Ert/python/python/ecl/test/ert_test_context.py b/ThirdParty/Ert/python/python/ecl/test/ert_test_context.py deleted file mode 100644 index dd89c5a720..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/ert_test_context.py +++ /dev/null @@ -1,117 +0,0 @@ -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'test_work_area.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os.path - -from cwrap import BaseCClass -from ert.enkf import EnKFMain, EnkfPrototype - -class ErtTest(BaseCClass): - TYPE_NAME = "ert_test" - - _alloc = EnkfPrototype("void* ert_test_context_alloc_python( char* , char*)", bind = False) - _set_store = EnkfPrototype("void* ert_test_context_set_store( ert_test , bool)") - _free = EnkfPrototype("void ert_test_context_free( ert_test )") - _get_cwd = EnkfPrototype("char* ert_test_context_get_cwd( ert_test )") - _get_enkf_main = EnkfPrototype("enkf_main_ref ert_test_context_get_main( ert_test )") - - - - def __init__(self, test_name, model_config, store_area=False): - if not os.path.exists(model_config): - raise IOError("The configuration file: %s does not exist" % model_config) - else: - c_ptr = self._alloc(test_name, model_config) - super(ErtTest, self).__init__(c_ptr) - self.setStore(store_area) - - self.__ert = None - - def setStore(self, store): - self._set_store(store) - - def getErt(self): - """ @rtype: EnKFMain """ - if self.__ert is None: - self.__ert = self._get_enkf_main() - - return self.__ert - - def free(self): - ert = self.getErt() - ert.umount() - self._free() - - def installWorkflowJob(self, job_name, job_path): - """ @rtype: bool """ - if os.path.exists(job_path) and os.path.isfile(job_path): - ert = self.getErt() - workflow_list = ert.getWorkflowList() - - workflow_list.addJob(job_name, job_path) - return workflow_list.hasJob(job_name) - else: - return False - - def runWorkflowJob(self, job_name, *arguments): - """ @rtype: bool """ - ert = self.getErt() - workflow_list = ert.getWorkflowList() - - if workflow_list.hasJob(job_name): - job = workflow_list.getJob(job_name) - job.run(ert, [arg for arg in arguments]) - return True - else: - return False - - - def getCwd(self): - """ - Returns the current working directory of this context. - @rtype: string - """ - return self._get_cwd() - - - -class ErtTestContext(object): - def __init__(self, test_name, model_config, store_area=False): - self.__test_name = test_name - self.__model_config = model_config - self.__store_area = store_area - self.__test_context = ErtTest(self.__test_name, self.__model_config, store_area=self.__store_area) - - - def __enter__(self): - """ @rtype: ErtTest """ - return self.__test_context - - - def __exit__(self, exc_type, exc_val, exc_tb): - del self.__test_context - return False - - - def getErt(self): - return self.__test_context.getErt() - - - def getCwd(self): - """ - Returns the current working directory of this context. - @rtype: string - """ - return self.__test_context.getCwd() diff --git a/ThirdParty/Ert/python/python/ecl/test/ert_test_runner.py b/ThirdParty/Ert/python/python/ecl/test/ert_test_runner.py deleted file mode 100644 index 0ca274508f..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/ert_test_runner.py +++ /dev/null @@ -1,63 +0,0 @@ -import os - -try: - from unittest2 import TestLoader, TextTestRunner -except ImportError: - from unittest import TestLoader, TextTestRunner - - -class ErtTestRunner(object): - - @staticmethod - def runTestSuite(tests , test_verbosity = 3): - test_runner = TextTestRunner(verbosity=test_verbosity) - result = test_runner.run(tests) - - return result.wasSuccessful() - - - @staticmethod - def findTestsInDirectory(path, recursive=True , pattern = "test*.py"): - loader = TestLoader() - test_suite = loader.discover(path , pattern = pattern) - - for (root, dirnames, filenames) in os.walk( path ): - for directory in dirnames: - test_suite.addTests(ErtTestRunner.findTestsInDirectory(os.path.join(root, directory), recursive , pattern)) - - return test_suite - - - @staticmethod - def runTestsInDirectory(path=".", recursive=True, test_verbosity=3): - test_suite = ErtTestRunner.findTestsInDirectory(path, recursive) - return ErtTestRunner.runTestSuite(test_suite) - - - @staticmethod - def runTestsInClass(classpath, test_verbosity=3): - klass = ErtTestRunner.importClass(classpath) - loader = TestLoader() - tests = loader.loadTestsFromTestCase(klass) - testRunner = TextTestRunner(verbosity=test_verbosity) - testRunner.run(tests) - - - @staticmethod - def importClass(classpath): - dot = classpath.rfind(".") - class_name = classpath[dot + 1:] - try: - m = __import__(classpath[0:dot], globals(), locals(), [class_name]) - return getattr(m, class_name) - except ImportError: - print("Failed to import: %s" % classpath) - raise - - - @staticmethod - def getTestsFromTestClass(test_class_path, argv=None): - klass = ErtTestRunner.importClass(test_class_path) - klass.argv = argv - loader = TestLoader() - return loader.loadTestsFromTestCase(klass) diff --git a/ThirdParty/Ert/python/python/ecl/test/extended_testcase.py b/ThirdParty/Ert/python/python/ecl/test/extended_testcase.py deleted file mode 100644 index 70bf73f918..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/extended_testcase.py +++ /dev/null @@ -1,181 +0,0 @@ -import numbers -import os -import os.path -import traceback -import sys - -try: - from unittest2 import TestCase -except ImportError: - from unittest import TestCase - -from .source_enumerator import SourceEnumerator -from ecl.util import installAbortSignals -from ecl.util import Version - -TESTDATA_ROOT = None -SHARE_ROOT = None -SOURCE_ROOT = None -BUILD_ROOT = None -try: - from test_env import * - assert( os.path.isdir( TESTDATA_ROOT )) - assert( os.path.isdir( SOURCE_ROOT )) - assert( os.path.isdir( BUILD_ROOT )) - if not SHARE_ROOT is None: - assert( os.path.isdir( SHARE_ROOT )) -except ImportError: - sys.stderr.write("Warning: could not import file test_env.py - this might lead to test failures.") - - -class _AssertNotRaisesContext(object): - - def __init__(self, test_class): - super(_AssertNotRaisesContext, self).__init__() - self._test_class = test_class - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, tb): - if exc_type is not None: - try: - exc_name = exc_type.__name__ - except AttributeError: - exc_name = str(exc_type) - self._test_class.fail("Exception: %s raised\n%s" % (exc_name, traceback.print_exception(exc_type, exc_value, tb))) - return True - - -""" -This class provides some extra functionality for testing values that are almost equal. -""" -class ExtendedTestCase(TestCase): - def __init__(self , *args , **kwargs): - self.__testdata_root = None - self.__share_root = None - installAbortSignals() - super(ExtendedTestCase , self).__init__(*args , **kwargs) - - - def __str__(self): - return 'ExtendedTestCase( TESTADATA_ROOT=%s, SOURCE_ROOT=%s, SHARE_ROOT=%s, BUILD_ROOT=%s)' % (TESTDATA_ROOT, - SOURCE_ROOT, - SHARE_ROOT, - BUILD_ROOT) - - def assertFloatEqual(self, first, second, msg=None, tolerance=1e-6): - try: - f_first, f_second = float(first), float(second) - diff = abs(f_first - f_second) - scale = max(1, abs(first) + abs(second)) - if msg is None: - msg = "Floats not equal: |%f - %f| > %g" % (f_first, f_second, tolerance) - self.assertTrue(diff < tolerance * scale, msg=msg) - except TypeError: - self.fail("Cannot compare as floats: %s (%s) and %s (%s)" % - (first, type(first), second, type(second))) - - - def assertAlmostEqualList(self, first, second, msg=None, tolerance=1e-6): - if len(first) != len(second): - self.fail("Lists are not of same length!") - - for index in range(len(first)): - self.assertFloatEqual( - first[index], second[index], - msg=msg, tolerance=tolerance - ) - - - def assertImportable(self, module_name): - try: - __import__(module_name) - except ImportError: - tb = traceback.format_exc() - self.fail("Module %s not found!\n\nTrace:\n%s" % (module_name, str(tb))) - except Exception: - tb = traceback.format_exc() - self.fail("Import of module %s caused errors!\n\nTrace:\n%s" % (module_name, str(tb))) - - - def assertFilesAreEqual(self, first, second): - if not self.__filesAreEqual(first, second): - self.fail("Buffer contents of files are not identical!") - - - def assertFilesAreNotEqual(self, first, second): - if self.__filesAreEqual(first, second): - self.fail("Buffer contents of files are identical!") - - def assertFileExists(self, path): - if not os.path.exists(path) or not os.path.isfile(path): - self.fail("The file: %s does not exist!" % path) - - def assertDirectoryExists(self, path): - if not os.path.exists(path) or not os.path.isdir(path): - self.fail("The directory: %s does not exist!" % path) - - def assertFileDoesNotExist(self, path): - if os.path.exists(path) and os.path.isfile(path): - self.fail("The file: %s exists!" % path) - - def assertDirectoryDoesNotExist(self, path): - if os.path.exists(path) and os.path.isdir(path): - self.fail("The directory: %s exists!" % path) - - def __filesAreEqual(self, first, second): - buffer1 = open(first).read() - buffer2 = open(second).read() - - return buffer1 == buffer2 - - def assertEnumIsFullyDefined(self, enum_class, enum_name, source_path, verbose=False): - enum_values = SourceEnumerator.findEnumerators(enum_name, os.path.join( SOURCE_ROOT , source_path)) - - for identifier, value in enum_values: - if verbose: - print("%s = %d" % (identifier, value)) - - self.assertTrue(enum_class.__dict__.has_key(identifier), "Enum does not have identifier: %s" % identifier) - class_value = enum_class.__dict__[identifier] - self.assertEqual(class_value, value, "Enum value for identifier: %s does not match: %s != %s" % (identifier, class_value, value)) - - - @staticmethod - def createSharePath(path): - return os.path.realpath(os.path.join(SHARE_ROOT , path)) - - - @staticmethod - def createTestPath(path): - return os.path.realpath(os.path.join(TESTDATA_ROOT , path)) - - - def assertNotRaises(self, func=None): - - context = _AssertNotRaisesContext(self) - if func is None: - return context - - with context: - func() - - @staticmethod - def slowTestShouldNotRun(): - """ - @param: The slow test flag can be set by environment variable SKIP_SLOW_TESTS = [True|False] - """ - - return os.environ.get("SKIP_SLOW_TESTS", "False") == "True" - - - @staticmethod - def requireVersion(major , minor , micro = "git"): - required_version = Version(major, minor , micro) - current_version = Version.currentVersion() - - if required_version < current_version: - return True - else: - return False diff --git a/ThirdParty/Ert/python/python/ecl/test/import_test_case.py b/ThirdParty/Ert/python/python/ecl/test/import_test_case.py deleted file mode 100644 index 761b029018..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/import_test_case.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import importlib -import os -import sys -import traceback -import unittest -import inspect -import imp - -class ImportTestCase(unittest.TestCase): - - def import_file(self, path): - return imp.load_source( "module", path) - - def import_module(self , module): - mod = importlib.import_module( module ) - return mod - - def import_package(self, package): - module = self.import_module( package ) - path = os.path.dirname( inspect.getfile( module ) ) - - for entry in sorted(os.listdir(path)): - entry_path = os.path.join(path, entry) - if os.path.isdir( entry_path ): - module = os.path.basename( entry ) - sub_module = "%s.%s" % (package , module) - self.import_package( sub_module ) - else: - module, ext = os.path.splitext( entry ) - if module == "__init__": - continue - - if ext == "py": - self.import_module("%s.%s" % (package , module)) - - return True diff --git a/ThirdParty/Ert/python/python/ecl/test/lint_test_case.py b/ThirdParty/Ert/python/python/ecl/test/lint_test_case.py deleted file mode 100644 index ff3bd729d6..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/lint_test_case.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import sys -import fnmatch -import os -import unittest -try: - from pylint import epylint as lint -except ImportError: - sys.stderr.write("Could not import pylint module - lint based testing will be skipped\n") - lint = None - - -class LintTestCase(unittest.TestCase): - """This class is a test case for linting.""" - - LINT_ARGS = ['-d', 'R,C,W'] + \ - ['--extension-pkg-whitelist=numpy'] - - - @staticmethod - def _get_lintable_files(paths, whitelist=()): - """Recursively traverses all folders in paths for *.py files""" - matches = [] - for folder in paths: - for root, _, filenames in os.walk(folder): - for filename in fnmatch.filter(filenames, '*.py'): - if filename not in whitelist: - matches.append(os.path.join(root, filename)) - return matches - - - def assertLinted(self, paths, whitelist=()): # noqa - """Takes a path to a folder or a list of paths to folders and recursively finds - all *.py files within that folder except the ones with filenames in whitelist. - - Will assert lint.lint(fname) == 0 for every *.py file found. - """ - if lint is None: - self.skipTest("pylint not installed") - - if isinstance(paths, str): - paths = [paths] - files = self._get_lintable_files(paths, whitelist=whitelist) - for f in files: - self.assertEqual(0, lint.lint(f, self.LINT_ARGS), 'Linting required for %s' % f) diff --git a/ThirdParty/Ert/python/python/ecl/test/path_context.py b/ThirdParty/Ert/python/python/ecl/test/path_context.py deleted file mode 100644 index 98dda72040..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/path_context.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -import shutil - -class PathContext(object): - def __init__(self , path , store = False): - self.path = path - self.cwd = os.getcwd() - self.store = store - self.path_list = [ ] - - if not os.path.exists(path): - work_path = path - - while True: - work_path , base = os.path.split(work_path) - if work_path: - if os.path.isdir(work_path): - break - else: - self.path_list.append( work_path ) - else: - break - - os.makedirs( path ) - else: - if not self.store: - raise OSError("Entry %s already exists" % path) - os.chdir( path ) - - - - def __exit__(self , exc_type , exc_val , exc_tb): - os.chdir( self.cwd ) - if self.store == False: - shutil.rmtree( self.path ) - for path in self.path_list: - try: - os.rmdir( path ) - except OSError: - break - - return False - - - def __enter__(self): - return self diff --git a/ThirdParty/Ert/python/python/ecl/test/source_enumerator.py b/ThirdParty/Ert/python/python/ecl/test/source_enumerator.py deleted file mode 100644 index e0c76300f1..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/source_enumerator.py +++ /dev/null @@ -1,39 +0,0 @@ -import os -import re - -class SourceEnumerator(object): - - @classmethod - def removeComments(cls, code_string): - code_string = re.sub(re.compile("/\*.*?\*/",re.DOTALL ) ,"" ,code_string) # remove all occurance streamed comments (/*COMMENT */) from string - code_string = re.sub(re.compile("//.*?\n" ) ,"" ,code_string) # remove all occurance singleline comments (//COMMENT\n ) from string - return code_string - - - @classmethod - def findEnum(cls, enum_name, full_source_file_path): - with open(full_source_file_path, "r") as f: - text = f.read() - - text = SourceEnumerator.removeComments(text) - - enum_pattern = re.compile("typedef\s+enum\s+\{(.*?)\}\s*(\w+?);", re.DOTALL) - - for enum in enum_pattern.findall(text): - if enum[1] == enum_name: - return enum[0] - - raise ValueError("Enum with name: '%s' not found!" % enum_name) - - - @classmethod - def findEnumerators(cls, enum_name, source_file): - enum_text = SourceEnumerator.findEnum(enum_name, source_file) - - enumerator_pattern = re.compile("(\w+?)\s*?=\s*?(\d+)") - - enumerators = [] - for enumerator in enumerator_pattern.findall(enum_text): - enumerators.append((enumerator[0], int(enumerator[1]))) - - return enumerators diff --git a/ThirdParty/Ert/python/python/ecl/test/temp_area.py b/ThirdParty/Ert/python/python/ecl/test/temp_area.py deleted file mode 100644 index 4679eed017..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/temp_area.py +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright (C) 2016 Statoil ASA, Norway. -# -# The file 'temp_area.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import os -import os.path -from ecl.util import UtilPrototype -from . import TestArea - -class TempArea(TestArea): - """TempArea class is essentially similar to the TestArea class, with - the only difference that the cwd is *not* changed into the newly - created area. - """ - - _temp_area_alloc = UtilPrototype("void* temp_area_alloc( char* )" , bind = False) - _temp_area_alloc_relative = UtilPrototype("void* temp_area_alloc_relative( char* , char* )" , bind = False) - - def __init__(self, name, prefix = None , store_area=False): - if prefix: - if os.path.exists( prefix ): - c_ptr = self._temp_area_alloc_relative(prefix , name) - else: - raise IOError("The prefix path:%s must exist" % prefix) - else: - c_ptr = self._temp_area_alloc(name) - super(TempArea, self).__init__(name , c_ptr = c_ptr , store_area = store_area) - - - def __str__(self): - return self.getPath() - - - def get_cwd(self): - """ - Since the TempArea class does *not* change the cwd this method - just returns the ordinary os.getcwd(). - """ - return os.getcwd() - - - def getPath(self): - """ - Will return the full path to the temporary working area. - """ - return self._get_cwd( ) - - - -class TempAreaContext(object): - def __init__(self, name, prefix = None , store_area=False): - self.name = name - self.store_area = store_area - self.prefix = prefix - - def __enter__(self): - """ - @rtype: TempArea - """ - self.temp_area = TempArea(self.name, prefix = self.prefix , store_area = self.store_area ) - return self.temp_area - - - def __exit__(self, exc_type, exc_val, exc_tb): - del self.temp_area - return False - - - diff --git a/ThirdParty/Ert/python/python/ecl/test/test_area.py b/ThirdParty/Ert/python/python/ecl/test/test_area.py deleted file mode 100644 index 0d2cb1cf57..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/test_area.py +++ /dev/null @@ -1,149 +0,0 @@ -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'test_work_area.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os.path - -from cwrap import BaseCClass -from ecl.util import UtilPrototype - - -class TestArea(BaseCClass): - _test_area_alloc = UtilPrototype("void* test_work_area_alloc( char* )" , bind = False) - _test_area_alloc_relative = UtilPrototype("void* test_work_area_alloc_relative( char* , char* )" , bind = False) - _free = UtilPrototype("void test_work_area_free( test_area )") - _install_file = UtilPrototype("void test_work_area_install_file( test_area , char* )") - _copy_directory = UtilPrototype("void test_work_area_copy_directory( test_area , char* )") - _copy_file = UtilPrototype("void test_work_area_copy_file( test_area , char* )") - _copy_directory_content = UtilPrototype("void test_work_area_copy_directory_content( test_area , char* )") - _copy_parent_directory = UtilPrototype("void test_work_area_copy_parent_directory( test_area , char* )") - _copy_parent_content = UtilPrototype("void test_work_area_copy_parent_content( test_area , char* )") - _get_cwd = UtilPrototype("char* test_work_area_get_cwd( test_area )") - _get_original_cwd = UtilPrototype("char* test_work_area_get_original_cwd( test_area )") - _set_store = UtilPrototype("void test_work_area_set_store( test_area , bool)") - _sync = UtilPrototype("void test_work_area_sync( test_area )") - - def __init__(self, test_name, prefix = None , store_area=False , c_ptr = None): - - if c_ptr is None: - if prefix: - if os.path.exists( prefix ): - c_ptr = self._test_area_alloc_relative(prefix , test_name) - else: - raise IOError("The prefix path:%s must exist" % prefix) - else: - c_ptr = self._test_area_alloc(test_name) - - super(TestArea, self).__init__(c_ptr) - self.set_store( store_area ) - - - def get_original_cwd(self): - return self._get_original_cwd() - - def get_cwd(self): - return self._get_cwd() - - def orgPath(self , path): - if os.path.isabs( path ): - return path - else: - return os.path.abspath( os.path.join( self.get_original_cwd( ) , path ) ) - - - # All the methods install_file() , copy_directory(), - # copy_parent_directory(), copy_parent_content(), - # copy_directory_content() and copy_file() expect an input - # argument which is relative to the original CWD - or absolute. - - def install_file( self, filename): - if os.path.isfile(self.orgPath(filename)): - self._install_file(filename) - else: - raise IOError("No such file:%s" % filename) - - - def copy_directory( self, directory): - if os.path.isdir( self.orgPath(directory) ): - self._copy_directory(directory) - else: - raise IOError("No such directory: %s" % directory) - - def copy_parent_directory( self , path): - if os.path.exists( self.orgPath(path) ): - self._copy_parent_directory( path) - else: - raise IOError("No such file or directory: %s" % path) - - - def copy_parent_content( self , path): - if os.path.exists( self.orgPath(path) ): - self._copy_parent_content(path) - else: - raise IOError("No such file or directory: %s" % path) - - def copy_directory_content( self, directory): - if os.path.isdir( self.orgPath(directory) ): - self._copy_directory_content(directory) - else: - raise IOError("No such directory: %s" % directory ) - - - def copy_file( self, filename): - if os.path.isfile( self.orgPath(filename) ): - self._copy_file(filename) - else: - raise IOError("No such file:%s" % filename) - - - def free(self): - self._free() - - - def set_store(self, store): - self._set_store(store) - - - def getFullPath(self , path): - if not os.path.exists( path ): - raise IOError("Path not found:%s" % path) - - if os.path.isabs( path ): - raise IOError("Path:%s is already absolute" % path) - - return os.path.join( self.get_cwd() , path ) - - - def sync(self): - return self._sync( ) - - - -class TestAreaContext(object): - def __init__(self, test_name, prefix = None , store_area=False): - self.test_name = test_name - self.store_area = store_area - self.prefix = prefix - - def __enter__(self): - """ - @rtype: TestArea - """ - self.test_area = TestArea(self.test_name, prefix = self.prefix , store_area = self.store_area ) - return self.test_area - - - def __exit__(self, exc_type, exc_val, exc_tb): - del self.test_area - return False diff --git a/ThirdParty/Ert/python/python/ecl/test/test_run.py b/ThirdParty/Ert/python/python/ecl/test/test_run.py deleted file mode 100644 index 496353ba4d..0000000000 --- a/ThirdParty/Ert/python/python/ecl/test/test_run.py +++ /dev/null @@ -1,158 +0,0 @@ -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'test_run.py' 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 -# the Free Software Foundation, teither version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import random -import os.path -import subprocess -import argparse -from .test_area import TestAreaContext - - -def path_exists( path ): - if os.path.exists( path ): - return (True , "Path:%s exists" % path) - else: - return (False , "ERROR: Path:%s does not exist" % path) - - -class TestRun(object): - default_ert_cmd = "ert" - default_ert_version = "stable" - default_path_prefix = None - - def __init__(self , config_file , args = [] , name = None): - if os.path.exists( config_file ) and os.path.isfile( config_file ): - self.parseArgs(args) - self.__ert_cmd = TestRun.default_ert_cmd - self.path_prefix = TestRun.default_path_prefix - self.config_file = config_file - - self.check_list = [] - self.workflows = [] - if name: - self.name = name - else: - self.name = config_file.replace("/" , ".") - while True: - if self.name[0] == ".": - self.name = self.name[1:] - else: - break - self.name += "/%08d" % random.randint(0,100000000) - else: - raise IOError("No such config file: %s" % config_file) - - - def parseArgs(self , args): - parser = argparse.ArgumentParser() - parser.add_argument("-v" , "--version" , default = self.default_ert_version) - parser.add_argument("args" , nargs="*") - result = parser.parse_args(args) - self.ert_version = result.version - self.args = result.args - - - def get_config_file(self): - return self.__config_file - - def set_config_file(self , input_config_file): - self.__config_file = os.path.basename( input_config_file ) - self.abs_config_file = os.path.abspath( input_config_file ) - - config_file = property( get_config_file , set_config_file ) - - #----------------------------------------------------------------- - - def set_path_prefix(self , path_prefix): - self.__path_prefix = path_prefix - - def get_path_prefix(self): - return self.__path_prefix - - path_prefix = property( get_path_prefix , set_path_prefix ) - - #----------------------------------------------------------------- - - def get_ert_cmd(self): - return self.__ert_cmd - - def set_ert_cmd(self , cmd): - self.__ert_cmd = cmd - - ert_cmd = property( get_ert_cmd , set_ert_cmd) - - #----------------------------------------------------------------- - - def get_workflows(self): - return self.workflows - - - def add_workflow(self , workflow): - self.workflows.append( workflow ) - - #----------------------------------------------------------------- - - def get_args(self): - return self.args - - #----------------------------------------------------------------- - - def add_check( self , check_func , arg): - if callable(check_func): - self.check_list.append( (check_func , arg) ) - else: - raise Exception("The checker:%s is not callable" % check_func ) - - #----------------------------------------------------------------- - - def __run(self , work_area ): - argList = [ self.ert_cmd , "-v" , self.ert_version ] - for arg in self.args: - argList.append( arg ) - - argList.append( self.config_file ) - for wf in self.workflows: - argList.append( wf ) - - status = subprocess.call( argList ) - if status == 0: - return (True , "ert has run successfully") - else: - return (False , "ERROR:: ert exited with status code:%s" % status) - - - def run(self): - if len(self.workflows): - with TestAreaContext(self.name , prefix = self.path_prefix , store_area = False) as work_area: - test_cwd = work_area.get_cwd() - work_area.copy_parent_content( self.abs_config_file ) - status = self.__run( work_area ) - global_status = status[0] - - status_list = [ status ] - if status[0]: - for (check_func , arg) in self.check_list: - status = check_func( arg ) - status_list.append( status ) - if not status[0]: - global_status = False - - if not global_status: - work_area.set_store( True ) - - return (global_status , test_cwd , status_list) - else: - raise Exception("Must have added workflows before invoking start()") - diff --git a/ThirdParty/Ert/python/python/ecl/util/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/util/CMakeLists.txt deleted file mode 100644 index 2a950d6958..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - bool_vector.py - buffer.py - ctime.py - double_vector.py - hash.py - int_vector.py - install_abort_signals.py - log.py - lookup_table.py - matrix.py - profiler.py - rng.py - stat.py - stringlist.py - #substitution_list.py - thread_pool.py - cthread_pool.py - time_vector.py - ui_return.py - util_func.py - vector_template.py - permutation_vector.py - version.py - arg_pack.py - path_format.py - cwd_context.py -) - -add_python_package("python.ecl.util" ${PYTHON_INSTALL_PREFIX}/ecl/util "${PYTHON_SOURCES}" True) - -add_subdirectory(enums) diff --git a/ThirdParty/Ert/python/python/ecl/util/__init__.py b/ThirdParty/Ert/python/python/ecl/util/__init__.py deleted file mode 100644 index 6519f170c8..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/__init__.py +++ /dev/null @@ -1,135 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file '__init__.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Package with utility classes, used by other ERT classes. - -The libutil library implements many utility functions and classes of -things like hash table and vector; these classes are extensively used -by the other ert libraries. The present wrapping here is to facilitate -use and interaction with various ert classes, in a pure python context -you are probably better served by using a plain python solution; -either based on built in python objects or well established third -party packages. - -The modules included in the util package are: - - tvector.py: This module implements the classes IntVector, - DoubleVector and BoolVector. This is a quite normal - implementation of a typed growable vector; but with a special - twist regarding default values. - - util_func.py: This module wraps a couple of stateless (i.e. there is - no class involved) functions from the util.c file. - -""" - -from __future__ import (absolute_import, division, - print_function, unicode_literals) - -import ecl -from cwrap import Prototype - - -class UtilPrototype(Prototype): - lib = ecl.load("libecl") - - def __init__(self, prototype, bind=True, allow_attribute_error=False): - super(UtilPrototype, self).__init__(UtilPrototype.lib, prototype, bind=bind, allow_attribute_error=allow_attribute_error) - - - -from .version import Version, EclVersion - -from .enums import RngAlgTypeEnum, RngInitModeEnum, LLSQResultEnum - -from .ctime import CTime - -from .permutation_vector import PermutationVector -from .vector_template import VectorTemplate -from .double_vector import DoubleVector -from .int_vector import IntVector -from .bool_vector import BoolVector -from .time_vector import TimeVector -from .stringlist import StringList -from .rng import RandomNumberGenerator -from .matrix import Matrix -from .stat import quantile, quantile_sorted, polyfit -from .log import Log -from .lookup_table import LookupTable -from .buffer import Buffer -from .hash import Hash, StringHash, DoubleHash, IntegerHash -from .ui_return import UIReturn -from .thread_pool import ThreadPool -from .cthread_pool import CThreadPool, startCThreadPool -from .install_abort_signals import installAbortSignals, updateAbortSignals -from .profiler import Profiler -from .arg_pack import ArgPack -from .path_format import PathFormat -from .cwd_context import CWDContext - - - -### -### monkey_the_camel is a function temporarily added to libecl while we are in -### the process of changing camelCase function names to snake_case function -### names. -### -### See https://github.com/Statoil/libecl/issues/142 for a discussion and for -### usage. -### - -import os -import warnings - -__cc = os.environ.get('ECLWARNING', None) # __cc in (None, 'user', 'dev', 'hard') - -def __silencio(msg): - pass - -def __user_warning(msg): - print('User warning: ' + msg) - -def __dev_warning(msg): - warnings.warn(msg, DeprecationWarning) - -def __hard_warning(msg): - raise UserWarning('CamelCase exception: ' + msg) - - -__ecl_camel_case_warning = __silencio -if __cc == 'user': - __ecl_camel_case_warning = __user_warning -elif __cc == 'dev': - __ecl_camel_case_warning = __dev_warning -elif __cc == 'hard': - __ecl_camel_case_warning = __hard_warning - - -def monkey_the_camel(class_, camel, method_, method_type=None): - """Creates a method "class_.camel" in class_ which prints a warning and forwards - to method_. method_type should be one of (None, classmethod, staticmethod), - and generates new methods accordingly. - """ - def shift(*args): - return args if (method_type != classmethod) else args[1:] - def warned_method(*args, **kwargs): - __ecl_camel_case_warning('Warning, %s is deprecated, use %s' % (camel, str(method_))) - return method_(*shift(*args), **kwargs) - if method_type == staticmethod: - warned_method = staticmethod(warned_method) - elif method_type == classmethod: - warned_method = classmethod(warned_method) - setattr(class_, camel, warned_method) diff --git a/ThirdParty/Ert/python/python/ecl/util/arg_pack.py b/ThirdParty/Ert/python/python/ecl/util/arg_pack.py deleted file mode 100644 index e20bd3fe99..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/arg_pack.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'arg_pack.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCClass -from ecl.util import UtilPrototype - - -class ArgPack(BaseCClass): - TYPE_NAME = "arg_pack" - - _alloc = UtilPrototype("void* arg_pack_alloc()" , bind = False) - _append_int = UtilPrototype("void arg_pack_append_int(arg_pack, int)") - _append_double = UtilPrototype("void arg_pack_append_double(arg_pack, double)") - _append_ptr = UtilPrototype("void arg_pack_append_ptr(arg_pack, void*)") - - _size = UtilPrototype("int arg_pack_size(arg_pack)") - _free = UtilPrototype("void arg_pack_free(arg_pack)") - - def __init__(self, *args): - c_ptr = self._alloc() - super(ArgPack, self).__init__(c_ptr) - self.child_list = [] - for arg in args: - self.append(arg) - - - def append(self, data): - if isinstance(data, int): - self._append_int(data) - elif isinstance(data, float): - self._append_double(data) - elif isinstance(data, BaseCClass): - self._append_ptr(BaseCClass.from_param(data)) - self.child_list.append(data) - else: - raise TypeError("Can only add int/double/basecclass") - - - def __len__(self): - return self._size() - - - def free(self): - self._free( ) diff --git a/ThirdParty/Ert/python/python/ecl/util/bool_vector.py b/ThirdParty/Ert/python/python/ecl/util/bool_vector.py deleted file mode 100644 index 9f920628a9..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/bool_vector.py +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'vector_template.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.util import VectorTemplate, UtilPrototype - - -class BoolVector(VectorTemplate): - default_format = "%8d" - - _alloc = UtilPrototype("void* bool_vector_alloc( int , bool )" , bind = False) - _create_active_mask = UtilPrototype("bool_vector_obj string_util_alloc_active_mask( char* )" , bind = False) - _active_list = UtilPrototype("int_vector_obj bool_vector_alloc_active_list(bool_vector)", bind = False) - _alloc_copy = UtilPrototype("bool_vector_obj bool_vector_alloc_copy( bool_vector )") - _update_active_mask = UtilPrototype("bool string_util_update_active_mask(char*, bool_vector)" , bind = False) - - _strided_copy = UtilPrototype("bool_vector_obj bool_vector_alloc_strided_copy( bool_vector , int , int , int)") - _free = UtilPrototype("void bool_vector_free( bool_vector )") - _iget = UtilPrototype("bool bool_vector_iget( bool_vector , int )") - _safe_iget = UtilPrototype("bool bool_vector_safe_iget( bool_vector , int )") - _iset = UtilPrototype("void bool_vector_iset( bool_vector , int , bool)") - _size = UtilPrototype("int bool_vector_size( bool_vector )") - _append = UtilPrototype("void bool_vector_append( bool_vector , bool )") - _idel_block = UtilPrototype("void bool_vector_idel_block( bool_vector , bool , bool )") - _idel = UtilPrototype("void bool_vector_idel( bool_vector , int )") - _pop = UtilPrototype("bool bool_vector_pop( bool_vector )") - _lshift = UtilPrototype("void bool_vector_lshift( bool_vector , int )") - _rshift = UtilPrototype("void bool_vector_rshift( bool_vector , int )") - _insert = UtilPrototype("void bool_vector_insert( bool_vector , int , bool)") - _fprintf = UtilPrototype("void bool_vector_fprintf( bool_vector , FILE , char* , char*)") - _sort = UtilPrototype("void bool_vector_sort( bool_vector )") - _rsort = UtilPrototype("void bool_vector_rsort( bool_vector )") - _reset = UtilPrototype("void bool_vector_reset( bool_vector )") - _set_read_only = UtilPrototype("void bool_vector_set_read_only( bool_vector , bool )") - _get_read_only = UtilPrototype("bool bool_vector_get_read_only( bool_vector )") - _get_max = UtilPrototype("bool bool_vector_get_max( bool_vector )") - _get_min = UtilPrototype("bool bool_vector_get_min( bool_vector )") - _get_max_index = UtilPrototype("int bool_vector_get_max_index( bool_vector , bool)") - _get_min_index = UtilPrototype("int bool_vector_get_min_index( bool_vector , bool)") - _shift = UtilPrototype("void bool_vector_shift( bool_vector , bool )") - _scale = UtilPrototype("void bool_vector_scale( bool_vector , bool )") - _div = UtilPrototype("void bool_vector_div( bool_vector , bool )") - _inplace_add = UtilPrototype("void bool_vector_inplace_add( bool_vector , bool_vector )") - _inplace_mul = UtilPrototype("void bool_vector_inplace_mul( bool_vector , bool_vector )") - _assign = UtilPrototype("void bool_vector_set_all( bool_vector , bool)") - _memcpy = UtilPrototype("void bool_vector_memcpy(bool_vector , bool_vector )") - _set_default = UtilPrototype("void bool_vector_set_default( bool_vector , bool)") - _get_default = UtilPrototype("bool bool_vector_get_default( bool_vector )") - _element_size = UtilPrototype("int bool_vector_element_size( bool_vector )") - - _permute = UtilPrototype("void bool_vector_permute(bool_vector, permutation_vector)") - _sort_perm = UtilPrototype("permutation_vector_obj bool_vector_alloc_sort_perm(bool_vector)") - _rsort_perm = UtilPrototype("permutation_vector_obj bool_vector_alloc_rsort_perm(bool_vector)") - - _contains = UtilPrototype("bool bool_vector_contains(bool_vector, bool)") - _select_unique = UtilPrototype("void bool_vector_select_unique(bool_vector)") - _element_sum = UtilPrototype("bool bool_vector_sum(bool_vector)") - _get_data_ptr = UtilPrototype("bool* bool_vector_get_ptr(bool_vector)") - _count_equal = UtilPrototype("int bool_vector_count_equal(bool_vector, bool)") - - def __init__(self, default_value=False, initial_size=0): - super(BoolVector, self).__init__(default_value, initial_size) - - def count(self, value=True): - """ @rtype: int """ - return self._count_equal(self, value) - - @classmethod - def createActiveMask(cls, range_string): - """ - Will create a BoolVector 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" => {F,T,F,F,T,T,T,T,F,F,T} - "1,4-7,10X" => {} - - The empty list will evaluate to false - @rtype: BoolVector - """ - return cls._create_active_mask(range_string) - - def updateActiveMask(self, range_string): - """ - Updates a bool vector based on a range string. - @type range_string: str - @type bool_vector: BoolVector - @rtype: bool - """ - return self._update_active_mask(range_string , self) - - @classmethod - def createFromList(cls, size, source_list): - """ - Allocates a bool vector from a Python list of indexes - @rtype: BoolVector - """ - bool_vector = BoolVector(False, size) - - for index in source_list: - index = int(index) - bool_vector[index] = True - - return bool_vector - - def createActiveList(self): - """ @rtype: ecl.util.IntVector """ - return self._active_list(self) - - def _tostr(self, arr = None): - if arr is None: - arr = self - return "".join(['1' if x else '0' for x in arr]) - - def __repr__(self): - """Will return BoolVector(size = 4, content = "0010") at 0x1729 and - if size > 10, will return content = "0001...100", i.e., |content|<=10. - """ - cnt = '' - ls = len(self) - if ls <= 20: - cnt = self._tostr() - else: - a,b = self[:9], self[-8:] - cnt = self._tostr(a) - cnt += "..." - cnt += self._tostr(b) - return 'BoolVector(size = %d, content = "%s") %s' % (ls, cnt, self._ad_str()) diff --git a/ThirdParty/Ert/python/python/ecl/util/buffer.py b/ThirdParty/Ert/python/python/ecl/util/buffer.py deleted file mode 100644 index 44a96cfd62..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/buffer.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'buffer.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCClass -from ecl.util import UtilPrototype - - -class Buffer(BaseCClass): - _alloc = UtilPrototype("void* buffer_alloc(int)" , bind = False) - _free = UtilPrototype("void buffer_free(buffer)") - - def __init__(self, size): - super(Buffer, self).__init__(self._alloc(size)) - - def free(self): - self._free() diff --git a/ThirdParty/Ert/python/python/ecl/util/cthread_pool.py b/ThirdParty/Ert/python/python/ecl/util/cthread_pool.py deleted file mode 100644 index 5c5824b2b7..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/cthread_pool.py +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'cthread_pool.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import ctypes - -from cwrap import BaseCClass -from ecl.util import UtilPrototype - - -class CThreadPool(BaseCClass): - TYPE_NAME = "thread_pool" - - _alloc = UtilPrototype("void* thread_pool_alloc(int, bool)", bind = False) - _free = UtilPrototype("void thread_pool_free(thread_pool)") - _add_job = UtilPrototype("void thread_pool_add_job(thread_pool, void*, void*)") - _join = UtilPrototype("void thread_pool_join(thread_pool)") - - def __init__(self, pool_size, start=True): - c_ptr = self._alloc(pool_size, start) - super(CThreadPool, self).__init__(c_ptr) - self.arg_list = [] - - def addTaskFunction(self, name, lib, c_function_name): - function = CThreadPool.lookupCFunction(lib, c_function_name) - - def wrappedFunction(arg): - return self.addTask(function, arg) - - setattr(self, name, wrappedFunction) - - def addTask(self, cfunc, arg): - """ - The function should come from CThreadPool.lookupCFunction(). - """ - if isinstance(arg, BaseCClass): - arg_ptr = BaseCClass.from_param(arg) - else: - arg_ptr = arg - - self.arg_list.append(arg) - self._add_job(cfunc, arg_ptr) - - def join(self): - self._join() - - def free(self): - self.join() - self._free() - - @staticmethod - def lookupCFunction(lib, name): - if isinstance(lib, ctypes.CDLL): - func = getattr(lib, name) - return func - else: - raise TypeError("The lib argument must be of type ctypes.CDLL") - - -class CThreadPoolContextManager(object): - def __init__(self, tp): - self.__tp = tp - - def __enter__(self): - return self.__tp - - def __exit__(self, exc_type, exc_val, exc_tb): - self.__tp.join() - return False - - -def startCThreadPool(size): - return CThreadPoolContextManager(CThreadPool(size, start=True)) diff --git a/ThirdParty/Ert/python/python/ecl/util/ctime.py b/ThirdParty/Ert/python/python/ecl/util/ctime.py deleted file mode 100644 index 04d7d42e2a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/ctime.py +++ /dev/null @@ -1,148 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'ctime.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -import ctypes -import datetime -import time - -from cwrap import BaseCValue -from ecl.util import UtilPrototype - - -class CTime(BaseCValue): - TYPE_NAME = "time_t" - DATA_TYPE = ctypes.c_long - _timezone = UtilPrototype("char* util_get_timezone()" , bind = False) - _timegm = UtilPrototype("long util_make_datetime_utc(int, int, int, int, int, int)" , bind = False) - - def __init__(self, value): - if isinstance(value, int): - value = value - elif isinstance(value, CTime): - value = value.value() - elif isinstance(value, datetime.datetime): - value = CTime._timegm(value.second, value.minute, value.hour, value.day, value.month, value.year) - elif isinstance(value, datetime.date): - value = CTime._timegm(0, 0, 0, value.day, value.month, value.year) - else: - raise NotImplementedError("Can not convert class %s to CTime" % value.__class__) - - super(CTime, self).__init__(value) - - def ctime(self): - """ @rtype: int """ - return self.value() - - def time(self): - """Return this time_t as a time.gmtime() object""" - return time.gmtime(self.value()) - - def date(self): - """Return this time_t as a datetime.date([year, month, day])""" - return datetime.date(*self.time()[0:3]) - - def datetime(self): - return datetime.datetime(*self.time()[0:6]) - - def __str__(self): - return self.datetime().strftime("%Y-%m-%d %H:%M:%S%z") - - def __ge__(self, other): - return self > other or self == other - - def __le__(self, other): - return self < other or self == other - - def __gt__(self, other): - if isinstance(other, CTime): - return self.value() > other.value() - elif isinstance(other, (int, datetime.datetime, datetime.date)): - return self > CTime(other) - else: - raise TypeError("CTime does not support type: %s" % other.__class__) - - def __lt__(self, other): - if isinstance(other, CTime): - return self.value() < other.value() - elif isinstance(other, (int, datetime.datetime, datetime.date)): - return self < CTime(other) - else: - raise TypeError("CTime does not support type: %s" % other.__class__) - - def __ne__(self, other): - return not self == other - - def __eq__(self, other): - if isinstance(other, CTime): - return self.value() == other.value() - elif isinstance(other, (int, datetime.datetime, datetime.date)): - return self == CTime(other) - elif isinstance(other, type(None)): - return False - else: - raise TypeError("CTime does not support type: %s" % other.__class__) - - def __imul__(self, other): - value = int(self.value() * other) - self.setValue(value) - return self - - def __hash__(self): - return hash(self.value()) - - def __iadd__(self, other): - if isinstance(other, CTime): - self.setValue(self.value() + other.value()) - return self - else: - self.setValue(self.value() + CTime(other).value()) - return self - - def __add__(self, other): - copy = CTime(self) - copy += other - return copy - - def __radd__(self, other): - return self + other - - def __mul__(self, other): - copy = CTime(self) - copy *= other - return copy - - def __rmul__(self, other): - return self * other - - def timetuple(self): - # this function is a requirement for comparing against datetime objects where the CTime is on the right side - pass - - def __repr__(self): - return "time_t value: %d [%s]" % (self.value(), str(self)) - - @property - def stripped(self): - return time.strptime(self, "%Y-%m-%d %H:%M:S%") - - @classmethod - def timezone(cls): - """ - Returns the current timezone "in" C - @rtype: str - """ - return CTime._timezone() diff --git a/ThirdParty/Ert/python/python/ecl/util/cwd_context.py b/ThirdParty/Ert/python/python/ecl/util/cwd_context.py deleted file mode 100644 index c51eb81399..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/cwd_context.py +++ /dev/null @@ -1,16 +0,0 @@ -import os - -class CWDContext(object): - def __init__(self , path): - self.cwd = os.getcwd() - if os.path.isdir( path ): - os.chdir( path ) - else: - raise IOError("Path:%s does not exist" % path) - - def __exit__(self , exc_type , exc_val , exc_tb): - os.chdir( self.cwd ) - return False - - def __enter__(self): - return self diff --git a/ThirdParty/Ert/python/python/ecl/util/double_vector.py b/ThirdParty/Ert/python/python/ecl/util/double_vector.py deleted file mode 100644 index 28a39cfc20..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/double_vector.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'double_vector.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.util import VectorTemplate, UtilPrototype - - -class DoubleVector(VectorTemplate): - default_format = "%8.4f" - - _alloc = UtilPrototype("void* double_vector_alloc( int , double )" , bind = False) - _alloc_copy = UtilPrototype("double_vector_obj double_vector_alloc_copy( double_vector )") - _strided_copy = UtilPrototype("double_vector_obj double_vector_alloc_strided_copy( double_vector , int , int , int)") - _free = UtilPrototype("void double_vector_free( double_vector )") - _iget = UtilPrototype("double double_vector_iget( double_vector , int )") - _safe_iget = UtilPrototype("double double_vector_safe_iget(double_vector , int )") - _iset = UtilPrototype("double double_vector_iset( double_vector , int , double)") - _size = UtilPrototype("int double_vector_size( double_vector )") - _append = UtilPrototype("void double_vector_append( double_vector , double )") - _idel_block = UtilPrototype("void double_vector_idel_block( double_vector , int , int )") - _pop = UtilPrototype("double double_vector_pop( double_vector )") - _idel = UtilPrototype("void double_vector_idel( double_vector , int )") - _lshift = UtilPrototype("void double_vector_lshift( double_vector , int )") - _rshift = UtilPrototype("void double_vector_rshift( double_vector , int )") - _insert = UtilPrototype("void double_vector_insert( double_vector , int , double)") - _fprintf = UtilPrototype("void double_vector_fprintf( double_vector , FILE , char* , char*)") - _sort = UtilPrototype("void double_vector_sort( double_vector )") - _rsort = UtilPrototype("void double_vector_rsort( double_vector )") - _reset = UtilPrototype("void double_vector_reset( double_vector )") - _get_read_only = UtilPrototype("bool double_vector_get_read_only( double_vector )") - _set_read_only = UtilPrototype("void double_vector_set_read_only( double_vector , bool )") - _get_max = UtilPrototype("double double_vector_get_max( double_vector )") - _get_min = UtilPrototype("double double_vector_get_min( double_vector )") - _get_max_index = UtilPrototype("int double_vector_get_max_index( double_vector , bool)") - _get_min_index = UtilPrototype("int double_vector_get_min_index( double_vector , bool)") - _shift = UtilPrototype("void double_vector_shift( double_vector , double )") - _scale = UtilPrototype("void double_vector_scale( double_vector , double )") - _div = UtilPrototype("void double_vector_div( double_vector , double )") - _inplace_add = UtilPrototype("void double_vector_inplace_add( double_vector , double_vector )") - _inplace_mul = UtilPrototype("void double_vector_inplace_mul( double_vector , double_vector )") - _assign = UtilPrototype("void double_vector_set_all( double_vector , double)") - _memcpy = UtilPrototype("void double_vector_memcpy(double_vector , double_vector )") - _set_default = UtilPrototype("void double_vector_set_default( double_vector , double)") - _get_default = UtilPrototype("double double_vector_get_default( double_vector )") - _element_size = UtilPrototype("int double_vector_element_size( double_vector )") - - _permute = UtilPrototype("void double_vector_permute(double_vector, permutation_vector)") - _sort_perm = UtilPrototype("permutation_vector_obj double_vector_alloc_sort_perm(double_vector)") - _rsort_perm = UtilPrototype("permutation_vector_obj double_vector_alloc_rsort_perm(double_vector)") - _contains = UtilPrototype("bool double_vector_contains(double_vector, double)") - _select_unique = UtilPrototype("void double_vector_select_unique(double_vector)") - _element_sum = UtilPrototype("double double_vector_sum(double_vector)") - _get_data_ptr = UtilPrototype("double* double_vector_get_ptr(double_vector)") - _count_equal = UtilPrototype("int double_vector_count_equal(double_vector, double)") - _init_range = UtilPrototype("void double_vector_init_range(double_vector, double , double , double)") - - def __init__(self, default_value=0, initial_size=0): - super(DoubleVector, self).__init__(default_value, initial_size) diff --git a/ThirdParty/Ert/python/python/ecl/util/enums/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/util/enums/CMakeLists.txt deleted file mode 100644 index fbf4917449..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/enums/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - rng_alg_type_enum.py - rng_init_mode_enum.py - ui_return_status_enum.py - llsq_result_enum.py - message_level_enum.py -) - -add_python_package("python.ecl.util.enums" ${PYTHON_INSTALL_PREFIX}/ecl/util/enums "${PYTHON_SOURCES}" True) - diff --git a/ThirdParty/Ert/python/python/ecl/util/enums/__init__.py b/ThirdParty/Ert/python/python/ecl/util/enums/__init__.py deleted file mode 100644 index 85882d14bd..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/enums/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .rng_init_mode_enum import RngInitModeEnum -from .rng_alg_type_enum import RngAlgTypeEnum -from .ui_return_status_enum import UIReturnStatusEnum -from .llsq_result_enum import LLSQResultEnum -from .message_level_enum import MessageLevelEnum diff --git a/ThirdParty/Ert/python/python/ecl/util/enums/llsq_result_enum.py b/ThirdParty/Ert/python/python/ecl/util/enums/llsq_result_enum.py deleted file mode 100644 index 3a0c70c2f1..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/enums/llsq_result_enum.py +++ /dev/null @@ -1,13 +0,0 @@ -from cwrap import BaseCEnum - - -class LLSQResultEnum(BaseCEnum): - TYPE_NAME = "llsq_result_enum" - LLSQ_SUCCESS = None - LLSQ_INVALID_DIM = None - LLSQ_UNDETERMINED = None - - -LLSQResultEnum.addEnum("LLSQ_SUCCESS" , 0) -LLSQResultEnum.addEnum("LLSQ_INVALID_DIM" , 1) -LLSQResultEnum.addEnum("LLSQ_UNDETERMINED" , 2) diff --git a/ThirdParty/Ert/python/python/ecl/util/enums/message_level_enum.py b/ThirdParty/Ert/python/python/ecl/util/enums/message_level_enum.py deleted file mode 100644 index efb2a61006..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/enums/message_level_enum.py +++ /dev/null @@ -1,18 +0,0 @@ -from cwrap import BaseCEnum - - -class MessageLevelEnum(BaseCEnum): - TYPE_NAME = "message_level_enum" - - LOG_CRITICAL = None - LOG_ERROR = None - LOG_WARNING = None - LOG_INFO = None - LOG_DEBUG = None - - -MessageLevelEnum.addEnum("LOG_CRITICAL", 0) -MessageLevelEnum.addEnum("LOG_ERROR", 1) -MessageLevelEnum.addEnum("LOG_WARNING", 2) -MessageLevelEnum.addEnum("LOG_INFO", 3) -MessageLevelEnum.addEnum("LOG_DEBUG", 4) diff --git a/ThirdParty/Ert/python/python/ecl/util/enums/rng_alg_type_enum.py b/ThirdParty/Ert/python/python/ecl/util/enums/rng_alg_type_enum.py deleted file mode 100644 index a93b47194e..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/enums/rng_alg_type_enum.py +++ /dev/null @@ -1,8 +0,0 @@ -from cwrap import BaseCEnum - -class RngAlgTypeEnum(BaseCEnum): - TYPE_NAME = "rng_alg_type_enum" - MZRAN = None - - -RngAlgTypeEnum.addEnum("MZRAN", 1) diff --git a/ThirdParty/Ert/python/python/ecl/util/enums/rng_init_mode_enum.py b/ThirdParty/Ert/python/python/ecl/util/enums/rng_init_mode_enum.py deleted file mode 100644 index 049ec0dd6a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/enums/rng_init_mode_enum.py +++ /dev/null @@ -1,14 +0,0 @@ -from cwrap import BaseCEnum - -class RngInitModeEnum(BaseCEnum): - TYPE_NAME = "rng_init_mode_enum" - INIT_DEFAULT = None - INIT_CLOCK = None - INIT_DEV_RANDOM = None - INIT_DEV_URANDOM = None - - -RngInitModeEnum.addEnum("INIT_DEFAULT", 0) -RngInitModeEnum.addEnum("INIT_CLOCK", 1) -RngInitModeEnum.addEnum("INIT_DEV_RANDOM", 2) -RngInitModeEnum.addEnum("INIT_DEV_URANDOM", 3) diff --git a/ThirdParty/Ert/python/python/ecl/util/enums/ui_return_status_enum.py b/ThirdParty/Ert/python/python/ecl/util/enums/ui_return_status_enum.py deleted file mode 100644 index 5c810ec127..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/enums/ui_return_status_enum.py +++ /dev/null @@ -1,11 +0,0 @@ -from cwrap import BaseCEnum - - -class UIReturnStatusEnum(BaseCEnum): - TYPE_NAME = "ui_return_status" - UI_RETURN_OK = None - UI_RETURN_FAIL = None - - -UIReturnStatusEnum.addEnum("UI_RETURN_OK", 1) -UIReturnStatusEnum.addEnum("UI_RETURN_FAIL", 2) diff --git a/ThirdParty/Ert/python/python/ecl/util/hash.py b/ThirdParty/Ert/python/python/ecl/util/hash.py deleted file mode 100644 index bd2a18289d..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/hash.py +++ /dev/null @@ -1,133 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'hash.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -from ctypes import c_void_p - -from cwrap import BaseCClass -from ecl.util import StringList, UtilPrototype - - -class Hash(BaseCClass): - _alloc = UtilPrototype("void* hash_alloc()" , bind = False) - _free = UtilPrototype("void hash_free(hash)") - _size = UtilPrototype("int hash_get_size(hash)") - _keys = UtilPrototype("stringlist_obj hash_alloc_stringlist(hash)") - _has_key = UtilPrototype("bool hash_has_key(hash, char*)") - _get = UtilPrototype("void* hash_get(hash, char*)") - _insert_ref = UtilPrototype("void hash_insert_ref(hash, char*, void*)") - - """ - Base hash class that supports string:void* values - """ - - def __init__(self): - c_ptr = self._alloc() - super(Hash, self).__init__(c_ptr) - - def __len__(self): - return self._size() - - def __getitem__(self, key): - if self._has_key(key): - return self._get(key) - else: - raise KeyError("Hash does not have key: %s" % key) - - def __setitem__(self, key, value): - if isinstance(value, c_void_p): - self._insert_ref(key, value) - else: - raise ValueError("Hash does not support type: %s" % value.__class__) - - def __contains__(self, key): - """ @rtype: bool """ - return self._has_key(key) - - def __iter__(self): - for key in self.keys(): - yield key - - def keys(self): - """ @rtype: StringList """ - return self._keys() - - def free(self): - self._free() - - def __str__(self): - return str(["%s: %s" % (key, self[key]) for key in self.keys()]) - - -class StringHash(Hash): - _get_string = UtilPrototype("char* hash_get_string(hash, char*)") - _insert_string = UtilPrototype("void hash_insert_string(hash, char*, char*)") - - def __init__(self): - super(StringHash, self).__init__() - - def __setitem__(self, key, value): - if isinstance(value, str): - self._insert_string(key, value) - else: - raise ValueError("StringHash does not support type: %s" % value.__class__) - - def __getitem__(self, key): - if key in self: - return self._get_string(key) - else: - raise KeyError("Hash does not have key: %s" % key) - - -class IntegerHash(Hash): - _get_int = UtilPrototype("int hash_get_int(hash, char*)") - _insert_int = UtilPrototype("void hash_insert_int(hash, char*, int)") - - def __init__(self): - super(IntegerHash, self).__init__() - - def __setitem__(self, key, value): - if isinstance(value, int): - self._insert_int(key, value) - else: - raise ValueError("IntegerHash does not support type: %s" % value.__class__) - - def __getitem__(self, key): - if key in self: - return self._get_int(key) - else: - raise KeyError("Hash does not have key: %s" % key) - - -class DoubleHash(Hash): - _get_double = UtilPrototype("double hash_get_double(hash, char*)") - _insert_double = UtilPrototype("void hash_insert_double(hash, char*, double)") - - def __init__(self): - super(DoubleHash, self).__init__() - - def __setitem__(self, key, value): - if isinstance(value, int): - value = float(value) - - if isinstance(value, float): - self._insert_double(key, value) - else: - raise ValueError("DoubleHash does not support type: %s" % value.__class__) - - def __getitem__(self, key): - if key in self: - return self._get_double( key) - else: - raise KeyError("Hash does not have key: %s" % key) diff --git a/ThirdParty/Ert/python/python/ecl/util/install_abort_signals.py b/ThirdParty/Ert/python/python/ecl/util/install_abort_signals.py deleted file mode 100644 index 59cddabe75..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/install_abort_signals.py +++ /dev/null @@ -1,16 +0,0 @@ -from ecl.util import UtilPrototype - - -def installAbortSignals(): - install_signals() - - -def updateAbortSignals(): - """ - Will install the util_abort_signal for all UNMODIFIED signals. - """ - update_signals() - - -install_signals = UtilPrototype("void util_install_signals()") -update_signals = UtilPrototype("void util_update_signals()") diff --git a/ThirdParty/Ert/python/python/ecl/util/int_vector.py b/ThirdParty/Ert/python/python/ecl/util/int_vector.py deleted file mode 100644 index 277a76f9eb..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/int_vector.py +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'int_vector.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.util import VectorTemplate, UtilPrototype - - -class IntVector(VectorTemplate): - default_format = "%d" - - _alloc = UtilPrototype("void* int_vector_alloc( int , int )" , bind = False) - _create_active_list = UtilPrototype("int_vector_obj string_util_alloc_active_list( char*)" , bind = False) - _create_value_list = UtilPrototype("int_vector_obj string_util_alloc_value_list( char*)" , bind = False) - _alloc_copy = UtilPrototype("int_vector_obj int_vector_alloc_copy( int_vector )") - _strided_copy = UtilPrototype("int_vector_obj int_vector_alloc_strided_copy( int_vector , int , int , int)") - _free = UtilPrototype("void int_vector_free( int_vector )") - _iget = UtilPrototype("int int_vector_iget( int_vector , int )") - _safe_iget = UtilPrototype("int int_vector_safe_iget( int_vector , int )") - _iset = UtilPrototype("int int_vector_iset( int_vector , int , int)") - _size = UtilPrototype("int int_vector_size( int_vector )") - _append = UtilPrototype("void int_vector_append( int_vector , int )") - _idel_block = UtilPrototype("void int_vector_idel_block( int_vector , int , int )") - _pop = UtilPrototype("int int_vector_pop( int_vector )") - _idel = UtilPrototype("void int_vector_idel( int_vector , int )") - _insert = UtilPrototype("void int_vector_insert( int_vector , int , int)") - _lshift = UtilPrototype("void int_vector_lshift( int_vector , int )") - _rshift = UtilPrototype("void int_vector_rshift( int_vector , int )") - _fprintf = UtilPrototype("void int_vector_fprintf( int_vector , FILE , char* , char*)") - _sort = UtilPrototype("void int_vector_sort( int_vector )") - _rsort = UtilPrototype("void int_vector_rsort( int_vector )") - _reset = UtilPrototype("void int_vector_reset( int_vector )") - _set_read_only = UtilPrototype("void int_vector_set_read_only( int_vector , bool )") - _get_read_only = UtilPrototype("bool int_vector_get_read_only( int_vector )") - _get_max = UtilPrototype("int int_vector_get_max( int_vector )") - _get_min = UtilPrototype("int int_vector_get_min( int_vector )") - _get_max_index = UtilPrototype("int int_vector_get_max_index( int_vector , bool)") - _get_min_index = UtilPrototype("int int_vector_get_min_index( int_vector , bool)") - _shift = UtilPrototype("void int_vector_shift( int_vector , int )") - _scale = UtilPrototype("void int_vector_scale( int_vector , int )") - _div = UtilPrototype("void int_vector_div( int_vector , int )") - _inplace_add = UtilPrototype("void int_vector_inplace_add( int_vector , int_vector )") - _inplace_mul = UtilPrototype("void int_vector_inplace_mul( int_vector , int_vector )") - _assign = UtilPrototype("void int_vector_set_all( int_vector , int)") - _memcpy = UtilPrototype("void int_vector_memcpy(int_vector , int_vector )") - _set_default = UtilPrototype("void int_vector_set_default( int_vector , int)") - _get_default = UtilPrototype("int int_vector_get_default( int_vector )") - _element_size = UtilPrototype("int int_vector_element_size( int_vector )") - - _permute = UtilPrototype("void int_vector_permute(int_vector, permutation_vector)") - _sort_perm = UtilPrototype("permutation_vector_obj int_vector_alloc_sort_perm(int_vector)") - _rsort_perm = UtilPrototype("permutation_vector_obj int_vector_alloc_rsort_perm(int_vector)") - _contains = UtilPrototype("bool int_vector_contains(int_vector, int)") - _select_unique = UtilPrototype("void int_vector_select_unique(int_vector)") - _element_sum = UtilPrototype("int int_vector_sum(int_vector)") - _get_data_ptr = UtilPrototype("int* int_vector_get_ptr(int_vector)") - _count_equal = UtilPrototype("int int_vector_count_equal(int_vector, int)") - _init_range = UtilPrototype("void int_vector_init_range(int_vector, int , int , 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/ThirdParty/Ert/python/python/ecl/util/log.py b/ThirdParty/Ert/python/python/ecl/util/log.py deleted file mode 100644 index 2e766b83a6..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/log.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'log.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import print_function -from cwrap import BaseCClass -from ecl.util import UtilPrototype - - -class Log(BaseCClass): - _get_filename = UtilPrototype("char* log_get_filename(log)") - _reopen = UtilPrototype("void log_reopen(log, char*)") - _get_level = UtilPrototype("int log_get_level(log)") - _set_level = UtilPrototype("void log_set_level(log, int)") - - def __init__(self): - raise NotImplementedError("Class can not be instantiated directly!") - - def get_filename(self): - return self._get_filename() - # return "ert_config.log" - - def reopen(self, filename): - print('Logfile cannot be reopened') - # cfunc.reopen( self , filename) - - def get_level(self): - return self._get_level() - - def set_level(self, level): - pass - # self._set_level(self, level) diff --git a/ThirdParty/Ert/python/python/ecl/util/lookup_table.py b/ThirdParty/Ert/python/python/ecl/util/lookup_table.py deleted file mode 100644 index 6497a8273c..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/lookup_table.py +++ /dev/null @@ -1,122 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'lookup_table.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -from cwrap import BaseCClass -from ecl.util import UtilPrototype - - -class LookupTable(BaseCClass): - _alloc = UtilPrototype("void* lookup_table_alloc_empty()" , bind = False) - _max = UtilPrototype("double lookup_table_get_max_value( lookup_table )") - _min = UtilPrototype("double lookup_table_get_min_value( lookup_table )") - _arg_max = UtilPrototype("double lookup_table_get_max_arg( lookup_table )") - _arg_min = UtilPrototype("double lookup_table_get_min_arg( lookup_table )") - _append = UtilPrototype("void lookup_table_append( lookup_table , double , double )") - _size = UtilPrototype("int lookup_table_get_size( lookup_table )") - _interp = UtilPrototype("double lookup_table_interp( lookup_table , double)") - _free = UtilPrototype("void lookup_table_free( lookup_table )") - _set_low_limit = UtilPrototype("void lookup_table_set_low_limit( lookup_table , double)") - _set_high_limit = UtilPrototype("void lookup_table_set_high_limit( lookup_table , double)") - _has_low_limit = UtilPrototype("bool lookup_table_has_low_limit( lookup_table)") - _has_high_limit = UtilPrototype("bool lookup_table_has_high_limit( lookup_table)") - - def __init__(self, lower_limit=None, upper_limit=None): - super(LookupTable, self).__init__(self._alloc()) - - if not lower_limit is None: - self.setLowerLimit(lower_limit) - - if not upper_limit is None: - self.setUpperLimit(upper_limit) - - def getMaxValue(self): - self.assertSize(1) - return self._max() - - def getMinValue(self): - self.assertSize(1) - return self._min() - - def getMinArg(self): - self.assertSize(1) - return self._arg_min() - - def getMaxArg(self): - self.assertSize(1) - return self._arg_max() - - def assertSize(self, N): - if len(self) < N: - raise ValueError("Lookup table is too small") - - def __len__(self): - return self._size() - - @property - def size(self): - return len(self) - - # Deprecated properties - @property - def max(self): - return self.getMaxValue() - - @property - def min(self): - return self.getMinValue() - - @property - def arg_max(self): - return self.getMaxArg() - - @property - def arg_min(self): - return self.getMinArg() - - def setLowerLimit(self, value): - self._set_low_limit(value) - - def hasLowerLimit(self): - return self._has_low_limit() - - def setUpperLimit(self, value): - self._set_high_limit(value) - - def hasUpperLimit(self): - return self._has_high_limit() - - def interp(self, x): - self.assertSize(2) - if x < self.getMinArg(): - if not self.hasLowerLimit(): - raise ValueError("Interpolate argument:%g is outside valid interval: [%g,%g]" % (x, self.getMinArg(), self.getMaxArg())) - elif x > self.getMaxArg(): - if not self.hasUpperLimit(): - raise ValueError("Interpolate argument:%g is outside valid interval: [%g,%g]" % (x, self.getMinArg(), self.getMaxArg())) - - return self._interp(x) - - def append(self, x, y): - self._append( x, y) - - #todo: necessary??? - def __del__(self): - self._free() - - def free(self): - self._free( ) - diff --git a/ThirdParty/Ert/python/python/ecl/util/matrix.py b/ThirdParty/Ert/python/python/ecl/util/matrix.py deleted file mode 100644 index cfb99f7046..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/matrix.py +++ /dev/null @@ -1,227 +0,0 @@ - -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'matrix.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -# The Matrix class implemented here wraps the C matrix implementation -# in matrix.c from the libutil library. The C matrix implementation -# has the very limited ambition of just barely satisfying the matrix -# needs of the EnKF algorithm, i.e. for general linear algebra -# applications you will probably be better served by a more complete -# matrix library. This applies even more so to this Python -# implementation; it is only here facilitate use of C libraries which -# expect a matrix instance as input (i.e. the LARS estimator). For -# general linear algebra in Python the numpy library is a natural -# choice. - - -from cwrap import BaseCClass,CFILE -from ecl.util import UtilPrototype - - -class Matrix(BaseCClass): - _matrix_alloc = UtilPrototype("void* matrix_alloc(int, int )" , bind = False) - _matrix_alloc_identity = UtilPrototype("matrix_obj matrix_alloc_identity( int )" , bind = False) - _alloc_transpose = UtilPrototype("matrix_obj matrix_alloc_transpose(matrix)") - _inplace_transpose = UtilPrototype("void matrix_inplace_transpose(matrix)") - _copy = UtilPrototype("matrix_obj matrix_alloc_copy(matrix)" ) - _sub_copy = UtilPrototype("matrix_obj matrix_alloc_sub_copy(matrix, int , int , int , int)" ) - _free = UtilPrototype("void matrix_free(matrix)") - _iget = UtilPrototype("double matrix_iget( matrix , int , int )") - _iset = UtilPrototype("void matrix_iset( matrix , int , int , double)") - _set_all = UtilPrototype("void matrix_scalar_set( matrix , double)") - _scale_column = UtilPrototype("void matrix_scale_column(matrix , int , double)") - _scale_row = UtilPrototype("void matrix_scale_row(matrix , int , double)") - _copy_column = UtilPrototype("void matrix_copy_column(matrix , matrix , int , int)" , bind = False) - _rows = UtilPrototype("int matrix_get_rows(matrix)") - _columns = UtilPrototype("int matrix_get_columns(matrix)") - _equal = UtilPrototype("bool matrix_equal(matrix, matrix)") - _pretty_print = UtilPrototype("void matrix_pretty_print(matrix, char*, char*)") - _fprint = UtilPrototype("void matrix_fprintf(matrix, char*, FILE)") - _random_init = UtilPrototype("void matrix_random_init(matrix, rng)") - _dump_csv = UtilPrototype("void matrix_dump_csv(matrix, char*)") - - # Requires BLAS. If the library does not have the - # matrix_alloc_matmul() function the prototype will have _func = - # None, and NotImplementedError( ) will be raised int the - # __call__() method if we try to use this function. - _alloc_matmul = UtilPrototype("matrix_obj matrix_alloc_matmul(matrix, matrix)" , bind = False, allow_attribute_error = True) - - # Requires BLAS! - @classmethod - def matmul(cls, m1,m2): - """ - Will return a new matrix which is matrix product of m1 and m2. - """ - if m1.columns( ) == m2.rows( ): - return cls._alloc_matmul( m1, m2) - else: - raise ValueError("Matrix size mismatch") - - - def __init__(self, rows, columns, value=0): - c_ptr = self._matrix_alloc(rows, columns) - super(Matrix, self).__init__(c_ptr) - self.setAll(value) - - def copy(self): - return self._copy( ) - - @classmethod - def identity(cls, dim): - """Returns a dim x dim identity matrix.""" - if dim < 1: - raise ValueError('Identity matrix must have positive size, %d not allowed.' % dim) - return cls._matrix_alloc_identity(dim) - - def subCopy(self, row_offset, column_offset, rows, columns): - if row_offset < 0 or row_offset >= self.rows(): - raise ValueError("Invalid row offset") - - if column_offset < 0 or column_offset >= self.columns(): - raise ValueError("Invalid column offset") - - if row_offset + rows > self.rows(): - raise ValueError("Invalid rows") - - if column_offset + columns > self.columns(): - raise ValueError("Invalid columns") - - return self._sub_copy( row_offset , column_offset , rows , columns) - - - def __str__(self): - s = "" - for i in range(self.rows()): - s += "[" - for j in range(self.columns()): - d = self._iget(i, j) - s += "%6.3g " % d - s += "]\n" - return s - - def __getitem__(self, index_tuple): - if not 0 <= index_tuple[0] < self.rows(): - raise IndexError("Expected 0 <= %d < %d" % (index_tuple[0], self.rows())) - - if not 0 <= index_tuple[1] < self.columns(): - raise IndexError("Expected 0 <= %d < %d" % (index_tuple[1], self.columns())) - - return self._iget(index_tuple[0], index_tuple[1]) - - def __setitem__(self, index_tuple, value): - if not 0 <= index_tuple[0] < self.rows(): - raise IndexError("Expected 0 <= %d < %d" % (index_tuple[0], self.rows())) - - if not 0 <= index_tuple[1] < self.columns(): - raise IndexError("Expected 0 <= %d < %d" % (index_tuple[1], self.columns())) - - return self._iset(index_tuple[0], index_tuple[1], value) - - def dims(self): - return self._rows(), self._columns() - - def rows(self): - """ @rtype: int """ - return self._rows() - - def transpose(self , inplace = False): - """ - Will transpose the matrix. By default a transposed copy is returned. - """ - if inplace: - self._inplace_transpose( ) - return self - else: - return self._alloc_transpose( ) - - - def columns(self): - """ @rtype: int """ - return self._columns() - - def __eq__(self, other): - assert isinstance(other, Matrix) - return self._equal(other) - - def scaleColumn(self, column, factor): - if not 0 <= column < self.columns(): - raise IndexError("Expected column: [0,%d) got:%d" % (self.columns(), column)) - self._scale_column(column, factor) - - def scaleRow(self, row, factor): - if not 0 <= row < self.rows(): - raise IndexError("Expected row: [0,%d) got:%d" % (self.rows(), row)) - self._scale_row(row, factor) - - def setAll(self, value): - self._set_all(value) - - def copyColumn(self, target_column, src_column): - columns = self.columns() - if not 0 <= src_column < columns: - raise ValueError("src column:%d invalid" % src_column) - - if not 0 <= target_column < columns: - raise ValueError("target column:%d invalid" % target_column) - - if src_column != target_column: - # The underlying C function accepts column copy between matrices. - Matrix._copy_column(self, self, target_column, src_column) - - - def dumpCSV(self , filename): - self._dump_csv( filename ) - - - def prettyPrint(self, name, fmt="%6.3g"): - self._pretty_print(name, fmt) - - def fprint(self , fileH , fmt = "%g "): - """Will print ASCII representation of matrix. - - The fileH argument should point to an open Python - filehandle. If you supply a fmt string it is important that it - contains a separator, otherwise you might risk that elements - overlap in the output. For the matrix: - - [0 1 2] - m = [3 4 5] - [6 7 8] - - The code: - - with open("matrix.txt" , "w") as f: - m.fprintf( f ) - - The file 'matrix.txt' will look like: - - 0 1 2 - 3 4 5 - 6 7 8 - - """ - self._fprint( fmt , CFILE( fileH)) - - - def randomInit(self, rng): - self._random_init(rng) - - def free(self): - self._free() - - - diff --git a/ThirdParty/Ert/python/python/ecl/util/path_format.py b/ThirdParty/Ert/python/python/ecl/util/path_format.py deleted file mode 100644 index 07d565c46f..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/path_format.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from cwrap import BaseCClass -from ecl.util import UtilPrototype - -# The path_fmt implementation hinges strongly on variable length -# argument lists in C - not clear if/how that maps over to Python, -# this Python class therefor has *very* limited functionality. - - -class PathFormat(BaseCClass): - TYPE_NAME = "path_fmt" - _alloc = UtilPrototype("void* path_fmt_alloc_directory_fmt(char*)", bind = False) - _str = UtilPrototype("char* path_fmt_get_fmt(path_fmt)") - _free = UtilPrototype("void path_fmt_free(path_fmt)") - - def __init__(self, path_fmt): - c_ptr = self._alloc( path_fmt ) - if c_ptr: - super(PathFormat, self).__init__(c_ptr) - else: - raise ValueError('Unable to construct path format "%s"' % path_fmt) - - def __repr__(self): - return self._create_repr('fmt=%s' % self._str()) - - def free(self): - self._free( ) diff --git a/ThirdParty/Ert/python/python/ecl/util/permutation_vector.py b/ThirdParty/Ert/python/python/ecl/util/permutation_vector.py deleted file mode 100644 index dabbd3788f..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/permutation_vector.py +++ /dev/null @@ -1,38 +0,0 @@ -from cwrap import BaseCClass -from ecl.util import UtilPrototype - - -class PermutationVector(BaseCClass): - TYPE_NAME = "permutation_vector" - _free = UtilPrototype("void perm_vector_free( permutation_vector )") - _size = UtilPrototype("int perm_vector_get_size( permutation_vector )") - _iget = UtilPrototype("int perm_vector_iget( permutation_vector , int)") - - - def __init__(self): - raise NotImplementedError("Can not instantiate PermutationVector directly") - - - def __len__(self): - return self._size( ) - - - def __str__(self): - s = "(" - for index in self: - s += " %d" % index - return s + ")" - - - def __getitem__(self, index): - if index < 0: - index += len(self) - - if 0 <= index < len(self): - return self._iget( index ) - else: - raise IndexError("Invalid index:%d" % index) - - - def free(self): - self._free( ) diff --git a/ThirdParty/Ert/python/python/ecl/util/profiler.py b/ThirdParty/Ert/python/python/ecl/util/profiler.py deleted file mode 100644 index ab35189cc9..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/profiler.py +++ /dev/null @@ -1,34 +0,0 @@ -from __future__ import absolute_import, division, print_function, unicode_literals - -try: - from StringIO import StringIO -except ImportError: - from io import StringIO - -import cProfile -import pstats -import sys - - -class Profiler(object): - - __profiler = None - """ :type: Profile """ - - @classmethod - def startProfiler(cls, subcalls=True, builtins=True): - cls.__profiler = cProfile.Profile() - cls.__profiler.enable(subcalls=subcalls, builtins=builtins) - - @classmethod - def stopProfiler(cls, sort_method="cumulative"): - if cls.__profiler is not None: - cls.__profiler.disable() - stream = StringIO() - stats_printer = pstats.Stats(cls.__profiler, stream=stream).sort_stats(sort_method) - stats_printer.print_stats() - cls.__profiler = None - print(stream.getvalue()) - else: - sys.stderr.write("WARNING: Profiler has not been started!\n") - diff --git a/ThirdParty/Ert/python/python/ecl/util/rng.py b/ThirdParty/Ert/python/python/ecl/util/rng.py deleted file mode 100644 index a747d31887..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/rng.py +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'rng.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os.path - -from cwrap import BaseCClass -from ecl.util import UtilPrototype -from ecl.util.enums import RngInitModeEnum, RngAlgTypeEnum - - -class RandomNumberGenerator(BaseCClass): - TYPE_NAME = "rng" - - _rng_alloc = UtilPrototype("void* rng_alloc(rng_alg_type_enum, rng_init_mode_enum)" , bind = False) - _free = UtilPrototype("void rng_free(rng)") - _get_double = UtilPrototype("double rng_get_double(rng)") - _get_int = UtilPrototype("int rng_get_int(rng, int)") - _get_max_int = UtilPrototype("uint rng_get_max_int(rng)") - _state_size = UtilPrototype("int rng_state_size(rng)") - _set_state = UtilPrototype("void rng_set_state(rng , char*)") - _load_state = UtilPrototype("void rng_load_state(rng , char*)") - _save_state = UtilPrototype("void rng_save_state(rng , char*)") - - def __init__(self, alg_type=RngAlgTypeEnum.MZRAN, init_mode=RngInitModeEnum.INIT_CLOCK): - assert isinstance(alg_type, RngAlgTypeEnum) - assert isinstance(init_mode, RngInitModeEnum) - - c_ptr = self._rng_alloc(alg_type, init_mode) - super(RandomNumberGenerator, self).__init__(c_ptr) - - def stateSize(self): - return self._state_size() - - def setState(self, seed_string): - state_size = self.stateSize() - if len(seed_string) < state_size: - raise ValueError("The seed string must be at least %d characters long" % self.stateSize()) - self._set_state( seed_string) - - def getDouble(self): - """ @rtype: float """ - return self._get_double() - - def getInt(self, max=None): - """ @rtype: float """ - if max is None: - max = self._get_max_int() - - return self._get_int(max) - - def free(self): - self._free() - - def loadState(self , seed_file): - """ - Will seed the RNG from the file @seed_file. - """ - if os.path.isfile( seed_file ): - self._load_state( seed_file ) - else: - raise IOError("No such file: %s" % seed_file) - - - def saveState(self , seed_file): - """ - Will save the state of the rng to @seed_file - """ - self._save_state( seed_file ) - diff --git a/ThirdParty/Ert/python/python/ecl/util/stat.py b/ThirdParty/Ert/python/python/ecl/util/stat.py deleted file mode 100644 index d219a7869a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/stat.py +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'stat.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -from collections import Sequence - -from cwrap import PrototypeError -from ecl.util import LLSQResultEnum, UtilPrototype, Matrix - - -quantile = UtilPrototype("double statistics_empirical_quantile(double_vector, double)") -"""@type: (ecl.util.DoubleVector, float)->float""" - -quantile_sorted = UtilPrototype("double statistics_empirical_quantile(double_vector, double)") -"""@type: (ecl.util.DoubleVector, float)->float""" - -try: - _polyfit = UtilPrototype("llsq_result_enum matrix_stat_polyfit(matrix, matrix, matrix, matrix)") -except PrototypeError: - _polyfit = None - -def polyfit(n, x, y, s=None): - """ - @type n: int - @type x: Matrix or Sequence - @type y: Matrix or Sequence - @type s: Matrix or Sequence or None - @return: tuple - """ - if _polyfit is None: - raise NotImplementedError("Sorry - your ert distribution has been built without lapack support") - - if isinstance(x, Matrix): - xm = x - else: - xm = Matrix(len(x), 1) - for i in range(len(x)): - xm[i, 0] = x[i] - - if isinstance(y, Matrix): - ym = y - else: - ym = Matrix(len(y), 1) - for i in range(len(y)): - ym[i, 0] = y[i] - - if s: - if isinstance(s, Matrix): - sm = s - else: - sm = Matrix(len(s), 1) - for i in range(len(s)): - sm[i, 0] = s[i] - else: - sm = s - - beta = Matrix(n, 1) - res = _polyfit(beta, xm, ym, sm) - - if not res == LLSQResultEnum.LLSQ_SUCCESS: - raise Exception("Linear Least Squares Estimator failed?") - - l = [] - for i in range(n): - l.append(beta[i, 0]) - - return tuple(l) diff --git a/ThirdParty/Ert/python/python/ecl/util/stringlist.py b/ThirdParty/Ert/python/python/ecl/util/stringlist.py deleted file mode 100644 index f4e22b03c6..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/stringlist.py +++ /dev/null @@ -1,308 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'stringlist.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Simple wrapping of stringlist 'class' from C library. - -The stringlist type from the libutil C library is a simple structure -consisting of a vector of \0 terminated char pointers - slightly -higher level than the (char ** string , int size) convention. - -For a pure Python application you should just stick with a normal -Python list of string objects; but when interfacing with the C -libraries there are situations where you might need to instantiate a -StringList object. - -The StringList constructor can take an optional argument which should -be an iterable consisting of strings, and the strings property will -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 __future__ import absolute_import, division, print_function, unicode_literals -from six import string_types -from ecl.util import UtilPrototype -from cwrap import BaseCClass - - -class StringList(BaseCClass): - TYPE_NAME = "stringlist" - - _alloc = UtilPrototype("void* stringlist_alloc_new( )", bind = False) - _free = UtilPrototype("void stringlist_free(stringlist )") - _append = UtilPrototype("void stringlist_append_copy(stringlist , char* )") - _iget = UtilPrototype("char* stringlist_iget(stringlist , int )") - _front = UtilPrototype("char* stringlist_front( stringlist )") - _back = UtilPrototype("char* stringlist_back( stringlist )") - _iget_copy = UtilPrototype("char* stringlist_iget_copy(stringlist, int)") - _iset = UtilPrototype("void stringlist_iset_copy( stringlist , int , char* )") - _get_size = UtilPrototype("int stringlist_get_size( stringlist )") - _contains = UtilPrototype("bool stringlist_contains(stringlist , char*)") - _equal = UtilPrototype("bool stringlist_equal(stringlist , stringlist)") - _sort = UtilPrototype("void stringlist_python_sort( stringlist , int)") - _pop = UtilPrototype("char* stringlist_pop(stringlist)") - _last = UtilPrototype("char* stringlist_get_last(stringlist)") - _find_first = UtilPrototype("int stringlist_find_first(stringlist, char*)") - - def __init__(self, initial=None): - """ - Creates a new stringlist instance. - - Creates a new stringlist instance. The optional argument - @initial should be an iterable of strings which will be the - initial content of the StringList; the content will be copied - from the initial list: - - S = StringList( initial = ["My" , "name" , "is", "John" , "Doe"] ) - - If an element in the @initial argument is not a string the - TypeError exception will be raised. - - If c_ptr argument is different from None, that should refer to - an already created stringlist instance; this Python will take - ownership of the underlying object. - """ - - c_ptr = self._alloc() - super(StringList, self).__init__(c_ptr) - if initial: - self._append_all(initial) - - def _append_all(self, lst): - for s in lst: - if isinstance(s, bytes): - s.decode('ascii') - if isinstance(s, string_types): - self.append(s) - else: - raise TypeError('Item is not a string: "%s".' % s) - - - def __eq__(self , other): - if len(self) == len(other): - if isinstance( other , StringList): - return self._equal(other) - else: - equal = True - for index,s2 in enumerate(other): - if self[index] != s2: - equal = False - break - return equal - else: - return False - - - def __setitem__(self, index, value): - if isinstance(index, int): - length = len(self) - if index < 0: - # Will only wrap backwards once - index = len(self) + index - - if index < 0 or index >= length: - raise IndexError("index must be in range %d <= %d < %d" % (0, index, len(self))) - if isinstance(value, bytes): - value = value.decode('ascii') - if isinstance(value, string_types): - self._iset(index, value) - else: - raise TypeError("Item: %s not string type" % value) - - - def __getitem__(self, index): - """ - Implements [] read operator on the stringlist. - - The __getitem__ method supports negative, i.e. from the right, - indexing; but not slices. - """ - if isinstance(index, int): - length = len(self) - if index < 0: - index += length - if index < 0 or index >= length: - raise IndexError("index must be in range %d <= %d < %d" % (0, index, len(self))) - else: - return self._iget(index) - else: - raise TypeError("Index should be integer type") - - def __contains__(self, s): - """ - Implements the 'in' operator. - - The 'in' check is based on string equality. - """ - return self._contains(s) - - - def __iadd__(self , other): - if isinstance(other, bytes): - other.decode('ascii') - if isinstance(other , string_types): - raise TypeError("Can not add strings with + - use append()") - for s in other: - self.append( s ) - return self - - - def __add__(self , other): - copy = StringList( initial = self ) - copy += other - return copy - - - def __ior__(self , other): - if isinstance(other, bytes): - other.decode('ascii') - if isinstance(other , string_types): - raise TypeError("Can not | with string.") - for s in other: - if not s in self: - self.append( s ) - return self - - - def __or__(self , other): - copy = StringList( initial = self ) - copy |= other - return copy - - - - def contains(self, s): - """ - Checks if the list contains @s. - - Functionality also available through the 'in' builtin in - Python. - """ - return s in self - - - def __len__(self): - """ - The length of the list - used to support builtin len(). - """ - return self._get_size( ) - - - def __str__(self): - """ - String representation of list; used when calling print." - """ - buffer = "[" - length = len(self) - for i in range(length): - if i == length - 1: - buffer += "\'%s\'" % self[i] - else: - buffer += "\'%s\'," % self[i] - buffer += "]" - return buffer - - def __repr__(self): - return 'StringList(size = %d) %s' % (len(self), self._ad_str()) - - def empty(self): - """Returns true if and only if list is empty.""" - return len(self) == 0 - - def pop(self): - """ - Will remove the last element from the list and return it. - - Will raise IndexError if list is empty. - """ - if not self.empty(): - return self._pop() - else: - raise IndexError("List empty. Cannot call pop().") - - - def append(self, s): - """ - Appends a new string @s to list. If the input argument is not a - string the string representation will be appended. - """ - if isinstance(s, bytes): - s.decode('ascii') - if isinstance(s, string_types): - self._append(s) - else: - self._append(str(s)) - - - @property - def strings(self): - """ - The strings in as a normal Python list of strings. - - The content is copied, so the StringList() instance can safely go - out of scope after the call has completed. Hmmmm - is that true? - """ - slist = [] - for s in self: - slist.append(s) - return slist - - @property - def last(self): - """ - Will return the last element in list. Raise IndexError if empty. - """ - if not self.empty(): - return self._last() - else: - raise IndexError("List empty. No such element last().") - - - def sort(self, cmp_flag=0): - """ - Will sort the list inplace. - - The string comparison can be altered with the value of the - optional cmp_flag parameter: - - 0 : Normal strcmp() string comparison - 1 : util_strcmp_int() string comparison - 2 : util_strcmp_float() string comparison - - """ - self._sort(cmp_flag) - - def index(self, value): - """ @rtype: int """ - if isinstance(value, bytes): - value.decode('ascii') - if isinstance(value, string_types): - return self._find_first(value) - raise KeyError('Cannot index by "%s", lst.index() needs a string.' % str(type(value))) - - def free(self): - self._free() - - - def front(self): - if not self.empty(): - return self._front() - else: - raise IndexError('List empty. No such element front().') - - def back(self): - if not self.empty(): - return self._back() - else: - raise IndexError('List empty. No such element back().') diff --git a/ThirdParty/Ert/python/python/ecl/util/thread_pool.py b/ThirdParty/Ert/python/python/ecl/util/thread_pool.py deleted file mode 100644 index fa5597398a..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/thread_pool.py +++ /dev/null @@ -1,151 +0,0 @@ -import multiprocessing -from threading import Thread -import time -import traceback - - -class Task(Thread): - def __init__(self, func, *args, **kwargs): - super(Task, self).__init__() - self.__func = func - self.__args = args - self.__kwargs = kwargs - - self.__started = False - self.__done = False - self.__failed = False - self.__start_time = None - - self.__verbose = False - - def setVerbose(self, verbose): - self.__verbose = verbose - - def run(self): - self.__start_time = time.time() - self.__started = True - try: - self.__func(*self.__args, **self.__kwargs) - except Exception: - self.__failed = True - traceback.print_exc() - finally: - self.__done = True - - if self.__verbose: - running_time = time.time() - self.__start_time - print("Running time of task: %f" % running_time) - - def isDone(self): - return self.__done - - def hasStarted(self): - return self.__started or self.isAlive() - - def isRunning(self): - return self.hasStarted() and not self.__done - - def hasFailed(self): - return self.__failed - - def join(self, timeout=None): - while not self.hasStarted() or self.isRunning(): - time.sleep(0.01) - - - -class ThreadPool(object): - - def __init__(self, size=None, verbose=False): - super(ThreadPool, self).__init__() - - if size is None: - size = multiprocessing.cpu_count() - - self.__size = size - self.__task_list = [] - self.__pool_finished = False - self.__runner_thread = None - self.__verbose = verbose - self.__start_time = None - - - def addTask(self, func, *args, **kwargs): - if self.__start_time is None: - task = Task(func, *args, **kwargs) - # task.setVerbose(self.__verbose) - self.__task_list.append(task) - else: - raise UserWarning("Can not add task after the pool has started!") - - def poolSize(self): - return self.__size - - def taskCount(self): - return len(self.__task_list) - - def __allTasksFinished(self): - for task in self.__task_list: - if not task.isDone(): - return False - - return True - - def runningCount(self): - count = 0 - - for task in self.__task_list: - if task.isRunning(): - count += 1 - - return count - - def doneCount(self): - count = 0 - - for task in self.__task_list: - if task.isDone(): - count += 1 - - return count - - def __findNextTask(self): - for task in self.__task_list: - if not task.hasStarted(): - return task - - return None - - def __start(self): - while not self.__allTasksFinished(): - if self.runningCount() < self.poolSize(): - task = self.__findNextTask() - - if task is not None: - task.start() - - time.sleep(0.001) - - self.__pool_finished = True - - - def nonBlockingStart(self): - self.__runner_thread = Thread() - self.__runner_thread.run = self.__start - self.__runner_thread.start() - self.__start_time = time.time() - - def join(self): - while not self.__pool_finished: - time.sleep(0.001) - - if self.__verbose: - running_time = time.time() - self.__start_time - print("Running time: %f using a pool size of: %d" % (running_time, self.poolSize())) - - def hasFailedTasks(self): - for task in self.__task_list: - if task.hasFailed(): - return True - - return False diff --git a/ThirdParty/Ert/python/python/ecl/util/time_vector.py b/ThirdParty/Ert/python/python/ecl/util/time_vector.py deleted file mode 100644 index 7821057fc7..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/time_vector.py +++ /dev/null @@ -1,170 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'vector_template.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import datetime -import re - -from ecl.util import VectorTemplate, CTime, UtilPrototype - - -class TimeVector(VectorTemplate): - TYPE_NAME = "time_t_vector" - default_format = "%d" - - _alloc = UtilPrototype("void* time_t_vector_alloc(int, time_t )" , bind = False) - _alloc_copy = UtilPrototype("time_t_vector_obj time_t_vector_alloc_copy(time_t_vector )") - _strided_copy = UtilPrototype("time_t_vector_obj time_t_vector_alloc_strided_copy(time_t_vector , int , int , int)") - _free = UtilPrototype("void time_t_vector_free( time_t_vector )") - _iget = UtilPrototype("time_t time_t_vector_iget( time_t_vector , int )") - _safe_iget = UtilPrototype("time_t time_t_vector_safe_iget( time_t_vector , int )") - _iset = UtilPrototype("time_t time_t_vector_iset( time_t_vector , int , time_t)") - _size = UtilPrototype("int time_t_vector_size( time_t_vector )") - _append = UtilPrototype("void time_t_vector_append( time_t_vector , time_t )") - _idel_block = UtilPrototype("void time_t_vector_idel_block( time_t_vector , int , int )") - _idel = UtilPrototype("void time_t_vector_idel( time_t_vector , int )") - _pop = UtilPrototype("time_t time_t_vector_pop( time_t_vector )") - _lshift = UtilPrototype("void time_t_vector_lshift( time_t_vector , int )") - _rshift = UtilPrototype("void time_t_vector_rshift( time_t_vector , int )") - _insert = UtilPrototype("void time_t_vector_insert( time_t_vector , int , time_t)") - _fprintf = UtilPrototype("void time_t_vector_fprintf( time_t_vector , FILE , char* , char*)") - _sort = UtilPrototype("void time_t_vector_sort( time_t_vector )") - _rsort = UtilPrototype("void time_t_vector_rsort( time_t_vector )") - _reset = UtilPrototype("void time_t_vector_reset( time_t_vector )") - _set_read_only = UtilPrototype("void time_t_vector_set_read_only( time_t_vector , bool )") - _get_read_only = UtilPrototype("bool time_t_vector_get_read_only( time_t_vector )") - _get_max = UtilPrototype("time_t time_t_vector_get_max( time_t_vector )") - _get_min = UtilPrototype("time_t time_t_vector_get_min( time_t_vector )") - _get_max_index = UtilPrototype("int time_t_vector_get_max_index( time_t_vector , bool)") - _get_min_index = UtilPrototype("int time_t_vector_get_min_index( time_t_vector , bool)") - _shift = UtilPrototype("void time_t_vector_shift( time_t_vector , time_t )") - _scale = UtilPrototype("void time_t_vector_scale( time_t_vector , time_t )") - _div = UtilPrototype("void time_t_vector_div( time_t_vector , time_t )") - _inplace_add = UtilPrototype("void time_t_vector_inplace_add( time_t_vector , time_t_vector )") - _inplace_mul = UtilPrototype("void time_t_vector_inplace_mul( time_t_vector , time_t_vector )") - _assign = UtilPrototype("void time_t_vector_set_all( time_t_vector , time_t)") - _memcpy = UtilPrototype("void time_t_vector_memcpy(time_t_vector , time_t_vector )") - _set_default = UtilPrototype("void time_t_vector_set_default( time_t_vector , time_t)") - _get_default = UtilPrototype("time_t time_t_vector_get_default( time_t_vector )") - _element_size = UtilPrototype("int time_t_vector_element_size( time_t_vector )") - - _permute = UtilPrototype("void time_t_vector_permute(time_t_vector, permutation_vector)") - _sort_perm = UtilPrototype("permutation_vector_obj time_t_vector_alloc_sort_perm(time_t_vector)") - _rsort_perm = UtilPrototype("permutation_vector_obj time_t_vector_alloc_rsort_perm(time_t_vector)") - _contains = UtilPrototype("bool time_t_vector_contains(time_t_vector, time_t)") - _select_unique = UtilPrototype("void time_t_vector_select_unique(time_t_vector)") - _element_sum = UtilPrototype("time_t time_t_vector_sum(time_t_vector)") - _count_equal = UtilPrototype("int time_t_vector_count_equal(time_t_vector, time_t)") - _init_range = UtilPrototype("void time_t_vector_init_range(time_t_vector, time_t , time_t , time_t)") - - def __init__(self, default_value=None, initial_size=0): - if default_value is None: - super(TimeVector, self).__init__(CTime(0), initial_size) - else: - try: - default = CTime(default_value) - except: - raise ValueError("default value invalid - must be type ctime() or date/datetime") - - super(TimeVector, self).__init__(default, initial_size) - - @classmethod - def parseTimeUnit(cls, deltaString): - deltaRegexp = re.compile("(?P\d*)(?P[dmy])", re.IGNORECASE) - matchObj = deltaRegexp.match(deltaString) - if matchObj: - try: - num = int(matchObj.group("num")) - except: - num = 1 - - timeUnit = matchObj.group("unit").lower() - return num, timeUnit - else: - raise TypeError("The delta string must be on form \'1d\', \'2m\', \'Y\' for one day, two months or one year respectively") - - def __str__(self): - """ - Returns string representantion of vector. - """ - string_list = [] - for d in self: - string_list.append("%s" % d) - - return str(string_list) - - def append(self, value): - self._append(CTime(value)) - - def __contains__(self, value): - return self._contains(CTime(value)) - - def nextTime(self, num, timeUnit): - currentTime = self[-1].datetime() - hour = currentTime.hour - minute = currentTime.minute - second = currentTime.second - - if timeUnit == "d": - td = datetime.timedelta(days=num) - currentTime += td - else: - day = currentTime.day - month = currentTime.month - year = currentTime.year - - if timeUnit == "y": - year += num - else: - month += num - 1 - (deltaYear, newMonth) = divmod(month, 12) - month = newMonth + 1 - year += deltaYear - currentTime = datetime.datetime(year, month, day, hour, minute, second) - - return currentTime - - def appendTime(self, num, timeUnit): - next = self.nextTime(num, timeUnit) - self.append(CTime(next)) - - @classmethod - def createRegular(cls, start, end, deltaString): - """ - The last element in the vector will be <= end; i.e. if the - question of whether the range is closed in the upper end - depends on the commensurability of the [start,end] interval - and the delta: - - createRegular(0 , 10 , delta=3) => [0,3,6,9] - createRegular(0 , 10 , delta=2) => [0,2,4,6,8,10] - """ - start = CTime(start) - end = CTime(end) - if start > end: - raise ValueError("The time interval is invalid start is after end") - - (num, timeUnit) = cls.parseTimeUnit(deltaString) - - timeVector = TimeVector() - currentTime = start - while currentTime <= end: - ct = CTime(currentTime) - timeVector.append(ct) - currentTime = timeVector.nextTime(num, timeUnit) - - return timeVector - - def getDataPtr(self): - raise NotImplementedError("The getDataPtr() function is not implemented for time_t vectors") diff --git a/ThirdParty/Ert/python/python/ecl/util/ui_return.py b/ThirdParty/Ert/python/python/ecl/util/ui_return.py deleted file mode 100644 index cfe4b28180..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/ui_return.py +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'ui_return.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import (absolute_import, division, - print_function, unicode_literals) - -from cwrap import BaseCClass -from ecl.util import UtilPrototype -from .enums import UIReturnStatusEnum - - -class UIReturn(BaseCClass): - TYPE_NAME = "ui_return" - - _alloc = UtilPrototype("void* ui_return_alloc( ui_return_status )" , bind = False) - _free = UtilPrototype("void ui_return_free(ui_return)") - _get_status = UtilPrototype("ui_return_status ui_return_get_status(ui_return)") - _get_help = UtilPrototype("char* ui_return_get_help(ui_return)") - _add_help = UtilPrototype("void ui_return_add_help(ui_return)") - _add_error = UtilPrototype("void ui_return_add_error(ui_return)") - _num_error = UtilPrototype("int ui_return_get_error_count(ui_return)") - _last_error = UtilPrototype("char* ui_return_get_last_error(ui_return)") - _first_error = UtilPrototype("char* ui_return_get_first_error(ui_return)") - _iget_error = UtilPrototype("char* ui_return_iget_error(ui_return , int)") - - def __init__(self , status): - c_ptr = self._alloc(status) - if c_ptr: - super(UIReturn, self).__init__(c_ptr) - else: - raise ValueError('Unable to construct UIReturn with status = %s' % str(status)) - - - def __nonzero__(self): - if self.status() == UIReturnStatusEnum.UI_RETURN_OK: - return True - else: - return False - - - def __len__(self): - return self._num_error() - - - def __getitem__(self , index): - if isinstance(index , int): - if index < 0: - index += len(self) - if 0 <= index < len(self): - return self._iget_error( index) - else: - raise IndexError('Invalid index. Valid range: [0, %d)' % len(self)) - else: - raise TypeError("Lookup type must be integer") - - - def iget_error(self , index): - return self[index] - - - def help_text(self): - help_text = self._get_help() - if help_text: - return help_text - else: - return "" - - def add_help(self, help_text): - self._add_help(help_text) - - - def status(self): - return self._get_status() - - - def __assert_error(self): - if self.status() == UIReturnStatusEnum.UI_RETURN_OK: - raise ValueError("Can not add error messages to object in state RETURN_OK") - - - def add_error(self, error): - self.__assert_error() - self._add_error(error) - - - def last_error(self): - self.__assert_error() - return self._last_error() - - - def first_error(self): - self.__assert_error() - return self._first_error() - - - def free(self): - self._free() - - def __repr__(self): - ec = len(self) - st = self.status() - ad = self._ad_str() - return 'UIReturn(error_count = %d, status = %s) %s' % (ec, st, ad) diff --git a/ThirdParty/Ert/python/python/ecl/util/util_func.py b/ThirdParty/Ert/python/python/ecl/util/util_func.py deleted file mode 100644 index 0d9e4aa2ac..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/util_func.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'util_func.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Module with utility functions from util.c -""" - -from ecl.util import UtilPrototype - -strcmp_int = UtilPrototype("int util_strcmp_int( char* , char* )") -""" -Function to compare strings with embedded integers. - -Will use proper numeric comparison when comparing strings with -embedded numbers, i.e. "CASE-9" will follow after "CASE-10" when -sorting: - - >> l = ["CASE-9" , "CASE-10"] - >> l.sort() - >> print(l) - ["CASE-10" , "CASE-9"] - >> l.sort( strcmp_int ) - >> print(l) - ["CASE-9" , "CASE-10"] - -When the standard strcmp() function is used for comparing strings -the '1' will compare as less than the '9' and the order will be -the reverse. Observe that the '-' is not interpreted as a sign -prefix. The strcmp_int function will interpret '.' as separating -character, wheras the strcmp_float() function will interpret '.' -as a descimal point. - -@type: (str, str) -> int -""" - -strcmp_float = UtilPrototype("int util_strcmp_float( char* , char* )") -""" -Function to compare strings with embedded numbers. - -See documentation of strcmp_int() for further details. -@type: (str, str) -> int -""" diff --git a/ThirdParty/Ert/python/python/ecl/util/vector_template.py b/ThirdParty/Ert/python/python/ecl/util/vector_template.py deleted file mode 100644 index 56b96c582b..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/vector_template.py +++ /dev/null @@ -1,647 +0,0 @@ -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'vector_template.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -""" -Typed vectors IntVector, DoubleVector and BoolVector. - -This module implements a quite simple typed vector which will grow -transparently as needed. The vector is created with a default value, -which will be used for not explicitly set indices. - - vec = IntVector( default_value = 66 ) - vec[0] = 10 - vec[2] = 10 - -After the 'vec[2] = 10' statement the vector has grown to contain -three elements. The element vec[1] has not been explicitly assigned by -the user, in that case the implementation has 'filled the hole' with -the default value (i.e. 66 in this case). So the statement - - print(vec[1]) - -will give '66'. The main part of the implementation is in terms of an -"abstract base class" TVector. The TVector class should be not -instantiated directly, instead the child classes IntVector, -DoubleVector or BoolVector should be used. - -The C-level has implementations for several fundamental types like -float and size_t not currently implemented in the Python version. -""" - -from __future__ import absolute_import, division, print_function, unicode_literals - -import sys - -from cwrap import CFILE, BaseCClass -from ecl.util import UtilPrototype - - - -class VectorTemplate(BaseCClass): - - def strided_copy(self, slice_range): - """ - Will create a new copy according to @slice. - - Mainly a support function to support slice based lookup like - - v = IntVector() - v[0] = 1 - v[1] = 1 - v[100] = 100 - ... - c = v[0:100:10] - - Now 'c' will be a Intvector() instance containing every tenth - element from 'v'. - """ - (start, stop, step) = slice_range.indices(len(self)) - if stop > start: - return self._strided_copy(start, stop, step) - else: - return None - - def __bool__(self): - """ - Will evaluate to False for empty vector. - """ - if len(self) == 0: - return False - else: - return True - - def __nonzero__(self): - return self.__bool__( ) - - - def copy(self): - """ - Create a new copy of the current vector. - """ - new = self._alloc_copy( ) - return new - - def __irshift__(self,shift): - if shift < 0: - raise ValueError("The shift must be positive") - self._rshift(shift) - return self - - def __ilshift__(self,shift): - if shift < 0: - raise ValueError("The shift must be positive") - if shift > len(self): - raise ValueError("The shift is too large %d > %d" % (shift, len(self))) - self._lshift( shift) - return self - - - def __rshift__(self,shift): - copy = self.copy() - copy >>= shift - return copy - - - def __lshift__(self,shift): - copy = self.copy() - copy <<= shift - return copy - - def __deepcopy__(self, memo): - new = self.copy() - return new - - def __init__(self, default_value=0, initial_size=0): - """ - Creates a new TVector instance. - """ - c_pointer = self._alloc(initial_size, default_value) - super(VectorTemplate, self).__init__(c_pointer) - self.element_size = self._element_size() - - def __contains__(self , value): - return self._contains( value) - - - def pop(self): - if len(self) > 0: - return self._pop() - else: - raise ValueError("Trying to pop from empty vector") - - - def str_data(self, width, index1, index2, fmt): - """ - Helper function for str() method. - """ - data = [] - s = "" - for index in range(index1, index2): - data.append(self[index]) - for index in range(len(data)): - s += fmt % data[index] - if index % width == (width - 1): - s += "\n" - return s - - - # The str() method is a verbatim copy of the implementation in - # ecl_kw.py. - def str(self, width=5, max_lines=10, fmt=None): - """ - Return string representation of vector for pretty printing. - - The function will return a string consisting of a header, and - then a chunk of data. The data will be formatted in @width - columns, and a maximum of @max_lines lines. If @max_lines is - not sufficient the first elements in the kewyord are - represented, a .... continuation line and then the last part - of the vector. If @max_lines is None all of the vector will be - printed, irrespectiv of how long it is. - - If a value is given for @fmt that is used as format string for - each element, otherwise a type-specific default format is - used. If given the @fmt string should contain spacing between - the elements. The implementation of the builtin method - __str__() is based on this method. - """ - - s = "" - lines = len(self) // width - if not fmt: - fmt = self.default_format + " " - - if max_lines is None or lines <= max_lines: - s += self.str_data(width, 0, len(self), fmt) - else: - s1 = width * max_lines // 2 - s += self.str_data(width, 0, s1, fmt) - s += " .... \n" - s += self.str_data(width, len(self) - s1, len(self), fmt) - - return s - - def __str__(self): - """ - Returns string representantion of vector. - """ - return self.str(max_lines=10, width=5) - - - def __getitem__(self, index): - """ - Implements read [] operator - @index can be slice instance. - """ - if isinstance(index, int): - length = len(self) - idx = index - if idx < 0: - idx += length - - if 0 <= idx < length: - return self._iget(idx) - else: - raise IndexError('Index must be in range %d <= %d < %d.' % (0, index, length)) - elif isinstance(index, slice): - return self.strided_copy(index) - else: - raise TypeError("Index should be integer or slice type.") - - def __setitem__(self, index, value): - """ - Implements write [] operator - @index must be integer or slice. - """ - ls = len(self) - if isinstance(index, int): - idx = index - if idx < 0: - idx += ls - self._iset(idx, value) - elif isinstance( index, slice ): - for i in range(*index.indices(ls)): - self[i] = value - else: - raise TypeError("Index should be integer type") - - ################################################################## - # Mathematical operations: - - def __IADD(self, delta, add): - """ - Low-level function implementing inplace add. - - The __IADD__ function implements the operation: - - v += a - - The variable which is added, i.e. @delta, can either be of the - same type as the current instance, or a numerical scalar. The - __IADD__ method implements both add and subtract, based on the - boolean flag @add. - - The __IADD__ method should not be called directly; but rather - via the __iadd__, __add__ and __radd__ methods which implement - the various addition operation, and the corresponding - subtraction operations: __isub__, __sub__ and __rsub__. - """ - if type(self) == type(delta): - if len(self) == len(delta): - # This is vector + vector operation. - if not add: - delta *= -1 - self._inplace_add(delta) - else: - raise ValueError("Incompatible sizes for add self:%d other:%d" % (len(self), len(delta))) - else: - if isinstance(delta, int) or isinstance(delta, float): - if not add: - delta *= -1 - self._shift(delta) - else: - raise TypeError("delta has wrong type:%s " % type(delta)) - - return self - - - def __iadd__(self, delta): - """ - Implements inplace add. @delta can be vector or scalar. - """ - return self.__IADD(delta, True) - - - def __isub__(self, delta): - """ - Implements inplace subtract. @delta can be vector or scalar. - """ - return self.__IADD(delta, False) - - - def __radd__(self, delta): - return self.__add__(delta) - - - def __add__(self, delta): - """ - Implements add operation - creating a new copy. - - b = DoubleVector() - c = DoubleVector() // Or alternatively scalar - .... - a = b + c - """ - copy = self._alloc_copy( ) - copy += delta - return copy - - def __sub__(self, delta): - """ - Implements subtraction - creating new copy. - """ - copy = self._alloc_copy( ) - copy -= delta - return copy - - - def __rsub__(self, delta): - return self.__sub__(delta) * -1 - - - def __imul__(self, factor): - """ - Low-level function implementing inplace multiplication. - - The __IMUL__ function implements the operation: - - v *= a - - The variable which is multiplied in, i.e. @factor, can either - be of the same type as the current instance, or a numerical - scalar. The __IMUL__ method should not be called directly, but - rather via the __mul__, __imul__ and __rmul__ functions. - """ - - if type(self) == type(factor): - # This is vector * vector operation. - if len(self) == len(factor): - self._inplace_mul(factor) - else: - raise ValueError("Incompatible sizes for mul self:%d other:%d" % (len(self), len(factor))) - else: - if isinstance(factor, int) or isinstance(factor, float): - self._scale(factor) - else: - raise TypeError("factor has wrong type:%s " % type(factor)) - - return self - - - def __mul__(self, factor): - copy = self._alloc_copy( ) - copy *= factor - return copy - - def __rmul__(self, factor): - return self.__mul__(factor) - - - def __div__(self, divisor): - if isinstance(divisor, int) or isinstance(divisor, float): - copy = self._alloc_copy( ) - copy._div(divisor) - return copy - else: - raise TypeError("Divisor has wrong type:%s" % type(divisor)) - - # End mathematical operations - ################################################################# - - # Essentally implements a = b - def assign(self, value): - """ - Implements assignment of type a = b. - - The @value parameter can either be a vector instance, in which - case the content of @value is copied into the current - instance, or a scalar in which case all the elements of the - vector are set to this value: - - v1 = IntVector() - v2 = IntVector() - - v1[10] = 77 - v2.assign( v1 ) # Now v2 contains identicall content to v1 - .... - v1.assign( 66 ) # Now v1 is a vector of 11 elements - all equal to 66 - - """ - if type(self) == type(value): - # This is a copy operation - self._memcpy(value) - else: - if isinstance(value, int) or isinstance(value, float): - self._assign(value) - else: - raise TypeError("Value has wrong type") - - def __len__(self): - """ - The number of elements in the vector. - """ - return self._size( ) - - - def printf(self, fmt=None, name=None, stream=sys.stdout): - """ - See also the str() method which returns string representantion - of the vector. - """ - cfile = CFILE(stream) - if not fmt: - fmt = self.default_format - self._fprintf(cfile, name, fmt) - - - def max(self): - if len(self) > 0: - return self._get_max() - else: - raise IndexError("The vector is empty!") - - def min(self): - if len(self) > 0: - return self._get_min() - else: - raise IndexError("The vector is empty!") - - - def minIndex(self, reverse=False): - """ - @type reverse: bool - @rtype: int - """ - if len(self) > 0: - return self._get_min_index(reverse) - else: - raise IndexError("The vector is empty!") - - def maxIndex(self, reverse=False): - """ - @type reverse: bool - @rtype: int - """ - if len(self) > 0: - return self._get_max_index(reverse) - else: - raise IndexError("The vector is empty!") - - def append(self, value): - self._append(value) - - def deleteBlock(self, index, block_size): - """ - Remove a block of size @block_size starting at @index. - - After the removal data will be left shifted. - """ - self._idel_block(index, block_size) - - def sort(self, reverse=False): - """ - Sort the vector inplace in increasing numerical order or decreasing order if reverse is True. - @type reverse: bool - """ - if not reverse: - self._sort() - else: - self._rsort() - - def clear(self): - self._reset() - - def safeGetByIndex(self, index): - return self._safe_iget(index) - - def setReadOnly(self, read_only): - self._set_read_only(read_only) - - def getReadOnly(self): - return self._get_read_only() - - def setDefault(self, value): - self._set_default(value) - - def getDefault(self): - return self._get_default() - - - def free(self): - self._free() - - def __repr__(self): - return self._create_repr('size = %d' % len(self)) - - def permute(self, permutation_vector): - """ - Reorders this vector based on the indexes in permutation_vector. - @type permutation_vector: PermutationVector - """ - - self._permute( permutation_vector) - - def permutationSort(self, reverse=False): - """ - Returns the permutation vector for sorting of this vector. Vector is not sorted. - @type reverse: bool - @@rtype: PermutationVector - """ - if len(self) > 0: - if not reverse: - return self._sort_perm() - else: - return self._rsort_perm() - - return None - - - def asList(self): - l = [0] * len(self) - for (index,value) in enumerate(self): - l[index] = value - - return l - - def selectUnique(self): - self._select_unique() - - - def elementSum(self): - return self._element_sum( ) - - - def getDataPtr(self): - "Low level function which returns a pointer to underlying storage" - # Observe that the get_data_ptr() function is not implemented - # for the TimeVector class. - return self._get_data_ptr() - - def countEqual(self , value): - return self._count_equal( value ) - - - def initRange(self , min_value , max_value , delta): - """ - Will fill the vector with the values from min_value to - max_value in steps of delta. The upper limit is guaranteed to - be inclusive, even if it is not commensurable with the delta. - """ - if delta == 0: - raise ValueError("Invalid range") - else: - self._init_range( min_value , max_value , delta ) - - @classmethod - def createRange(cls , min_value , max_value , delta): - """ - Will create new vector and initialize a range. - """ - vector = cls( ) - vector.initRange( min_value , max_value , delta ) - return vector - - def _strided_copy(self, *_): - raise NotImplementedError() - def _rshift(self, *_): - raise NotImplementedError() - def _lshift(self, *_): - raise NotImplementedError() - def _alloc(self, *_): - raise NotImplementedError() - def _element_size(self, *_): - raise NotImplementedError() - def _contains(self, *_): - raise NotImplementedError() - def _pop(self, *_): - raise NotImplementedError() - def default_format(self, *_): - raise NotImplementedError() - def _iget(self, *_): - raise NotImplementedError() - def _iset(self, *_): - raise NotImplementedError() - def _inplace_add(self, *_): - raise NotImplementedError() - def _shift(self, *_): - raise NotImplementedError() - def _alloc_copy(self, *_): - raise NotImplementedError() - def _inplace_mul(self, *_): - raise NotImplementedError() - def _scale(self, *_): - raise NotImplementedError() - def _memcpy(self, *_): - raise NotImplementedError() - def _assign(self, *_): - raise NotImplementedError() - def _size(self, *_): - raise NotImplementedError() - def _fprintf(self, *_): - raise NotImplementedError() - def _get_max(self, *_): - raise NotImplementedError() - def _get_min(self, *_): - raise NotImplementedError() - def _get_min_index(self, *_): - raise NotImplementedError() - def _get_max_index(self, *_): - raise NotImplementedError() - def _append(self, *_): - raise NotImplementedError() - def _idel_block(self, *_): - raise NotImplementedError() - def _sort(self, *_): - raise NotImplementedError() - def _rsort(self, *_): - raise NotImplementedError() - def _reset(self, *_): - raise NotImplementedError() - def _safe_iget(self, *_): - raise NotImplementedError() - def _set_read_only(self, *_): - raise NotImplementedError() - def _get_read_only(self, *_): - raise NotImplementedError() - def _set_default(self, *_): - raise NotImplementedError() - def _get_default(self, *_): - raise NotImplementedError() - def _free(self, *_): - raise NotImplementedError() - def _permute(self, *_): - raise NotImplementedError() - def _sort_perm(self, *_): - raise NotImplementedError() - def _rsort_perm(self, *_): - raise NotImplementedError() - def _select_unique(self, *_): - raise NotImplementedError() - def _element_sum(self, *_): - raise NotImplementedError() - def _get_data_ptr(self, *_): - raise NotImplementedError() - def _count_equal(self, *_): - raise NotImplementedError() - def _init_range(self, *_): - raise NotImplementedError() diff --git a/ThirdParty/Ert/python/python/ecl/util/version.py b/ThirdParty/Ert/python/python/ecl/util/version.py deleted file mode 100644 index dbbc66c74d..0000000000 --- a/ThirdParty/Ert/python/python/ecl/util/version.py +++ /dev/null @@ -1,118 +0,0 @@ -from ecl.util import UtilPrototype - - -def cmp_method(method): - def cmp_wrapper(self, other): - if not isinstance(other, Version): - other = Version(other[0], other[1], other[2]) - - return method(self, other) - - return cmp_wrapper - - - -class Version(object): - - - def __init__(self, major, minor, micro, git_commit = None, build_time = None): - self.major = major - self.minor = minor - self.micro = micro - try: - self.micro_int = int(micro) - self.is_devel = False - except ValueError: - self.micro_int = -1 - self.is_devel = True - self.build_time = build_time - self.git_commit = git_commit - - def isDevelVersion(self): - return self.is_devel - - def versionString(self): - return "%d.%d.%s" % (self.major, self.minor, self.micro) - - def versionTuple(self): - return self.major, self.minor, self.micro - - def __cmpTuple(self): - return self.major, self.minor, self.micro_int - - def __str__(self): - return self.versionString() - - def __repr__(self): - status = 'production' - git_commit = self.getGitCommit( short = True ) - if self.is_devel: - status = 'development' - fmt = 'Version(major=%d, minor=%d, micro="%s", commit="%s", status="%s")' - return fmt % (self.major, self.minor, self.micro, git_commit, status) - - @cmp_method - def __eq__(self, other): - return self.versionTuple() == other.versionTuple() - - def __ne__(self, other): - return not (self == other) - - def __hash__(self): - return hash(self.versionTuple()) - - # 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 - - # but not in the == test. - - @cmp_method - def __ge__(self, other): - return self.__cmpTuple() >= other.__cmpTuple() - - @cmp_method - def __lt__(self, other): - return not (self >= other) - - @cmp_method - def __le__(self, other): - return self.__cmpTuple() <= other.__cmpTuple() - - @cmp_method - def __gt__(self, other): - return not (self <= other) - - def getBuildTime(self): - if self.build_time is None: - return "?????" - else: - return self.build_time - - def getGitCommit(self, short=False): - if self.git_commit is None: - return "???????" - else: - if short: - return self.git_commit[0:8] - else: - return self.git_commit - - -class EclVersion(Version): - _build_time = UtilPrototype("char* ecl_version_get_build_time()") - _git_commit = UtilPrototype("char* ecl_version_get_git_commit()") - _major_version = UtilPrototype("int ecl_version_get_major_version()") - _minor_version = UtilPrototype("int ecl_version_get_minor_version()") - _micro_version = UtilPrototype("char* ecl_version_get_micro_version()") - _is_devel = UtilPrototype("bool ecl_version_is_devel_version()") - - def __init__(self): - major = self._major_version( ) - minor = self._minor_version( ) - 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) - - - diff --git a/ThirdParty/Ert/python/python/ecl/well/CMakeLists.txt b/ThirdParty/Ert/python/python/ecl/well/CMakeLists.txt deleted file mode 100644 index b37c7f17c4..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - well_connection.py - well_connection_direction_enum.py - well_info.py - well_segment.py - well_state.py - well_time_line.py - well_type_enum.py -) - -add_python_package("python.ecl.well" ${PYTHON_INSTALL_PREFIX}/ecl/well "${PYTHON_SOURCES}" True) - diff --git a/ThirdParty/Ert/python/python/ecl/well/__init__.py b/ThirdParty/Ert/python/python/ecl/well/__init__.py deleted file mode 100644 index 8616443f30..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -import ecl -import ecl.util -import ecl.geo -import ecl.ecl - -from cwrap import Prototype - -class WellPrototype(Prototype): - lib = ecl.load("libecl") - - def __init__(self, prototype, bind=True): - super(WellPrototype, self).__init__(WellPrototype.lib, prototype, bind=bind) - -from .well_type_enum import WellTypeEnum -from .well_connection_direction_enum import WellConnectionDirectionEnum -from .well_connection import WellConnection -from .well_segment import WellSegment -from .well_state import WellState -from .well_time_line import WellTimeLine -from .well_info import WellInfo diff --git a/ThirdParty/Ert/python/python/ecl/well/well_connection.py b/ThirdParty/Ert/python/python/ecl/well/well_connection.py deleted file mode 100644 index 8dc86af3ac..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/well_connection.py +++ /dev/null @@ -1,108 +0,0 @@ -from cwrap import BaseCClass -from ecl.well import WellPrototype, WellConnectionDirectionEnum - -class WellConnection(BaseCClass): - TYPE_NAME = "well_connection" - - _i = WellPrototype("int well_conn_get_i(well_connection)") - _j = WellPrototype("int well_conn_get_j(well_connection)") - _k = WellPrototype("int well_conn_get_k(well_connection)") - _segment_id = WellPrototype("int well_conn_get_segment_id(well_connection)") - _is_open = WellPrototype("bool well_conn_open(well_connection)") - _is_msw = WellPrototype("bool well_conn_MSW(well_connection)") - _fracture_connection = WellPrototype("bool well_conn_fracture_connection(well_connection)") - _matrix_connection = WellPrototype("bool well_conn_matrix_connection(well_connection)") - _connection_factor = WellPrototype("double well_conn_get_connection_factor(well_connection)") - _equal = WellPrototype("bool well_conn_equal(well_connection, well_connection)") - _get_dir = WellPrototype("void* well_conn_get_dir(well_connection)") - _oil_rate = WellPrototype("double well_conn_get_oil_rate(well_connection)") - _gas_rate = WellPrototype("double well_conn_get_gas_rate(well_connection)") - _water_rate = WellPrototype("double well_conn_get_water_rate(well_connection)") - _volume_rate = WellPrototype("double well_conn_get_volume_rate(well_connection)") - - _oil_rate_si = WellPrototype("double well_conn_get_oil_rate_si(well_connection)") - _gas_rate_si = WellPrototype("double well_conn_get_gas_rate_si(well_connection)") - _water_rate_si = WellPrototype("double well_conn_get_water_rate_si(well_connection)") - _volume_rate_si = WellPrototype("double well_conn_get_volume_rate_si(well_connection)") - - def __init__(self): - raise NotImplementedError("Class can not be instantiated directly") - - - def isOpen(self): - """ @rtype: bool """ - return self._is_open() - - - def ijk(self): - """ @rtype: tuple of (int, int, int) """ - i = self._i() - j = self._j() - k = self._k() - return i, j, k - - def direction(self): - """ @rtype: WellConnectionDirectionEnum """ - return self._get_dir() - - def segmentId(self): - """ @rtype: int """ - return self._segment_id() - - def isFractureConnection(self): - """ @rtype: bool """ - return self._fracture_connection() - - def isMatrixConnection(self): - """ @rtype: bool """ - return self._matrix_connection() - - def connectionFactor(self): - """ @rtype: float """ - return self._connection_factor() - - def __eq__(self, other): - return self._equal(other) - - def __ne__(self, other): - return not self == other - - def free(self): - pass - - def isMultiSegmentWell(self): - """ @rtype: bool """ - return self._is_msw() - - def __repr__(self): - ijk = str(self.ijk()) - frac = 'fracture ' if self.isFractureConnection() else '' - open_ = 'open ' if self.isOpen() else 'shut ' - msw = ' (multi segment)' if self.isMultiSegmentWell() else '' - dir = WellConnectionDirectionEnum(self.direction()) - addr = self._address() - return 'WellConnection(%s %s%s%s, rates = (O:%s,G:%s,W:%s), direction = %s) at 0x%x' % (ijk, frac, open_, msw, self.oilRate(), self.gasRate(), self.waterRate(), dir, addr) - - def gasRate(self): - return self._gas_rate() - - def waterRate(self): - return self._water_rate() - - def oilRate(self): - return self._oil_rate() - - def volumeRate(self): - return self._volume_rate() - - def gasRateSI(self): - return self._gas_rate_si() - - def waterRateSI(self): - return self._water_rate_si() - - def oilRateSI(self): - return self._oil_rate_si() - - def volumeRateSI(self): - return self._volume_rate_si() diff --git a/ThirdParty/Ert/python/python/ecl/well/well_connection_direction_enum.py b/ThirdParty/Ert/python/python/ecl/well/well_connection_direction_enum.py deleted file mode 100644 index 084d796f94..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/well_connection_direction_enum.py +++ /dev/null @@ -1,15 +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/ThirdParty/Ert/python/python/ecl/well/well_info.py b/ThirdParty/Ert/python/python/ecl/well/well_info.py deleted file mode 100644 index 3ec514854c..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/well_info.py +++ /dev/null @@ -1,122 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from os.path import isfile -from cwrap import BaseCClass -from ecl.ecl import EclGrid -from ecl.ecl.ecl_file import EclFile -from ecl.well import WellTimeLine, WellPrototype - - -class WellInfo(BaseCClass): - TYPE_NAME = "well_info" - - _alloc = WellPrototype("void* well_info_alloc(ecl_grid)", bind = False) - _free = WellPrototype("void well_info_free(well_info)") - _load_rstfile = WellPrototype("void well_info_load_rstfile(well_info, char*, bool)") - _load_rst_eclfile = WellPrototype("void well_info_load_rst_eclfile(well_info, ecl_file, bool)") - _get_well_count = WellPrototype("int well_info_get_num_wells(well_info)") - _iget_well_name = WellPrototype("char* well_info_iget_well_name(well_info, int)") - _has_well = WellPrototype("bool well_info_has_well(well_info, char*)") - _get_ts = WellPrototype("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 - """ - c_ptr = self._alloc(grid) - super(WellInfo, self).__init__(c_ptr) - if not c_ptr: - raise ValueError('Unable to construct WellInfo from grid %s.' % str(grid)) - - if rst_file is not None: - if isinstance(rst_file, list): - for item in rst_file: - self.addWellFile(item, load_segment_information) - else: - self.addWellFile(rst_file, load_segment_information) - - - def __repr__(self): - return 'WellInfo(well_count = %d) at 0x%x' % (len(self), self._address()) - - def __len__(self): - """ @rtype: int """ - return self._get_well_count( ) - - - def __getitem__(self, item): - """ - @type item: int or str - @rtype: WellTimeLine - """ - - if isinstance(item, str): - if not item in self: - raise KeyError("The well '%s' is not in this set." % item) - well_name = item - - elif isinstance(item, int): - if not 0 <= item < len(self): - raise IndexError("Index must be in range 0 <= %d < %d" % (item, len(self))) - well_name = self._iget_well_name( item ) - - return self._get_ts(well_name).setParent(self) - - def __iter__(self): - """ @rtype: iterator of WellTimeLine """ - index = 0 - - while index < len(self): - yield self[index] - index += 1 - - - def allWellNames(self): - """ @rtype: list of str """ - return [self._iget_well_name(index) for index in range(0, len(self))] - - - def __contains__(self, item): - """ - @type item: str - @rtype: bool - """ - return self._has_well( item ) - - def _assert_file_exists(self, rst_file): - if not isfile(rst_file): - raise IOError('No such file %s' % rst_file) - - def addWellFile(self, rst_file, load_segment_information): - """ @type rstfile: str or EclFile """ - 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) - else: - raise TypeError("Expected the RST file to be a filename or an EclFile instance.") - - - def hasWell(self , well_name): - return well_name in self - - - def free(self): - self._free( ) diff --git a/ThirdParty/Ert/python/python/ecl/well/well_segment.py b/ThirdParty/Ert/python/python/ecl/well/well_segment.py deleted file mode 100644 index 6e7aeb2f40..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/well_segment.py +++ /dev/null @@ -1,76 +0,0 @@ -from cwrap import BaseCClass -from ecl.well import WellPrototype - -class WellSegment(BaseCClass): - TYPE_NAME = "well_segment" - - _active = WellPrototype("bool well_segment_active(well_segment)") - _main_stem = WellPrototype("bool well_segment_main_stem(well_segment)") - _nearest_wellhead = WellPrototype("bool well_segment_nearest_wellhead(well_segment)") - _id = WellPrototype("int well_segment_get_id(well_segment)") - _link_count = WellPrototype("int well_segment_get_link_count(well_segment)") - _branch_id = WellPrototype("int well_segment_get_branch_id(well_segment)") - _outlet_id = WellPrototype("int well_segment_get_outlet_id(well_segment)") - _depth = WellPrototype("double well_segment_get_depth(well_segment)") - _length = WellPrototype("double well_segment_get_length(well_segment)") - _total_length = WellPrototype("double well_segment_get_total_length(well_segment)") - _diameter = WellPrototype("double well_segment_get_diameter(well_segment)") - - def __init__(self): - raise NotImplementedError("Class can not be instantiated directly") - - def free(self): - pass - - def __repr__(self): - return 'WellSegment(%s) at 0x%x' % (str(self), self._address()) - - def __str__(self): - return "{Segment ID:%d BranchID:%d Length:%g}" % (self.id() , self.branchId() , self.length()) - - def id(self): - """ @rtype: int """ - return self._id() - - def linkCount(self): - """ @rtype: int """ - return self._link_count() - - def branchId(self): - """ @rtype: int """ - return self._branch_id() - - def outletId(self): - """ @rtype: int """ - return self._outlet_id() - - def isActive(self): - """ @rtype: bool """ - return self._active() - - def isMainStem(self): - """ @rtype: bool """ - return self._main_stem() - - def isNearestWellHead(self): - """ @rtype: bool """ - return self._nearest_wellhead() - - def depth(self): - """ @rtype: float """ - return self._depth() - - def __len__(self): - return self.length() - - def length(self): - """ @rtype: float """ - return self._length() - - def totalLength(self): - """ @rtype: float """ - return self._total_length() - - def diameter(self): - """ @rtype: float """ - return self._diameter() diff --git a/ThirdParty/Ert/python/python/ecl/well/well_state.py b/ThirdParty/Ert/python/python/ecl/well/well_state.py deleted file mode 100644 index 6d0cadf567..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/well_state.py +++ /dev/null @@ -1,164 +0,0 @@ -from cwrap import BaseCClass -from ecl.well import WellTypeEnum, WellConnection, WellPrototype -from ecl.util import CTime - -class WellState(BaseCClass): - TYPE_NAME = "well_state" - - _global_connections_size = WellPrototype("int well_conn_collection_get_size(void*)", bind = False) - _global_connections_iget = WellPrototype("well_connection_ref well_conn_collection_iget(void*, int)", bind = False) - _segment_collection_size = WellPrototype("int well_segment_collection_get_size(void*)", bind = False) - _segment_collection_iget = WellPrototype("well_segment_ref well_segment_collection_iget(void*, int)", bind = False) - _has_global_connections = WellPrototype("bool well_state_has_global_connections(well_state)") - _get_global_connections = WellPrototype("void* well_state_get_global_connections(well_state)") - _get_segment_collection = WellPrototype("void* well_state_get_segments(well_state)") - _branches = WellPrototype("void* well_state_get_branches(well_state)") - _segments = WellPrototype("void* well_state_get_segments(well_state)") - _get_name = WellPrototype("char* well_state_get_name(well_state)") - _is_open = WellPrototype("bool well_state_is_open(well_state)") - _is_msw = WellPrototype("bool well_state_is_MSW(well_state)") - _well_number = WellPrototype("int well_state_get_well_nr(well_state)") - _report_number = WellPrototype("int well_state_get_report_nr(well_state)") - _has_segment_data = WellPrototype("bool well_state_has_segment_data(well_state)") - _sim_time = WellPrototype("time_t well_state_get_sim_time(well_state)") - _well_type = WellPrototype("well_type_enum well_state_get_type(well_state)") - _oil_rate = WellPrototype("double well_state_get_oil_rate(well_state)") - _gas_rate = WellPrototype("double well_state_get_gas_rate(well_state)") - _water_rate = WellPrototype("double well_state_get_water_rate(well_state)") - _volume_rate = WellPrototype("double well_state_get_volume_rate(well_state)") - _oil_rate_si = WellPrototype("double well_state_get_oil_rate_si(well_state)") - _gas_rate_si = WellPrototype("double well_state_get_gas_rate_si(well_state)") - _water_rate_si = WellPrototype("double well_state_get_water_rate_si(well_state)") - _volume_rate_si = WellPrototype("double well_state_get_volume_rate_si(well_state)") - _get_global_well_head = WellPrototype("well_connection_ref well_state_get_global_wellhead(well_state)") - - def __init__(self): - raise NotImplementedError("Class can not be instantiated directly") - - def name(self): - """ @rtype: str """ - return self._get_name( ) - - def isOpen(self): - """ @rtype: bool """ - return self._is_open( ) - - def free(self): - pass - - def wellHead(self): - well_head = self._get_global_well_head() - well_head.setParent( self ) - return well_head - - def wellNumber(self): - """ @rtype: int """ - return self._well_number( ) - - def reportNumber(self): - """ @rtype: int """ - return self._report_number( ) - - def simulationTime(self): - """ @rtype: CTime """ - return self._sim_time( ) - - def wellType(self): - """ @rtype: WellTypeEnum """ - return self._well_type( ) - - def hasGlobalConnections(self): - """ @rtype: bool """ - return self._has_global_connections( ) - - def globalConnections(self): - """ @rtype: list of WellConnection """ - global_connections = self._get_global_connections( ) - count = self._global_connections_size( global_connections ) - - values = [] - for index in range(count): - value = self._global_connections_iget(global_connections, index).setParent( self ) - values.append(value) - return values - - def __len__(self): - return self.numSegments() - - def __getitem__(self, idx): - return self.igetSegment(idx) - - def numSegments(self): - """ @rtype: int """ - segment_collection = self._get_segment_collection( ) - count = self._segment_collection_size(segment_collection) - return count - - - def segments(self): - """ @rtype: list of WellSegment """ - segment_collection = self._get_segment_collection( ) - - values = [] - for index in range(self.numSegments()): - value = self._segment_collection_iget(segment_collection, index).setParent(self) - values.append(value) - - return values - - - def igetSegment(self , seg_idx): - """ @rtype: WellSegment """ - if seg_idx < 0: - seg_idx += len(self) - - if not 0 <= seg_idx < self.numSegments(): - raise IndexError("Invalid index:%d - valid range [0,%d)" % (seg_idx , len(self))) - - segment_collection = self._get_segment_collection( ) - return self._segment_collection_iget(segment_collection, seg_idx).setParent(self) - - def isMultiSegmentWell(self): - """ @rtype: bool """ - return self._is_msw( ) - - def hasSegmentData(self): - """ @rtype: bool """ - return self._has_segment_data( ) - - def __repr__(self): - name = self.name() - if name: - name = '%s' % name - else: - name = '[no name]' - msw = ' (multi segment)' if self.isMultiSegmentWell() else '' - wn = str(self.wellNumber()) - type_ = self.wellType() - open_ = 'open' if self.isOpen() else 'shut' - cnt = '%s%s, number = %s, type = "%s", state = %s' % (name, msw, wn, type_, open_) - return self._create_repr(cnt) - - def gasRate(self): - return self._gas_rate( ) - - def waterRate(self): - return self._water_rate( ) - - def oilRate(self): - return self._oil_rate( ) - - def volumeRate(self): - return self._volume_rate( ) - - def gasRateSI(self): - return self._gas_rate_si( ) - - def waterRateSI(self): - return self._water_rate_si( ) - - def oilRateSI(self): - return self._oil_rate_si( ) - - def volumeRateSI(self): - return self._volume_rate_si( ) diff --git a/ThirdParty/Ert/python/python/ecl/well/well_time_line.py b/ThirdParty/Ert/python/python/ecl/well/well_time_line.py deleted file mode 100644 index bc42a20e82..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/well_time_line.py +++ /dev/null @@ -1,42 +0,0 @@ -from cwrap import BaseCClass -from ecl.well import WellState, WellPrototype - -class WellTimeLine(BaseCClass): - TYPE_NAME = "well_time_line" - _size = WellPrototype("int well_ts_get_size(well_time_line)") - _name = WellPrototype("char* well_ts_get_name(well_time_line)") - _iget = WellPrototype("well_state_ref well_ts_iget_state(well_time_line, int)") - - def __init__(self): - raise NotImplementedError("Class can not be instantiated directly") - - def getName(self): - return self._name() - - def __len__(self): - """ @rtype: int """ - return self._size() - - - def __getitem__(self, index): - """ - @type index: int - @rtype: WellState - """ - - if index < 0: - index += len(self) - - if not 0 <= index < len(self): - raise IndexError("Index must be in range 0 <= %d < %d" % (index, len(self))) - - return self._iget(index).setParent(self) - - def free(self): - pass - - def __repr__(self): - n = self.getName() - l = len(self) - cnt = 'name = %s, size = %d' % (n,l) - return self._create_repr(cnt) diff --git a/ThirdParty/Ert/python/python/ecl/well/well_type_enum.py b/ThirdParty/Ert/python/python/ecl/well/well_type_enum.py deleted file mode 100644 index f44e01fd22..0000000000 --- a/ThirdParty/Ert/python/python/ecl/well/well_type_enum.py +++ /dev/null @@ -1,16 +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/ThirdParty/Ert/python/python/legacy/ert/CMakeLists.txt b/ThirdParty/Ert/python/python/legacy/ert/CMakeLists.txt deleted file mode 100644 index dc308b5229..0000000000 --- a/ThirdParty/Ert/python/python/legacy/ert/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(PYTHON_SOURCES - __init__.py - ecl/__init__.py - ecl/faults/__init__.py - geo/__init__.py - well/__init__.py - util/__init__.py - test/__init__.py -) -add_python_package("python.ert" ${PYTHON_INSTALL_PREFIX}/ert "${PYTHON_SOURCES}" True) - diff --git a/ThirdParty/Ert/python/python/legacy/ert/__init__.py b/ThirdParty/Ert/python/python/legacy/ert/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/python/legacy/ert/ecl/__init__.py b/ThirdParty/Ert/python/python/legacy/ert/ecl/__init__.py deleted file mode 100644 index bdc9ad8458..0000000000 --- a/ThirdParty/Ert/python/python/legacy/ert/ecl/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -from ecl.ecl import EclFileEnum, EclFileFlagEnum, EclPhaseEnum, EclUnitTypeEnum , EclUtil -from ecl.ecl import EclTypeEnum, EclDataType -from ecl.ecl import EclSumVarType -from ecl.ecl import EclSumTStep -from ecl.ecl import EclSum #, EclSumVector, EclSumNode, EclSMSPECNode -from ecl.ecl import EclSumKeyWordVector -from ecl.ecl import EclPLTCell, EclRFTCell -from ecl.ecl import EclRFT, EclRFTFile -from ecl.ecl import FortIO, openFortIO -from ecl.ecl import EclKW -from ecl.ecl import Ecl3DKW -from ecl.ecl import EclFileView -from ecl.ecl import EclFile , openEclFile -from ecl.ecl import Ecl3DFile -from ecl.ecl import EclInitFile -from ecl.ecl import EclRestartFile -from ecl.ecl import EclGrid -from ecl.ecl import EclRegion -from ecl.ecl import EclSubsidence -from ecl.ecl import phase_deltag, deltag -from ecl.ecl import EclGrav -from ecl.ecl import EclSumNode -from ecl.ecl import EclSumVector -from ecl.ecl import EclNPV , NPVPriceVector -from ecl.ecl import EclCmp -from ecl.ecl import EclGridGenerator diff --git a/ThirdParty/Ert/python/python/legacy/ert/ecl/faults/__init__.py b/ThirdParty/Ert/python/python/legacy/ert/ecl/faults/__init__.py deleted file mode 100644 index 2d336c1fd6..0000000000 --- a/ThirdParty/Ert/python/python/legacy/ert/ecl/faults/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from ecl.ecl.faults import Layer -from ecl.ecl.faults import FaultCollection -from ecl.ecl.faults import Fault -from ecl.ecl.faults import FaultLine -from ecl.ecl.faults import FaultSegment , SegmentMap -from ecl.ecl.faults import FaultBlock , FaultBlockCell -from ecl.ecl.faults import FaultBlockLayer diff --git a/ThirdParty/Ert/python/python/legacy/ert/geo/__init__.py b/ThirdParty/Ert/python/python/legacy/ert/geo/__init__.py deleted file mode 100644 index 67f4193aa3..0000000000 --- a/ThirdParty/Ert/python/python/legacy/ert/geo/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from ecl.geo import GeoPointset -from ecl.geo import GeoRegion -from ecl.geo import CPolyline -from ecl.geo import CPolylineCollection -from ecl.geo import Polyline -from ecl.geo import XYZIo -from ecl.geo import GeometryTools -from ecl.geo import Surface diff --git a/ThirdParty/Ert/python/python/legacy/ert/test/__init__.py b/ThirdParty/Ert/python/python/legacy/ert/test/__init__.py deleted file mode 100644 index 912a43a595..0000000000 --- a/ThirdParty/Ert/python/python/legacy/ert/test/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -from ecl.test import TestRun -from ecl.test import path_exists -from ecl.test import ExtendedTestCase -from ecl.test import SourceEnumerator -from ecl.test import TestArea , TestAreaContext -from ecl.test import TempArea , TempAreaContext -from ecl.test import ErtTestRunner -from ecl.test import PathContext -from ecl.test import LintTestCase -from ecl.test import ImportTestCase diff --git a/ThirdParty/Ert/python/python/legacy/ert/util/__init__.py b/ThirdParty/Ert/python/python/legacy/ert/util/__init__.py deleted file mode 100644 index 926907fc6a..0000000000 --- a/ThirdParty/Ert/python/python/legacy/ert/util/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -from ecl.util import Version -from ecl.util import RngAlgTypeEnum, RngInitModeEnum, LLSQResultEnum -from ecl.util import CTime -from ecl.util import PermutationVector -from ecl.util import VectorTemplate -from ecl.util import DoubleVector -from ecl.util import IntVector -from ecl.util import BoolVector -from ecl.util import TimeVector -from ecl.util import StringList -from ecl.util import RandomNumberGenerator -from ecl.util import Matrix -from ecl.util import quantile, quantile_sorted, polyfit -from ecl.util import Log -from ecl.util import LookupTable -from ecl.util import Buffer -from ecl.util import Hash, StringHash, DoubleHash, IntegerHash -from ecl.util import UIReturn -from ecl.util import ThreadPool -from ecl.util import CThreadPool, startCThreadPool -from ecl.util import installAbortSignals, updateAbortSignals -from ecl.util import Profiler -from ecl.util import ArgPack -from ecl.util import PathFormat - -try: - from res.util import SubstitutionList -except ImportError: - pass \ No newline at end of file diff --git a/ThirdParty/Ert/python/python/legacy/ert/well/__init__.py b/ThirdParty/Ert/python/python/legacy/ert/well/__init__.py deleted file mode 100644 index 5a699e5689..0000000000 --- a/ThirdParty/Ert/python/python/legacy/ert/well/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from ecl.well import WellTypeEnum -from ecl.well import WellConnectionDirectionEnum -from ecl.well import WellConnection -from ecl.well import WellSegment -from ecl.well import WellState -from ecl.well import WellTimeLine -from ecl.well import WellInfo diff --git a/ThirdParty/Ert/python/python/test_env.py.in b/ThirdParty/Ert/python/python/test_env.py.in deleted file mode 100644 index 9fd11ea156..0000000000 --- a/ThirdParty/Ert/python/python/test_env.py.in +++ /dev/null @@ -1,6 +0,0 @@ -import os - -TESTDATA_ROOT = os.getenv("ERT_TEST_ROOT_PATH") or "${PROJECT_SOURCE_DIR}/test-data" -SOURCE_ROOT = "${PROJECT_SOURCE_DIR}" -BUILD_ROOT = "${PROJECT_BINARY_DIR}" - diff --git a/ThirdParty/Ert/python/tests/bin_tests/test_summary_resample.py b/ThirdParty/Ert/python/tests/bin_tests/test_summary_resample.py index fbd1e6c178..c265382c00 100644 --- a/ThirdParty/Ert/python/tests/bin_tests/test_summary_resample.py +++ b/ThirdParty/Ert/python/tests/bin_tests/test_summary_resample.py @@ -39,7 +39,7 @@ def fgpt(days): def create_case(num_mini_step = 10, case = "CSV"): length = 100 - return createEclSum(case, [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)], + return createEclSum(case, [("FOPT", None , 0, "SM3") , ("FOPR" , None , 0, "SM3/DAY"), ("FGPT" , None , 0, "SM3")], sim_length_days = length, num_report_step = 10, num_mini_step = num_mini_step, diff --git a/ThirdParty/Ert/python/tests/cwrap/CMakeLists.txt b/ThirdParty/Ert/python/tests/cwrap/CMakeLists.txt deleted file mode 100644 index 56200ef2d9..0000000000 --- a/ThirdParty/Ert/python/tests/cwrap/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -set(TEST_SOURCES - __init__.py - test_basecclass.py - test_basecenum.py - test_basecvalue.py - test_metawrap.py - test_cfile.py -) - -add_python_package("python.tests.cwrap" ${PYTHON_INSTALL_PREFIX}/tests/cwrap "${TEST_SOURCES}" False) - -addPythonTest(tests.cwrap.test_basecclass.BaseCClassTest) -addPythonTest(tests.cwrap.test_basecenum.BaseCEnumTest) -addPythonTest(tests.cwrap.test_basecvalue.BaseCValueTest) -addPythonTest(tests.cwrap.test_metawrap.MetaWrapTest) -addPythonTest(tests.cwrap.test_cfile.CFILETest) - diff --git a/ThirdParty/Ert/python/tests/cwrap/__init__.py b/ThirdParty/Ert/python/tests/cwrap/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/tests/cwrap/test_basecclass.py b/ThirdParty/Ert/python/tests/cwrap/test_basecclass.py deleted file mode 100644 index f2925d67b6..0000000000 --- a/ThirdParty/Ert/python/tests/cwrap/test_basecclass.py +++ /dev/null @@ -1,19 +0,0 @@ -from cwrap import BaseCClass -from ecl.test import ExtendedTestCase - - -class BaseCClassTest(ExtendedTestCase): - - def test_none_assertion(self): - self.assertFalse(None > 0) - - def test_creation(self): - with self.assertRaises(ValueError): - obj = BaseCClass(0) - - - obj = BaseCClass( 10 ) - self.assertTrue( obj ) - - obj._invalidateCPointer( ) - self.assertFalse( obj ) diff --git a/ThirdParty/Ert/python/tests/cwrap/test_basecenum.py b/ThirdParty/Ert/python/tests/cwrap/test_basecenum.py deleted file mode 100644 index b5f44efa95..0000000000 --- a/ThirdParty/Ert/python/tests/cwrap/test_basecenum.py +++ /dev/null @@ -1,91 +0,0 @@ -from cwrap import BaseCEnum -from ecl.test import ExtendedTestCase - - - -class BaseCEnumTest(ExtendedTestCase): - def test_base_c_enum(self): - class enum(BaseCEnum): - pass - - enum.addEnum("ONE", 1) - enum.addEnum("TWO", 2) - enum.addEnum("THREE", 3) - enum.addEnum("FOUR", 4) - - class enum2(BaseCEnum): - pass - - enum2.addEnum("ONE", 1) - enum2.addEnum("TWO", 4) - - self.assertEqual(enum.ONE, 1) - self.assertEqual(enum.TWO, 2) - self.assertEqual(enum.FOUR, 4) - - self.assertListEqual(enum.enums(), [enum.ONE, enum.TWO, enum.THREE, enum.FOUR]) - - self.assertEqual(enum(4), enum.FOUR) - - self.assertNotEqual(enum2(4), enum.FOUR) - self.assertEqual(enum2(4), enum2.TWO) - - self.assertEqual(str(enum.ONE), "ONE") - - - self.assertEqual(enum.ONE + enum.TWO, enum.THREE) - self.assertEqual(enum.ONE + enum.FOUR, 5) - - with self.assertRaises(ValueError): - e = enum(5) - - - self.assertEqual(enum.THREE & enum.ONE, enum.ONE) - self.assertEqual(enum.ONE | enum.TWO, enum.THREE) - self.assertEqual(enum.THREE ^ enum.TWO, enum.ONE) - - - with self.assertRaises(AssertionError): - e = enum.ONE + enum2.ONE - - with self.assertRaises(AssertionError): - e = enum.ONE & enum2.ONE - - with self.assertRaises(AssertionError): - e = enum.ONE | enum2.ONE - - with self.assertRaises(AssertionError): - e = enum.ONE ^ enum2.ONE - - - def test_in_operator(self): - class PowerOf2(BaseCEnum): - pass - - PowerOf2.addEnum("ONE", 1) - PowerOf2.addEnum("TWO", 2) - PowerOf2.addEnum("FOUR", 4) - - three = PowerOf2.ONE | PowerOf2.TWO - - self.assertEqual(int(three), 3) - - self.assertIn(PowerOf2.TWO, three) - self.assertIn(PowerOf2.ONE, three) - self.assertNotIn(PowerOf2.FOUR, three) - - def test_repr_and_str(self): - class MyLonelyEnum(BaseCEnum): - pass - - MyLonelyEnum.addEnum("ONE", 1) - MyLonelyEnum.addEnum("TWO", 2) - MyLonelyEnum.addEnum("THREE", 3) - MyLonelyEnum.addEnum("FOUR", 4) - - tri = MyLonelyEnum.THREE - - self.assertEqual(repr(tri), 'MyLonelyEnum(name = "THREE", value = 3)') - self.assertEqual(str(tri), 'THREE') - self.assertEqual(tri.name, 'THREE') - self.assertEqual(tri.value, 3) diff --git a/ThirdParty/Ert/python/tests/cwrap/test_basecvalue.py b/ThirdParty/Ert/python/tests/cwrap/test_basecvalue.py deleted file mode 100644 index 4066333221..0000000000 --- a/ThirdParty/Ert/python/tests/cwrap/test_basecvalue.py +++ /dev/null @@ -1,71 +0,0 @@ -import ecl -from ctypes import c_ubyte, c_double -from cwrap import BaseCValue, Prototype -from ecl.test import ExtendedTestCase - -class TestPrototype(Prototype): - lib = ecl.load("libecl") - - def __init__(self, prototype): - super(TestPrototype, self).__init__(self.lib, prototype) - -class UnsignedByteValue(BaseCValue): - DATA_TYPE = c_ubyte - - -class MaxDouble(BaseCValue): - TYPE_NAME = "pow_double" - DATA_TYPE = c_double - - -class BaseCValueTest(ExtendedTestCase): - def setUp(self): - self.double_max = TestPrototype("pow_double util_double_max(double, double)") - - - def test_illegal_type(self): - class ExceptionValueTest(BaseCValue): - DATA_TYPE = str - def __init__(self, value): - super(ExceptionValueTest, self).__init__(value) - - with self.assertRaises(ValueError): - test = ExceptionValueTest("Failure") - - - class NoDataTypeTest(BaseCValue): - def __init__(self, value): - super(NoDataTypeTest, self).__init__(value) - - with self.assertRaises(ValueError): - test = ExceptionValueTest(0) - - - def test_creation(self): - test_value = UnsignedByteValue(255) - - self.assertEqual(test_value.value(), 255) - - test_value.setValue(256) - self.assertEqual(test_value.value(), 0) - - self.assertEqual(test_value.type(), c_ubyte) - - - def test_from_param(self): - test_value = UnsignedByteValue(127) - - self.assertEqual(UnsignedByteValue.from_param(test_value).value, 127) - - with self.assertRaises(AttributeError): - UnsignedByteValue.from_param(None) - - with self.assertRaises(ValueError): - UnsignedByteValue.from_param("exception") - - - def test_double_max(self): - double_max = self.double_max(2.97, 2.98) - - self.assertIsInstance(double_max, MaxDouble) - self.assertEqual(double_max.value(), 2.98) diff --git a/ThirdParty/Ert/python/tests/cwrap/test_cfile.py b/ThirdParty/Ert/python/tests/cwrap/test_cfile.py deleted file mode 100644 index 1df29bfe8c..0000000000 --- a/ThirdParty/Ert/python/tests/cwrap/test_cfile.py +++ /dev/null @@ -1,31 +0,0 @@ -import ecl -from cwrap import Prototype, CFILE -from ecl.test.extended_testcase import ExtendedTestCase -from ecl.test.test_area import TestAreaContext - - -# Local copies so that the real ones don't get changed -class TestUtilPrototype(Prototype): - lib = ecl.load("libecl") - def __init__(self, prototype, bind=False): - super(TestUtilPrototype, self).__init__(TestUtilPrototype.lib, prototype, bind=bind) - -fileno = TestUtilPrototype("int fileno(FILE)") - - -class CFILETest(ExtendedTestCase): - - def test_cfile(self): - with TestAreaContext("cfile_tests") as test_area: - - with open("test", "w") as f: - f.write("some content") - - with open("test", "r") as f: - cfile = CFILE(f) - - self.assertEqual(fileno(cfile), f.fileno()) - - def test_cfile_error(self): - with self.assertRaises(TypeError): - cfile = CFILE("some text") diff --git a/ThirdParty/Ert/python/tests/cwrap/test_metawrap.py b/ThirdParty/Ert/python/tests/cwrap/test_metawrap.py deleted file mode 100644 index e82db53d6d..0000000000 --- a/ThirdParty/Ert/python/tests/cwrap/test_metawrap.py +++ /dev/null @@ -1,122 +0,0 @@ -from __future__ import absolute_import, division, print_function, unicode_literals -from six import string_types -import ctypes - -import ecl -from cwrap import BaseCClass, Prototype, PrototypeError -from ecl.test import ExtendedTestCase - - -# Local copies so that the real ones don't get changed -class TestUtilPrototype(Prototype): - lib = ecl.load("libecl") - def __init__(self, prototype, bind=False): - super(TestUtilPrototype, self).__init__(TestUtilPrototype.lib, prototype, bind=bind) - -class BoundTestUtilPrototype(TestUtilPrototype): - def __init__(self, prototype): - super(BoundTestUtilPrototype, self).__init__(prototype, bind=True) - - -class StringList(BaseCClass): - TYPE_NAME = "test_stringlist" - - __len__ = BoundTestUtilPrototype("int stringlist_get_size(test_stringlist)") - free = BoundTestUtilPrototype("void stringlist_free(test_stringlist)") - - _alloc = TestUtilPrototype("void* stringlist_alloc_new()", bind = False) - _iget = TestUtilPrototype("char* stringlist_iget(test_stringlist, int)") - _append = TestUtilPrototype("void stringlist_append_copy(test_stringlist, char*)") - - def __init__(self, initial=None): - c_ptr = self._alloc() - super(StringList, self).__init__(c_ptr) - - if initial: - for s in initial: - if isinstance(s, bytes): - s.decode('ascii') - if isinstance(s, string_types): - self.append(s) - else: - raise TypeError("Item: %s not a string" % s) - - def __getitem__(self, index): - if isinstance(index, int): - length = len(self) - if index < 0: - index += length - if index < 0 or index >= length: - raise IndexError("index must be in range %d <= %d < %d" % (0, index, len(self))) - else: - return self._iget(self, index) - else: - raise TypeError("Index should be integer type") - - def append(self, string): - if isinstance(string, bytes): - s.decode('ascii') - if isinstance(string, string_types): - self._append(self, string) - else: - self._append(self, str(string)) - - - -class MetaWrapTest(ExtendedTestCase): - - def test_stringlist_wrap(self): - items = ["A", "C", "E"] - stringlist = StringList(items) - self.assertEqual(len(stringlist), len(items)) - - self.assertIn("free", StringList.__dict__) - self.assertEqual(StringList.free.__name__, "stringlist_free") - - for index, item in enumerate(items): - self.assertEqual(item, stringlist[index]) - - - def test_already_registered(self): - with self.assertRaises(PrototypeError): - Prototype.registerType("test_stringlist", None) - - def test_error_in_prototype_illegal_return_type(self): - func = TestUtilPrototype("test_stringlist util_alloc_date_stamp_utc()") - - with self.assertRaises(PrototypeError): - func() - - def test_prototype_known_return_type(self): - stringlist = StringList(["B", "D", "F"]) - func = TestUtilPrototype("test_stringlist_ref stringlist_alloc_shallow_copy(stringlist)") - result = func(stringlist) - self.assertIsInstance(result, StringList) - - for index, value in enumerate(stringlist): - self.assertEqual(result[index], value) - - - def test_invalid_function(self): - func = TestUtilPrototype("void stringlist_missing_function()") - with self.assertRaises(PrototypeError): - func() - - - def test_invalid_prototype(self): - func = TestUtilPrototype("void util_alloc_date_stamp_utc(") - with self.assertRaises(PrototypeError): - func() - - - def test_function_type(self): - def stringObj(c_ptr): - char_ptr = ctypes.c_char_p(c_ptr) - python_string = char_ptr.value - return python_string.decode('ascii') - - Prototype.registerType("string_obj", stringObj) - - dateStamp = TestUtilPrototype("string_obj util_alloc_date_stamp_utc()") - date_stamp = dateStamp() - self.assertIsInstance(date_stamp, string_types) diff --git a/ThirdParty/Ert/python/tests/ecl/CMakeLists.txt b/ThirdParty/Ert/python/tests/ecl/CMakeLists.txt deleted file mode 100644 index 5eb3c91721..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/CMakeLists.txt +++ /dev/null @@ -1,97 +0,0 @@ -set(NFS_RUNPATH "" CACHE STRING "Disk area which is shared among cluster nodes and can be used as CWD for LSF/RSH jobs.") -set(RSH_SERVERS "" CACHE STRING "List of nodes which will be used to test the RSH driver") - -set(TEST_SOURCES - __init__.py - test_deprecation.py - test_removed.py - test_ecl_3dkw.py - test_ecl_file_statoil.py - test_ecl_file.py - test_ecl_init_file.py - test_ecl_restart_file.py - test_debug.py - test_ecl_sum.py - test_ecl_sum_vector.py - test_fault_blocks.py - test_fault_blocks_statoil.py - test_faults.py - test_fortio.py - test_grdecl.py - test_grid.py - test_cell.py - test_grid_statoil.py - test_grid_generator.py - test_indexed_read.py - test_ecl_kw_statoil.py - test_ecl_kw.py - test_kw_function.py - test_layer.py - test_npv.py - test_region.py - test_region_statoil.py - test_restart.py - test_rft.py - test_rft_statoil.py - test_rft_cell.py - test_statoil_faults.py - test_sum_statoil.py - test_ecl_util.py - test_ecl_cmp.py - test_sum.py - test_grav.py - test_geertsma.py - test_ecl_type.py - test_restart_head.py - test_fk_user_data.py -) - -add_python_package("python.tests.ecl" ${PYTHON_INSTALL_PREFIX}/tests/ecl "${TEST_SOURCES}" False) - -addPythonTest(tests.ecl.test_fk_user_data.FKTest) -addPythonTest(tests.ecl.test_cell.CellTest) -addPythonTest(tests.ecl.test_grid.GridTest LABELS SLOW_1) -addPythonTest(tests.ecl.test_grid_generator.GridGeneratorTest LABELS SLOW_2) -addPythonTest(tests.ecl.test_ecl_kw.KWTest LABELS SLOW_2) -addPythonTest(tests.ecl.test_kw_function.KWFunctionTest) -addPythonTest(tests.ecl.test_ecl_3dkw.Ecl3DKWTest ) -addPythonTest(tests.ecl.test_rft.RFTTest) -addPythonTest(tests.ecl.test_rft_cell.RFTCellTest) -addPythonTest(tests.ecl.test_sum.SumTest) -addPythonTest(tests.ecl.test_layer.LayerTest ) -addPythonTest(tests.ecl.test_faults.FaultTest ) -addPythonTest(tests.ecl.test_fault_blocks.FaultBlockTest ) -addPythonTest(tests.ecl.test_deprecation.Deprecation_1_9_Test ) -addPythonTest(tests.ecl.test_deprecation.Deprecation_2_0_Test ) -addPythonTest(tests.ecl.test_deprecation.Deprecation_2_1_Test ) -addPythonTest(tests.ecl.test_removed.Removed_2_1_Test ) -addPythonTest(tests.ecl.test_ecl_util.EclUtilTest ) -addPythonTest(tests.ecl.test_fortio.FortIOTest) -addPythonTest(tests.ecl.test_ecl_file.EclFileTest) -addPythonTest(tests.ecl.test_grav.EclGravTest) -addPythonTest(tests.ecl.test_geertsma.GeertsmaTest) -addPythonTest(tests.ecl.test_ecl_type.EclDataTypeTest) -addPythonTest(tests.ecl.test_region.RegionTest) -addPythonTest(tests.ecl.test_debug.DebugTest) - - -if (STATOIL_TESTDATA_ROOT) - addPythonTest(tests.ecl.test_ecl_file_statoil.EclFileStatoilTest LABELS StatoilData) - addPythonTest(tests.ecl.test_grdecl.GRDECLTest LABELS StatoilData) - addPythonTest(tests.ecl.test_grid_statoil.GridTest LABELS StatoilData:Slow) - addPythonTest(tests.ecl.test_ecl_kw_statoil.KWTest LABELS StatoilData) - addPythonTest(tests.ecl.test_ecl_init_file.InitFileTest LABELS StatoilData) - addPythonTest(tests.ecl.test_ecl_restart_file.RestartFileTest LABELS StatoilData) - addPythonTest(tests.ecl.test_restart.RestartTest LABELS StatoilData ) - addPythonTest(tests.ecl.test_region_statoil.RegionTest LABELS StatoilData) - addPythonTest(tests.ecl.test_rft_statoil.RFTTest LABELS StatoilData) - addPythonTest(tests.ecl.test_sum_statoil.SumTest LABELS StatoilData) - addPythonTest(tests.ecl.test_ecl_sum_vector.EclSumVectorTest LABELS StatoilData) - addPythonTest(tests.ecl.test_ecl_sum.EclSumTest LABELS StatoilData) - addPythonTest(tests.ecl.test_statoil_faults.StatoilFaultTest LABELS StatoilData) - addPythonTest(tests.ecl.test_fault_blocks_statoil.FaultBlockTest LABELS StatoilData) - addPythonTest(tests.ecl.test_npv.NPVTest LABELS StatoilData) - addPythonTest(tests.ecl.test_indexed_read.EclIndexedReadTest LABELS StatoilData) - addPythonTest(tests.ecl.test_ecl_cmp.EclCmpTest LABELS StatoilData) - addPythonTest(tests.ecl.test_restart_head.RestartHeadTest LABELS StatoilData) -endif() diff --git a/ThirdParty/Ert/python/tests/ecl/__init__.py b/ThirdParty/Ert/python/tests/ecl/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/tests/ecl/test_cell.py b/ThirdParty/Ert/python/tests/ecl/test_cell.py deleted file mode 100644 index 1764b7fe7c..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_cell.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.ecl import Cell, EclGrid -from ecl.test import ExtendedTestCase - -class CellTest(ExtendedTestCase): - - def setUp(self): - fk = self.createTestPath('local/ECLIPSE/faarikaal/faarikaal1.EGRID') - self.grid = EclGrid(fk) - self.cell = self.grid[3455] - self.actives = [c for c in self.grid if c.active] - - def test_init(self): - cell = self.grid[0] - self.assertEqual(0, cell.global_index) - - def test_actives(self): - self.assertEqual(4160, len(self.actives)) - - def test_volumes(self): - actives = self.actives - vols = [c.volume for c in actives] - vmin, vmax = min(vols), max(vols) - self.assertFloatEqual(vmin, 1332.328921) - self.assertFloatEqual(vmax, 10104.83204) - self.assertFloatEqual(actives[2000].dz, 1.68506) - - act_dim = (48.5676, 54.1515, 1.685) # cell dimension in meter - cel_dim = self.cell.dimension - self.assertEqual(3, len(cel_dim)) - for d in range(2): - self.assertFloatEqual(act_dim[d], cel_dim[d]) - - def test_indices(self): - c = self.cell - self.assertEqual(3455, c.global_index) - self.assertEqual(2000, c.active_index) - self.assertEqual((4,1,82), c.ijk) - self.assertEqual(c.ijk, (c.i, c.j, c.k)) - - def test_coordinates(self): - c = self.cell - corners = c.corners - self.assertEqual(8, len(corners)) - se0 = corners[5] # upper south east - se0_act = (606900.002, 5202050.07, 5149.26) - for i in range(3): - self.assertFloatEqual(se0[i], se0_act[i]) - - coordinate = c.coordinate - coor_act = (606866.883, 5202064.939, 5154.52) - - for i in range(3): - self.assertFloatEqual(coordinate[i], coor_act[i]) - - xyz = c.coordinate - self.assertIn(xyz, c) - - def test_eq(self): - c1 = self.cell - c2 = self.grid[4,1,82] - c3 = self.grid[1,1,82] - self.assertEqual(c1,c2) - self.assertEqual(c2,c1) - self.assertNotEqual(c1, 'notacell') - self.assertNotEqual(c1,c3) - self.assertNotEqual(c3,c1) - - def test_getitem_3(self): - c = self.cell - d = self.grid[4,1,82] - self.assertEqual(c, d) - - def test_validity(self): - self.assertTrue(self.cell.valid_geometry) - self.assertTrue(self.cell.valid) - - def test_repr(self): - c = self.cell - r = repr(c) - self.assertTrue(r.startswith('Cell(4, 1, 82, active, ')) - self.assertIn('faarikaal1.EGRID', r) diff --git a/ThirdParty/Ert/python/tests/ecl/test_debug.py b/ThirdParty/Ert/python/tests/ecl/test_debug.py deleted file mode 100644 index 344527d34a..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_debug.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# The file 'test_debug.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.test import debug_msg, ExtendedTestCase - -class DebugTest(ExtendedTestCase): - - def test_create(self): - msg = debug_msg( "DEBUG" ) - self.assertIn( __file__[:-1] , msg ) - self.assertIn( "DEBUG" , msg ) diff --git a/ThirdParty/Ert/python/tests/ecl/test_deprecation.py b/ThirdParty/Ert/python/tests/ecl/test_deprecation.py deleted file mode 100644 index cd818abc5e..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_deprecation.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'test_deprecation.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import warnings -import time -import datetime - -from ecl.test import ExtendedTestCase, TestAreaContext -from ecl.ecl import EclFile, EclGrid, EclKW, EclDataType, EclGrid, EclRegion -from ecl.ecl import FortIO, openFortIO, EclRFT, EclGridGenerator -from ecl.test.ecl_mock import createEclSum -from ecl.util import BoolVector - -# 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(ExtendedTestCase): - pass - -class Deprecation_2_0_Test(ExtendedTestCase): - - 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 ) - - t.sync() - f = EclFile( "TEST" ) - -class Deprecation_1_9_Test(ExtendedTestCase): - - def test_EclRegion_properties(self): - grid = EclGridGenerator.createRectangular( (10,10,10) , (1,1,1)) - region = EclRegion( grid , False ) diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_3dkw.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_3dkw.py deleted file mode 100644 index f6bdabb0c3..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_3dkw.py +++ /dev/null @@ -1,202 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'test_kw.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os -import random - -from ecl.util import IntVector -from ecl.ecl import Ecl3DKW , EclKW, EclDataType, EclFile, FortIO, EclFileFlagEnum , EclGrid -from ecl.test import ExtendedTestCase , TestAreaContext - - - -class Ecl3DKWTest(ExtendedTestCase): - - 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 ) - self.assertEqual( len(kw) , grid.getNumActive()) - - self.assertEqual( (10,10,10) , kw.dims() ) - - - def test_create_global_size( 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 , global_active = True) - self.assertEqual( len(kw) , grid.getGlobalSize()) - - kw.assign(50) - self.assertEqual( kw[0,0,0] , 50 ) - - kw[0,0,0] = 45 - self.assertEqual( kw[0,0,0] , 45 ) - - - 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) - kw.assign(3) - self.assertEqual( 3 * nx*ny*nz , sum(kw)) - - kw[1,1,1] = 0 - kw[3,3,3] = 0 - kw[6,6,6] = 0 - - self.assertEqual( 3 * nx*ny*nz - 9 , sum(kw)) - kw.fixUninitialized( grid ) - self.assertEqual( 3 * nx*ny*nz , sum(kw)) - - - - def test_getitem( 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 , default_value = 77) - - with self.assertRaises(IndexError): - kw[1000] - - with self.assertRaises(IndexError): - kw[0,10,100] - - with self.assertRaises(ValueError): - kw[1,1] - - with self.assertRaises(ValueError): - kw[1,1,1,1] - - kw.assign(99) - - self.assertEqual( kw[0,0,0] , 77 ) - self.assertEqual( kw[0,0,1] , 99 ) - - - - def test_setitem( 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 , default_value = 77) - - with self.assertRaises(IndexError): - kw[1000] - - with self.assertRaises(IndexError): - kw[0,10,100] - - with self.assertRaises(ValueError): - kw[1,1] - - with self.assertRaises(ValueError): - kw[1,1,1,1] - - kw.assign(99) - self.assertEqual( kw[0,0,0] , 77 ) - self.assertEqual( kw[0,0,1] , 99 ) - - - with self.assertRaises(ValueError): - kw[0,0,0] = 88 - - kw[0,0,1] = 100 - self.assertEqual( kw[0,0,1] , 100 ) - - - - def test_cast(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_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 ) - - with self.assertRaises(ValueError): - Ecl3DKW.castFromKW(kw_wrong_size , grid) - - Ecl3DKW.castFromKW(kw_global_size , grid) - self.assertTrue( isinstance( kw_global_size , Ecl3DKW)) - - Ecl3DKW.castFromKW(kw_active_size , grid , default_value = 66) - self.assertTrue( isinstance( kw_active_size , Ecl3DKW)) - - 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 ) - kw.setDefault(55) - self.assertTrue( 55 , kw.getDefault()) - - - def test_compressed_copy(self): - actnum = IntVector(default_value = 1 , initial_size = 1000) - 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) - for i in range(len(kw)): - kw[i] = i - - kw_copy = kw.compressedCopy() - self.assertTrue( isinstance( kw_copy , EclKW ) ) - - self.assertEqual(len(kw_copy) , 500) - for i in range(len(kw_copy)): - self.assertEqual(kw_copy[i] , 2*i) - - - - def test_global_copy(self): - actnum = IntVector(default_value = 1 , initial_size = 1000) - 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) - for i in range(len(kw)): - kw[i] = i - - kw.setDefault( 177 ) - kw_copy = kw.globalCopy() - self.assertTrue( isinstance( kw_copy , EclKW ) ) - - self.assertEqual(len(kw_copy) , 1000) - for i in range(len(kw)): - self.assertEqual(kw_copy[2*i] , i) - self.assertEqual(kw_copy[2*i + 1] , kw.getDefault()) diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_cmp.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_cmp.py deleted file mode 100644 index 807c0b9ab0..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_cmp.py +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'test_ecl_cmp.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.test import ExtendedTestCase , TestAreaContext -from ecl.test.ecl_mock import createEclSum -from ecl.ecl import EclCmp - -class EclCmpTest(ExtendedTestCase): - def setUp(self): - self.root1 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE") - self.root2 = self.createTestPath("Statoil/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/ThirdParty/Ert/python/tests/ecl/test_ecl_file.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_file.py deleted file mode 100644 index bd6ff62248..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_file.py +++ /dev/null @@ -1,256 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import shutil -import datetime -import os.path -import gc -from unittest import skipIf - - -from ecl.ecl import EclFile, FortIO, EclKW , openFortIO , openEclFile -from ecl.ecl import EclFileFlagEnum, EclDataType, EclFileEnum -from ecl.util import CWDContext -from ecl.test import ExtendedTestCase , TestAreaContext, PathContext - -def createFile( name , kw_list ): - with openFortIO(name , mode = FortIO.WRITE_MODE) as f: - for kw in kw_list: - kw.fwrite( f ) - - -def loadKeywords( name ): - kw_list = [] - f = EclFile( name ) - for kw in f: - kw_list.append( kw ) - - return kw_list - - - - -class EclFileTest(ExtendedTestCase): - - def assertFileType(self , filename , expected): - file_type , step , fmt_file = EclFile.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 )) - - - def test_IOError(self): - with self.assertRaises(IOError): - EclFile("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 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 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() - - ecl_file_index = EclFile("TEST", 0, "INDEX_FILE") - for kw in ["KW1","KW2","KW3","KW4"]: - self.assertIn( kw , ecl_file_index ) - - with self.assertRaises(IOError): - ecl_file.write_index("does-not-exist/INDEX") - - os.mkdir("read-only") - os.chmod("read-only", 0o444) - - with self.assertRaises(IOError): - ecl_file.write_index("read-only/INDEX") - - with self.assertRaises(IOError): - ecl_file_index = EclFile("TEST", 0, "index_does_not_exist") - - shutil.copyfile( "INDEX_FILE" , "INDEX_perm_denied") - os.chmod("INDEX_perm_denied", 0o000) - with self.assertRaises(IOError): - ecl_file_index = EclFile("TEST", 0, "INDEX_perm_denied") - - - os.mkdir("path") - shutil.copyfile("TEST" , "path/TEST") - ecl_file = EclFile("path/TEST") - ecl_file.write_index("path/index") - - with CWDContext("path"): - ecl_file = EclFile("TEST" , 0 , "index") - - - def test_save_kw(self): - with TestAreaContext("python/ecl_file/save_kw"): - data = range(1000) - kw = EclKW("MY_KEY", len(data), EclDataType.ECL_INT) - for index, val in enumerate(data): - kw[index] = val - - clean_dump = "my_clean_file" - fortio = FortIO(clean_dump, FortIO.WRITE_MODE) - kw.fwrite(fortio) - fortio.close() - - test_file = "my_dump_file" - fortio = FortIO(test_file, FortIO.WRITE_MODE) - kw.fwrite(fortio) - fortio.close() - - self.assertFilesAreEqual(clean_dump, test_file) - - ecl_file = EclFile(test_file, flags=EclFileFlagEnum.ECL_FILE_WRITABLE) - loaded_kw = ecl_file["MY_KEY"][0] - self.assertTrue(kw.equal(loaded_kw)) - - ecl_file.save_kw(loaded_kw) - ecl_file.close() - - self.assertFilesAreEqual(clean_dump, test_file) - - ecl_file = EclFile(test_file) - loaded_kw = ecl_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) - - for i in range(len(kw1)): - kw1[i] = i - kw2[i] = 2*i - kw3[i] = 3*i - - kw_list = [kw1 , kw2 , kw2] - - with TestAreaContext("context") as ta: - createFile("TEST" , kw_list ) - gc.collect() - kw_list2 = loadKeywords( "TEST" ) - - for kw1,kw2 in zip(kw_list,kw_list2): - self.assertEqual( kw1, kw2 ) - - - 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") - - - with self.assertRaises(IOError): - f = EclFile("CASE.FINIT") - - - def test_block_view(self): - with TestAreaContext("python/ecl_file/view"): - with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f: - for i in range(5): - header = EclKW("HEADER" , 1 , EclDataType.ECL_INT ) - header[0] = i - - data1 = EclKW("DATA1" , 100 , EclDataType.ECL_INT ) - data1.assign( i ) - - - data2 = EclKW("DATA2" , 100 , EclDataType.ECL_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)]) - with self.assertRaises(KeyError): - ecl_file.blockView("NO" , 1) - - with self.assertRaises(IndexError): - ecl_file.blockView("HEADER" , 100) - - with self.assertRaises(IndexError): - ecl_file.blockView("HEADER" , 1000) - - bv = ecl_file.blockView("HEADER" , -1) - - - for i in range(5): - view = ecl_file.blockView("HEADER" , i) - self.assertEqual( len(view) , 3) - header = view["HEADER"][0] - data1 = view["DATA1"][0] - data2 = view["DATA2"][0] - - self.assertEqual( header[0] , i ) - self.assertEqual( data1[99] , i ) - self.assertEqual( data2[99] , i*10 ) - - - for i in range(5): - view = ecl_file.blockView2("HEADER" , "DATA2", i ) - self.assertEqual( len(view) , 2) - header = view["HEADER"][0] - data1 = view["DATA1"][0] - - self.assertEqual( header[0] , i ) - self.assertEqual( data1[99] , i ) - - self.assertFalse( "DATA2" in view ) - - view = ecl_file.blockView2("HEADER" , None, 0 ) - self.assertEqual( len(view) , len(ecl_file)) - - view = ecl_file.blockView2(None , "DATA2", 0 ) - #self.assertEqual( len(view) , 2) - #self.assertTrue( "HEADER" in view ) - #self.assertTrue( "DATA1" in view ) - #self.assertFalse( "DATA2" in view ) diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_file_statoil.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_file_statoil.py deleted file mode 100644 index 63b6a628da..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_file_statoil.py +++ /dev/null @@ -1,277 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import datetime -import os.path -from unittest import skipIf - -from ecl.ecl import EclFile, FortIO, EclKW , openFortIO , openEclFile -from ecl.ecl import EclFileFlagEnum, EclFileEnum - -from ecl.test import ExtendedTestCase , TestAreaContext - - - - -class EclFileStatoilTest(ExtendedTestCase): - def setUp(self): - self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") - self.test_fmt_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.FUNRST") - - def assertFileType(self , filename , expected): - file_type , step , fmt_file = EclFile.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.write_index("index") - f1 = EclFile( 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 ) - 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) ) - - with self.assertRaises(KeyError): - rst_file.restart_get_kw("Missing" , dtime = datetime.date( 2004,1,1)) - - with self.assertRaises(IndexError): - rst_file.restart_get_kw("SWAT" , dtime = datetime.date( 1985 , 1 , 1)) - - - - def test_iget_named(self): - f = EclFile(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) - fortio = FortIO("ECLIPSE.UNRST", FortIO.WRITE_MODE) - rst_file.fwrite(fortio) - fortio.close() - rst_file.close() - self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file) - - - - - @skipIf(ExtendedTestCase.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.copy_file(self.test_file) - rst_file = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_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) - - swat1 = rst_file1["SWAT"][0] - swat2 = rst_file2["SWAT"][0] - swat2.assign(swat1) - - rst_file2.save_kw(swat2) - self.assertTrue(swat1.equal(swat2)) - rst_file1.close() - rst_file2.close() - - # Random failure .... - self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file) - - - - @skipIf(ExtendedTestCase.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.copy_file(self.test_fmt_file) - rst_file = EclFile("ECLIPSE.FUNRST", flags=EclFileFlagEnum.ECL_FILE_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) - - swat1 = rst_file1["SWAT"][0] - swat2 = rst_file2["SWAT"][0] - - swat2.assign(swat1) - rst_file2.save_kw(swat2) - self.assertTrue(swat1.equal(swat2)) - rst_file1.close() - rst_file2.close() - - # Random failure .... - self.assertFilesAreEqual("ECLIPSE.FUNRST", self.test_fmt_file) - - - def test_truncated(self): - with TestAreaContext("python/ecl_file/truncated") as work_area: - work_area.copy_file(self.test_file) - size = os.path.getsize("ECLIPSE.UNRST") - with open("ECLIPSE.UNRST" , "r+") as f: - f.truncate( size / 2 ) - - with self.assertRaises(IOError): - rst_file = EclFile("ECLIPSE.UNRST") - - with self.assertRaises(IOError): - rst_file = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE) - - def test_restart_view(self): - f = EclFile( self.test_file ) - with self.assertRaises(ValueError): - v = f.restartView( ) - - v = f.restartView( sim_days = 274 ) - v = f.restartView( sim_time = datetime.date( 2004,1,1) ) - v = f.restartView( report_step = 30 ) - v = f.restartView( seqnum_index = 30 ) - - - def test_index(self): - with TestAreaContext("python/ecl_file/truncated"): - f0 = EclFile( self.test_file ) - f0.write_index( "index" ) - - f1 = EclFile( self.test_file , index_filename = "index") - for kw0,kw1 in zip(f0,f1): - self.assertEqual(kw0,kw1) - - - def test_ix_case(self): - f = EclFile( self.createTestPath( "Statoil/ECLIPSE/ix/summary/Create_Region_Around_Well.SMSPEC")) - - # Keywords - self.assertTrue( "KEYWORDS" in f ) - keywords_loaded = list(f["KEYWORDS"][0]) - keywords_from_file = [ - 'TIME', 'YEARS', 'AAQR', 'AAQT', 'AAQP', 'AAQR', 'AAQT', - 'AAQP', 'AAQR', 'AAQT', 'AAQP', 'FPPW', 'FPPO', 'FPPG', 'FNQT', - 'FNQR', 'FEIP', 'FWPT', 'FWIT', 'FWIP', 'FWGR', 'FVPT', 'FVPR', - 'FVIT', 'FVIR', 'FPR', 'FOPT', 'FOIT', 'FOIR', 'FOIPL', - 'FOIPG', 'FOIP', 'FGPT', 'FGIT', 'FGIPL', 'FGIPG', 'FGIP', - 'FAQT', 'FAQR', 'FGOR', 'FWCT', 'FGSR', 'FGIR', 'FGPR', 'FWIR', - 'FWPR', 'FOPR', 'MEMORYTS', 'NAIMFRAC', 'TCPUDAY', 'TCPUTS', - 'NBAKFL', 'NNUMST', 'NNUMFL', 'NEWTFL', 'MSUMNEWT', 'MSUMLINS', - 'MLINEARS', 'NLINEARS', 'NEWTON', 'ELAPSED', 'TCPU', - 'TIMESTEP', 'GOPR', 'GOPR', 'GOPR', 'GWPR', 'GWPR', 'GWPR', - 'GWIR', 'GWIR', 'GWIR', 'GGPR', 'GGPR', 'GGPR', 'GWCT', 'GWCT', - 'GWCT', 'GGOR', 'GGOR', 'GGOR', 'GGIR', 'GGIR', 'GGIR', 'GGIT', - 'GGIT', 'GGIT', 'GGPT', 'GGPT', 'GGPT', 'GOIR', 'GOIR', 'GOIR', - 'GOIT', 'GOIT', 'GOIT', 'GOPT', 'GOPT', 'GOPT', 'GVIR', 'GVIR', - 'GVIR', 'GVIT', 'GVIT', 'GVIT', 'GVPR', 'GVPR', 'GVPR', 'GVPT', - 'GVPT', 'GVPT', 'GWGR', 'GWGR', 'GWGR', 'GWIT', 'GWIT', 'GWIT', - 'GWPT', 'GWPT', 'GWPT', 'WOPR', 'WOPR', 'WOPR', 'WOPR', 'WOPR', - 'WOPR', 'WWPR', 'WWPR', 'WWPR', 'WWPR', 'WWPR', 'WWPR', 'WWIR', - 'WWIR', 'WWIR', 'WWIR', 'WWIR', 'WWIR', 'WGPR', 'WGPR', 'WGPR', - 'WGPR', 'WGPR', 'WGPR', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', - 'WWCT', 'WMCTL', 'WMCTL', 'WMCTL', 'WMCTL', 'WMCTL', 'WMCTL', - 'WGOR', 'WGOR', 'WGOR', 'WGOR', 'WGOR', 'WGOR', 'WAPI', 'WAPI', - 'WAPI', 'WAPI', 'WAPI', 'WAPI', 'WBHP', 'WBHP', 'WBHP', 'WBHP', - 'WBHP', 'WBHP', 'WGIR', 'WGIR', 'WGIR', 'WGIR', 'WGIR', 'WGIR', - 'WGIT', 'WGIT', 'WGIT', 'WGIT', 'WGIT', 'WGIT', 'WGPT', 'WGPT', - 'WGPT', 'WGPT', 'WGPT', 'WGPT', 'WOIR', 'WOIR', 'WOIR', 'WOIR', - 'WOIR', 'WOIR', 'WOIT', 'WOIT', 'WOIT', 'WOIT', 'WOIT', 'WOIT', - 'WOPT', 'WOPT', 'WOPT', 'WOPT', 'WOPT', 'WOPT', 'WPIG', 'WPIG', - 'WPIG', 'WPIG', 'WPIG', 'WPIG', 'WPIO', 'WPIO', 'WPIO', 'WPIO', - 'WPIO', 'WPIO', 'WPIW', 'WPIW', 'WPIW', 'WPIW', 'WPIW', 'WPIW', - 'WTHP', 'WTHP', 'WTHP', 'WTHP', 'WTHP', 'WTHP', 'WVIR', 'WVIR', - 'WVIR', 'WVIR', 'WVIR', 'WVIR', 'WVIT', 'WVIT', 'WVIT', 'WVIT', - 'WVIT', 'WVIT', 'WVPR', 'WVPR', 'WVPR', 'WVPR', 'WVPR', 'WVPR', - 'WVPT', 'WVPT', 'WVPT', 'WVPT', 'WVPT', 'WVPT', 'WWGR', 'WWGR', - 'WWGR', 'WWGR', 'WWGR', 'WWGR', 'WWIT', 'WWIT', 'WWIT', 'WWIT', - 'WWIT', 'WWIT', 'WWPT', 'WWPT', 'WWPT', 'WWPT', 'WWPT', 'WWPT', - 'WBHT', 'WBHT', 'WBHT', 'WBHT', 'WBHT', 'WBHT', 'WBP', 'WBP', - 'WBP', 'WBP', 'WBP', 'WBP', 'WWCT', 'WWCT', 'WWCT', 'WWCT', - 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', - 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', - 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT', 'WWCT' - ] - - padd = lambda str_len : (lambda s : s + (" " * (max(0, str_len-len(s))))) - self.assertEqual(map(padd(8), keywords_from_file), keywords_loaded) - - # Names - self.assertTrue( "NAMES" in f ) - names_loaded = list(f["NAMES"][0]) - names_from_file = [ - '', '', 'AQFR_1', 'AQFR_1', 'AQFR_1', 'AQFR_2', 'AQFR_2', - 'AQFR_2', 'AQFR_3', 'AQFR_3', 'AQFR_3', 'FIELD', 'FIELD', - 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', - 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', - 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', - 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', - 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', - 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', - 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', 'FIELD', - 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', - 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', - 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', - 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', - 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', - 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', - 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', 'TWO', 'FIELD', 'ONE', - 'TWO', 'FIELD', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', - 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', - 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', - 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', - 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', - 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', - 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', - 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', - 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', - 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', - 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', - 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', - 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', - 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', - 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', - 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', - 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', - 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', - 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', - 'GI', 'I2', 'I4', 'I6', 'I8', 'HWELL_PROD', 'GI', 'I2', 'I4', - 'I6', 'I8', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', - ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', - ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', - ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', - ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', - ':+:+:+:+', ':+:+:+:+', ':+:+:+:+', ':+:+:+:+' - ] - - self.assertEqual(map(padd(10), names_from_file), names_loaded) diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_init_file.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_init_file.py deleted file mode 100644 index 3792354d54..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_init_file.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'test_ecl_init_file.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -from ecl.test import ExtendedTestCase -from ecl.ecl import (Ecl3DKW, EclKW, EclInitFile, EclFile, FortIO, - EclFileFlagEnum, EclGrid) - -class InitFileTest(ExtendedTestCase): - - - def setUp(self): - self.grid_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") - self.init_file = self.createTestPath("Statoil/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/ThirdParty/Ert/python/tests/ecl/test_ecl_kw.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_kw.py deleted file mode 100644 index f88f5e4c91..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_kw.py +++ /dev/null @@ -1,475 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'test_kw.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os -import random -import numpy -import warnings - -from ecl.ecl import (EclKW, EclDataType, EclTypeEnum, EclFile, FortIO, - EclFileFlagEnum, openFortIO) - -from ecl.test import ExtendedTestCase, TestAreaContext - - -def copy_long(): - src = EclKW("NAME", 100, EclDataType.ECL_FLOAT) - copy = src.sub_copy(0, 2000) - - -def copy_offset(): - src = EclKW("NAME", 100, EclDataType.ECL_FLOAT) - copy = src.sub_copy(200, 100) - - -class KWTest(ExtendedTestCase): - - def test_name(self): - kw = EclKW('TEST', 3, EclDataType.ECL_INT) - self.assertEqual(kw.name, 'TEST') - self.assertIn('TEST', repr(kw)) - kw.name = 'SCHMEST' - self.assertEqual(kw.name, 'SCHMEST') - self.assertIn('SCHMEST', repr(kw)) - - def test_min_max(self): - kw = EclKW("TEST", 3, EclDataType.ECL_INT) - kw[0] = 10 - kw[1] = 5 - kw[2] = 0 - - self.assertEqual(10, kw.getMax()) - self.assertEqual(0 , kw.getMin()) - self.assertEqual((0,10) , kw.getMinMax()) - - - def test_deprecated_datatypes(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - kw = EclKW("Test", 10, EclTypeEnum.ECL_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) - self.assertTrue(len(w) == 0) - - self.assertEqual(EclTypeEnum.ECL_INT_TYPE, kw.type) - - self.assertTrue(len(w) > 0) - self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) - - def kw_test(self, data_type, data, fmt): - name1 = "file1.txt" - name2 = "file2.txt" - kw = EclKW("TEST", len(data), data_type) - i = 0 - for d in data: - kw[i] = d - i += 1 - - file1 = open(name1, "w") - kw.fprintf_data(file1, fmt) - file1.close() - - file2 = open(name2, "w") - for d in data: - file2.write(fmt % d) - file2.close() - self.assertFilesAreEqual(name1, name2) - self.assertEqual(kw.data_type, data_type) - - def test_create(self): - with self.assertRaises(ValueError): - EclKW("ToGodDamnLong", 100, EclDataType.ECL_CHAR) - - def test_sum(self): - for ecl_type in [EclDataType.ECL_CHAR, EclDataType.ECL_STRING(42)]: - kw_string = EclKW("STRING", 100, ecl_type) - with self.assertRaises(ValueError): - kw_string.sum() - - kw_int = EclKW("INT", 4, EclDataType.ECL_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[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[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[0] = False - kw_b[1] = True - kw_b[2] = False - kw_b[3] = True - 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") - self.kw_test(EclDataType.ECL_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") - self.kw_test(EclDataType.ECL_BOOL, [True, True, True, False, True], "%4d\n") - self.kw_test(EclDataType.ECL_CHAR, ["1", "22", "4444", "666666", "88888888"], "%-8s\n") - - for str_len in range(1000): - self.kw_test(EclDataType.ECL_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"): - - data = [random.random() for i in range(10000)] - - kw = EclKW("TEST", len(data), EclDataType.ECL_DOUBLE) - i = 0 - for d in data: - kw[i] = d - i += 1 - - pfx = 'EclKW(' - self.assertEqual(pfx, repr(kw)[:len(pfx)]) - - fortio = FortIO("ECL_KW_TEST", FortIO.WRITE_MODE) - kw.fwrite(fortio) - fortio.close() - - fortio = FortIO("ECL_KW_TEST") - - kw2 = EclKW.fread(fortio) - - self.assertTrue(kw.equal(kw2)) - - ecl_file = EclFile("ECL_KW_TEST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE) - kw3 = ecl_file["TEST"][0] - self.assertTrue(kw.equal(kw3)) - ecl_file.save_kw(kw3) - ecl_file.close() - - fortio = FortIO("ECL_KW_TEST", FortIO.READ_AND_WRITE_MODE) - kw4 = EclKW.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] - self.assertTrue(kw.equal(kw5)) - - - - def test_fprintf_data(self): - with TestAreaContext("kw_no_header"): - kw = EclKW("REGIONS", 10, EclDataType.ECL_INT) - for i in range(len(kw)): - kw[i] = i - - fileH = open("test", "w") - kw.fprintf_data(fileH) - fileH.close() - - fileH = open("test", "r") - data = [] - for line in fileH.readlines(): - tmp = line.split() - for elm in tmp: - data.append(int(elm)) - - for (v1,v2) in zip(data,kw): - self.assertEqual(v1,v2) - - - def test_sliced_set(self): - kw = EclKW("REGIONS", 10, EclDataType.ECL_INT) - kw.assign(99) - kw[0:5] = 66 - self.assertEqual(kw[0], 66) - self.assertEqual(kw[4], 66) - self.assertEqual(kw[5], 99) - - - def test_long_name(self): - with self.assertRaises(ValueError): - EclKW("LONGLONGNAME", 10, EclDataType.ECL_INT) - - kw = EclKW("REGIONS", 10, EclDataType.ECL_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) - ]: - kw = EclKW("NAME", 10, ecl_type) - with self.assertRaises(TypeError): - abs_kw = abs(kw) - - kw = EclKW("NAME", 10, EclDataType.ECL_INT) - for i in range(len(kw)): - kw[i] = -i - - abs_kw = abs(kw) - for i in range(len(kw)): - self.assertEqual(kw[i], -i) - self.assertEqual(abs_kw[i], i) - - - def test_fmt(self): - kw1 = EclKW("NAME1", 100, EclDataType.ECL_INT) - kw2 = EclKW("NAME2", 100, EclDataType.ECL_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 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) - - self.assertTrue(kw1 == kw1b) - self.assertTrue(kw2 == kw2b) - - f = EclFile("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) - - - with self.assertRaises(IndexError): - EclKW.firstDifferent(kw1, kw2, offset=100) - - with self.assertRaises(ValueError): - EclKW.firstDifferent(kw1, kw3) - - with self.assertRaises(TypeError): - EclKW.firstDifferent(kw1, kw4) - - - with self.assertRaises(IndexError): - kw1.firstDifferent(kw2, offset=100) - - with self.assertRaises(ValueError): - kw1.firstDifferent(kw3) - - with self.assertRaises(TypeError): - kw1.firstDifferent(kw4) - - - kw1.assign(1) - kw2.assign(1) - - self.assertEqual(kw1.firstDifferent(kw2), len(kw1)) - - kw1[0] = 100 - self.assertEqual(kw1.firstDifferent(kw2), 0) - self.assertEqual(kw1.firstDifferent(kw2, offset=1), len(kw1)) - kw1[10] = 100 - self.assertEqual(kw1.firstDifferent(kw2, offset=1), 10) - - - kw4.assign(1.0) - kw5.assign(1.0) - self.assertEqual(kw4.firstDifferent(kw5), len(kw4)) - - kw4[10] *= 1.0001 - self.assertEqual(kw4.firstDifferent(kw5), 10) - - self.assertEqual(kw4.firstDifferent(kw5, epsilon=1.0), len(kw4)) - 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) - - - shift = 0.0001 - value = 1000 - - abs_diff = shift - rel_diff = shift / (shift + 2* value) - kw1.assign(value) - kw2.assign(value + shift) - - - self.assertTrue( kw1.equal_numeric(kw2, abs_epsilon=abs_diff * 1.1, rel_epsilon=rel_diff * 1.1)) - self.assertFalse(kw1.equal_numeric(kw2, abs_epsilon=abs_diff * 1.1, rel_epsilon=rel_diff * 0.9)) - self.assertFalse(kw1.equal_numeric(kw2, abs_epsilon=abs_diff * 0.9, rel_epsilon=rel_diff * 1.1)) - self.assertTrue( kw1.equal_numeric(kw2, abs_epsilon=0, rel_epsilon=rel_diff * 1.1)) - self.assertTrue( kw1.equal_numeric(kw2, abs_epsilon=abs_diff * 1.1, rel_epsilon=0)) - - def test_mul(self): - kw1 = EclKW("Name1", 10, EclDataType.ECL_INT) - kw1.assign(10) - - kw2 = EclKW("Name1", 10, EclDataType.ECL_INT) - kw2.assign(2) - - kw3 = kw1 * kw2 - kw4 = kw1 + kw2 - self.assertEqual(len(kw3), len(kw1)) - self.assertEqual(len(kw4), len(kw1)) - for v in kw3: - self.assertEqual(v, 20) - - for v in kw4: - self.assertEqual(v, 12) - - - def test_numpy(self): - kw1 = EclKW("DOUBLE", 10, EclDataType.ECL_DOUBLE) - - view = kw1.numpyView() - copy = kw1.numpyCopy() - - self.assertTrue(copy[ 0 ] == kw1[ 0 ]) - self.assertTrue(view[ 0 ] == kw1[ 0 ]) - - kw1[ 0 ] += 1 - 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)]: - kw2 = EclKW("TEST_KW", 10, ecl_type) - with self.assertRaises(ValueError): - kw2.numpyView() - - def test_slice(self): - N = 100 - kw = EclKW("KW", N, EclDataType.ECL_INT) - for i in range(len(kw)): - kw[i] = i - - even = kw[0:len(kw):2] - odd = kw[1:len(kw):2] - - self.assertEqual(len(even), N/2) - self.assertEqual(len(odd) , N/2) - - for i in range(len(even)): - self.assertEqual(even[i], 2*i) - self.assertEqual(odd[i], 2*i + 1) - - - def test_resize(self): - N = 4 - kw = EclKW("KW", N, EclDataType.ECL_INT) - for i in range(N): - kw[i] = i - - kw.resize(2*N) - self.assertEqual(len(kw), 2*N) - for i in range(N): - self.assertEqual(kw[i], i) - - kw.resize(N/2) - self.assertEqual(len(kw), N/2) - for i in range(N/2): - self.assertEqual(kw[i], i) - - - def test_typename(self): - kw = EclKW("KW", 100, EclDataType.ECL_INT) - - self.assertEqual(kw.typeName(), "INTE") - - def test_string_alloc(self): - kw = EclKW("KW", 10, EclDataType.ECL_STRING(30)) - - for i in range(10): - kw[i] = str(i)*30 - - for i in range(10): - self.assertEqual(str(i)*30, kw[i]) - - 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)) - for i in range(10): - kw[i] = str(i)*str_len - - file_name = "ecl_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) - - 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)) - for i in range(10): - kw[i] = str(i)*str_len - - file_name = "ecl_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) - - self.assertEqual(kw, loaded_kw) - - - def test_string_padding(self): - kw = EclKW("TEST_KW", 1, EclDataType.ECL_STRING(4)) - kw[0] = "AB" - self.assertEqual(kw[0], "AB ") - - kw = EclKW("TEST_KW", 1, EclDataType.ECL_CHAR) - kw[0] = "ABCD" - self.assertEqual(kw[0], "ABCD ") diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_kw_statoil.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_kw_statoil.py deleted file mode 100644 index 21d6b63c40..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_kw_statoil.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'test_kw.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os -import random -from ecl.ecl import EclKW, EclDataType, EclFile, FortIO, EclFileFlagEnum - -from ecl.test import ExtendedTestCase , TestAreaContext - - -def copy_long(): - src = EclKW("NAME", 100, EclDataType.ECL_FLOAT) - copy = src.sub_copy(0, 2000) - - -def copy_offset(): - src = EclKW("NAME", 100, EclDataType.ECL_FLOAT) - copy = src.sub_copy(200, 100) - - -class KWTest(ExtendedTestCase): - def test_fortio_size( self ): - unrst_file_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") - unrst_file = EclFile(unrst_file_path) - size = 0 - for kw in unrst_file: - size += kw.fortIOSize() - - stat = os.stat(unrst_file_path) - self.assertTrue(size == stat.st_size) - - - - - def test_sub_copy(self): - unrst_file_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") - unrst_file = EclFile(unrst_file_path) - swat = unrst_file["SWAT"][0] - - swat1 = swat.sub_copy(0, -1) - swat2 = swat.sub_copy(0, len(swat)) - - self.assertTrue(swat.equal(swat1)) - self.assertTrue(swat.equal(swat2)) - - swat3 = swat.sub_copy(20000, 100, new_header="swat") - self.assertTrue(swat3.getName() == "swat") - self.assertTrue(len(swat3) == 100) - equal = True - for i in range(len(swat3)): - if swat3[i] != swat[i + 20000]: - equal = False - self.assertTrue(equal) - - self.assertRaises(IndexError, copy_long) - self.assertRaises(IndexError, copy_offset) - - - def test_equal(self): - kw1 = EclKW("TEST", 3, EclDataType.ECL_CHAR) - kw1[0] = "Test1" - kw1[1] = "Test13" - kw1[2] = "Test15" - - kw2 = EclKW("TEST", 3, EclDataType.ECL_CHAR) - kw2[0] = "Test1" - kw2[1] = "Test13" - kw2[2] = "Test15" - - self.assertTrue(kw1.equal(kw2)) - self.assertTrue(kw1.equal_numeric(kw2)) - - kw2[2] = "Test15X" - self.assertFalse(kw1.equal(kw2)) - self.assertFalse(kw1.equal_numeric(kw2)) - - unrst_file_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") - unrst_file = EclFile(unrst_file_path) - kw1 = unrst_file["PRESSURE"][0] - kw2 = kw1.deep_copy() - - self.assertTrue(kw1.equal(kw2)) - self.assertTrue(kw1.equal_numeric(kw2)) - - kw2 *= 1.00001 - self.assertFalse(kw1.equal(kw2)) - self.assertFalse(kw1.equal_numeric(kw2, epsilon=1e-8)) - self.assertTrue(kw1.equal_numeric(kw2, epsilon=1e-2)) - - kw1 = unrst_file["ICON"][10] - kw2 = kw1.deep_copy() - self.assertTrue(kw1.equal(kw2)) - self.assertTrue(kw1.equal_numeric(kw2)) - - kw1[-1] += 1 - self.assertFalse(kw1.equal(kw2)) - self.assertFalse(kw1.equal_numeric(kw2)) - - diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_restart_file.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_restart_file.py deleted file mode 100644 index e2779e6d5e..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_restart_file.py +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'test_ecl_init_file.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import datetime - -from ecl.test import ExtendedTestCase -from ecl.ecl import Ecl3DKW , EclKW, EclRestartFile , EclFile, FortIO, EclFileFlagEnum , EclGrid - -class RestartFileTest(ExtendedTestCase): - def setUp(self): - self.grid_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") - self.unrst_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") - self.xrst_file0 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0000") - self.xrst_file10 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0010") - self.xrst_file20 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0020") - - - def test_load(self): - g = EclGrid( self.grid_file ) - f = EclRestartFile( g , self.unrst_file ) - - head = f["INTEHEAD"][0] - self.assertTrue( isinstance( head , EclKW )) - - swat = f["SWAT"][0] - self.assertTrue( isinstance( swat , Ecl3DKW )) - - pressure = f["PRESSURE"][0] - self.assertTrue( isinstance( pressure , Ecl3DKW )) - - - def test_type(self): - g = EclGrid( self.grid_file ) - with self.assertRaises(ValueError): - f = EclRestartFile( 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 ) - - self.assertTrue( f_unrst.unified() ) - self.assertFalse( f_x0.unified() ) - self.assertFalse( f_x10.unified() ) - self.assertFalse( f_x20.unified() ) - - self.assertEqual( [(10 , datetime.datetime( 2000 , 10 , 1 , 0 , 0 , 0 ) , 274.0)] , f_x10.timeList()) - - unrst_timeList = f_unrst.timeList() - self.assertEqual( len(unrst_timeList) , 63 ) - self.assertEqual( (62 , datetime.datetime( 2004 , 12 , 31 , 0 , 0 , 0 ) , 1826.0) , unrst_timeList[62]); - diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_sum.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_sum.py deleted file mode 100644 index f729589909..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_sum.py +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'test_ecl_sum.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import datetime -import os.path - -from cwrap import CFILE -from ecl.ecl import EclSum, EclSumKeyWordVector, EclFile -from ecl.ecl import FortIO, openFortIO, openEclFile, EclKW -from ecl.test import ExtendedTestCase, TestAreaContext - - -class EclSumTest(ExtendedTestCase): - - - def setUp(self): - self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") - self.ecl_sum = EclSum(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) - 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) - 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) - 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*") - - with self.assertRaises(KeyError): - ecl_sum_vector.addKeyword("MISSING") - - dtime = datetime.datetime(2002, 1, 1, 0, 0, 0) - with TestAreaContext("EclSum/csv_dump"): - test_file_name = self.createTestPath("dump.csv") - outputH = open(test_file_name, "w") - self.ecl_sum.dumpCSVLine(dtime, ecl_sum_vector, outputH) - assert os.path.isfile(test_file_name) - - - def test_truncated_smspec(self): - with TestAreaContext("EclSum/truncated_smspec") as ta: - ta.copy_file(self.test_file) - ta.copy_file(self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) - - file_size = os.path.getsize("ECLIPSE.SMSPEC") - with open("ECLIPSE.SMSPEC","r+") as f: - f.truncate(file_size / 2) - - with self.assertRaises(IOError): - EclSum("ECLIPSE") - - - def test_truncated_data(self): - with TestAreaContext("EclSum/truncated_data") as ta: - ta.copy_file(self.test_file) - ta.copy_file(self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) - - - file_size = os.path.getsize("ECLIPSE.UNSMRY") - with open("ECLIPSE.UNSMRY","r+") as f: - f.truncate(file_size / 2) - - with self.assertRaises(IOError): - EclSum("ECLIPSE") - - - def test_missing_smspec_keyword(self): - with TestAreaContext("EclSum/truncated_data") as ta: - ta.copy_file(self.test_file) - ta.copy_file(self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) - - with openEclFile("ECLIPSE.SMSPEC") as f: - kw_list = [] - for kw in f: - kw_list.append(EclKW.copy(kw)) - - with openFortIO("ECLIPSE.SMSPEC", mode=FortIO.WRITE_MODE) as f: - for kw in kw_list: - if kw.getName() == "KEYWORDS": - continue - kw.fwrite(f) - - with self.assertRaises(IOError): - EclSum("ECLIPSE") - - - def test_missing_unsmry_keyword(self): - with TestAreaContext("EclSum/truncated_data") as ta: - ta.copy_file(self.test_file) - ta.copy_file(self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) - - with openEclFile("ECLIPSE.UNSMRY") as f: - kw_list = [] - for kw in f: - kw_list.append(EclKW.copy(kw)) - - - with openFortIO("ECLIPSE.UNSMRY", mode=FortIO.WRITE_MODE) as f: - c = 0 - for kw in kw_list: - if kw.getName() == "PARAMS": - if c % 5 == 0: - continue - c += 1 - kw.fwrite(f) - - with self.assertRaises(IOError): - EclSum("ECLIPSE") - - - def test_labscale(self): - case = self.createTestPath("Statoil/ECLIPSE/LabScale/HDMODEL") - sum = EclSum(case) - 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(), 0.8125) diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_sum_tstep.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_sum_tstep.py deleted file mode 100644 index 8a15241a09..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_sum_tstep.py +++ /dev/null @@ -1,41 +0,0 @@ -from datetime import datetime -import random -from ecl.ecl import EclSumTStep, EclSum -from ecl.test import ExtendedTestCase - - -class EclSumTStepTest(ExtendedTestCase): - - def test_creation(self): - ecl_sum = EclSum.writer("TEST", datetime(2010, 1, 1), 10, 10, 10) - ecl_sum.addVariable("FOPT") - ecl_sum.addVariable("FOPR") - - smspec = ecl_sum.cNamespace().get_smspec(ecl_sum) - - test_data = [(1, 0, 10), (1, 1, 20), (1, 2, 30), (2, 0, 40)] - - for report_step, mini_step, sim_days in test_data: - ecl_sum_tstep = EclSumTStep(report_step, mini_step, sim_days, smspec) - - self.assertEqual(ecl_sum_tstep.getSimDays(), sim_days) - self.assertEqual(ecl_sum_tstep.getReport(), report_step) - self.assertEqual(ecl_sum_tstep.getMiniStep(), mini_step) - - self.assertTrue("FOPT" in ecl_sum_tstep) - self.assertTrue("FOPR" in ecl_sum_tstep) - self.assertFalse("WWCT" in ecl_sum_tstep) - - random_float = random.random() - ecl_sum_tstep["FOPT"] = random_float - ecl_sum_tstep["FOPR"] = random_float + 1 - - self.assertAlmostEqual(random_float, ecl_sum_tstep["FOPT"], places=5) - self.assertAlmostEqual(random_float + 1, ecl_sum_tstep["FOPR"], places=5) - - with self.assertRaises(KeyError): - ecl_sum_tstep["FROPR"] = 2 - - with self.assertRaises(KeyError): - value = ecl_sum_tstep["FROPR"] - diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_sum_vector.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_sum_vector.py deleted file mode 100644 index a5bfebf7fb..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_sum_vector.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'test_ecl_sum_vector.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -try: - from unittest2 import skipIf -except ImportError: - from unittest import skipIf - -import warnings - -from ecl.ecl import EclSumVector, EclSum -from ecl.test import ExtendedTestCase - - -class EclSumVectorTest(ExtendedTestCase): - - - def setUp(self): - self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") - self.ecl_sum = EclSum(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) - assert 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 - self.assertEqual(63, len(t)) - self.assertEqual('BARSA', t.unit) - pfx = 'EclSumVector(key = ' - self.assertEqual(pfx, repr(t)[:len(pfx)]) diff --git a/ThirdParty/Ert/python/tests/ecl/test_ecl_type.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_type.py deleted file mode 100644 index 48da066718..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_type.py +++ /dev/null @@ -1,139 +0,0 @@ -from ecl.test import TestAreaContext, ExtendedTestCase - -from ecl.ecl import EclDataType, EclTypeEnum - -def get_const_size_types(): - return EclTypeEnum.enums()[:-1:] - -class EclDataTypeTest(ExtendedTestCase): - - # 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 = 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/ThirdParty/Ert/python/tests/ecl/test_ecl_util.py b/ThirdParty/Ert/python/tests/ecl/test_ecl_util.py deleted file mode 100644 index 497f52769c..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_ecl_util.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'sum_test.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.ecl import EclGrid , EclUtil, EclTypeEnum , EclFileEnum, EclPhaseEnum, EclUnitTypeEnum -from ecl.test import ExtendedTestCase - - -class EclUtilTest(ExtendedTestCase): - - def test_enums(self): - source_file_path = "lib/include/ert/ecl/ecl_util.h" - 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.h" - 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/ThirdParty/Ert/python/tests/ecl/test_fault_blocks.py b/ThirdParty/Ert/python/tests/ecl/test_fault_blocks.py deleted file mode 100644 index 9275c9a5dc..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_fault_blocks.py +++ /dev/null @@ -1,468 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'test_fault_blocks.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -from __future__ import print_function -from unittest import skipIf -import warnings - -from ecl.ecl import EclGrid, EclKW , EclRegion, EclDataType -from ecl.ecl.faults import FaultBlock, FaultBlockLayer, FaultBlockCell,FaultCollection -from ecl.geo import Polyline , CPolylineCollection -from ecl.test import ExtendedTestCase , TestAreaContext - - -class FaultBlockTest(ExtendedTestCase): - def setUp(self): - self.grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) ) - self.kw = EclKW( "FAULTBLK" , self.grid.getGlobalSize() , EclDataType.ECL_INT ) - self.kw.assign( 1 ) - - reg = EclRegion( self.grid , False ) - - for k in range(self.grid.getNZ()): - reg.clear( ) - reg.select_kslice( k , k ) - self.kw.assign( k , mask = reg ) - 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 ) - kw.assign( 0 ) - for j in range(1,4): - for i in range(1,4): - g = i + j*grid.getNX() - kw[g] = 1 - - layer = FaultBlockLayer( grid , 0 ) - layer.scanKeyword( kw ) - block = layer[1] - - self.assertEqual( (2.50 , 2.50) , block.getCentroid() ) - self.assertEqual( len(block) , 9) - self.assertEqual( layer , block.getParentLayer() ) - - def test_get_ijk(self): - with TestAreaContext("python/fault_block_layer/neighbour") as work_area: - with open("kw.grdecl","w") as fileH: - fileH.write("FAULTBLK \n") - fileH.write("1 1 1 0 0\n") - fileH.write("1 2 2 0 3\n") - fileH.write("4 2 2 3 3\n") - fileH.write("4 4 4 0 0\n") - fileH.write("4 4 4 0 5\n") - fileH.write("/\n") - - kw = EclKW.read_grdecl(open("kw.grdecl") , "FAULTBLK" , ecl_type = EclDataType.ECL_INT) - - grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) ) - layer = FaultBlockLayer( grid , 0 ) - layer.loadKeyword( kw ) - - block = layer[0,0] - self.assertEqual( block.getBlockID() , 1 ) - - block = layer[2,2] - self.assertEqual( block.getBlockID() , 2 ) - - with self.assertRaises(ValueError): - layer[3,3] - - with self.assertRaises(IndexError): - layer[5,5] - - - - def test_neighbours(self): - - with TestAreaContext("python/fault_block_layer/neighbour") as work_area: - with open("kw.grdecl","w") as fileH: - fileH.write("FAULTBLK \n") - fileH.write("1 1 1 0 0\n") - fileH.write("1 2 2 0 3\n") - fileH.write("4 2 2 3 3\n") - fileH.write("4 4 4 0 0\n") - fileH.write("4 4 4 0 5\n") - fileH.write("/\n") - - kw = EclKW.read_grdecl(open("kw.grdecl") , "FAULTBLK" , ecl_type = EclDataType.ECL_INT) - - grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) ) - layer = FaultBlockLayer( grid , 0 ) - - layer.loadKeyword( kw ) - block1 = layer.getBlock( 1 ) - block2 = layer.getBlock( 2 ) - block3 = layer.getBlock( 3 ) - block4 = layer.getBlock( 4 ) - block5 = layer.getBlock( 5 ) - self.assertEqual( block1.getParentLayer() , layer ) - - #Expected: 1 -> {2,4}, 2 -> {1,3,4}, 3 -> {2}, 4 -> {1,2}, 5-> {} - - neighbours = block1.getNeighbours() - self.assertEqual( len(neighbours) , 2) - self.assertTrue( block2 in neighbours ) - self.assertTrue( block4 in neighbours ) - - neighbours = block2.getNeighbours() - self.assertEqual( len(neighbours) , 3) - self.assertTrue( block1 in neighbours ) - self.assertTrue( block3 in neighbours ) - self.assertTrue( block4 in neighbours ) - - neighbours = block3.getNeighbours() - self.assertEqual( len(neighbours) , 1) - self.assertTrue( block2 in neighbours ) - - neighbours = block4.getNeighbours() - self.assertEqual( len(neighbours) , 2) - self.assertTrue( block1 in neighbours ) - self.assertTrue( block2 in neighbours ) - - neighbours = block5.getNeighbours() - self.assertEqual( len(neighbours) , 0) - - - - - def test_neighbours2(self): - nx = 8 - ny = 8 - nz = 1 - grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) - layer = FaultBlockLayer( grid , 0 ) - with TestAreaContext("python/FaultBlocks/neighbours"): - with open("faultblock.grdecl","w") as fileH: - fileH.write("FAULTBLK \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("3 3 3 3 2 2 2 2 \n") - fileH.write("3 3 3 3 2 2 2 2 \n") - fileH.write("3 3 3 3 2 2 2 2 \n") - fileH.write("3 3 3 3 2 2 2 2 \n") - fileH.write("/\n") - - kw = EclKW.read_grdecl(open("faultblock.grdecl") , "FAULTBLK" , ecl_type = EclDataType.ECL_INT) - with open("faults.grdecl" , "w") as f: - f.write("FAULTS\n") - f.write("\'FY\' 1 4 4 4 1 1 'Y' /\n") - f.write("\'FX\' 4 4 1 8 1 1 'X' /\n") - f.write("/") - - faults = FaultCollection( grid , "faults.grdecl") - layer.loadKeyword( kw ) - b1 = layer.getBlock( 1 ) - b2 = layer.getBlock( 2 ) - b3 = layer.getBlock( 3 ) - - nb = b1.getNeighbours() - self.assertTrue( b2 in nb ) - self.assertTrue( b3 in nb ) - - polylines1 = CPolylineCollection() - p1 = polylines1.createPolyline(name="P1") - p1.addPoint(4,0) - p1.addPoint(4,4) - p1.addPoint(4,8) - nb = b1.getNeighbours( polylines = polylines1 ) - self.assertFalse( b2 in nb ) - self.assertTrue( b3 in nb ) - - - polylines2 = CPolylineCollection() - p1 = polylines2.createPolyline(name="P2") - p1.addPoint(0,4) - p1.addPoint(4,4) - nb = b1.getNeighbours( polylines = polylines2 ) - self.assertTrue( b2 in nb ) - self.assertFalse( b3 in nb ) - - - - layer.addFaultBarrier( faults["FY"] ) - nb = b1.getNeighbours() - self.assertTrue( b2 in nb ) - self.assertFalse( b3 in nb ) - - layer.addFaultBarrier( faults["FX"] ) - nb = b1.getNeighbours() - self.assertEqual( len(nb) , 0 ) - - - def test_neighbours3(self): - nx = 8 - ny = 8 - nz = 1 - grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) - layer = FaultBlockLayer( grid , 0 ) - with TestAreaContext("python/FaultBlocks/neighbours"): - with open("faultblock.grdecl","w") as fileH: - fileH.write("FAULTBLK \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 1 1 1 1 2 2 2 \n") - fileH.write("1 1 1 1 1 2 2 2 \n") - fileH.write("1 1 1 1 1 2 2 2 \n") - fileH.write("1 1 1 1 1 2 2 2 \n") - fileH.write("/\n") - - kw = EclKW.read_grdecl(open("faultblock.grdecl") , "FAULTBLK" , ecl_type = EclDataType.ECL_INT) - with open("faults.grdecl" , "w") as f: - f.write("FAULTS\n") - f.write("\'FX\' 4 4 1 4 1 1 'X' /\n") - f.write("\'FX\' 5 5 5 8 1 1 'X' /\n") - f.write("/") - - faults = FaultCollection( grid , "faults.grdecl") - layer.loadKeyword( kw ) - b1 = layer.getBlock( 1 ) - b2 = layer.getBlock( 2 ) - - nb = b1.getNeighbours() - self.assertTrue( b2 in nb ) - - layer.addFaultBarrier( faults["FX"] , link_segments = False) - nb = b1.getNeighbours() - 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 ) - kw.assign( 0 ) - for j in range(1,4): - for i in range(1,4): - g = i + j*grid.getNX() - kw[g] = 1 - - layer = FaultBlockLayer( grid , 0 ) - #with self.assertRaises: - # layer.getEdgePolygon( ) - - - - def test_fault_block_layer(self): - with self.assertRaises(ValueError): - layer = FaultBlockLayer( self.grid , -1 ) - - with self.assertRaises(ValueError): - layer = FaultBlockLayer( self.grid , self.grid.getGlobalSize() ) - - layer = FaultBlockLayer( self.grid , 1 ) - self.assertEqual( 1 , layer.getK() ) - - kw = EclKW( "FAULTBLK" , self.grid.getGlobalSize() , EclDataType.ECL_FLOAT ) - with self.assertRaises(ValueError): - layer.scanKeyword( kw ) - - layer.scanKeyword( self.kw ) - self.assertEqual( 2 , len(layer) ) - - with self.assertRaises(TypeError): - ls = layer["JJ"] - - l = [] - for blk in layer: - l.append( blk ) - self.assertEqual( len(l) , 2 ) - - l0 = layer[0] - l1 = layer[1] - self.assertTrue( isinstance(l1 , FaultBlock )) - l0.getCentroid() - l1.getBlockID() - - with self.assertRaises(IndexError): - l2 = layer[2] - - - self.assertEqual( True , 1 in layer) - self.assertEqual( True , 2 in layer) - self.assertEqual( False , 77 in layer) - self.assertEqual( False , 177 in layer) - - l1 = layer.getBlock( 1 ) - self.assertTrue( isinstance(l1 , FaultBlock )) - - with self.assertRaises(KeyError): - l =layer.getBlock(66) - - with self.assertRaises(KeyError): - layer.deleteBlock(66) - - layer.deleteBlock(2) - self.assertEqual( 1 , len(layer)) - blk = layer[0] - self.assertEqual( blk.getBlockID() , 1 ) - - with self.assertRaises(KeyError): - layer.addBlock(1) - - blk2 = layer.addBlock(2) - self.assertEqual( len(layer) , 2 ) - - blk3 = layer.addBlock() - self.assertEqual( len(layer) , 3 ) - - - layer.addBlock(100) - layer.addBlock(101) - layer.addBlock(102) - layer.addBlock(103) - - layer.deleteBlock(2) - blk1 = layer.getBlock( 103 ) - blk2 = layer[-1] - self.assertEqual( blk1.getBlockID() , blk2.getBlockID() ) - - fault_block = layer[0] - fault_block.assignToRegion( 2 ) - self.assertEqual( [2] , list(fault_block.getRegionList())) - - fault_block.assignToRegion( 2 ) - self.assertEqual( [2] , list(fault_block.getRegionList())) - - fault_block.assignToRegion( 3 ) - self.assertEqual( [2,3] , list(fault_block.getRegionList())) - - fault_block.assignToRegion( 1 ) - self.assertEqual( [1,2,3] , list(fault_block.getRegionList())) - - fault_block.assignToRegion( 2 ) - self.assertEqual( [1,2,3] , list(fault_block.getRegionList())) - - - def test_add_polyline_barrier1(self): - grid = EclGrid.createRectangular( (4,1,1) , (1,1,1) ) - layer = FaultBlockLayer( self.grid , 0 ) - polyline = Polyline( init_points = [ (1.99 , 0.001) , (2.01 , 0.99)]) - - points = [((1,0) , (2,0))] - - geo_layer = layer.getGeoLayer() - for p1,p2 in points: - self.assertTrue(geo_layer.cellContact( p1 , p2 )) - - layer.addPolylineBarrier( polyline ) - for p1,p2 in points: - print(p1,p2) - self.assertFalse(geo_layer.cellContact( p1 , p2 )) - - - - def test_add_polyline_barrier2(self): - grid = EclGrid.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) ]) - - points = [((0,0) , (0,1)), - ((2,0) , (2,1)), - ((4,0) , (4,1)), - ((6,0) , (6,1)), - ((8,0) , (8,1)), - # - ((8,1) , (9,1)), - ((8,3) , (9,3)), - ((8,5) , (9,5)), - ((8,7) , (9,7))] - - geo_layer = layer.getGeoLayer() - for p1,p2 in points: - self.assertTrue(geo_layer.cellContact( p1 , p2 )) - - layer.addPolylineBarrier( polyline ) - for p1,p2 in points: - print(p1,p2) - self.assertFalse(geo_layer.cellContact( p1 , p2 )) - - - - - - - def test_fault_block_layer_export(self): - layer = FaultBlockLayer( self.grid , 1 ) - kw1 = EclKW( "FAULTBLK" , self.grid.getGlobalSize() + 1 , EclDataType.ECL_INT ) - with self.assertRaises(ValueError): - layer.exportKeyword( kw1 ) - - kw2 = EclKW( "FAULTBLK" , self.grid.getGlobalSize() , EclDataType.ECL_FLOAT ) - with self.assertRaises(TypeError): - layer.exportKeyword(kw2) - - - def test_internal_blocks(self): - nx = 8 - ny = 8 - nz = 1 - grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) - layer = FaultBlockLayer( grid , 0 ) - with TestAreaContext("python/FaultBlocks/internal_blocks"): - with open("faultblock.grdecl","w") as fileH: - fileH.write("FAULTBLK \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 4 4 1 2 5 5 2 \n") - fileH.write("1 4 4 1 2 5 5 2 \n") - fileH.write("1 1 1 1 2 2 2 2 \n") - fileH.write("1 1 1 1 1 2 2 2 \n") - fileH.write("1 1 3 1 1 2 2 2 \n") - fileH.write("1 1 1 1 1 2 2 2 \n") - fileH.write("1 1 1 1 1 2 2 2 \n") - fileH.write("/\n") - - - kw = EclKW.read_grdecl(open("faultblock.grdecl") , "FAULTBLK" , ecl_type = EclDataType.ECL_INT) - with open("faults.grdecl" , "w") as f: - f.write("FAULTS\n") - f.write("\'FX\' 4 4 1 4 1 1 'X' /\n") - f.write("\'FX\' 5 5 4 4 1 1 'Y' /\n") - f.write("\'FX\' 5 5 5 8 1 1 'X' /\n") - f.write("/") - - faults = FaultCollection( grid , "faults.grdecl") - - layer.loadKeyword( kw ) - layer.addFaultBarrier( faults["FX"] ) - b1 = layer.getBlock( 1 ) - b2 = layer.getBlock( 2 ) - b3 = layer.getBlock( 3 ) - b4 = layer.getBlock( 4 ) - b5 = layer.getBlock( 5 ) - - - nb = b1.getNeighbours() - for b in nb: - print('Block:%d' % b.getBlockID()) - - self.assertTrue( len(nb) == 2 ) - self.assertTrue( b3 in nb ) - self.assertTrue( b4 in nb ) - - nb = b2.getNeighbours() - self.assertTrue( len(nb) == 1 ) - self.assertTrue( b5 in nb ) diff --git a/ThirdParty/Ert/python/tests/ecl/test_fault_blocks_statoil.py b/ThirdParty/Ert/python/tests/ecl/test_fault_blocks_statoil.py deleted file mode 100644 index 8be7f2fc0a..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_fault_blocks_statoil.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'test_fault_blocks.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -try: - from unittest2 import skipIf -except ImportError: - from unittest import skipIf - -from ecl.ecl import EclGrid, EclDataType , EclKW -from ecl.test import ExtendedTestCase -from ecl.ecl.faults import FaultBlock, FaultBlockLayer - -class FaultBlockTest(ExtendedTestCase): - def setUp(self): - self.grid = EclGrid( self.createTestPath("Statoil/ECLIPSE/Mariner/MARINER.EGRID")) - fileH = open( self.createTestPath("Statoil/ECLIPSE/Mariner/faultblock.grdecl") ) - self.kw = EclKW.read_grdecl( fileH , "FAULTBLK" , ecl_type = EclDataType.ECL_INT ) - - - - def test_load(self): - for k in range(self.grid.getNZ()): - faultBlocks = FaultBlockLayer(self.grid , k) - faultBlocks.scanKeyword( self.kw ) - for block in faultBlocks: - centroid = block.getCentroid() - diff --git a/ThirdParty/Ert/python/tests/ecl/test_faults.py b/ThirdParty/Ert/python/tests/ecl/test_faults.py deleted file mode 100644 index aa73ceae9f..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_faults.py +++ /dev/null @@ -1,796 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'test_faults.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from unittest import skipIf -import time -from ecl import util - -from ecl.ecl.faults import FaultCollection, Fault, FaultLine, FaultSegment,FaultBlockLayer -from ecl.ecl import EclGrid, EclKW, EclDataType -from ecl.test import ExtendedTestCase, TestAreaContext -from ecl.geo import Polyline , CPolyline - - -class FaultTest(ExtendedTestCase): - @classmethod - def setUpClass(cls): - cls.grid = EclGrid.createRectangular( (151,100,50) , (1,1,1)) - - def setUp(self): - self.faults1 = self.createTestPath("local/ECLIPSE/FAULTS/fault1.grdecl") - self.faults2 = self.createTestPath("local/ECLIPSE/FAULTS/fault2.grdecl") - - - def test_PolylineIJ(self): - nx = 10 - ny = 10 - nz = 10 - grid = EclGrid.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-") - f.addRecord(2 , 2 , 1 , 1 , 0,0 , "Y") - - pl = f.getIJPolyline( 0 ) - self.assertEqual(pl , [(0,0) , (2,0) , (2,2) , (3,2)]) - - - def test_empty_collection(self): - faults = FaultCollection() - self.assertEqual(0 , len(faults)) - - self.assertFalse( faults.hasFault("FX") ) - - with self.assertRaises(TypeError): - f = faults[ [] ] - - with self.assertRaises(KeyError): - f = faults["FX"] - - with self.assertRaises(IndexError): - f = faults[0] - - self.assertFalse( "NAME" in faults ) - - def test_collection_invalid_arg(self): - with self.assertRaises(ValueError): - faults = FaultCollection(self.faults1) - - with self.assertRaises(ValueError): - faults = FaultCollection(self.faults1 , self.faults2) - - - - def test_splitLine(self): - faults = FaultCollection(self.grid) - with self.assertRaises(ValueError): - # Not slash terminated - t = faults.splitLine("'F1' 149 149 29 29 1 43 'Y'") - - with self.assertRaises(ValueError): - # Not integer - t = faults.splitLine("'F1' 149 149 29 29 1 43X 'Y' /") - - with self.assertRaises(ValueError): - # Missing item - t = faults.splitLine("'F1' 149 29 29 1 43 'Y' /") - - with self.assertRaises(ValueError): - # Quote fuckup - t = faults.splitLine("'F1 149 149 29 29 1 43 'X' /") - - - def test_empty_fault( self ): - f = Fault(self.grid , "NAME") - self.assertEqual("NAME" , f.getName()) - - with self.assertRaises(Exception): - g = f["Key"] - - - def test_empty_faultLine(self): - fl = FaultLine(self.grid , 10) - self.assertEqual( 10 , fl.getK()) - self.assertEqual( 0 , len(fl) ) - - with self.assertRaises(TypeError): - f = fl[ "Test" ] - - with self.assertRaises(IndexError): - f = fl[0] - - - - def test_faultLine_center(self): - nx = 10 - ny = 10 - nz = 2 - grid = EclGrid.createRectangular( (nx,ny,nz) , (0.1,0.1,0.1)) - fl = FaultLine(grid , 0) - C1 = (nx + 1) * 5 + 3 - C2 = C1 + 2 - C3 = C2 + 2 - - s1 = FaultSegment( C1 , C2 ) - s2 = FaultSegment( C2 , C3 ) - - fl.tryAppend( s1 ) - fl.tryAppend( s2 ) - - self.assertEqual( len(fl) , 2 ) - self.assertEqual( fl.center() , (0.50 , 0.50) ) - - - - def test_faultLine(self): - fl = FaultLine(self.grid , 10) - S1 = FaultSegment(0 , 10) - S2 = FaultSegment(10 , 20) - fl.tryAppend( S1 ) - fl.tryAppend( S2 ) - fl.verify() - S3 = FaultSegment(20 , 30) - fl.tryAppend( S3 ) - fl.verify() - #--- - fl = FaultLine(self.grid , 10) - S1 = FaultSegment(0 , 10) - S2 = FaultSegment(20 , 10) - fl.tryAppend( S1 ) - self.assertTrue( fl.tryAppend( S2 ) ) - fl.verify() - #--- - fl = FaultLine(self.grid , 10) - S1 = FaultSegment(10 , 0) - S2 = FaultSegment(20 , 10) - fl.tryAppend( S1 ) - fl.tryAppend( S2 ) - fl.verify() - #--- - fl = FaultLine(self.grid , 10) - S1 = FaultSegment(10 , 0) - S2 = FaultSegment(10 , 20) - fl.tryAppend( S1 ) - fl.tryAppend( S2 ) - fl.verify() - - fl = FaultLine(self.grid , 10) - S1 = FaultSegment(10 , 0) - S2 = FaultSegment(10 , 20) - fl.tryAppend( S1 ) - fl.tryAppend( S2 ) - S3 = FaultSegment(40 , 30) - self.assertTrue( fl.tryAppend(S3) == False ) - self.assertEqual( len(fl) , 2 ) - - pl = fl.getPolyline( ) - self.assertIsInstance( pl , CPolyline ) - self.assertEqual( len(pl) , len(fl) + 1 ) - - S3 = FaultSegment(20 , 30) - fl.tryAppend( S3 ) - pl = fl.getPolyline( ) - self.assertIsInstance( pl , CPolyline ) - self.assertEqual( len(pl) , len(fl) + 1 ) - - - - - def test_load(self): - faults = FaultCollection(self.grid , self.faults1) - self.assertEqual( 3 , len(faults)) - faults.load( self.grid , self.faults2 ) - self.assertEqual( 7 , len(faults)) - fault1 = faults["F1"] - layer8 = fault1[8] - self.assertEqual( len(layer8) , 1 ) - - with self.assertRaises(IOError): - faults.load(self.grid , "No/this/does/not/exist") - - - def test_connect_faults(self): - grid = EclGrid.createRectangular( (100,100,10) , (1,1,1)) - - # Fault1 Fault4 - # | | - # | | - # | | - # | ------- Fault2 | - # | | - # | | - # - # -------- Fault3 - # - - fault1 = Fault(grid , "Fault1") - fault2 = Fault(grid , "Fault2") - fault3 = Fault(grid , "Fault3") - fault4 = Fault(grid , "Fault4") - - fault1.addRecord(1 , 1 , 10 , grid.getNY() - 1 , 0 , 0 , "X") - fault2.addRecord(5 , 10 , 15 , 15 , 0 , 0 , "Y") - fault3.addRecord(5 , 10 , 5 , 5 , 0 , 0 , "Y") - fault4.addRecord(20 , 20 , 10 , grid.getNY() - 1 , 0 , 0 , "X") - - - for other_fault in [fault2 , fault3,fault4]: - with self.assertRaises(ValueError): - fault1.extendToFault( other_fault ,0) - - with self.assertRaises(ValueError): - fault2.extendToFault( fault3 , 0) - - for other_fault in [fault1 , fault2,fault4]: - with self.assertRaises(ValueError): - fault3.extendToFault( other_fault ,0 ) - - for other_fault in [fault1 , fault2,fault3]: - with self.assertRaises(ValueError): - fault4.extendToFault( other_fault , 0) - - ext21 = fault2.extendToFault( fault1 , 0) - self.assertEqual(len(ext21) , 2) - p0 = ext21[0] - p1 = ext21[1] - self.assertEqual(p0 , (5 , 16)) - self.assertEqual(p1 , (2 , 16)) - - - ext24 = fault2.extendToFault( fault4,0 ) - self.assertEqual(len(ext24) , 2) - p0 = ext24[0] - p1 = ext24[1] - self.assertEqual(p0 , (11 , 16)) - self.assertEqual(p1 , (21 , 16)) - - - def test_intersect_intRays(self): - p1 = (0,0) - dir1 = (1,0) - p2 = (0,0) - dir2 = (0,1) - - line = Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - self.assertEqual( line , [] ) - - # Opposite direction - p3 = (-1,0) - dir3 = (-1,0) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p3,dir3)) - - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p3,dir3),(p1,dir1)) - - # Parallell with offset - p4 = (0,1) - dir4 = (1,0) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p4,dir4)) - - p5 = (0,1) - dir5 = (-1,0) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p5,dir5)) - - p6 = (1,1) - dir6 = (1,0) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p6,dir6)) - - p2 = (-1,0) - dir2 = (-1,0) - join = Fault.intersectFaultRays(( p2,dir1),(p1,dir2)) - self.assertEqual( join , [p2 , p1]) - - join = Fault.intersectFaultRays(( p1,dir3),(p3,dir1)) - self.assertEqual( join , [p1 , p3]) - - p2 = (1,0) - dir2 = (1,0) - join = Fault.intersectFaultRays(( p1,dir1),(p2,dir2)) - self.assertEqual( join , [p1 , p2]) - - # Orthogonal - p2 = (1,1) - dir2 = (0,1) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - - p2 = (0,1) - dir2 = (0,1) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - - p2 = (-1,0) - dir2 = (0,1) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - - p2 = (-1,1) - dir2 = (0,1) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - - p2 = (-1,1) - dir2 = (0,-1) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - - p2 = (3,-1) - dir2 = (0,-1) - with self.assertRaises(ValueError): - Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - - p2 = (1,-1) - dir2 = (0,1) - join = Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - self.assertEqual(join , [p1 , (1,0) , p2]) - - p2 = (1,1) - dir2 = (0,-1) - join = Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - self.assertEqual(join , [p1 , (1,0) , p2]) - - p2 = (0,3) - dir2 = (0,-1) - join = Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - self.assertEqual(join , [p1 , p2]) - - p2 = (3,0) - dir2 = (0,-1) - join = Fault.intersectFaultRays(( p1,dir1),(p2,dir2 )) - self.assertEqual(join , [p1 , p2]) - - - def test_join_faults(self): - grid = EclGrid.createRectangular( (100,100,10) , (1,1,1)) - - # Fault1 Fault4 - # | | - # | | - # | | - # | ------- Fault2 | - # | | - # | | - # - # -------- Fault3 - # - - fault1 = Fault(grid , "Fault1") - fault2 = Fault(grid , "Fault2") - fault3 = Fault(grid , "Fault3") - fault4 = Fault(grid , "Fault4") - - fault1.addRecord(1 , 1 , 10 , grid.getNY() - 1 , 0 , 0 , "X") - fault2.addRecord(5 , 10 , 15 , 15 , 0 , 0 , "Y") - fault3.addRecord(5 , 10 , 5 , 5 , 0 , 0 , "Y") - fault4.addRecord(20 , 20 , 10 , grid.getNY() - 1 , 0 , 0 , "X") - - rays = fault1.getEndRays(0) - self.assertEqual( rays[0] , [(2,10) , (0,-1)]) - self.assertEqual( rays[1] , [(2,100) , (0,1)]) - - extra = Fault.joinFaults( fault1 , fault3 , 0) - self.assertEqual( extra , [(2,10) , (2,6) , (5,6)] ) - - - def test_contact(self): - grid = EclGrid.createRectangular( (100,100,10) , (1,1,1)) - - # Fault1 Fault4 - # | | - # | | - # | | - # | ----------------------+-- Fault2 - # | | - # | | - # - # -------- Fault3 - # - - fault1 = Fault(grid , "Fault1") - fault2 = Fault(grid , "Fault2") - fault3 = Fault(grid , "Fault3") - fault4 = Fault(grid , "Fault4") - - fault1.addRecord(1 , 1 , 10 , grid.getNY() - 1 , 0 , 0 , "X") - fault2.addRecord(5 , 30 , 15 , 15 , 0 , 0 , "Y") - fault3.addRecord(2 , 10 , 9 , 9 , 0 , 0 , "Y") - fault4.addRecord(20 , 20 , 10 , grid.getNY() - 1 , 0 , 0 , "X") - - #self.assertFalse( fault1.intersectsFault(fault2 , 0) ) - #self.assertFalse( fault2.intersectsFault(fault1 , 0) ) - - #self.assertTrue( fault2.intersectsFault(fault4 , 0) ) - #self.assertTrue( fault4.intersectsFault(fault2 , 0) ) - - self.assertTrue( fault1.intersectsFault(fault1 , 0) ) - #self.assertTrue( fault3.intersectsFault(fault3 , 0) ) - - - - def test_iter(self): - faults = FaultCollection(self.grid , self.faults1 , self.faults2) - self.assertEqual( 7 , len(faults)) - c = 0 - for f in faults: - c += 1 - self.assertEqual( c , len(faults)) - - for f in ["F1","F2","F3" ,"F4"]: - self.assertTrue( f in faults ) - - self.assertFalse("FX" in faults ) - - - - def test_fault(self): - f = Fault(self.grid , "NAME") - - with self.assertRaises(ValueError): - # Invalid face - f.addRecord( 10 , 10 , 11 , 11 , 1 , 43 , "F") - - - with self.assertRaises(ValueError): - # Invalid coordinates - f.addRecord( -1 , 10 , 11 , 11 , 1 , 43 , "X") - - with self.assertRaises(ValueError): - # Invalid coordinates - f.addRecord( 10000 , 10 , 11 , 11 , 1 , 43 , "X") - - with self.assertRaises(ValueError): - # Invalid coordinates - f.addRecord( 10 , 9 , 11 , 11 , 1 , 43 , "X") - - - with self.assertRaises(ValueError): - # Invalid coordinates - f.addRecord( 10 , 9 , 11 , 11 , 1 , 43 , "X") - - with self.assertRaises(ValueError): - # Invalid coordinates/face combination - f.addRecord( 10 , 11 , 11 , 11 , 1 , 43 , "X") - - with self.assertRaises(ValueError): - # Invalid coordinates/face combination - f.addRecord( 10 , 11 , 11 , 12 , 1 , 43 , "Y") - - f.addRecord(10 , 10 , 0 , 10 , 1 , 10 , "X") - - - def test_segment(self ): - s0 = FaultSegment(0 , 10) - self.assertEqual(s0.getC1() , 0 ) - self.assertEqual(s0.getC2() , 10 ) - - s0.swap() - self.assertEqual(s0.getC1() , 10 ) - self.assertEqual(s0.getC2() , 0 ) - - - - - def test_fault_line(self ): - faults = FaultCollection(self.grid , self.faults1 , self.faults2) - for fault in faults: - for layer in fault: - for fl in layer: - fl.verify() - - - def test_fault_line_order(self): - nx = 120 - ny = 60 - nz = 43 - grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) - with TestAreaContext("python/faults/line_order"): - with open("faults.grdecl" , "w") as f: - f.write("""FAULTS -\'F\' 105 107 50 50 1 43 \'Y\' / -\'F\' 108 108 50 50 1 43 \'X\' / -\'F\' 108 108 50 50 22 43 \'Y\' / -\'F\' 109 109 49 49 1 43 \'Y\' / -\'F\' 110 110 49 49 1 43 \'X\' / -\'F\' 111 111 48 48 1 43 \'Y\' / -/ -""") - faults = FaultCollection( grid , "faults.grdecl" ) - - fault = faults["F"] - layer = fault[29] - self.assertEqual(len(layer) , 2) - - line1 = layer[0] - line2 = layer[1] - self.assertEqual(len(line1) , 4) - self.assertEqual(len(line2) , 2) - - seg0 = line1[0] - seg1 = line1[1] - seg2 = line1[2] - seg3 = line1[3] - self.assertEqual( seg0.getCorners() , (50 * (nx + 1) + 104 , 50 * (nx + 1) + 107)) - self.assertEqual( seg1.getCorners() , (50 * (nx + 1) + 107 , 50 * (nx + 1) + 108)) - self.assertEqual( seg2.getCorners() , (50 * (nx + 1) + 108 , 49 * (nx + 1) + 108)) - self.assertEqual( seg3.getCorners() , (49 * (nx + 1) + 108 , 49 * (nx + 1) + 109)) - - - - - - def test_neighbour_cells(self): - nx = 10 - ny = 8 - nz = 7 - grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) - faults_file = self.createTestPath("local/ECLIPSE/FAULTS/faults_nb.grdecl") - faults = FaultCollection( grid , faults_file ) - - fault = faults["FY"] - self.assertEqual(len(fault),1) - fault_layer = fault[0] - - fl1 = fault_layer[0] - nb_cells1 = fl1.getNeighborCells() - true_nb_cells1 = [(0, nx) , (1,nx + 1), (2,nx+2) , (3,nx + 3) , (4,nx+4)] - self.assertListEqual( nb_cells1 , true_nb_cells1 ) - - fl2 = fault_layer[1] - nb_cells2 = fl2.getNeighborCells() - true_nb_cells2 = [(6, nx+6) , (7,nx + 7), (8 , nx+8) , (9,nx + 9)] - self.assertListEqual( nb_cells2 , true_nb_cells2 ) - - nb_cells = fault_layer.getNeighborCells() - self.assertListEqual( nb_cells , true_nb_cells1 + true_nb_cells2) - - - fault = faults["FY0"] - fault_layer = fault[0] - fl1 = fault_layer[0] - nb_cells1 = fl1.getNeighborCells() - true_nb_cells1 = [(-1,0) , (-1,1), (-1,2)] - self.assertListEqual( nb_cells1 , true_nb_cells1 ) - - - fault = faults["FYNY"] - fault_layer = fault[0] - fl1 = fault_layer[0] - nb_cells1 = fl1.getNeighborCells() - true_nb_cells1 = [(nx * (ny - 1) , -1), (nx * (ny - 1) + 1 , -1), (nx * (ny - 1) + 2, -1)] - self.assertListEqual( nb_cells1 , true_nb_cells1 ) - - fault = faults["FX"] - fault_layer = fault[0] - fl1 = fault_layer[0] - nb_cells1 = fl1.getNeighborCells() - true_nb_cells1 = [(0,1) , (nx , nx+1) , (2*nx , 2*nx + 1)] - self.assertListEqual( nb_cells1 , true_nb_cells1 ) - - - fault = faults["FX0"] - fault_layer = fault[0] - fl1 = fault_layer[0] - nb_cells1 = fl1.getNeighborCells() - true_nb_cells1 = [(-1 , 0) , (-1 , nx) , (-1 , 2*nx)] - self.assertListEqual( nb_cells1 , true_nb_cells1 ) - - fault = faults["FXNX"] - fault_layer = fault[0] - fl1 = fault_layer[0] - nb_cells1 = fl1.getNeighborCells() - true_nb_cells1 = [(nx -1 , -1) , (2*nx -1 , -1) , (3*nx - 1 , -1)] - self.assertListEqual( nb_cells1 , true_nb_cells1 ) - - - def test_polyline_intersection(self): - grid = EclGrid.createRectangular( (100,100,10) , (0.25 , 0.25 , 1)) - - # Fault1 Fault4 - # | | - # | | - # | | - # | ------- Fault2 | - # | | - # | | - # (5 , 2.50) - # -------- Fault3 - # - - fault1 = Fault(grid , "Fault1") - fault2 = Fault(grid , "Fault2") - fault3 = Fault(grid , "Fault3") - fault4 = Fault(grid , "Fault4") - - fault1.addRecord(1 , 1 , 10 , grid.getNY() - 1 , 0 , 0 , "X") - fault2.addRecord(5 , 10 , 15 , 15 , 0 , 0 , "Y") - fault3.addRecord(5 , 10 , 5 , 5 , 0 , 0 , "Y") - fault4.addRecord(20 , 20 , 10 , grid.getNY() - 1 , 0 , 0 , "X") - - - polyline = Polyline( init_points = [(4 , 4) , (8,4)]) - self.assertTrue( fault4.intersectsPolyline( polyline , 0)) - - cpolyline = CPolyline( init_points = [(4 , 4) , (8,4)]) - self.assertTrue( fault4.intersectsPolyline( cpolyline , 0)) - - polyline = Polyline( init_points = [(8 , 4) , (16,4)]) - self.assertFalse( fault4.intersectsPolyline( polyline , 0)) - - cpolyline = CPolyline( init_points = [(8 , 4) , (16,4)]) - self.assertFalse( fault4.intersectsPolyline( cpolyline , 0)) - - - def test_num_linesegment(self): - nx = 10 - ny = 10 - nz = 1 - grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) - with TestAreaContext("python/faults/line_order"): - with open("faults.grdecl" , "w") as f: - f.write("""FAULTS -\'F1\' 1 4 2 2 1 1 \'Y\' / -\'F1\' 6 8 2 2 1 1 \'Y\' / -\'F2\' 1 8 2 2 1 1 \'Y\' / -/ -""") - faults = FaultCollection( grid , "faults.grdecl" ) - - f1 = faults["F1"] - f2 = faults["F2"] - self.assertEqual( 2 , f1.numLines(0)) - self.assertEqual( 1 , f2.numLines(0)) - - - def test_extend_to_polyline(self): - grid = EclGrid.createRectangular( (3,3,1) , (1 , 1 , 1)) - - # o o o o - # - # o---o---o---o - # - # o===+ o o - # | - # o o o o - - fault1 = Fault(grid , "Fault") - - fault1.addRecord(0 , 0 , 0 , 0 , 0 , 0 , "X-") - fault1.addRecord(0 , 0 , 0 , 0 , 0 , 0 , "Y") - - polyline = CPolyline( init_points = [(0,2) , (3,2)]) - points = fault1.extendToPolyline( polyline , 0 ) - self.assertEqual( points , [(1,1) , (2,2)]) - - end_join = fault1.endJoin( polyline , 0 ) - self.assertEqual( end_join, [(1,1) , (0,2)] ) - - polyline2 = CPolyline( init_points = [(0.8,2) , (0.8,0.8)]) - end_join = fault1.endJoin( polyline2 , 0 ) - self.assertIsNone( end_join ) - - - def test_extend_polyline_on(self): - grid = EclGrid.createRectangular( (3,3,1) , (1 , 1 , 1)) - - # o o o o - # - # o---o---o---o - # - # o===o===o===o - # - # o o o o - - fault1 = Fault(grid , "Fault") - fault1.addRecord(0 , 2 , 0 , 0 , 0 , 0 , "Y") - - polyline0 = CPolyline( init_points = [(0,2)]) - polyline1 = CPolyline( init_points = [(0,2) , (3,2)]) - polyline2 = CPolyline( init_points = [(1,3) , (1,2)]) - polyline3 = CPolyline( init_points = [(1,3) , (1,0)]) - - with self.assertRaises(ValueError): - fault1.extendPolylineOnto( polyline0 , 0 ) - - points = fault1.extendPolylineOnto( polyline1 , 0 ) - self.assertIsNone( points ) - - points = fault1.extendPolylineOnto( polyline2 , 0) - self.assertEqual( points , [(1,2) , (1,1)]) - - points = fault1.extendPolylineOnto( polyline3 , 0) - self.assertIsNone( points ) - - - def test_stepped(self): - grid = EclGrid.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.assign(1) - block_kw[5] = 2 - block_kw[11] = 2 - block_kw[14:18] = 2 - block_kw[14:18] = 2 - block_kw[20:23] = 2 - - layer0 = FaultBlockLayer( grid , 0 ) - layer0.scanKeyword( block_kw ) - layer0.addFaultBarrier( f ) - self.assertTrue( layer0.cellContact((0,0) , (1,0))) - self.assertFalse( layer0.cellContact((4,0) , (5,0))) - - layer1 = FaultBlockLayer( grid , 1 ) - layer1.scanKeyword( block_kw ) - layer1.addFaultBarrier( f ) - self.assertTrue( layer1.cellContact((0,0) , (1,0))) - self.assertFalse( layer1.cellContact((4,0) , (5,0))) - - layer2 = FaultBlockLayer( grid , 2 ) - layer2.scanKeyword( block_kw ) - layer2.addFaultBarrier( f ) - self.assertTrue( layer2.cellContact((0,0) , (1,0))) - self.assertFalse( layer2.cellContact((1,0) , (2,0))) - - layer3 = FaultBlockLayer( grid , 3 ) - layer3.scanKeyword( block_kw ) - layer3.addFaultBarrier( f ) - self.assertTrue( layer3.cellContact((0,0) , (1,0))) - self.assertFalse( layer3.cellContact((1,0) , (2,0))) - - - - def test_connectWithPolyline(self): - grid = EclGrid.createRectangular( (4,4,1) , (1 , 1 , 1)) - - - # o o o o o - # - # o o o o o - # - # o---o---o---o---o - # - # o o o o o - # | - # o o o o o - - fault1 = Fault(grid , "Fault1") - fault1.addRecord(0 , 3 , 1 , 1 , 0 , 0 , "Y") - - fault2 = Fault(grid , "Fault2") - fault2.addRecord(1 , 1 , 0 , 0 , 0 , 0 , "X") - - fault3 = Fault(grid , "Fault3") - fault3.addRecord(1 , 1 , 0 , 2 , 0 , 0 , "X") - - self.assertIsNone( fault3.connect( fault1 , 0 )) - - - intersect = fault2.connect( fault1 , 0 ) - self.assertEqual( len(intersect) , 2 ) - p1 = intersect[0] - p2 = intersect[1] - - self.assertEqual( p1 , (2,1)) - self.assertEqual( p2 , (2,2)) - diff --git a/ThirdParty/Ert/python/tests/ecl/test_fk_user_data.py b/ThirdParty/Ert/python/tests/ecl/test_fk_user_data.py deleted file mode 100644 index b3d48befea..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_fk_user_data.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2017 Statoil ASA, Norway. -# -# The file 'test_ecl_cell_containment.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.ecl import EclGrid -from ecl.test import ExtendedTestCase, TestAreaContext - -class FKTest(ExtendedTestCase): - - def test_cell_containment(self): - - grid_location = "local/ECLIPSE/faarikaal/faarikaal%d.EGRID" - well_location = "local/ECLIPSE/faarikaal/faarikaal%d.txt" - - for i in range(1, 8): - grid_file = self.createTestPath(grid_location % i) - well_file = self.createTestPath(well_location % i) - - grid = EclGrid(grid_file) - - # Load well data - with open(well_file, "r") as f: - lines = [line.split() for line in f.readlines()] - - points = [map(float, line[:3:]) for line in lines] - exp_cells = [tuple(map(int, line[3::])) for line in lines] - - msg = "Expected point %s to be in cell %s, was in %s." - for point, exp_cell in zip(points, exp_cells): - reported_cell = grid.find_cell(*point) - self.assertEqual( - exp_cell, - reported_cell, - msg % (str(point), str(exp_cell), str(reported_cell)) - ) diff --git a/ThirdParty/Ert/python/tests/ecl/test_fortio.py b/ThirdParty/Ert/python/tests/ecl/test_fortio.py deleted file mode 100644 index 01e51ff3d3..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_fortio.py +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os -from random import randint -from ecl.ecl import FortIO, EclDataType, EclKW , openFortIO, EclFile -from ecl.test import ExtendedTestCase, TestAreaContext - - - - -class FortIOTest(ExtendedTestCase): - - - - - def test_open_write(self): - with TestAreaContext("python/fortio/write"): - f = FortIO("newfile", FortIO.WRITE_MODE) - self.assertTrue(os.path.exists("newfile")) - - def test_noex(self): - with self.assertRaises(IOError): - 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[0] = 99 - kw1[1] = 77 - kw2[0] = 113 - kw2[1] = 335 - - with TestAreaContext("python/fortio/write-kw"): - f = FortIO("test", FortIO.WRITE_MODE, fmt_file=False) - kw1.fwrite(f) - - f = FortIO("test", FortIO.APPEND_MODE) - kw2.fwrite(f) - - f = FortIO("test", fmt_file=False) - k1 = EclKW.fread(f) - k2 = EclKW.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[0] = 99 - kw1[1] = 77 - kw2[0] = 113 - kw2[1] = 335 - - with TestAreaContext("python/fortio/ftruncate") as t: - with openFortIO("file" , mode = FortIO.WRITE_MODE) as f: - kw1.fwrite(f) - pos1 = f.getPosition( ) - kw2.fwrite(f) - - t.sync( ) - # Truncate file in read mode; should fail hard. - with openFortIO("file") as f: - with self.assertRaises(IOError): - f.truncate( ) - - - with openFortIO("file" , mode = FortIO.READ_AND_WRITE_MODE) as f: - f.seek( pos1 ) - f.truncate( ) - - - f = EclFile("file") - self.assertEqual( len(f) , 1) - kw1_ = f[0] - self.assertEqual( kw1 , kw1_) - - - - def test_fortio_creation(self): - with TestAreaContext("python/fortio/create"): - w = FortIO("test", FortIO.WRITE_MODE) - rw = FortIO("test", FortIO.READ_AND_WRITE_MODE) - r = FortIO("test", FortIO.READ_MODE) - a = FortIO("test", FortIO.APPEND_MODE) - - w.close() - w.close() # should not fail - - - - - - def test_context(self): - with TestAreaContext("python/fortio/context") as t: - kw1 = EclKW("KW" , 2456 , EclDataType.ECL_FLOAT) - for i in range(len(kw1)): - kw1[i] = randint(0,1000) - - with openFortIO("file" , mode = FortIO.WRITE_MODE) as f: - kw1.fwrite( f ) - self.assertEqual( f.filename() , "file") - - t.sync( ) - - with openFortIO("file") as f: - kw2 = EclKW.fread( f ) - - self.assertTrue( kw1 == kw2 ) - - - def test_is_fortran_file(self): - with TestAreaContext("python/fortio/guess"): - kw1 = EclKW("KW" , 12345 , EclDataType.ECL_FLOAT) - with openFortIO("fortran_file" , mode = FortIO.WRITE_MODE) as f: - kw1.fwrite( f ) - - with open("text_file" , "w") as f: - kw1.write_grdecl( f ) - - self.assertTrue( FortIO.isFortranFile( "fortran_file" )) - self.assertFalse( FortIO.isFortranFile( "text_file" )) diff --git a/ThirdParty/Ert/python/tests/ecl/test_geertsma.py b/ThirdParty/Ert/python/tests/ecl/test_geertsma.py deleted file mode 100644 index 5ff2850716..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_geertsma.py +++ /dev/null @@ -1,144 +0,0 @@ -import datetime -from ecl.ecl import EclGrid, EclKW, EclDataType, openFortIO, FortIO, EclFile, EclSubsidence - -from ecl.test import ExtendedTestCase , TestAreaContext - -import numpy as np - - -def create_init(grid, case): - poro = EclKW("PORO", grid.getNumActive(), EclDataType.ECL_FLOAT) - porv = poro.copy() - porv.setName("PORV") - for g in range(grid.getGlobalSize()): - porv[g] *= grid.cell_volume(global_index=g) - - with openFortIO("%s.INIT" % case, mode=FortIO.WRITE_MODE) as f: - poro.fwrite(f) - porv.fwrite(f) - - -def create_restart(grid, case, p1, p2=None): - with openFortIO("%s.UNRST" % case, mode=FortIO.WRITE_MODE) as f: - seq_hdr = EclKW("SEQNUM", 1, EclDataType.ECL_FLOAT) - seq_hdr[0] = 10 - p = EclKW("PRESSURE", grid.getNumActive(), EclDataType.ECL_FLOAT) - for i in range(len(p1)): - p[i] = p1[i] - - header = EclKW("INTEHEAD", 67, EclDataType.ECL_INT) - header[64] = 1 - header[65] = 1 - header[66] = 2000 - - seq_hdr.fwrite(f) - header.fwrite(f) - p.fwrite(f) - - if p2: - seq_hdr[0] = 20 - header[66] = 2010 - for i in range(len(p2)): - p[i] = p2[i] - - seq_hdr.fwrite(f) - header.fwrite(f) - p.fwrite(f) - - -class GeertsmaTest(ExtendedTestCase): - - @staticmethod - def test_geertsma_kernel(): - grid = EclGrid.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") - - restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) - - subsidence = EclSubsidence(grid, init) - subsidence.add_survey_PRESSURE("S1", restart_view1) - - youngs_modulus = 5E8 - poisson_ratio = 0.3 - seabed = 0 - above = 100 - topres = 2000 - receiver = (1000, 1000, 0) - - dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) - np.testing.assert_almost_equal(dz, 3.944214576168326e-09) - - receiver = (1000, 1000, topres - seabed - above) - - dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) - np.testing.assert_almost_equal(dz, 5.8160298201497136e-08) - - @staticmethod - def test_geertsma_kernel_2_source_points_2_vintages(): - grid = EclGrid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100)) - - with TestAreaContext("Subsidence"): - p1 = [1, 10] - p2 = [10, 20] - create_restart(grid, "TEST", p1, p2) - create_init(grid, "TEST") - - init = EclFile("TEST.INIT") - restart_file = EclFile("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.add_survey_PRESSURE("S1", restart_view1) - subsidence.add_survey_PRESSURE("S2", restart_view2) - - youngs_modulus = 5E8 - poisson_ratio = 0.3 - seabed = 0 - receiver = (1000, 1000, 0) - - dz1 = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) - np.testing.assert_almost_equal(dz1, 8.65322541521704e-07) - - dz2 = subsidence.evalGeertsma("S2", None, receiver, youngs_modulus, poisson_ratio, seabed) - np.testing.assert_almost_equal(dz2, 2.275556615015282e-06) - - np.testing.assert_almost_equal(dz1-dz2, -1.4102340734935779e-06) - - dz = subsidence.evalGeertsma("S1", "S2", receiver, youngs_modulus, poisson_ratio, seabed) - np.testing.assert_almost_equal(dz, dz1-dz2) - - @staticmethod - def test_geertsma_kernel_seabed(): - grid = EclGrid.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") - - restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) - - subsidence = EclSubsidence(grid, init) - subsidence.add_survey_PRESSURE("S1", restart_view1) - - youngs_modulus = 5E8 - poisson_ratio = 0.3 - seabed = 300 - above = 100 - topres = 2000 - receiver = (1000, 1000, topres - seabed - above) - - dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) - np.testing.assert_almost_equal(dz, 5.819790154474284e-08) - - diff --git a/ThirdParty/Ert/python/tests/ecl/test_grav.py b/ThirdParty/Ert/python/tests/ecl/test_grav.py deleted file mode 100644 index 3772db8448..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_grav.py +++ /dev/null @@ -1,25 +0,0 @@ -import time -from ecl.ecl import EclGrav, EclKW, EclGrid, EclFile, EclDataType, openFortIO, FortIO -from ecl.test import ExtendedTestCase , TestAreaContext - - -class EclGravTest(ExtendedTestCase): - - - 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/ThirdParty/Ert/python/tests/ecl/test_grdecl.py b/ThirdParty/Ert/python/tests/ecl/test_grdecl.py deleted file mode 100644 index 7c6b1b05c6..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_grdecl.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import os -from ecl.ecl import EclKW,EclGrid,Ecl3DKW -from ecl.test import ExtendedTestCase - - - - - -class GRDECLTest(ExtendedTestCase): - def setUp(self): - self.src_file = self.createTestPath("Statoil/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(open(self.src_file, "r"), "PERMX") - self.assertTrue(kw) - - grid = EclGrid( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE" )) - kw = Ecl3DKW.read_grdecl(grid , open(self.src_file, "r"), "PERMX") - self.assertTrue( isinstance( kw , Ecl3DKW )) - - - - def test_reload( self ): - kw = EclKW.read_grdecl(open(self.src_file, "r"), "PERMX") - tmp_file1 = "/tmp/permx1.grdecl" - tmp_file2 = "/tmp/permx2.grdecl" - self.addFile(tmp_file1) - self.addFile(tmp_file2) - - fileH = open(tmp_file1, "w") - kw.write_grdecl(fileH) - fileH.close() - - kw1 = EclKW.read_grdecl(open(tmp_file1, "r"), "PERMX") - - fileH = open(tmp_file2, "w") - kw1.write_grdecl(fileH) - fileH.close() - - self.assertFilesAreEqual(tmp_file1, tmp_file2) - - - def test_fseek( self ): - file = open(self.src_file, "r") - self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) - self.assertFalse(EclKW.fseek_grdecl(file, "PERMY")) - file.close() - - file = open(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 = open(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 = open(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/ThirdParty/Ert/python/tests/ecl/test_grid.py b/ThirdParty/Ert/python/tests/ecl/test_grid.py deleted file mode 100644 index 0152414bb9..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_grid.py +++ /dev/null @@ -1,587 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'test_grid.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os.path -from unittest import skipIf -import time -import itertools -from numpy import linspace - -from ecl.util import IntVector -from ecl.ecl import EclGrid, EclKW, EclDataType, EclUnitTypeEnum, EclFile -from ecl.ecl import EclGridGenerator as GridGen -from ecl.ecl.faults import Layer , FaultCollection -from ecl.test import ExtendedTestCase , TestAreaContext - -# This dict is used to verify that corners are mapped to the correct -# cell with respect to containment. -CORNER_HOME = { - (0, 0, 0) : 0, (0, 0, 1) : 9, (0, 0, 2) : 18, (0, 0, 3) : 18, - (0, 1, 0) : 3, (0, 1, 1) : 12, (0, 1, 2) : 21, (0, 1, 3) : 21, - (0, 2, 0) : 6, (0, 2, 1) : 15, (0, 2, 2) : 24, (0, 2, 3) : 24, - (0, 3, 0) : 6, (0, 3, 1) : 15, (0, 3, 2) : 24, (0, 3, 3) : 24, - (1, 0, 0) : 1, (1, 0, 1) : 10, (1, 0, 2) : 19, (1, 0, 3) : 19, - (1, 1, 0) : 4, (1, 1, 1) : 13, (1, 1, 2) : 22, (1, 1, 3) : 22, - (1, 2, 0) : 7, (1, 2, 1) : 16, (1, 2, 2) : 25, (1, 2, 3) : 25, - (1, 3, 0) : 7, (1, 3, 1) : 16, (1, 3, 2) : 25, (1, 3, 3) : 25, - (2, 0, 0) : 2, (2, 0, 1) : 11, (2, 0, 2) : 20, (2, 0, 3) : 20, - (2, 1, 0) : 5, (2, 1, 1) : 14, (2, 1, 2) : 23, (2, 1, 3) : 23, - (2, 2, 0) : 8, (2, 2, 1) : 17, (2, 2, 2) : 26, (2, 2, 3) : 26, - (2, 3, 0) : 8, (2, 3, 1) : 17, (2, 3, 2) : 26, (2, 3, 3) : 26, - (3, 0, 0) : 2, (3, 0, 1) : 11, (3, 0, 2) : 20, (3, 0, 3) : 20, - (3, 1, 0) : 5, (3, 1, 1) : 14, (3, 1, 2) : 23, (3, 1, 3) : 23, - (3, 2, 0) : 8, (3, 2, 1) : 17, (3, 2, 2) : 26, (3, 2, 3) : 26, - (3, 3, 0) : 8, (3, 3, 1) : 17, (3, 3, 2) : 26, (3, 3, 3) : 26 -} - -def createVolumeTestGridBase(dim, dV, offset=1): - return [ - GridGen.create_grid(dim, dV, offset=0), - GridGen.create_grid(dim, dV, offset=offset), - GridGen.create_grid(dim, dV, offset=offset, irregular_offset=True), - GridGen.create_grid(dim, dV, offset=offset, concave=True), - GridGen.create_grid(dim, dV, offset=offset, irregular=True), - GridGen.create_grid(dim, dV, offset=offset, concave=True, irregular=True), - GridGen.create_grid(dim, dV, offset=offset, irregular_offset=True, concave=True), - GridGen.create_grid(dim, dV, offset=0, faults=True), - GridGen.create_grid(dim, dV, offset=offset, faults=True), - GridGen.create_grid(dim, dV, escape_origo_shift=(100, 100, 0), scale=2), - GridGen.create_grid(dim, dV, escape_origo_shift=(100, 100, 0), scale=0.5), - GridGen.create_grid(dim, dV, escape_origo_shift=(100, 100, 0), translation=(50,50,0)), - GridGen.create_grid(dim, dV, escape_origo_shift=(100, 100, 0), rotate=True), - GridGen.create_grid(dim, dV, escape_origo_shift=(100, 100, 0), misalign=True), - GridGen.create_grid(dim, dV, offset=offset, escape_origo_shift=(100, 100, 0), - irregular_offset=True, concave=True, irregular=True, - scale=1.5, translation=(5,5,0), rotate=True, - misalign=True) - ] - -def createContainmentTestBase(): - return [ - (3, GridGen.create_grid((6,6,6), (1,1,1), offset=1)), - (10, GridGen.create_grid((3,3,3), (1,1,1), offset=1, concave=True)), - (4, GridGen.create_grid((10,10,1), (1,1,1), offset=0., misalign=True)), - (3, - GridGen.create_grid((6,6,6), (1,1,1), offset=0., - escape_origo_shift=(100, 100, 0), - irregular_offset=True, concave=True, irregular=True, - scale=1.5, translation=(5,5,0), - misalign=True - ) - ) - ] - -def getMinMaxValue(grid): - corners = [ - grid.getCellCorner(i, cell) - for i in range(8) - for cell in range(grid.getGlobalSize()) - ] - - return [(min(values), max(values)) for values in zip(*corners)] - -def createWrapperGrid(grid): - """ - Creates a grid that occupies the same space as the given grid, - but that consists of a single cell. - """ - - x, y, z = grid.getNX()-1, grid.getNY()-1, grid.getNZ()-1 - corner_pos = [ - (0, 0, 0), (x, 0, 0), (0, y, 0), (x, y, 0), - (0, 0, z), (x, 0, z), (0, y, z), (x, y, z) - ] - - corners = [ - grid.getCellCorner(i, ijk=pos) - for i, pos in enumerate(corner_pos) - ] - - return GridGen.create_single_cell_grid(corners) - -def average(points): - p = reduce(lambda a,b: (a[0]+b[0], a[1]+b[1], a[2]+b[2]), points) - return [elem/float(len(points)) for elem in p] - -# This test class should only have test cases which do not require -# external test data. Tests involving Statoil test data are in the -# test_grid_statoil module. -class GridTest(ExtendedTestCase): - - def test_oom_grid(self): - nx = 2000 - ny = 2000 - nz = 2000 - - with self.assertRaises(MemoryError): - grid = GridGen.createRectangular( (nx,ny,nz), (1,1,1)) - - - - def test_posXYEdge(self): - nx = 10 - ny = 11 - grid = GridGen.createRectangular( (nx,ny,1) , (1,1,1) ) - self.assertEqual( grid.findCellCornerXY(0,0,0) , 0 ) - self.assertEqual( grid.findCellCornerXY(nx,0,0) , nx) - self.assertEqual( grid.findCellCornerXY(0 , ny , 0) , (nx + 1 ) * ny ) - self.assertEqual( grid.findCellCornerXY(nx,ny,0) , (nx + 1 ) * (ny + 1) - 1) - - self.assertEqual( grid.findCellCornerXY(0.25,0,0) , 0 ) - self.assertEqual( grid.findCellCornerXY(0,0.25,0) , 0 ) - - self.assertEqual( grid.findCellCornerXY(nx - 0.25,0,0) , nx ) - self.assertEqual( grid.findCellCornerXY(nx , 0.25,0) , nx ) - - self.assertEqual( grid.findCellCornerXY(0 , ny - 0.25, 0) , (nx + 1 ) * ny ) - self.assertEqual( grid.findCellCornerXY(0.25 , ny , 0) , (nx + 1 ) * ny ) - - self.assertEqual( grid.findCellCornerXY(nx -0.25 ,ny,0) , (nx + 1 ) * (ny + 1) - 1) - self.assertEqual( grid.findCellCornerXY(nx , ny - 0.25,0) , (nx + 1 ) * (ny + 1) - 1) - - - def test_dims(self): - grid = GridGen.createRectangular( (10,20,30) , (1,1,1) ) - self.assertEqual( grid.getNX() , 10 ) - self.assertEqual( grid.getNY() , 20 ) - self.assertEqual( grid.getNZ() , 30 ) - self.assertEqual( grid.getGlobalSize() , 30*10*20 ) - - self.assertEqual( grid.getDims() , (10,20,30,6000) ) - - def test_create(self): - with self.assertRaises(ValueError): - grid = GridGen.createRectangular( (10,20,30) , (1,1,1) , actnum = [0,1,1,2]) - - with self.assertRaises(ValueError): - grid = GridGen.createRectangular( (10,20,30) , (1,1,1) , actnum = IntVector(initial_size = 10)) - grid = GridGen.createRectangular( (10,20,30) , (1,1,1) ) # actnum=None -> all active - self.assertEqual( grid.getNumActive( ) , 30*20*10) - actnum = IntVector(default_value = 1 , initial_size = 6000) - actnum[0] = 0 - actnum[1] = 0 - grid = GridGen.createRectangular( (10,20,30) , (1,1,1) , actnum = actnum) - self.assertEqual( grid.getNumActive( ) , 30*20*10 - 2) - - def test_all_iters(self): - fk = self.createTestPath('local/ECLIPSE/faarikaal/faarikaal1.EGRID') - grid = EclGrid(fk) - cell = grid[3455] - self.assertEqual(3455, cell.global_index) - cell = grid[(4,1,82)] - self.assertEqual(3455, cell.global_index) - self.assertEqual(grid.cell(global_index=3455), - grid.cell(active_index=2000)) - self.assertEqual(grid.cell(global_index=3455), - grid.cell(i=4, j=1, k=82)) - - na = grid.get_num_active() - self.assertEqual(na, 4160) - cnt = 0 - for c in grid.cells(active=True): - cnt += 1 - self.assertTrue(c.active) - self.assertEqual(cnt, 4160) - - cnt = len([c for c in grid.cells()]) - self.assertEqual(cnt, len(grid)) - - - 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(' - 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"): - grid.save_EGRID("CASE.EGRID") - g2 = EclGrid("CASE.EGRID") - r2 = repr(g2) - self.assertEqual(pfx, r2[:len(pfx)]) - self.assertEqual(type(r2), type('')) - self.assertEqual(type(g2.getName()), type('')) - - def test_node_pos(self): - grid = GridGen.createRectangular( (10,20,30) , (1,1,1) ) - with self.assertRaises(IndexError): - grid.getNodePos(-1,0,0) - - with self.assertRaises(IndexError): - grid.getNodePos(11,0,0) - - p0 = grid.getNodePos(0,0,0) - self.assertEqual( p0 , (0,0,0)) - - p7 = grid.getNodePos(10,20,30) - self.assertEqual( p7 , (10,20,30)) - - - def test_truncated_file(self): - grid = GridGen.createRectangular( (10,20,30) , (1,1,1) ) - with TestAreaContext("python/ecl_grid/truncated"): - grid.save_EGRID( "TEST.EGRID") - - size = os.path.getsize( "TEST.EGRID") - with open("TEST.EGRID" , "r+") as f: - f.truncate( size / 2 ) - - with self.assertRaises(IOError): - EclGrid("TEST.EGRID") - - def test_posXY1(self): - nx = 4 - ny = 1 - nz = 1 - grid = GridGen.createRectangular( (nx,ny,nz) , (1,1,1) ) - (i,j) = grid.findCellXY( 0.5 , 0.5, 0 ) - self.assertEqual(i , 0) - self.assertEqual(j , 0) - - (i,j) = grid.findCellXY( 3.5 , 0.5, 0 ) - self.assertEqual(i , 3) - self.assertEqual(j , 0) - - - def test_init_ACTNUM(self): - nx = 10 - ny = 23 - nz = 7 - grid = GridGen.createRectangular( (nx,ny,nz) , (1,1,1) ) - actnum = grid.exportACTNUM() - - self.assertEqual( len(actnum) , nx*ny*nz ) - self.assertEqual( actnum[0] , 1 ) - self.assertEqual( actnum[nx*ny*nz - 1] , 1 ) - - actnum_kw = grid.exportACTNUMKw( ) - self.assertEqual(len(actnum_kw) , len(actnum)) - for a1,a2 in zip(actnum, actnum_kw): - self.assertEqual(a1, a2) - - - def test_posXY(self): - nx = 10 - ny = 23 - nz = 7 - grid = GridGen.createRectangular( (nx,ny,nz) , (1,1,1) ) - with self.assertRaises(IndexError): - grid.findCellXY( 1 , 1, -1 ) - - with self.assertRaises(IndexError): - grid.findCellXY( 1 , 1, nz + 1 ) - - with self.assertRaises(ValueError): - grid.findCellXY(15 , 78 , 2) - - - i,j = grid.findCellXY( 1.5 , 1.5 , 2 ) - self.assertEqual(i , 1) - self.assertEqual(j , 1) - - - for i in range(nx): - for j in range(ny): - p = grid.findCellXY(i + 0.5 , j+ 0.5 , 0) - self.assertEqual( p[0] , i ) - self.assertEqual( p[1] , j ) - - c = grid.findCellCornerXY( 0.10 , 0.10 , 0 ) - self.assertEqual(c , 0) - - c = grid.findCellCornerXY( 0.90 , 0.90 , 0 ) - self.assertEqual( c , (nx + 1) + 1 ) - - c = grid.findCellCornerXY( 0.10 , 0.90 , 0 ) - self.assertEqual( c , (nx + 1) ) - - c = grid.findCellCornerXY( 0.90 , 0.90 , 0 ) - self.assertEqual( c , (nx + 1) + 1 ) - - c = grid.findCellCornerXY( 0.90 , 0.10 , 0 ) - self.assertEqual( c , 1 ) - - def test_compressed_copy(self): - nx = 10 - ny = 10 - nz = 10 - grid = GridGen.createRectangular( (nx,ny,nz) , (1,1,1) ) - kw1 = EclKW("KW" , 1001 , EclDataType.ECL_INT ) - with self.assertRaises(ValueError): - cp = grid.compressedKWCopy( kw1 ) - - - def test_dxdydz(self): - nx = 10 - ny = 10 - nz = 10 - grid = GridGen.createRectangular( (nx,ny,nz) , (2,3,4) ) - - (dx,dy,dz) = grid.getCellDims( active_index = 0 ) - self.assertEqual( dx , 2 ) - self.assertEqual( dy , 3 ) - self.assertEqual( dz , 4 ) - - def test_numpy3D(self): - nx = 10 - ny = 7 - nz = 5 - grid = GridGen.createRectangular((nx,ny,nz) , (1,1,1)) - kw = EclKW( "SWAT" , nx*ny*nz , EclDataType.ECL_FLOAT ) - numpy_3d = grid.create3D( kw ) - - def test_len(self): - nx = 10 - ny = 11 - nz = 12 - actnum = EclKW( "ACTNUM" , nx*ny*nz , EclDataType.ECL_INT ) - actnum[0] = 1 - actnum[1] = 1 - actnum[2] = 1 - actnum[3] = 1 - - grid = GridGen.createRectangular( (nx,ny,nz) , (1,1,1), actnum = actnum) - self.assertEqual( len(grid) , nx*ny*nz ) - self.assertEqual( grid.getNumActive( ) , 4 ) - - def test_export(self): - dims = (3, 3, 3) - 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) - - self.assertEqual(zcorn, grid.export_zcorn()) - self.assertEqual(coord, grid.export_coord()) - - def test_output_units(self): - n = 10 - 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") - g = f["GRIDUNIT"][0] - self.assertEqual( g[0].strip( ) , "FEET" ) - g2 = EclGrid("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") - 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") - g = f["GRIDUNIT"][0] - self.assertEqual( g[0].strip() , "CM" ) - g2 = EclGrid("CASE.EGRID") - self.assertFloatEqual( g2.cell_volume( global_index = 0 ) , 100*100*100 ) - - def test_volume(self): - dim = (10,10,10) - dV = (2,2,2) - - grids = createVolumeTestGridBase(dim, dV) - for grid in grids: - tot_vol = createWrapperGrid(grid).cell_volume(0) - cell_volumes = [grid.cell_volume(i) for i in range(grid.getGlobalSize())] - self.assertTrue(min(cell_volumes) >= 0) - self.assertFloatEqual(sum(cell_volumes), tot_vol) - - def test_unique_containment(self): - test_base = createContainmentTestBase() - - for steps_per_unit, grid in test_base: - wgrid = createWrapperGrid(grid) - - (xmin, xmax), (ymin, ymax), (zmin, zmax) = getMinMaxValue(wgrid) - x_space = linspace(xmin-1, xmax+1, (xmax-xmin+2)*steps_per_unit+1) - y_space = linspace(ymin-1, ymax+1, (ymax-ymin+2)*steps_per_unit+1) - z_space = linspace(zmin-1, zmax+1, (zmax-zmin+2)*steps_per_unit+1) - - for x, y, z in itertools.product(x_space, y_space, z_space): - hits = [ - grid.cell_contains(x, y, z, i) - for i in range(grid.getGlobalSize()) - ].count(True) - - self.assertIn(hits, [0, 1]) - - expected = 1 if wgrid.cell_contains(x, y, z, 0) else 0 - self.assertEqual( - expected, - hits, - 'Expected %d for (%g,%g,%g), got %d' % (expected, x, y, z, hits) - ) - - def test_cell_corner_containment(self): - n = 4 - d = 10 - grid = GridGen.createRectangular( (n, n, n), (d, d, d)) - - for x, y, z in itertools.product(range(0, n*d+1, d), repeat=3): - self.assertEqual( - 1, - [grid.cell_contains(x, y, z, i) for i in range(n**3)].count(True) - ) - - def test_cell_corner_containment_compatability(self): - grid = GridGen.createRectangular( (3,3,3), (1,1,1) ) - - for x, y, z in itertools.product(range(4), repeat=3): - for i in range(27): - if grid.cell_contains(x, y, z, i): - self.assertEqual( - CORNER_HOME[(x,y,z)], - i - ) - - def test_cell_face_containment(self): - n = 4 - d = 10 - grid = GridGen.createRectangular( (n, n, n), (d, d, d)) - - for x, y, z in itertools.product(range(d/2, n*d, d), repeat=3): - for axis, direction in itertools.product(range(3), [-1, 1]): - p = [x, y, z] - p[axis] = p[axis] + direction*d/2 - self.assertEqual( - 1, - [grid.cell_contains(p[0], p[1], p[2], i) for i in range(n**3)].count(True) - ) - - # This test generates a cell that is concave on ALL 6 sides - def test_concave_cell_containment(self): - points = [ - (5, 5, 5), - (20, 10, 10), - (10, 20, 10), - (25, 25, 5), - (10, 10, 20), - (25, 5, 25), - (5, 25, 25), - (20, 20, 20) - ] - - grid = GridGen.create_single_cell_grid(points) - - assertPoint = lambda p : self.assertTrue( - grid.cell_contains(p[0], p[1], p[2], 0) - ) - - assertNotPoint = lambda p : self.assertFalse( - grid.cell_contains(p[0], p[1], p[2], 0) - ) - - # Cell center - assertPoint(average(points)); - - # "Side" center - assertNotPoint(average(points[0:4:])) - assertNotPoint(average(points[4:8:])) - assertNotPoint(average(points[1:8:2])) - assertNotPoint(average(points[0:8:2])) - assertNotPoint(average(points[0:8:4] + points[1:8:4])) - assertNotPoint(average(points[2:8:4] + points[3:8:4])) - - # Corners - for p in points: - assertPoint(p) - - # Edges - edges = ([(i, i+1) for i in range(0, 8, 2)] + - [(i, i+2) for i in [0, 1, 4, 5]] + - [(i, i+4) for i in range(4)] + - [(1,2), (2,7), (1,7), (4,7), (2,4), (4,1)]) - for a,b in edges: - assertPoint(average([points[a], points[b]])) - - # Epsilon inside from corners - middle_point = average(points) - for p in points: - assertPoint(average(20*[p] + [middle_point])) - - # Espilon outside - middle_point[2] = 0 - for p in points[0:4:]: - assertNotPoint(average(20*[p] + [middle_point])) - - middle_point[2] = 30 - for p in points[4:8:]: - assertNotPoint(average(20*[p] + [middle_point])) - - # This test generates a cell that is strictly convex on ALL 6 sides - def test_concvex_cell_containment(self): - points = [ - (10, 10, 10), - (25, 5, 5), - (5, 25, 5), - (20, 20, 10), - (5, 5, 25), - (20, 10, 20), - (10, 20, 20), - (25, 25, 25) - ] - - grid = GridGen.create_single_cell_grid(points) - - assertPoint = lambda p : self.assertTrue( - grid.cell_contains(p[0], p[1], p[2], 0) - ) - - assertNotPoint = lambda p : self.assertFalse( - grid.cell_contains(p[0], p[1], p[2], 0) - ) - - # Cell center - assertPoint(average(points)); - - # "Side" center - assertPoint(average(points[0:4:])) - assertPoint(average(points[4:8:])) - assertPoint(average(points[1:8:2])) - assertPoint(average(points[0:8:2])) - assertPoint(average(points[0:8:4] + points[1:8:4])) - assertPoint(average(points[2:8:4] + points[3:8:4])) - - # Corners - for p in points: - assertPoint(p) - - # Edges - edges = ([(i, i+1) for i in range(0, 8, 2)] + - [(i, i+2) for i in [0, 1, 4, 5]] + - [(i, i+4) for i in range(4)] + - [(1,2), (2,7), (1,7), (4,7), (2,4), (4,1)]) - for a,b in edges: - assertPoint(average([points[a], points[b]])) - - # Epsilon inside from corners - middle_point = average(points) - for p in points: - assertPoint(average(20*[p] + [middle_point])) - - # Espilon outside - middle_point[2] = 0 - for p in points[0:4:]: - assertNotPoint(average(20*[p] + [middle_point])) - - middle_point[2] = 30 - for p in points[4:8:]: - assertNotPoint(average(20*[p] + [middle_point])) diff --git a/ThirdParty/Ert/python/tests/ecl/test_grid_generator.py b/ThirdParty/Ert/python/tests/ecl/test_grid_generator.py deleted file mode 100644 index ff2d8f087d..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_grid_generator.py +++ /dev/null @@ -1,272 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2017 Statoil ASA, Norway. -# -# The file 'test_grid_generator.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from itertools import product as prod -import operator, random, numpy - -from ecl.ecl import EclGrid, EclKW, EclDataType -from ecl.ecl import EclGridGenerator as GridGen -from ecl.test import ExtendedTestCase, TestAreaContext - - -def generate_ijk_bounds(dims): - ibounds = [(l, u) for l in range(dims[0]) for u in range(l, dims[0])] - jbounds = [(l, u) for l in range(dims[1]) for u in range(l, dims[1])] - kbounds = [(l, u) for l in range(dims[2]) for u in range(l, dims[2])] - return prod(ibounds, jbounds, kbounds) - -def decomposition_preserving(ijk_bound): - return sum(zip(*ijk_bound)[0])%2 is 0 - -class GridGeneratorTest(ExtendedTestCase): - - def setUp(self): - self.test_base = [ - ( - list(GridGen.create_coord((4,4,4), (1,1,1))), - list(GridGen.create_zcorn((4,4,4), (1,1,1), offset=0)), - GridGen.create_grid((4,4,4), (1,1,1), offset=0) - ), - ( - list( - GridGen.create_coord((5,5,5), (1,1,1), - translation=(10,10,0)) - ), - list( - GridGen.create_zcorn((5,5,5), (1,1,1), offset=0.5, - irregular_offset=True, concave=True, irregular=True) - ), - GridGen.create_grid( - (5,5,5), (1,1,1), offset=0.5, - irregular=True, irregular_offset=True, concave=True, - translation=(10,10,0) - ) - ) - ] - - def test_extract_grid_decomposition_change(self): - dims = (4,4,4) - zcorn = list(GridGen.create_zcorn(dims, (1,1,1), offset=0)) - coord = list(GridGen.create_coord(dims, (1,1,1))) - - ijk_bounds = generate_ijk_bounds(dims) - for ijk_bounds in ijk_bounds: - if decomposition_preserving(ijk_bounds): - GridGen.extract_subgrid_data(dims, coord, zcorn, ijk_bounds) - else: - with self.assertRaises(ValueError): - GridGen.extract_subgrid_data(dims, coord, zcorn, ijk_bounds) - - GridGen.extract_subgrid_data(dims, - coord, zcorn, - ijk_bounds, - decomposition_change=True) - - def test_extract_grid_invalid_bounds(self): - dims = (3,3,3) - zcorn = list(GridGen.create_zcorn(dims, (1,1,1), offset=0)) - coord = list(GridGen.create_coord(dims, (1,1,1))) - - with self.assertRaises(ValueError): - GridGen.extract_subgrid_data(dims, coord, zcorn, ((-1,0), (2,2), (2,2))) - - with self.assertRaises(ValueError): - GridGen.extract_subgrid_data(dims, coord, zcorn, ((1,6), (2,2), (2,2))) - - with self.assertRaises(ValueError): - GridGen.extract_subgrid_data(dims, coord, zcorn, ((1,2), (2,0), (2,2))) - - def test_extract_grid_slice_spec(self): - dims = (4,4,4) - zcorn = list(GridGen.create_zcorn(dims, (1,1,1), offset=0)) - coord = list(GridGen.create_coord(dims, (1,1,1))) - - ijk_bounds = generate_ijk_bounds(dims) - for ijk in ijk_bounds: - ijk = list(ijk) - for i in range(3): - if len(set(ijk[i])) == 1: - ijk[i] = ijk[i][0] - - GridGen.extract_subgrid_data(dims, - coord, zcorn, - ijk, - decomposition_change=True) - - def assertSubgrid(self, grid, subgrid, ijk_bound): - sijk_space = prod(*[range(d) for d in subgrid.getDims()[:-1:]]) - for sijk in sijk_space: - gijk = tuple([a+b for a, b in zip(sijk, zip(*ijk_bound)[0])]) - - self.assertEqual( - [subgrid.getCellCorner(i, ijk=sijk) for i in range(8)], - [grid.getCellCorner(i, ijk=gijk) for i in range(8)] - ) - - self.assertEqual(grid.active(ijk=gijk), subgrid.active(ijk=sijk)) - - def test_validate_cells(self): - for coord, zcorn, grid in self.test_base: - grid_dims = grid.getDims()[:-1:] - ijk_bounds = generate_ijk_bounds(grid_dims) - for ijk_bound in ijk_bounds: - if not decomposition_preserving(ijk_bound): - continue - - sub_dims = tuple([u-l+1 for l, u in ijk_bound]) - sub_coord, sub_zcorn, _ = GridGen.extract_subgrid_data( - grid_dims, - coord, - zcorn, - ijk_bound - ) - - subgrid = EclGrid.create(sub_dims, sub_zcorn, sub_coord, None) - self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) - self.assertSubgrid(grid, subgrid, ijk_bound) - - def test_actnum_extraction(self): - dims = (4,4,4) - - coord = GridGen.create_coord(dims, (1,1,1)) - zcorn = GridGen.create_zcorn(dims, (1,1,1), offset=0) - - actnum = EclKW("ACTNUM", reduce(operator.mul, dims), EclDataType.ECL_INT) - random.seed(1337) - for i in range(len(actnum)): - actnum[i] = random.randint(0, 1) - - grid = EclGrid.create(dims, zcorn, coord, actnum) - - ijk_bounds = generate_ijk_bounds(dims) - for ijk_bound in ijk_bounds: - if not decomposition_preserving(ijk_bound): - continue - - sub = GridGen.extract_subgrid_data( - dims, - coord, - zcorn, - ijk_bound, - actnum=actnum - ) - - 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) - self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) - self.assertSubgrid(grid, subgrid, ijk_bound) - - def test_translation(self): - dims = (3,3,3) - - 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) - - ijk_bound = [(0, d-1) for d in dims] - translation = (1, 2, 3) - sub_coord, sub_zcorn, _ = GridGen.extract_subgrid_data( - dims, - coord, - zcorn, - ijk_bound, - translation=translation - ) - - tgrid = EclGrid.create(dims, sub_zcorn, sub_coord, None) - self.assertEqual(grid.getGlobalSize(), tgrid.getGlobalSize()) - - for gi in range(grid.getGlobalSize()): - translation = numpy.array(translation) - corners = [grid.getCellCorner(i, gi) for i in range(8)] - corners = [tuple(numpy.array(c)+translation) for c in corners] - - tcorners = [tgrid.getCellCorner(i, gi) for i in range(8)] - - self.assertEqual(corners, tcorners) - - def test_subgrid_extration(self): - for _, _, grid in self.test_base[:-1:]: - grid_dims = grid.getDims()[:-1:] - ijk_bounds = generate_ijk_bounds(grid_dims) - for ijk_bound in ijk_bounds: - if not decomposition_preserving(ijk_bound): - continue - - sub_dims = tuple([u-l+1 for l, u in ijk_bound]) - subgrid = GridGen.extract_subgrid(grid, ijk_bound) - - self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) - self.assertSubgrid(grid, subgrid, ijk_bound) - - def test_subgrid_translation(self): - grid = GridGen.create_grid((4,4,4), (1,1,1), offset=0.5, - irregular=True, irregular_offset=True, concave=True, - translation=(10,10,0)) - - # Create grid with MAPAXES - mapaxes = EclKW("MAPAXES", 6, EclDataType.ECL_FLOAT) - for i, val in enumerate([1200, 1400, 2500, 2500, 3700, 4000]): - mapaxes[i] = val - - grid = EclGrid.create( - grid.getDims(), - grid.export_zcorn(), - grid.export_coord(), - None, - mapaxes=mapaxes - ) - - for translation in [ - (0,0,0), - (10, 10, 100), - (-1, -1, -1) - ]: - subgrid = GridGen.extract_subgrid( - grid, - ((0,3), (0,3), (0,3)), - translation=translation - ) - - self.assertEqual(grid.getDims(), subgrid.getDims()) - - translation = numpy.array(translation) - for gindex in range(grid.getGlobalSize()): - grid_corners = [ - grid.getCellCorner(i, global_index=gindex) - for i in range(8) - ] - - subgrid_corners = [ - subgrid.getCellCorner(i, global_index=gindex) - for i in range(8) - ] - - subgrid_corners = [ - list(numpy.array(corner) - translation) - for corner in subgrid_corners - ] - - for gc, sc in zip(grid_corners, subgrid_corners): - self.assertAlmostEqualList( - gc, - sc, - msg="Failed to translate corners correctly." + - "Expected %s, was %s." % (gc, sc), - tolerance=10e-10 - ) diff --git a/ThirdParty/Ert/python/tests/ecl/test_grid_statoil.py b/ThirdParty/Ert/python/tests/ecl/test_grid_statoil.py deleted file mode 100644 index 89129deadc..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_grid_statoil.py +++ /dev/null @@ -1,408 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'test_grid.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import math - -try: - from unittest2 import skipIf -except ImportError: - from unittest import skipIf - -import time -from ecl.ecl import EclDataType, EclKW, EclGrid, EclFile, openEclFile -from ecl.util import DoubleVector, IntVector -from ecl.test import ExtendedTestCase , TestAreaContext - - -class GridTest(ExtendedTestCase): - def egrid_file(self): - return self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") - - - def grid_file(self): - return self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID") - - - def grdecl_file(self): - return self.createTestPath("Statoil/ECLIPSE/Gurbat/include/example_grid_sim.GRDECL") - - def test_loadFromFile(self): - g1 = EclGrid.loadFromFile( self.egrid_file() ) - g2 = EclGrid.loadFromFile( self.grdecl_file() ) - - self.assertTrue( isinstance( g1 , EclGrid ) ) - self.assertTrue( isinstance( g2 , EclGrid ) ) - - - def test_corner(self): - grid = EclGrid(self.egrid_file()) - nx = grid.getNX() - ny = grid.getNY() - nz = grid.getNZ() - - (x1,y1,z1) = grid.getCellCorner( 0 , ijk = (0,0,0)) - (x2,y2,z2) = grid.getLayerXYZ( 0 , 0 ) - self.assertEqual(x1,x2) - self.assertEqual(y1,y2) - self.assertEqual(z1,z2) - - (x1,y1,z1) = grid.getCellCorner( 0 , ijk = (0,1,0)) - (x2,y2,z2) = grid.getLayerXYZ( (nx + 1) , 0 ) - self.assertEqual(x1,x2) - self.assertEqual(y1,y2) - self.assertEqual(z1,z2) - - (x1,y1,z1) = grid.getCellCorner( 1 , ijk = (nx - 1,0,0)) - (x2,y2,z2) = grid.getLayerXYZ( nx , 0 ) - self.assertEqual(x1,x2) - self.assertEqual(y1,y2) - self.assertEqual(z1,z2) - - (x1,y1,z1) = grid.getCellCorner( 4 , ijk = (0,0,nz-1)) - (x2,y2,z2) = grid.getLayerXYZ( 0 , nz ) - self.assertEqual(x1,x2) - self.assertEqual(y1,y2) - self.assertEqual(z1,z2) - - (x1,y1,z1) = grid.getCellCorner( 7 , ijk = (nx-1,ny-1,nz-1)) - (x2,y2,z2) = grid.getLayerXYZ( (nx + 1)*(ny + 1) - 1 , nz ) - self.assertEqual(x1,x2) - self.assertEqual(y1,y2) - self.assertEqual(z1,z2) - - - - with self.assertRaises(IndexError): - grid.getLayerXYZ( -1 , 0 ) - - with self.assertRaises(IndexError): - grid.getLayerXYZ( (nx + 1)*(ny + 1) , 0 ) - - with self.assertRaises(IndexError): - grid.getLayerXYZ( 0 , -1 ) - - with self.assertRaises(IndexError): - grid.getLayerXYZ( 0 , nz + 1 ) - - - def test_GRID( self ): - grid = EclGrid(self.grid_file()) - self.assertTrue(grid) - - - - def test_EGRID( self ): - grid = EclGrid(self.egrid_file()) - self.assertTrue(grid) - dims = grid.getDims() - self.assertEqual(dims[0] , grid.getNX()) - self.assertEqual(dims[1] , grid.getNY()) - self.assertEqual(dims[2] , grid.getNZ()) - - - - def create(self, filename, load_actnum=True): - fileH = open(filename, "r") - specgrid = EclKW.read_grdecl(fileH, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False) - zcorn = EclKW.read_grdecl(fileH, "ZCORN") - coord = EclKW.read_grdecl(fileH, "COORD") - if load_actnum: - actnum = EclKW.read_grdecl(fileH, "ACTNUM", ecl_type=EclDataType.ECL_INT) - else: - actnum = None - - mapaxes = EclKW.read_grdecl(fileH, "MAPAXES") - grid = EclGrid.create(specgrid, zcorn, coord, actnum, mapaxes=mapaxes) - return grid - - - def test_rect(self): - with TestAreaContext("python/grid-test/testRect"): - a1 = 1.0 - a2 = 2.0 - a3 = 3.0 - grid = EclGrid.createRectangular((9, 9, 9), (a1, a2, a3)) - grid.save_EGRID("rect.EGRID") - grid2 = EclGrid("rect.EGRID") - self.assertTrue(grid) - self.assertTrue(grid2) - - (x, y, z) = grid.get_xyz(ijk=(4, 4, 4)) - self.assertAlmostEqualList([x, y, z], [4.5 * a1, 4.5 * a2, 4.5 * a3]) - - v = grid.cell_volume(ijk=(4, 4, 4)) - self.assertFloatEqual(v, a1 * a2 * a3) - - z = grid.depth(ijk=(4, 4, 4 )) - self.assertFloatEqual(z, 4.5 * a3) - - g1 = grid.global_index(ijk=(2, 2, 2)) - g2 = grid.global_index(ijk=(4, 4, 4)) - (dx, dy, dz) = grid.distance(g2, g1) - self.assertAlmostEqualList([dx, dy, dz], [2 * a1, 2 * a2, 2 * a3]) - - self.assertTrue(grid.cell_contains(2.5 * a1, 2.5 * a2, 2.5 * a3, ijk=(2, 2, 2))) - - #ijk = grid.find_cell(1.5 * a1 , 2.5 * a2 , 3.5 * a3) - #self.assertAlmostEqualList(ijk, [1, 2, 3]) - - - def test_create(self): - grid = self.create(self.grdecl_file()) - self.assertTrue(grid) - - - def test_grdecl_load(self): - with self.assertRaises(IOError): - grid = EclGrid.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") - - actnum = IntVector(default_value = 1 , initial_size = 1000) - actnum[0] = 0 - g1 = EclGrid.createRectangular((10,10,10) , (1,1,1) , actnum = actnum ) - self.assertEqual( g1.getNumActive() , actnum.elementSum() ) - g1.save_EGRID("G.EGRID") - - with openEclFile("G.EGRID") as f: - with open("grid.grdecl" , "w") as f2: - f2.write("SPECGRID\n") - f2.write(" 10 10 10 \'F\' /\n") - - coord_kw = f["COORD"][0] - coord_kw.write_grdecl( f2 ) - - zcorn_kw = f["ZCORN"][0] - zcorn_kw.write_grdecl( f2 ) - - actnum_kw = f["ACTNUM"][0] - actnum_kw.write_grdecl( f2 ) - - g2 = EclGrid.loadFromGrdecl("grid.grdecl") - self.assertTrue( g1.equal( g2 )) - - - - def test_ACTNUM(self): - g1 = self.create(self.grdecl_file()) - g2 = self.create(self.grdecl_file(), load_actnum=False) - self.assertTrue(g1.equal(g2)) - - - def test_time(self): - t0 = time.clock() - g1 = EclGrid(self.egrid_file()) - t1 = time.clock() - t = t1 - t0 - self.assertTrue(t < 1.0) - - - def test_save(self): - with TestAreaContext("python/grid-test/testSave"): - g1 = EclGrid(self.egrid_file()) - - g1.save_EGRID("test.EGRID") - g2 = EclGrid("test.EGRID") - self.assertTrue(g1.equal(g2)) - - g1.save_GRID("test.GRID") - g2 = EclGrid("test.GRID") - self.assertTrue(g1.equal(g2)) - - fileH = open("test.grdecl", "w") - g1.save_grdecl(fileH) - fileH.close() - g2 = self.create("test.grdecl") - self.assertTrue(g1.equal(g2)) - - @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of coarse grid skipped!") - def test_coarse(self): - #work_area = TestArea("python/grid-test/testCoarse") - with TestAreaContext("python/grid-test/testCoarse"): - testGRID = True - g1 = EclGrid(self.createTestPath("Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2.EGRID")) - - g1.save_EGRID("LGC.EGRID") - g2 = EclGrid("LGC.EGRID") - self.assertTrue(g1.equal(g2, verbose=True)) - - if testGRID: - g1.save_GRID("LGC.GRID") - g3 = EclGrid("LGC.GRID") - self.assertTrue(g1.equal(g3, verbose=True)) - - self.assertTrue(g1.coarse_groups() == 3384) - - - def test_raise_IO_error(self): - with self.assertRaises(IOError): - g = EclGrid("/does/not/exist.EGRID") - - def test_boundingBox(self): - grid = EclGrid.createRectangular((10,10,10) , (1,1,1)) - with self.assertRaises(ValueError): - bbox = grid.getBoundingBox2D(layer = -1 ) - - with self.assertRaises(ValueError): - bbox = grid.getBoundingBox2D( layer = 11 ) - - bbox = grid.getBoundingBox2D( layer = 10 ) - self.assertEqual( bbox , ((0,0) , (10, 0) , (10 , 10) , (0,10))) - - - with self.assertRaises(ValueError): - grid.getBoundingBox2D( lower_left = (-1,0) ) - - with self.assertRaises(ValueError): - grid.getBoundingBox2D( lower_left = (6,10) ) - - bbox = grid.getBoundingBox2D( lower_left = (3,3) ) - self.assertEqual( bbox , ((3,3) , (10,3) , (10,10) , (3,10))) - - with self.assertRaises(ValueError): - grid.getBoundingBox2D( lower_left = (3,3) , upper_right = (2,2)) - - bbox = grid.getBoundingBox2D( lower_left = (3,3) , upper_right = (7,7)) - self.assertEqual( bbox , ((3,3) , (7,3) , (7,7) , (3,7))) - - - - - - @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of dual grid skipped!") - def test_dual(self): - with TestAreaContext("python/grid-test/testDual"): - grid = EclGrid(self.egrid_file()) - self.assertFalse(grid.dualGrid()) - self.assertTrue(grid.getNumActiveFracture() == 0) - - grid2 = EclGrid(self.grid_file()) - self.assertFalse(grid.dualGrid()) - self.assertTrue(grid.getNumActiveFracture() == 0) - - dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID")) - self.assertTrue(dgrid.getNumActive() == dgrid.getNumActiveFracture()) - self.assertTrue(dgrid.getNumActive() == 46118) - - dgrid2 = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID")) - self.assertTrue(dgrid.getNumActive() == dgrid.getNumActiveFracture()) - self.assertTrue(dgrid.getNumActive() == 46118) - self.assertTrue(dgrid.equal(dgrid2)) - - - # 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(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID")) - self.assertTrue(dgrid.getNumActive() == 106) - self.assertTrue(dgrid.getNumActiveFracture() == 105) - - self.assertTrue(dgrid.get_active_fracture_index(global_index=0) == -1) - self.assertTrue(dgrid.get_active_fracture_index(global_index=2) == -1) - self.assertTrue(dgrid.get_active_fracture_index(global_index=3) == 0) - self.assertTrue(dgrid.get_active_fracture_index(global_index=107) == 104) - - self.assertTrue(dgrid.get_active_index(global_index=1) == 1) - self.assertTrue(dgrid.get_active_index(global_index=105) == 105) - self.assertTrue(dgrid.get_active_index(global_index=106) == -1) - self.assertTrue(dgrid.get_global_index1F(2) == 5) - - dgrid.save_EGRID("DUAL_DIFF.EGRID") - dgrid2 = EclGrid("DUAL_DIFF.EGRID") - self.assertTrue(dgrid.equal(dgrid2 , verbose = True)) - - - @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of numActive large memory skipped!") - def test_num_active_large_memory(self): - case = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE") - vecList = [] - for i in range(12500): - vec = DoubleVector() - vec[81920] = 0 - vecList.append(vec) - - grid1 = EclGrid(case) - grid2 = EclGrid(case) - self.assertEqual(grid1.getNumActive(), grid2.getNumActive()) - self.assertEqual(grid1.getNumActive(), 34770) - - - def test_no_mapaxes_check_for_nan(self): - grid_paths = ["Statoil/ECLIPSE/NoMapaxes/ECLIPSE.EGRID", "Statoil/ECLIPSE/NoMapaxes/ECLIPSE.GRID"] - - for grid_path in grid_paths: - test_grid_path = self.createTestPath(grid_path) - grid = EclGrid(test_grid_path) - - xyz = grid.get_xyz(ijk=(0, 0, 0)) - self.assertFalse(math.isnan(xyz[0])) - self.assertFalse(math.isnan(xyz[1])) - self.assertFalse(math.isnan(xyz[2])) - - xyz = grid.get_xyz(ijk=(1, 1, 1)) - self.assertFalse(math.isnan(xyz[0])) - self.assertFalse(math.isnan(xyz[1])) - self.assertFalse(math.isnan(xyz[2])) - - - def test_valid_geometry(self): - grid = EclGrid( self.createTestPath("Statoil/ECLIPSE/GRID_INVALID_CELL/PRED_RESEST_0_R_13_0.GRID")) - self.assertTrue( grid.validCellGeometry( ijk = (27,0,0)) ) - self.assertFalse( grid.validCellGeometry( ijk = (0,0,0)) ) - - - def test_volume_kw(self): - grid = EclGrid(self.egrid_file()) - vol = grid.createVolumeKeyword( ) - self.assertEqual( len(vol) , grid.getNumActive()) - for active_index , volume in enumerate(vol): - self.assertEqual( volume , grid.cell_volume( active_index = active_index )) - - vol = grid.createVolumeKeyword( active_size = False ) - self.assertEqual( len(vol) , grid.getGlobalSize()) - for global_index , volume in enumerate(vol): - self.assertEqual( volume , grid.cell_volume( global_index = global_index )) - - - - def test_large_case(self): - grdecl_file = self.createTestPath("Statoil/ECLIPSE/1.6.0_issueGrdecl/test_aug2016_gridOnly.grdecl") - grid = EclGrid.loadFromGrdecl( grdecl_file ) - - - def test_lgr_get(self): - grid = EclGrid(self.createTestPath("Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID")) - for (nr,name) in [ ( 104 , "LG003017"), - (2 , "LG006024"), - ( 4 , "LG005025"), - ( 82 , "LG011029"), - (100 , "LG007021"), - (110 , "LG003014")]: - lgr_name = grid.get_lgr( name ) - lgr_nr = grid.get_lgr( nr ) - - self.assertEqual( lgr_name , lgr_nr ) - - with self.assertRaises(KeyError): - grid.get_lgr("NO/SUCHLGR") - - with self.assertRaises(KeyError): - grid.get_lgr(1024) diff --git a/ThirdParty/Ert/python/tests/ecl/test_indexed_read.py b/ThirdParty/Ert/python/tests/ecl/test_indexed_read.py deleted file mode 100644 index 8de919409a..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_indexed_read.py +++ /dev/null @@ -1,116 +0,0 @@ -import ctypes -import ecl - -from ecl.ecl import EclPrototype -from ecl.ecl import EclKW, EclFile, EclDataType, FortIO -from ecl.test import ExtendedTestCase, TestAreaContext -from ecl.util import IntVector - -class EclIndexedReadTest(ExtendedTestCase): - _freadIndexedData = EclPrototype("void ecl_kw_fread_indexed_data_python(fortio, int, ecl_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*)", bind = False) # ecl_file, kw, index, index_map, buffer - - def test_ecl_kw_indexed_read(self): - with TestAreaContext("ecl_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) - - for index in range(element_count): - ecl_kw[index] = index - - ecl_kw.fwrite(fortio) - - fortio.close() - - - fortio = FortIO("index_test", mode=FortIO.READ_MODE) - - new_ecl_kw = EclKW.fread(fortio) - - for index in range(element_count): - self.assertEqual(new_ecl_kw[index], index) - - index_map = IntVector() - index_map.append(2) - index_map.append(3) - index_map.append(5) - index_map.append(7) - index_map.append(11) - index_map.append(13) - index_map.append(313) - index_map.append(1867) - index_map.append(5227) - index_map.append(7159) - index_map.append(12689) - index_map.append(18719) - index_map.append(32321) - index_map.append(37879) - index_map.append(54167) - index_map.append(77213) - index_map.append(88843) - index_map.append(99991) - - char_buffer = ctypes.create_string_buffer(len(index_map) * ctypes.sizeof(ctypes.c_int)) - - self._freadIndexedData(fortio, 24, EclDataType.ECL_INT, element_count, index_map, char_buffer) - - int_buffer = ctypes.cast(char_buffer, ctypes.POINTER(ctypes.c_int)) - - 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) - - element_count = 100000 - ecl_kw_1 = EclKW("TEST1", element_count, EclDataType.ECL_INT) - ecl_kw_2 = EclKW("TEST2", element_count, EclDataType.ECL_INT) - - for index in range(element_count): - ecl_kw_1[index] = index - ecl_kw_2[index] = index + 3 - - ecl_kw_1.fwrite(fortio) - ecl_kw_2.fwrite(fortio) - - fortio.close() - - ecl_file = EclFile("ecl_file_index_test") - - index_map = IntVector() - index_map.append(2) - index_map.append(3) - index_map.append(5) - index_map.append(7) - index_map.append(11) - index_map.append(13) - index_map.append(313) - index_map.append(1867) - index_map.append(5227) - index_map.append(7159) - index_map.append(12689) - index_map.append(18719) - index_map.append(32321) - index_map.append(37879) - index_map.append(54167) - index_map.append(77213) - index_map.append(88843) - index_map.append(99991) - - char_buffer_1 = ctypes.create_string_buffer(len(index_map) * ctypes.sizeof(ctypes.c_int)) - char_buffer_2 = ctypes.create_string_buffer(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) - - 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)) - - for index, index_map_value in enumerate(index_map): - self.assertEqual(index_map_value, int_buffer_1[index]) - self.assertEqual(index_map_value, int_buffer_2[index] - 3) diff --git a/ThirdParty/Ert/python/tests/ecl/test_kw_function.py b/ThirdParty/Ert/python/tests/ecl/test_kw_function.py deleted file mode 100644 index 4f45f2f313..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_kw_function.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'test_kw_function.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os -import random -from ecl.ecl import EclKW, EclDataType, EclGrid , Ecl3DKW -from ecl.util import IntVector -from ecl.test import ExtendedTestCase - -class KWFunctionTest(ExtendedTestCase): - - def test_region_filter(self): - nx = 10 - ny = 10 - nz = 1 - 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) - self.assertEqual( grid.getNumActive() , nx*ny*nz - 1 ) - - kw = Ecl3DKW.create( "REGIONS" , grid , EclDataType.ECL_INT , global_active = True ) - kw.assign( 0 ) - kw[0:nx*ny/2] = 1 - kw[5,2,0] = 0 - kw[0,9,0] = 2 - - kw.fixUninitialized( grid ) - - # Not assigned because they are in contact with a '2'; these - # two are problem cells. - self.assertEqual( kw[0,ny - 2,0] , 0) - self.assertEqual( kw[1,ny - 1,0] , 0) - - # Not assigned because it is inactive - self.assertEqual( kw[nx - 1,ny - 1,0] , 0) - - self.assertEqual( kw[5,2,0] , 1 ) - for j in range(5,10): - self.assertEqual( kw[5,j,0] , 1 ) - - for i in range(10): - self.assertEqual( kw[i,7,0] , 1 ) - diff --git a/ThirdParty/Ert/python/tests/ecl/test_layer.py b/ThirdParty/Ert/python/tests/ecl/test_layer.py deleted file mode 100644 index 370eb6ae8e..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_layer.py +++ /dev/null @@ -1,306 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'test_layer.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from unittest import skipIf -import time - -from ecl.util import IntVector -from ecl.ecl import EclGrid -from ecl.geo import CPolyline -from ecl.ecl.faults import Layer , FaultCollection -from ecl.test import ExtendedTestCase , TestAreaContext - - -class LayerTest(ExtendedTestCase): - def setUp(self): - pass - - - def test_create_layer(self): - layer = Layer(10,10) - self.assertTrue( isinstance( layer , Layer )) - - - def test_add_cell(self): - layer = Layer(10,10) - with self.assertRaises(ValueError): - layer[100,100] = 199 - - with self.assertRaises(ValueError): - layer[100,"X"] = 199 - - with self.assertRaises(ValueError): - layer[100] = 199 - - layer[5,5] = 88 - self.assertEqual(layer[5,5] , 88) - - - - def test_contact(self): - nx = 20 - ny = 10 - layer = Layer(nx,ny) - grid = EclGrid.createRectangular( (nx,ny,1) , (1,1,1) ) - - with self.assertRaises(IndexError): - layer.cellContact( (-1,0),(1,1) ) - - with self.assertRaises(IndexError): - layer.cellContact( (20,0),(1,1) ) - - - self.assertFalse( layer.cellContact((0,0) , (2,0)) ) - self.assertFalse( layer.cellContact((1,0) , (1,0)) ) - - self.assertTrue( layer.cellContact((0,0) , (1,0)) ) - self.assertTrue( layer.cellContact((1,0) , (0,0)) ) - - self.assertTrue( layer.cellContact((0,0) , (0,1)) ) - self.assertTrue( layer.cellContact((0,1) , (0,0)) ) - - self.assertFalse( layer.cellContact((0,0) , (1,1)) ) - self.assertFalse( layer.cellContact((1,1) , (0,0)) ) - - self.assertTrue( layer.cellContact((4,0) , (5,0)) ) - self.assertTrue( layer.cellContact((0,4) , (0,5)) ) - - with TestAreaContext("Layer/barrier"): - with open("faults.grdecl" , "w") as f: - f.write("FAULTS\n") - f.write("\'FX\' 5 5 1 10 1 1 'X' /\n") - f.write("\'FY\' 1 10 5 5 1 1 'Y' /\n") - f.write("/") - - faults = FaultCollection( grid , "faults.grdecl") - - layer.addFaultBarrier( faults["FX"] , 0 ) - self.assertFalse( layer.cellContact((4,0) , (5,0)) ) - - layer.addFaultBarrier( faults["FY"] , 0 ) - self.assertFalse( layer.cellContact((0,4) , (0,5)) ) - - self.assertFalse( layer.cellContact((9,4) , (9,5)) ) - self.assertTrue( layer.cellContact((10,4) , (10,5)) ) - - def test_get_barrier(self): - layer = Layer(10,10) - self.assertFalse( layer.leftBarrier(5,5) ) - self.assertFalse( layer.bottomBarrier(5,5) ) - - layer.addIJBarrier([(1,1),(2,1),(2,2)]) - self.assertTrue( layer.bottomBarrier(1,1) ) - self.assertTrue( layer.leftBarrier(2,1) ) - - - - def test_fault_barrier(self): - nx = 120 - ny = 60 - nz = 43 - grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) - with TestAreaContext("python/faults/line_order"): - with open("faults.grdecl" , "w") as f: - f.write("""FAULTS -\'F\' 105 107 50 50 1 43 \'Y\' / -\'F\' 108 108 50 50 1 43 \'X\' / -\'F\' 108 108 50 50 22 43 \'Y\' / -\'F\' 109 109 49 49 1 43 \'Y\' / -\'F\' 110 110 49 49 1 43 \'X\' / -\'F\' 111 111 48 48 1 43 \'Y\' / -/ -""") - with open("faults.grdecl") as f: - faults = FaultCollection( grid , "faults.grdecl" ) - - - # Fault layout: - # - # +---+---+---+---+ - # | - # +---+ + - # | - # +---+ - - - fault = faults["F"] - layer = Layer(nx,ny) - fault_pairs = [((104,49),(104,50)), - ((105,49),(105,50)), - ((106,49),(106,50)), - ((107,49),(108,49)), - ((107,49),(107,50)), - ((108,48),(108,49)), - ((109,48),(110,48)), - ((110,47),(110,48))] - gap_pair = ((109,48),(109,49)) - - - for p1,p2 in fault_pairs: - self.assertTrue(layer.cellContact( p1 , p2 )) - - p1,p2 = gap_pair - self.assertTrue(layer.cellContact( p1 , p2 )) - - - layer.addFaultBarrier(fault , 30 , link_segments = False) - for p1,p2 in fault_pairs: - self.assertFalse(layer.cellContact( p1 , p2 )) - p1,p2 = gap_pair - self.assertTrue(layer.cellContact( p1 , p2 )) - - layer.addFaultBarrier(fault , 30) - p1,p2 = gap_pair - self.assertFalse(layer.cellContact( p1 , p2 )) - - - def test_contact2(self): - nx = 10 - ny = 10 - layer = Layer(nx,ny) - grid = EclGrid.createRectangular( (nx,ny,1) , (1,1,1) ) - - # Too short - with self.assertRaises(ValueError): - layer.addIJBarrier( [(1,5)] ) - - # Out of range - with self.assertRaises(ValueError): - layer.addIJBarrier( [(10,15),(5,5)] ) - - # Out of range - with self.assertRaises(ValueError): - layer.addIJBarrier( [(7,7),(-5,5)] ) - - # Must have either i1 == i2 or j1 == j2 - with self.assertRaises(ValueError): - layer.addIJBarrier( [(7,8),(6,5)] ) - - p1 = (0 , 4) - p2 = (0 , 5) - self.assertTrue(layer.cellContact( p1 , p2 )) - layer.addIJBarrier( [(0,5) , (nx , 5)] ) - self.assertFalse(layer.cellContact( p1 , p2 )) - - - - def test_update_connected(self): - nx = 10 - ny = 10 - layer = Layer(nx,ny) - - layer[0,0] = 100 - self.assertEqual( layer[0,0], 100 ) - layer.clearCells() - self.assertEqual( layer[0,0], 0 ) - self.assertEqual( layer.cellSum( ) , 0 ) - - with self.assertRaises(ValueError): - layer.updateConnected( (10,10) , 10 ) - - layer[0,0] = 77 - with self.assertRaises(ValueError): - layer.updateConnected( (0,0) , 10 , org_value = 0) - - layer.updateConnected( (0,0) , 10 ) - self.assertEqual( 10 , layer.cellSum() ) - - layer[0,0] = 0 - layer.updateConnected( (0,0) , 3 ) - self.assertEqual( nx*ny*3 , layer.cellSum() ) - - layer.addIJBarrier( [(5,0), (5,10)] ) - layer.clearCells( ) - self.assertEqual( 0 , layer.cellSum( ) ) - layer.updateConnected( (0,0) , 1 ) - - self.assertEqual( 50 , layer.cellSum( ) ) - self.assertEqual( layer[4,0] , 1 ) - self.assertEqual( layer[5,0] , 0 ) - - layer = Layer(nx,ny) - layer.addIJBarrier( [(5,0), (5,5)] ) - layer.updateConnected( (0,0) , 1 ) - self.assertEqual( 100 , layer.cellSum( ) ) - - - def test_matching(self): - d = 10 - layer = Layer(d,d) - - for i in range(d): - layer[i,i] = 10 - - cell_list = layer.cellsEqual( 1 ) - self.assertEqual( cell_list , [] ) - - cell_list = layer.cellsEqual( 10 ) - self.assertEqual( cell_list , [ (i,i) for i in range(d)] ) - - - def test_add_polyline_barrier(self): - d = 10 - layer = Layer(d,d) - grid = EclGrid.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): - self.assertTrue( layer.bottomBarrier(i,i) ) - if i < (d - 1): - self.assertTrue( layer.leftBarrier(i+1,i) ) - - - def test_active(self): - d = 10 - layer = Layer(d,d) - with self.assertRaises( ValueError ): - layer.activeCell(d+1,d+2) - - self.assertTrue( layer.activeCell(1,2) ) - - grid = EclGrid.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) ) - 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) - layer.updateActive( grid , 0 ) - self.assertTrue( layer.activeCell(1,2) ) - self.assertFalse( layer.activeCell(0,0) ) - - - def test_assign(self): - layer = Layer(10,5) - self.assertEqual( layer.cellSum() , 0 ) - - layer.assign(10) - self.assertEqual( layer.cellSum() , 500 ) - - - - def test_count_equal(self): - layer = Layer(10,10) - self.assertEqual( 100 , layer.countEqual( 0 )) - self.assertEqual( 0 , layer.countEqual( 1 )) - - layer[3,3] = 3 - self.assertEqual( 1 , layer.countEqual( 3 )) diff --git a/ThirdParty/Ert/python/tests/ecl/test_npv.py b/ThirdParty/Ert/python/tests/ecl/test_npv.py deleted file mode 100644 index dceda077c1..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_npv.py +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import os -import datetime -import math - -try: - from unittest2 import skipIf, skipUnless, skipIf -except ImportError: - from unittest import skipIf, skipUnless, skipIf - -from ecl.ecl import EclSum -from ecl.ecl import EclNPV , NPVPriceVector - -from ecl.util import StringList, TimeVector, DoubleVector , CTime -from ecl.test import ExtendedTestCase , TestAreaContext - - -base = "ECLIPSE" -path = "Statoil/ECLIPSE/Gurbat" -case = "%s/%s" % (path, base) - -def callable(x): - return 1 - -def linear1(x): - return x - -def linear2(x): - return 2*x - - -class NPVTest(ExtendedTestCase): - def setUp(self): - self.case = self.createTestPath(case) - - - def test_create(self): - with self.assertRaises(Exception): - npv = EclNPV("/does/not/exist") - - npv = EclNPV( self.case ) - - - def test_eval_npv(self): - npv = EclNPV( self.case ) - with self.assertRaises(ValueError): - npv.eval() - - - def test_expression(self): - npv = EclNPV( self.case ) - self.assertIsNone( npv.getExpression() ) - npv.setExpression( "[FOPT]*$OIL_PRICE - [FGIT]*$GAS_PRICE") - self.assertEqual( npv.getExpression() , "[FOPT]*$OIL_PRICE - [FGIT]*$GAS_PRICE") - self.assertIn( "FOPT" , npv.getKeyList() ) - self.assertIn( "FGIT" , npv.getKeyList() ) - - with self.assertRaises(ValueError): - npv.parseExpression("[FOPT") - - with self.assertRaises(ValueError): - npv.parseExpression("FOPT]") - - with self.assertRaises(KeyError): - npv.parseExpression("[FoPT]") - - with self.assertRaises(ValueError): - npv.parseExpression("[FOPR]") - - parsedExpression = npv.parseExpression("[FOPT]") - self.assertEqual( parsedExpression , "FOPT[i]") - self.assertEqual( 1 , len(npv.getKeyList() )) - - - parsedExpression = npv.parseExpression("[FOPT]*2 + [FGPT] - [WOPT:OP_1]") - self.assertEqual( parsedExpression , "FOPT[i]*2 + FGPT[i] - WOPT_OP_1[i]") - keyList = npv.getKeyList() - self.assertEqual( 3 , len(keyList)) - self.assertIn( "FOPT" , keyList ) - self.assertIn( "FGPT" , keyList ) - self.assertIn( "WOPT:OP_1" , keyList ) - - - def test_period(self): - npv = EclNPV( self.case ) - self.assertIsNone(npv.start) - self.assertIsNone(npv.end) - self.assertEqual("1Y" , npv.interval) - - - def test_eval(self): - npv = EclNPV(self.case) - npv.compile("[FOPT]") - npv1 = npv.evalNPV() - - npv2 = 0 - sum = EclSum(self.case) - trange = sum.timeRange() - fopr = sum.blockedProduction("FOPT" , trange) - for v in fopr: - npv2 += v - self.assertAlmostEqual( npv1 , npv2 ) - - npv.compile("[FOPT] - 0.5*[FOPT] - 0.5*[FOPT]") - npv1 = npv.evalNPV() - self.assertTrue( abs(npv1) < 1e-2 ) - - npv.compile("[WOPT:OP_1] - 0.5*[WOPT:OP_1] - 0.5*[WOPT:OP_1]") - npv1 = npv.evalNPV() - self.assertTrue( abs(npv1) < 1e-2 ) - - - - def test_price_vector(self): - with self.assertRaises(ValueError): - NPVPriceVector("NotList") - - with self.assertRaises(ValueError): - NPVPriceVector(1.25) - - with self.assertRaises(ValueError): - NPVPriceVector((1,25)) - - with self.assertRaises(ValueError): - NPVPriceVector([1,2,3]) - - with self.assertRaises(ValueError): - NPVPriceVector([(1,25) , ("String",100,100)]) - - with self.assertRaises(ValueError): - NPVPriceVector([(1,25) , ("String",100)]) - - NPVPriceVector([(datetime.datetime(2010 , 1 , 1 , 0 , 0 , 0) , 100)]) - NPVPriceVector([(datetime.date(2010 , 1 , 1 ) , 100)]) - NPVPriceVector([("19/06/2010" , 100)]) - - with self.assertRaises(ValueError): - NPVPriceVector([("01/01/2000" , 100), - ("01/01/1999" , 100)]) - - with self.assertRaises(ValueError): - NPVPriceVector([("01/01/2000" , "String")]) - - NPVPriceVector([("01/01/2000" , 100)]) - NPVPriceVector([("01/01/2000" , 77.99)]) - NPVPriceVector([("01/01/2000" , callable)]) - - - vec = NPVPriceVector([("01/01/2000" , 100), - ("01/02/2000" , 200), - ("01/03/2000" , 300)]) - - with self.assertRaises(ValueError): - vec.eval( datetime.date( 1999 , 1 , 1)) - - self.assertEqual( datetime.date( 2000 , 1 , 1 ) , NPVPriceVector.assertDate( datetime.date(2000,1,1) )) - self.assertEqual( datetime.date( 2000 , 1 , 1 ) , NPVPriceVector.assertDate( CTime(datetime.date(2000,1,1)) )) - - - self.assertEqual( 100 , vec.eval( datetime.date( 2000 , 1 , 10))) - self.assertEqual( 100 , vec.eval( datetime.datetime( 2000 , 1 , 10 , 0,0,0))) - self.assertEqual( 100 , vec.eval( CTime(datetime.datetime( 2000 , 1 , 10 , 0,0,0)))) - - self.assertEqual( 300 , vec.eval( datetime.date( 2000 , 4, 1))) - - - vec = NPVPriceVector([("01/01/2000" , linear1), - ("01/02/2000" , linear2), - ("01/03/2000" , 300)]) - - self.assertEqual( 300 , vec.eval( datetime.date( 2000 , 3 , 10))) - self.assertEqual( 0 , vec.eval( datetime.date( 2000 , 1 , 1) )) - self.assertEqual( 10 , vec.eval( datetime.date( 2000 , 1 , 11) )) - self.assertEqual( 20 , vec.eval( datetime.date( 2000 , 1 , 21) )) - - self.assertEqual( 0 , vec.eval( datetime.date( 2000 , 2 , 1) )) - self.assertEqual( 20 , vec.eval( datetime.date( 2000 , 2 , 11) )) - self.assertEqual( 40 , vec.eval( datetime.date( 2000 , 2 , 21) )) diff --git a/ThirdParty/Ert/python/tests/ecl/test_region.py b/ThirdParty/Ert/python/tests/ecl/test_region.py deleted file mode 100644 index b24b3d7969..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_region.py +++ /dev/null @@ -1,89 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# The file 'test_region.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -from ecl.ecl import EclGrid, EclKW, EclRegion, EclDataType -from ecl.ecl.faults import Layer -from ecl.test import ExtendedTestCase -from ecl.util import IntVector - -class RegionTest(ExtendedTestCase): - - 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 ) - - kw_int[0:49] = 1 - region = EclRegion(grid, False) - region.select_equal( kw_int , 1 ) - glist = region.getGlobalList() - for g in glist: - self.assertEqual( kw_int[g] , 1 ) - - with self.assertRaises(ValueError): - 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 ) - - kw_mask[0:50] = 1 - - for i in range(len(int_value)): - float_value[i] = i - double_value[i] = i - int_value[i] = i - bool_value[i] = True - - region = EclRegion(grid, False) - region.select_equal( kw_mask , 1 ) - - self.assertEqual( int_value.sum( ) , 99*100/2 ) - self.assertEqual( int_value.sum( mask = region ) , 49*50/2 ) - self.assertEqual( double_value.sum( mask = region ) , 1.0*49*50/2 ) - self.assertEqual( float_value.sum( mask = region ) , 1.0*49*50/2 ) - self.assertEqual( bool_value.sum( mask = region ) , 50 ) - - - 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) - - self.assertFalse( region ) - self.assertEqual( 0, region.active_size( )) - self.assertEqual( 0, region.global_size( )) - - region.select_all( ) - self.assertTrue( region ) - self.assertEqual( 50, region.active_size( )) - self.assertEqual( 100, region.global_size( )) - - region.deselect_all() - self.assertFalse( region ) - self.assertEqual( 0, region.active_size( )) - self.assertEqual( 0, region.global_size( )) - - region = EclRegion(grid, False) - region.select_inactive() - self.assertTrue( region ) - self.assertEqual( 0 , region.active_size( )) - self.assertEqual( 50, region.global_size( )) - diff --git a/ThirdParty/Ert/python/tests/ecl/test_region_statoil.py b/ThirdParty/Ert/python/tests/ecl/test_region_statoil.py deleted file mode 100644 index fbe0c8035c..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_region_statoil.py +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'test_region.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -from ecl.ecl import EclFile, EclGrid, EclRegion -from ecl.ecl.faults import Layer -from ecl.test import ExtendedTestCase - - -class RegionTest(ExtendedTestCase): - def setUp(self): - case = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE") - self.grid = EclGrid(case) - self.rst_file = EclFile("%s.UNRST" % case) - self.init_file = EclFile("%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.select_more(P, 260) - fipnum.mul(-1, mask=reg) - self.assertFalse(fipnum.equal(fipnum_copy)) - - fipnum.mul(-1, mask=reg) - self.assertTrue(fipnum.equal(fipnum_copy)) - - def test_equal(self): - reg1 = EclRegion(self.grid , False) - reg2 = EclRegion(self.grid , False) - - self.assertTrue( reg1 == reg2 ) - - reg1.select_islice(4 , 6) - self.assertFalse( reg1 == reg2 ) - reg2.select_islice(4,7) - self.assertFalse( reg1 == reg2 ) - reg1.select_islice(7,7) - self.assertTrue( reg1 == reg2 ) - - - def test_kw_idiv(self): - P = self.rst_file["PRESSURE"][5] - fipnum = self.init_file["FIPNUM"][0] - fipnum_copy = fipnum.deep_copy() - - reg = EclRegion(self.grid, False) - reg.select_more(P, 260) - fipnum.div(-1, mask=reg) - self.assertFalse(fipnum.equal(fipnum_copy)) - - fipnum.div(-1, mask=reg) - self.assertTrue(fipnum.equal(fipnum_copy)) - - - def test_kw_iadd(self): - P = self.rst_file["PRESSURE"][5] - fipnum = self.init_file["FIPNUM"][0] - fipnum_copy = fipnum.deep_copy() - - reg = EclRegion(self.grid, False) - reg.select_more(P, 260) - fipnum.add(1, mask=reg) - self.assertFalse(fipnum.equal(fipnum_copy)) - - reg.invert() - fipnum.add(1, mask=reg) - - fipnum.sub(1) - self.assertTrue(fipnum.equal(fipnum_copy)) - - - def test_kw_isub(self): - P = self.rst_file["PRESSURE"][5] - fipnum = self.init_file["FIPNUM"][0] - fipnum_copy = fipnum.deep_copy() - - reg = EclRegion(self.grid, False) - reg.select_more(P, 260) - fipnum.sub(1, mask=reg) - self.assertFalse(fipnum.equal(fipnum_copy)) - fipnum.add(1, mask=reg) - self.assertTrue(fipnum.equal(fipnum_copy)) - - - def test_slice(self): - reg = EclRegion(self.grid, False) - reg.select_islice(0, 5) - OK = True - - global_list = reg.getGlobalList() - self.assertEqual(global_list.parent(), reg) - - for gi in global_list: - (i, j, k) = self.grid.get_ijk(global_index=gi) - if i > 5: - OK = False - self.assertTrue(OK) - self.assertTrue(self.grid.getNY() * self.grid.getNZ() * 6 == len(reg.getGlobalList())) - - reg.select_jslice(7, 8, intersect=True) - OK = True - for gi in reg.getGlobalList(): - (i, j, k) = self.grid.get_ijk(global_index=gi) - if i > 5: - OK = False - - if j < 7 or j > 8: - OK = False - - self.assertTrue(OK) - self.assertTrue(2 * self.grid.getNZ() * 6 == len(reg.getGlobalList())) - - reg2 = EclRegion(self.grid, False) - reg2.select_kslice(3, 5) - reg &= reg2 - OK = True - for gi in reg.getGlobalList(): - (i, j, k) = self.grid.get_ijk(global_index=gi) - if i > 5: - OK = False - - if j < 7 or j > 8: - OK = False - - if k < 3 or k > 5: - OK = False - - self.assertTrue(OK) - self.assertTrue(2 * 3 * 6 == len(reg.getGlobalList())) - - - - def test_index_list(self): - reg = EclRegion(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) - (x,y,z) = self.grid.get_xyz( ijk=(10,10,0) ) - dx = 0.1 - dy = 0.1 - reg.select_inside_polygon( [(x-dx,y-dy) , (x-dx,y+dy) , (x+dx,y+dy) , (x+dx,y-dy)] ) - self.assertTrue( self.grid.getNZ() == len(reg.getGlobalList())) - - - def test_heidrun(self): - root = self.createTestPath("Statoil/ECLIPSE/Heidrun") - grid = EclGrid( "%s/FF12_2013B2_AMAP_AOP-J15_NO62_MOVEX.EGRID" % root) - - polygon = [] - with open("%s/polygon.ply" % root) as fileH: - for line in fileH.readlines(): - tmp = line.split() - polygon.append( (float(tmp[0]) , float(tmp[1]))) - self.assertEqual( len(polygon) , 11 ) - - reg = EclRegion( grid , False ) - reg.select_inside_polygon( polygon ) - self.assertEqual( 0 , len(reg.getGlobalList()) % grid.getNZ()) - - - def test_layer(self): - region = EclRegion(self.grid, False) - layer = Layer( self.grid.getNX() , self.grid.getNY() + 1) - with self.assertRaises(ValueError): - region.selectFromLayer( layer , 0 , 1 ) - - layer = Layer( self.grid.getNX() , self.grid.getNY() ) - layer[0,0] = 1 - layer[1,1] = 1 - layer[2,2] = 1 - - with self.assertRaises(ValueError): - region.selectFromLayer( layer , -1 , 1 ) - - with self.assertRaises(ValueError): - region.selectFromLayer( layer , self.grid.getNZ() , 1 ) - - region.selectFromLayer( layer , 0 , 2 ) - glist = region.getGlobalList() - self.assertEqual(0 , len(glist)) - - region.selectFromLayer( layer , 0 , 1 ) - glist = region.getGlobalList() - self.assertEqual(3 , len(glist)) diff --git a/ThirdParty/Ert/python/tests/ecl/test_removed.py b/ThirdParty/Ert/python/tests/ecl/test_removed.py deleted file mode 100644 index fd41e1e434..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_removed.py +++ /dev/null @@ -1,34 +0,0 @@ -import time -import datetime - -from ecl.test import ExtendedTestCase, TestAreaContext -from ecl.ecl import EclFile,EclKW,EclDataType,openFortIO, FortIO - - - -class Removed_2_1_Test(ExtendedTestCase): - def test_ecl_file_block(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 ) - - t.sync() - - f = EclFile( "TEST" ) - with self.assertRaises(NotImplementedError): - f.select_block( "KW" , 100 ) - - with self.assertRaises(NotImplementedError): - f.select_global( ) - - with self.assertRaises(NotImplementedError): - f.select_restart_section( index = None , report_step = None , sim_time = None) - - with self.assertRaises(NotImplementedError): - f.select_restart_section( ) - - with self.assertRaises(NotImplementedError): - EclFile.restart_block( "TEST" ) - diff --git a/ThirdParty/Ert/python/tests/ecl/test_restart.py b/ThirdParty/Ert/python/tests/ecl/test_restart.py deleted file mode 100644 index c9e91be399..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_restart.py +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -from _ctypes import ArgumentError -import os -import datetime -from ecl.ecl import EclFile -from ecl.test import ExtendedTestCase - - - - - -class RestartTest(ExtendedTestCase): - def setUp(self): - self.xfile0 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0000") - self.u_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") - self.fmt_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.FUNRST") - self.grid_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") - 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 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)) - - f = EclFile(fname) - self.assertTrue(f.has_report_step(4)) - self.assertTrue(f.has_report_step(0)) - self.assertTrue(f.has_report_step(62)) - - self.assertFalse(f.has_report_step(-1)) - self.assertFalse(f.has_report_step(100)) - - - def test_report(self): - self.report_file_test(self.u_file) - - - def test_date(self): - f = EclFile(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))) - self.assertFalse(EclFile.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))) - self.assertFalse(EclFile.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) - self.assertListEqual(rlist, rlist0) - - f = EclFile(fname) - rlist = f.report_list - self.assertListEqual(rlist, rlist0) - - - def test_report_list(self): - rlist0 = range(63) - self.report_list_file_test(self.u_file, rlist0) - - rlist0 = [0] - self.report_list_file_test(self.xfile0, rlist0) - - f = EclFile(self.grid_file) - with self.assertRaises(ArgumentError): #argumentError wraps the expected TypeError - EclFile.file_report_list(f) - - - def test_dates(self): - f = EclFile(self.u_file) - dates = f.dates - self.assertTrue(len(dates) == 63) - - f = EclFile(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) - self.assertTrue(f.getFilename() == self.u_file) - - f = EclFile(self.xfile0) - self.assertTrue(f.getFilename() == self.xfile0) - - - def test_kw( self ): - f = EclFile(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) - - self.assertTrue(kw1.equal(kw2)) - self.assertTrue(kw1.equal(kw3)) - - with self.assertRaises(IndexError): - kw4 = f.restart_get_kw("SWAT", datetime.datetime(2009, 3, 17)) - diff --git a/ThirdParty/Ert/python/tests/ecl/test_restart_head.py b/ThirdParty/Ert/python/tests/ecl/test_restart_head.py deleted file mode 100644 index bd1468a73e..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_restart_head.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'test_ecl_init_file.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import datetime - -from ecl.test import ExtendedTestCase -from ecl.ecl import Ecl3DKW , EclKW, EclRestartFile , EclFile, FortIO, EclFileFlagEnum , EclGrid - -class RestartHeadTest(ExtendedTestCase): - def setUp(self): - self.grid_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") - self.unrst_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") - self.xrst_file0 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0000") - - def test_headers(self): - g = EclGrid( self.grid_file ) - f = EclRestartFile( g , self.unrst_file ) - - headers = f.headers( ) - self.assertEqual( len(headers) , 63 ) - - with self.assertRaises(IndexError): - f.get_header(1000) - - header = f.get_header( 10 ) - details = header.well_details( ) - self.assertTrue( "NXCONZ" in details ) - self.assertTrue( "NCWMAX" in details ) - diff --git a/ThirdParty/Ert/python/tests/ecl/test_rft.py b/ThirdParty/Ert/python/tests/ecl/test_rft.py deleted file mode 100644 index 3ff440b42c..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_rft.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2016 Statoil ASA, Norway. -# -# The file 'test_rft.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -import datetime -from ecl.util import CTime -from ecl.ecl import EclRFTFile, EclRFTCell, EclPLTCell -from ecl.ecl.rft import WellTrajectory -from ecl.test import ExtendedTestCase -from ecl.ecl import EclRFT - -class RFTTest(ExtendedTestCase): - - 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, MSW)' - self.assertEqual(pfx, repr(rft)[:len(pfx)]) diff --git a/ThirdParty/Ert/python/tests/ecl/test_rft_cell.py b/ThirdParty/Ert/python/tests/ecl/test_rft_cell.py deleted file mode 100644 index 87276f6ad3..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_rft_cell.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'test_rft_cell.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -from ecl.ecl import EclRFTCell, EclPLTCell -from ecl.test import ExtendedTestCase - - -# def out_of_range(): -# rftFile = ecl.EclRFTFile(RFT_file) -# rft = rftFile[100] - - -class RFTCellTest(ExtendedTestCase): - def setUp(self): - self.RFT_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT") - self.PLT_file = self.createTestPath("Statoil/ECLIPSE/RFT/TEST1_1A.RFT") - - def test_RFT_cell(self): - i = 10 - j = 8 - k = 100 - depth = 100 - pressure = 65 - swat = 0.56 - sgas = 0.10 - cell = EclRFTCell(i, j, k, depth, pressure, swat, sgas) - - self.assertEqual(i, cell.get_i()) - self.assertEqual(j, cell.get_j()) - self.assertEqual(k, cell.get_k()) - - self.assertFloatEqual(pressure, cell.pressure) - self.assertFloatEqual(depth, cell.depth) - self.assertFloatEqual(swat, cell.swat) - self.assertFloatEqual(sgas, cell.sgas) - self.assertFloatEqual(1 - (sgas + swat), cell.soil) - - - def test_PLT_cell(self): - i = 2 - j = 16 - k = 100 - depth = 100 - pressure = 65 - orat = 0.78 - grat = 88 - wrat = 97213 - conn_start = 214 - conn_end = 400 - flowrate = 111 - oil_flowrate = 12 - gas_flowrate = 132 - water_flowrate = 13344 - - cell = EclPLTCell(i, j, k, depth, pressure, orat, grat, wrat, conn_start, conn_end, flowrate, - oil_flowrate, gas_flowrate, water_flowrate) - - - self.assertEqual(i, cell.get_i()) - self.assertEqual(j, cell.get_j()) - self.assertEqual(k, cell.get_k()) - - self.assertFloatEqual(pressure, cell.pressure) - self.assertFloatEqual(depth, cell.depth) - self.assertFloatEqual(orat, cell.orat) - self.assertFloatEqual(grat, cell.grat) - self.assertFloatEqual(wrat, cell.wrat) - - self.assertFloatEqual(conn_start, cell.conn_start) - self.assertFloatEqual(conn_end, cell.conn_end) - self.assertFloatEqual(flowrate, cell.flowrate) - self.assertFloatEqual(oil_flowrate, cell.oil_flowrate) - self.assertFloatEqual(gas_flowrate, cell.gas_flowrate) - self.assertFloatEqual(water_flowrate, cell.water_flowrate) - - - - - - diff --git a/ThirdParty/Ert/python/tests/ecl/test_rft_statoil.py b/ThirdParty/Ert/python/tests/ecl/test_rft_statoil.py deleted file mode 100644 index 22214e9f7f..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_rft_statoil.py +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'test_rft_statoil.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from __future__ import print_function -import datetime -from ecl.ecl import EclRFTFile, EclRFTCell, EclPLTCell -from ecl.ecl.rft import WellTrajectory -from ecl.test import ExtendedTestCase - - -class RFTTest(ExtendedTestCase): - def setUp(self): - self.RFT_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT") - self.PLT_file = self.createTestPath("Statoil/ECLIPSE/RFT/TEST1_1A.RFT") - - - def test_RFT_load(self): - rftFile = EclRFTFile(self.RFT_file) - - rft = rftFile[0] - cell = rft.ijkget((32, 53, 0)) - self.assertIsInstance(cell, EclRFTCell) - - self.assertEqual(2, rftFile.size()) - self.assertEqual(0, rftFile.size(well="OP*")) - self.assertEqual(0, rftFile.size(well="XXX")) - self.assertEqual(1, rftFile.size(date=datetime.date(2000, 6, 1))) - self.assertEqual(0, rftFile.size(date=datetime.date(2000, 6, 17))) - - cell = rft.ijkget((30, 20, 1880)) - self.assertIsNone(cell) - - for rft in rftFile: - self.assertTrue(rft.is_RFT()) - self.assertFalse(rft.is_SEGMENT()) - self.assertFalse(rft.is_PLT()) - self.assertFalse(rft.is_MSW()) - - for cell in rft: - self.assertIsInstance(cell, EclRFTCell) - - cell0 = rft.iget_sorted(0) - self.assertIsInstance(cell, EclRFTCell) - rft.sort() - - for h in rftFile.getHeaders(): - print(h) - self.assertIsInstance(h[1], datetime.date) - - - def test_PLT_load(self): - pltFile = EclRFTFile(self.PLT_file) - plt = pltFile[11] - self.assertTrue(plt.is_PLT()) - self.assertFalse(plt.is_SEGMENT()) - self.assertFalse(plt.is_RFT()) - self.assertFalse(plt.is_MSW()) - - for cell in plt: - self.assertIsInstance(cell, EclPLTCell) - - - def test_exceptions(self): - with self.assertRaises(IndexError): - rftFile = EclRFTFile(self.RFT_file) - rft = rftFile[100] - - - def test_basics(self): - wt = WellTrajectory(self.createTestPath("Statoil/ert-statoil/spotfire/gendata_rft_zone/E-3H.txt")) - self.assertEqual(len(wt), 38) - self.assertTrue(isinstance(str(wt), str)) - self.assertTrue(isinstance(repr(wt), str)) - self.assertEqual('WellTrajectory(len=38)', repr(wt)) - - def test_trajectory(self): - with self.assertRaises(IOError): - WellTrajectory("/does/no/exist") - - with self.assertRaises(UserWarning): - WellTrajectory(self.createTestPath("Statoil/ert-statoil/spotfire/gendata_rft_zone/invalid_float.txt")) - - with self.assertRaises(UserWarning): - WellTrajectory(self.createTestPath("Statoil/ert-statoil/spotfire/gendata_rft_zone/missing_item.txt")) - - wt = WellTrajectory(self.createTestPath("Statoil/ert-statoil/spotfire/gendata_rft_zone/E-3H.txt")) - self.assertEqual(len(wt), 38) - - with self.assertRaises(IndexError): - p = wt[38] - - p0 = wt[0] - self.assertEqual(p0.utm_x, 458920.671 ) - self.assertEqual(p0.utm_y, 7324939.077 ) - self.assertEqual(p0.measured_depth, 2707.5000) - - pm1 = wt[-1] - p37 = wt[37] - self.assertEqual(p37, pm1) - - - - def test_PLT(self): - rft_file = EclRFTFile(self.createTestPath("Statoil/ECLIPSE/Heidrun/RFT/2C3_MR61.RFT")) - - rft0 = rft_file[0] - rft1 = rft_file[1] - rft2 = rft_file[2] - rft3 = rft_file[3] - - self.assertTrue(rft0.is_RFT()) - self.assertTrue(rft1.is_RFT()) - self.assertTrue(rft2.is_PLT()) - self.assertTrue(rft3.is_PLT()) - - self.assertEqual(len(rft0), 42) - self.assertEqual(len(rft1), 37) - self.assertEqual(len(rft2), 42) - self.assertEqual(len(rft3), 37) - - self.assertFloatEqual(rft0[0].pressure, 0.22919502E+03) - self.assertFloatEqual(rft0[0].depth , 0.21383721E+04) - - self.assertFloatEqual(rft1[0].pressure, 0.22977950E+03) - self.assertFloatEqual(rft1[0].depth , 0.21384775E+04) - - self.assertFloatEqual(rft2[0].pressure, 0.19142435E+03) - self.assertFloatEqual(rft2[0].depth , 0.21383721E+04) diff --git a/ThirdParty/Ert/python/tests/ecl/test_statoil_faults.py b/ThirdParty/Ert/python/tests/ecl/test_statoil_faults.py deleted file mode 100644 index 2d362b8713..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_statoil_faults.py +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'test_faults.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -try: - from unittest2 import skipIf -except ImportError: - from unittest import skipIf - -import time -from ecl.ecl.faults import FaultCollection, Fault, FaultLine, FaultSegment -from ecl.ecl import EclGrid, EclKW, EclDataType -from ecl.test import ExtendedTestCase - - - -class StatoilFaultTest(ExtendedTestCase): - def loadGrid(self): - grid_file = self.createTestPath("Statoil/ECLIPSE/Faults/grid.grdecl") - fileH = open(grid_file, "r") - specgrid = EclKW.read_grdecl(fileH, "SPECGRID", ecl_type=EclDataType.ECL_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) - - return EclGrid.create(specgrid, zcorn, coord, actnum) - - - - - def test_load(self): - grid = self.loadGrid() - faults_file = self.createTestPath("Statoil/ECLIPSE/Faults/faults.grdecl") - faults = FaultCollection( grid , faults_file ) - for fault in faults: - for layer in fault: - for fl in layer: - fl.verify() - - - - def test_splitLine2(self): - grid = self.loadGrid( ) - f = Fault(grid , "DF41_C") - -# 179 180 181 -# o o o o o o o o o o o o o o -# | -# 78 | -# o o o o o o o o o o o o o o -# | -# 77 | -# o o o o o o o o o o o o o o -# | -# 76 | -# o o o o o o o o o o o o o o -# | -# 75 | -# o o o o o o o o o o o o o o -# -# 74 -# o o o o o o o o o o o o o o -# -# 73 -# o o o o-----o o o o o o o o o o -# | -# 72 | -# o o o o-----o o o o o o o o o o -# -# 71 -# o o o o-----o o o o o o o o o o -# | -# 70 | -# o o o o o o o o o o o o o o -# | -# 69 | -# o o o o o o o o o o o o o o -# -# 68 -# o o o o o o o o o o o o o o -# -# 67 -# o o o o o o o o o o o o o o -# -# 66 -# o o o o o o o o o o o o o o -# | -# 65 | -# o o o o-----o o o o o o o o o o - - - f.addRecord( 179, 179 , 77 , 78 , 0 , 42 , 'X' ) - f.addRecord( 179, 179 , 75 , 76 , 0 , 41 , 'X' ) - f.addRecord( 180, 180 , 72 , 72 , 0 , 41 , 'X' ) - f.addRecord( 180, 180 , 72 , 72 , 0 , 41 , 'Y' ) - f.addRecord( 180, 180 , 72 , 72 , 0 , 41 , 'Y-' ) - - f.addRecord( 180, 180 , 70 , 70 , 0 , 42 , 'Y' ) - f.addRecord( 180, 180 , 69 , 70 , 0 , 42 , 'X' ) - f.addRecord( 180, 180 , 65 , 65 , 0 , 42 , 'X' ) - f.addRecord( 180, 180 , 65 , 65 , 0 , 42 , 'Y-' ) - - - ij_polyline = f.getIJPolyline( 19 ) - ij_list = [(180, 79), (180, 77), (180, 75), - (180, 73), (181, 73), (181, 72), (180, 72), - (180, 71), (181, 71), (181, 69), - (181, 66), (181, 65), (180, 65)] - - self.assertEqual(ij_polyline , ij_list) - - - - - - diff --git a/ThirdParty/Ert/python/tests/ecl/test_sum.py b/ThirdParty/Ert/python/tests/ecl/test_sum.py deleted file mode 100644 index 2401a4c925..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_sum.py +++ /dev/null @@ -1,315 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import os -import datetime -import csv -import shutil -from unittest import skipIf, skipUnless, skipIf - -from ecl.ecl import EclSum, EclSumVarType, FortIO, openFortIO, EclKW, EclDataType, EclSumKeyWordVector -from ecl.test import ExtendedTestCase, TestAreaContext -from ecl.test.ecl_mock import createEclSum - -def fopr(days): - return days - -def fopt(days): - return days - -def fgpt(days): - if days < 50: - return days - else: - return 100 - days - -class SumTest(ExtendedTestCase): - - - def test_mock(self): - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)]) - self.assertTrue("FOPT" in case) - self.assertFalse("WWCT:OPX" in case) - - def test_TIME_special_case(self): - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)]) - keys = case.keys() - self.assertEqual( len(keys) , 2 ) - self.assertIn( "FOPT" , keys ) - self.assertIn( "FOPR" , keys ) - - - keys = case.keys(pattern = "*") - self.assertEqual( len(keys) , 2 ) - self.assertIn( "FOPT" , keys ) - self.assertIn( "FOPR" , keys ) - - - def test_identify_var_type(self): - self.assertEnumIsFullyDefined( EclSumVarType , "ecl_smspec_var_type" , "lib/include/ert/ecl/smspec_node.h") - 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 ) - - case = createEclSum("CSV" , [("FOPT", None , 0) , - ("FOPR" , None , 0), - ("AARQ" , None , 10), - ("RGPT" , None ,1)]) - - node1 = case.smspec_node( "FOPT" ) - self.assertEqual( node1.varType( ) , EclSumVarType.ECL_SMSPEC_FIELD_VAR ) - - node2 = case.smspec_node( "AARQ:10" ) - self.assertEqual( node2.varType( ) , EclSumVarType.ECL_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.getNum( ) , 1 ) - self.assertTrue( node3.isTotal( )) - - self.assertLess( node1, node3 ) - self.assertGreater( node2, node3 ) - self.assertEqual( node1, node1 ) - self.assertNotEqual( node1, node2 ) - - with self.assertRaises(TypeError): - a = node1 < 1 - - def test_csv_export(self): - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)]) - sep = ";" - with TestAreaContext("ecl/csv"): - case.exportCSV( "file.csv" , sep = sep) - self.assertTrue( os.path.isfile( "file.csv" ) ) - input_file = csv.DictReader( open("file.csv") , delimiter = sep ) - for row in input_file: - self.assertIn("DAYS", row) - self.assertIn("DATE", row) - self.assertIn("FOPT", row) - self.assertIn("FOPR", row) - self.assertEqual( len(row) , 4 ) - break - - - - with TestAreaContext("ecl/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) - for row in input_file: - self.assertIn("DAYS", row) - self.assertIn("DATE", row) - self.assertIn("FOPT", row) - self.assertEqual( len(row) , 3 ) - break - - - - with TestAreaContext("ecl/csv"): - date_format = "%y-%m-%d" - sep = "," - case.exportCSV( "file.csv" , keys = ["F*"] , sep=sep , date_format = date_format) - self.assertTrue( os.path.isfile( "file.csv" ) ) - with open("file.csv") as f: - time_index = -1 - for line in f.readlines(): - tmp = line.split( sep ) - self.assertEqual( len(tmp) , 4) - - if time_index >= 0: - d = datetime.datetime.strptime( tmp[1] , date_format ) - self.assertEqual( case.iget_date( time_index ) , d ) - - time_index += 1 - - - def test_solve(self): - length = 100 - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)], - sim_length_days = length, - num_report_step = 10, - num_mini_step = 10, - func_table = {"FOPT" : fopt, - "FOPR" : fopr , - "FGPT" : fgpt }) - - self.assert_solve( case ) - - def assert_solve(self, case): - with self.assertRaises( KeyError ): - case.solveDays( "MISSING:KEY" , 0.56) - - sol = case.solveDays( "FOPT" , 150 ) - self.assertEqual( len(sol) , 0 ) - - sol = case.solveDays( "FOPT" , -10 ) - self.assertEqual( len(sol) , 0 ) - - sol = case.solveDays( "FOPT" , 50 ) - self.assertEqual( len(sol) , 1 ) - self.assertFloatEqual( sol[0] , 50 ) - - sol = case.solveDays( "FOPT" , 50.50 ) - self.assertEqual( len(sol) , 1 ) - self.assertFloatEqual( sol[0] , 50.50 ) - - sol = case.solveDays( "FOPR" , 50.90 ) - self.assertEqual( len(sol) , 1 ) - self.assertFloatEqual( sol[0] , 50.00 + 1.0/86400 ) - - sol = case.solveDates("FOPR" , 50.90) - t = case.getDataStartTime( ) + datetime.timedelta( days = 50 ) + datetime.timedelta( seconds = 1 ) - self.assertEqual( sol[0] , t ) - - sol = case.solveDays( "FOPR" , 50.90 , rates_clamp_lower = False) - self.assertEqual( len(sol) , 1 ) - self.assertFloatEqual( sol[0] , 51.00 ) - - sol = case.solveDays( "FGPT" ,25.0) - self.assertEqual( len(sol) , 2 ) - self.assertFloatEqual( sol[0] , 25.00 ) - self.assertFloatEqual( sol[1] , 75.00 ) - - sol = case.solveDates( "FGPT" , 25 ) - self.assertEqual( len(sol) , 2 ) - t0 = case.getDataStartTime( ) - t1 = t0 + datetime.timedelta( days = 25 ) - t2 = t0 + datetime.timedelta( days = 75 ) - self.assertEqual( sol[0] , t1 ) - self.assertEqual( sol[1] , t2 ) - - - def test_ecl_sum_vector_algebra(self): - scalar = 0.78 - addend = 2.718281828459045 - - # setup - length = 100 - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)], - sim_length_days = length, - num_report_step = 10, - num_mini_step = 10, - func_table = {"FOPT" : fopt, - "FOPR" : fopr , - "FGPT" : fgpt }) - with self.assertRaises( KeyError ): - case.scaleVector( "MISSING:KEY" , scalar) - case.shiftVector( "MISSING:KEY" , addend) - - # scale all vectors with scalar - for key in case.keys(): - x = case.get_values(key) # get vector key - case.scaleVector(key , scalar) - y = case.get_values(key) - x = x * scalar # numpy vector scaling - for i in range(len(x)): - self.assertFloatEqual(x[i], y[i]) - - # shift all vectors with addend - for key in case.keys(): - x = case.get_values(key) # get vector key - case.shiftVector(key , addend) - y = case.get_values(key) - x = x + addend # numpy vector shifting - for i in range(len(x)): - self.assertFloatEqual(x[i], y[i]) - - - def test_different_names(self): - length = 100 - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)], - sim_length_days = length, - num_report_step = 10, - num_mini_step = 10, - func_table = {"FOPT" : fopt, - "FOPR" : fopr , - "FGPT" : fgpt }) - - with TestAreaContext("sum_different"): - case.fwrite( ) - shutil.move("CSV.SMSPEC" , "CSVX.SMSPEC") - with self.assertRaises(IOError): - case2 = EclSum.load( "Does/not/exist" , "CSV.UNSMRY") - - with self.assertRaises(IOError): - case2 = EclSum.load( "CSVX.SMSPEC" , "CSVX.UNSMRY") - - case2 = EclSum.load( "CSVX.SMSPEC" , "CSV.UNSMRY" ) - self.assert_solve( case2 ) - - def test_invalid(self): - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)], - sim_length_days = 100, - num_report_step = 10, - num_mini_step = 10, - func_table = {"FOPT" : fopt, - "FOPR" : fopr , - "FGPT" : fgpt }) - - with TestAreaContext("sum_invalid"): - case.fwrite( ) - with open("CASE.txt", "w") as f: - f.write("No - this is not EclKW file ....") - - with self.assertRaises( IOError ): - case2 = EclSum.load( "CSV.SMSPEC" , "CASE.txt" ) - - with self.assertRaises( IOError ): - case2 = EclSum.load( "CASE.txt" , "CSV.UNSMRY" ) - - kw1 = EclKW("TEST1", 30, EclDataType.ECL_INT) - kw2 = EclKW("TEST2", 30, EclDataType.ECL_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") - - with self.assertRaises( IOError ): - case2 = EclSum.load( "CASE.KW" , "CSV.UNSMRY" ) - - - def test_kw_vector(self): - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)], - sim_length_days = 100, - num_report_step = 10, - num_mini_step = 10, - func_table = {"FOPT" : fopt, - "FOPR" : fopr , - "FGPT" : fgpt }) - kw_list = EclSumKeyWordVector( case ) - kw_list.add_keyword("FOPT") - kw_list.add_keyword("FOPR") - kw_list.add_keyword("FGPT") - - t = case.getDataStartTime( ) + datetime.timedelta( days = 43 ); - data = case.get_interp_row( kw_list , t ) - for d1,d2 in zip(data, [ case.get_interp("FOPT", date = t), - case.get_interp("FOPT", date = t), - case.get_interp("FOPT", date = t) ]): - - self.assertFloatEqual(d1,d2) - - tmp = [] - for key in kw_list: - tmp.append(key) - - for (k1,k2) in zip(kw_list,tmp): - self.assertEqual(k1,k2) diff --git a/ThirdParty/Ert/python/tests/ecl/test_sum_statoil.py b/ThirdParty/Ert/python/tests/ecl/test_sum_statoil.py deleted file mode 100644 index aa543b250e..0000000000 --- a/ThirdParty/Ert/python/tests/ecl/test_sum_statoil.py +++ /dev/null @@ -1,500 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import os -import datetime - -from unittest import skipIf, skipUnless, skipIf - -from ecl.ecl import EclSum, EclFile - -from ecl.util import StringList, TimeVector, DoubleVector - -from ecl.test import ExtendedTestCase , TestAreaContext -import csv - -base = "ECLIPSE" -path = "Statoil/ECLIPSE/Gurbat" -case = "%s/%s" % (path, base) - - - - -def sum_get(*args): - sum = args[0] - key = args[1] - vec = sum[key] - - -class SumTest(ExtendedTestCase): - def setUp(self): - self.case = self.createTestPath(case) - self.ecl_sum = EclSum(self.case) - - self.assertIsInstance(self.ecl_sum, EclSum) - - - def test_load(self): - self.assertIsNotNone(self.ecl_sum, "Load failed") - - - def test_invalid(self): - with self.assertRaises(IOError): - sum = EclSum("Does/not/exist") - - - def test_KeyError(self): - sum = self.ecl_sum - with self.assertRaises(KeyError): - v = sum["KeyMissing"] - - with self.assertRaises(KeyError): - v = sum.get_interp("Missing" , days = 750) - - with self.assertRaises(KeyError): - 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 ) - - - def test_interp(self): - sum = self.ecl_sum - - self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", days=750), 0.11719122) - self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", date=datetime.date(2004, 1, 1)), 0.603358387947) - - v = sum.get_interp_vector("WOPT:OP_1", days_list=[100, 200, 400]) - self.assertAlmostEqualList([805817.11875, 1614955.34677419, 3289267.67857143 ], v) - - v = sum.get_interp_vector("WGPT:OP_2", date_list=[datetime.date(2002, 1, 1), datetime.date(2003, 1, 1), datetime.date(2004, 1, 1)]) - self.assertAlmostEqualList(v, [8.20773632e+08, 9.68444032e+08, 1.02515213e+09]) - - self.assertEqual(sum.get_interp("FOPT" , days = 0) , 0) - - self.assertEqual(sum.get_interp("WOPR:OP_1" , days = 0) , 0) - self.assertEqual(sum.get_interp("WOPR:OP_1" , date=datetime.date(2000,1,1)) , 0) - - self.assertEqual(sum.get_interp("WOPR:OP_1" , days = 31) , 7996) - self.assertEqual(sum.get_interp("WOPR:OP_1" , date=datetime.date(2000,2,1)) , 7996) - - FPR = sum["FPR"] - self.assertFloatEqual(sum.get_interp("FPR" , days = 0) , FPR[0].value) - self.assertFloatEqual(sum.get_interp("FPR" , days = 31) , FPR[1].value) - - with self.assertRaises(ValueError): - sum.get_interp("WOPR:OP_1") - - with self.assertRaises(ValueError): - sum.get_interp("WOPR:OP_1" , days=10 , date = datetime.date(2000,1,1)) - - - def test_LLINEAR(self): - sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/LGRISSUE/EM-LTAA-ISEG_CARFIN_NWPROPS")) - self.assertTrue( sum.has_key("LLINEARS") ) - - - - def test_wells(self): - wells = self.ecl_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.sort() - self.assertListEqual([well for well in wells], ["OP_3", "WI_3"]) - - groups = self.ecl_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") - 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.get_last_value("FGPT"), 6605249024.0) - self.assertEqual( len(self.ecl_sum) , 63 ) - - - def test_dates( self ): - sum = self.ecl_sum - d = sum.dates - - self.assertEqual(d[0], datetime.datetime(2000, 1, 1, 0, 0, 0)) - self.assertEqual(d[62], datetime.datetime(2004, 12, 31, 0, 0, 0)) - self.assertEqual(len(d), 63) - self.assertEqual(d[25], datetime.datetime(2001, 12, 1, 0, 0, 0)) - self.assertEqual(sum.iget_date(25), datetime.datetime(2001, 12, 1, 0, 0, 0)) - - mpl_dates = sum.mpl_dates - self.assertAlmostEqual(mpl_dates[25], 730820) - - days = sum.days - self.assertAlmostEqual(days[50], 1461) - - self.assertEqual(sum.start_time, datetime.datetime(2000, 1, 1, 0, 0, 0)) - self.assertEqual(sum.end_time, datetime.datetime(2004, 12, 31, 0, 0, 0)) - self.assertTrue(sum.check_sim_time(datetime.datetime(2004, 12, 31, 0, 0, 0))) - self.assertEqual(sum.end_date , datetime.date(2004, 12, 31)) - - - - def test_dates2( self ): - sum = EclSum(self.createTestPath("Statoil/ECLIPSE/FF12/FF12_2013B3_AMAP2")) - self.assertEqual(sum.end_date , datetime.date(2045, 1, 1)) - - - - - - def test_keys(self): - sum = self.ecl_sum - self.assertRaises(KeyError, sum.__getitem__, "BJARNE") - - v = sum["FOPT"] - self.assertEqual(len(v), 63) - - - def test_index(self): - sum = self.ecl_sum - index = sum.get_key_index("TCPUDAY") - self.assertEqual(index, 10239) - - - def test_report(self): - sum = self.ecl_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) - self.assertEqual(sum.get_report(date=datetime.date(2012, 10, 3)), -1) - - self.assertEqual(sum.get_report(days=91), 3) - self.assertEqual(sum.get_report(days=92), -1) - self.assertAlmostEqual(sum.get_interp("FOPT", days=91), sum.get_from_report("FOPT", 3)) - - self.assertEqual(sum.first_report, 1) - self.assertEqual(sum.last_report, 62) - - self.assertEqual(sum.get_report_time(10), datetime.date(2000, 10, 1)) - self.assertFloatEqual(sum.get_from_report("FOPT", 10), 6.67447e+06) - - - @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test skipped") - def test_fwrite(self): - # todo: What is tested here? - # work_area = TestArea("python/sum-test/fwrite", True) - with TestAreaContext("python/sum-test/fwrite") as work_area: - self.ecl_sum.fwrite(ecl_case="CASE") - self.assertTrue(True) - - - def test_block(self): - sum = self.ecl_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(self.createTestPath("Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1")) - base = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE")) - pred = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"), include_restart=False) - - self.assertIsNotNone(hist) - self.assertIsNotNone(base) - 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)) - - - def test_case2( self ): - cwd = os.getcwd() - os.chdir(self.createTestPath(path)) - sum = EclSum(base) - self.assertIsNone(sum.path) - self.assertTrue(sum.base == base) - self.assertTrue(sum.case == base) - self.assertTrue(sum.abs_path == self.createTestPath(path)) - os.chdir(cwd) - - - def test_var_properties( self ): - sum = self.ecl_sum - self.assertRaises(KeyError, sum.smspec_node, "BJARNE") - - node = sum.smspec_node("FOPT") - self.assertTrue(node.isTotal()) - self.assertFalse(node.isHistorical()) - - node = sum.smspec_node("FOPR") - self.assertFalse(node.isTotal()) - self.assertFalse(node.isHistorical()) - self.assertTrue(node.keyword == "FOPR") - - node = sum.smspec_node("FOPRH") - self.assertFalse(node.isTotal()) - self.assertTrue(node.isHistorical()) - self.assertTrue(node.isRate()) - self.assertTrue(node.keyword == "FOPRH") - - node = sum.smspec_node("WOPR:OP_1") - self.assertFalse(node.isTotal()) - self.assertTrue(node.isRate()) - self.assertTrue(node.keyword == "WOPR") - - node = sum.smspec_node("WOPT:OP_1") - self.assertTrue(node.isTotal()) - self.assertFalse(node.isRate()) - self.assertTrue(node.unit == "SM3") - self.assertTrue(node.wgname == "OP_1") - self.assertTrue(node.keyword == "WOPT") - - self.assertTrue(sum.unit("FOPR") == "SM3/DAY") - - node = sum.smspec_node("FOPTH") - self.assertTrue(node.isTotal()) - self.assertFalse(node.isRate()) - self.assertIsNone(node.wgname) - node = sum.smspec_node("BPR:1095") - self.assertEqual(node.num, 1095) - - def test_stringlist_gc(self): - sum = EclSum(self.case) - wells = sum.wells() - well1 = wells[0] - del wells - self.assertTrue(well1 == "OP_1") - - - def test_stringlist_reference(self): - sum = EclSum(self.case) - wells = sum.wells() - self.assertListEqual([well for well in wells], ['OP_1', 'OP_2', 'OP_3', 'OP_4', 'OP_5', 'WI_1', 'WI_2', 'WI_3']) - self.assertIsInstance(wells, StringList) - - - def test_stringlist_setitem(self): - sum = EclSum(self.case) - wells = sum.wells() - wells[0] = "Bjarne" - well0 = wells[0] - self.assertTrue(well0 == "Bjarne") - self.assertTrue(wells[0] == "Bjarne") - wells[0] = "XXX" - self.assertTrue(well0 == "Bjarne") - self.assertTrue(wells[0] == "XXX") - - - def test_segment(self): - sum = EclSum(self.createTestPath("Statoil/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: - tmp = var.split(":") - nr = int(tmp[2]) - 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.ecl_sum.alloc_data_vector(key_index, True), DoubleVector) - - def test_timeRange(self): - sum = EclSum(self.case) - with self.assertRaises(TypeError): - trange = sum.timeRange(interval = "1") - trange = sum.timeRange(interval = "1X") - trange = sum.timeRange(interval = "YY") - trange = sum.timeRange(interval = "MY") - - with self.assertRaises(ValueError): - trange = sum.timeRange( start = datetime.datetime(2000,1,1) , end = datetime.datetime(1999,1,1) ) - - sim_start = datetime.datetime(2000, 1, 1, 0, 0, 0) - sim_end = datetime.datetime(2004, 12, 31, 0, 0, 0) - trange = sum.timeRange( interval = "1Y") - self.assertTrue( trange[0] == datetime.date( 2000 , 1 , 1 )) - self.assertTrue( trange[1] == datetime.date( 2001 , 1 , 1 )) - self.assertTrue( trange[2] == datetime.date( 2002 , 1 , 1 )) - self.assertTrue( trange[3] == datetime.date( 2003 , 1 , 1 )) - self.assertTrue( trange[4] == datetime.date( 2004 , 1 , 1 )) - self.assertTrue( trange[5] == datetime.date( 2005 , 1 , 1 )) - - trange = sum.timeRange( interval = "1M") - self.assertTrue( trange[0] == datetime.date( 2000 , 1 , 1 )) - self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 )) - - trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15), interval = "1M") - self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 )) - self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 )) - - trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15) , end = datetime.date( 2003 , 1 , 15), interval = "1M") - self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 )) - self.assertTrue( trange[-1] == datetime.date( 2003 , 2 , 1 )) - - trange = sum.timeRange( start = datetime.date( 2002 , 1 , 15) , end = datetime.datetime( 2003 , 1 , 15,0,0,0), interval = "1M") - self.assertTrue( trange[0] == datetime.date( 2002 , 1 , 1 )) - self.assertTrue( trange[-1] == datetime.date( 2003 , 2 , 1 )) - - - - # Loading this dataset is a test of loading a case where one report step is missing. - def test_Heidrun(self): - sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS")) - self.assertEqual( 452 , len(sum)) - self.assertFloatEqual( 1.8533144e+8 , sum.get_last_value("FOPT")) - - trange = sum.timeRange( start = datetime.date( 2015 , 1 , 1), interval = "1M") - self.assertTrue( trange[0] == datetime.date( 2016 , 2 , 1 )) - for t in trange: - sum.get_interp( "FOPT" , date = t ) - - - - def test_regularProduction(self): - sum = EclSum(self.case) - with self.assertRaises(TypeError): - trange = TimeVector.createRegular( sum.start_time , sum.end_time , "1M" ) - prod = sum.blockedProduction("FOPR" , trange) - - with self.assertRaises(KeyError): - trange = TimeVector.createRegular( sum.start_time , sum.end_time , "1M" ) - prod = sum.blockedProduction("NoNotThis" , trange) - - trange = sum.timeRange(interval = "2Y") - self.assertTrue( trange[0] == datetime.date( 2000 , 1 , 1 )) - self.assertTrue( trange[-1] == datetime.date( 2006 , 1 , 1 )) - - trange = sum.timeRange(interval = "5Y") - self.assertTrue( trange[0] == datetime.date( 2000 , 1 , 1 )) - self.assertTrue( trange[-1] == datetime.date( 2005 , 1 , 1 )) - - trange = sum.timeRange(interval = "6M") - wprod1 = sum.blockedProduction("WOPT:OP_1" , trange) - wprod2 = sum.blockedProduction("WOPT:OP_2" , trange) - wprod3 = sum.blockedProduction("WOPT:OP_3" , trange) - wprod4 = sum.blockedProduction("WOPT:OP_4" , trange) - wprod5 = sum.blockedProduction("WOPT:OP_5" , trange) - - fprod = sum.blockedProduction("FOPT" , trange) - gprod = sum.blockedProduction("GOPT:OP" , trange) - wprod = wprod1 + wprod2 + wprod3 + wprod4 + wprod5 - for (w,f,g) in zip(wprod, fprod,gprod): - self.assertFloatEqual( w , f ) - 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.addVariable( "FOPT" ) - self.assertTrue( writer.has_key( "FOPT" )) - - writer.addTStep( 1 , 100 ) - - - def test_aquifer(self): - case = EclSum( self.createTestPath( "Statoil/ECLIPSE/Aquifer/06_PRESSURE_R009-0")) - self.assertTrue( "AAQR:2" in case ) - - - def test_restart_mapping(self): - history = EclSum( self.createTestPath( "Statoil/ECLIPSE/SummaryRestart/iter-1/NOR-2013A_R007-0") ) - total = EclSum( self.createTestPath( "Statoil/ECLIPSE/SummaryRestart/Prediction/NOR-2013A_R007_PRED-0") , include_restart = True) - - history_dates = history.get_dates( ) - total_dates = total.get_dates( ) - for i in range(len(history_dates)): - self.assertEqual( history_dates[i] , total_dates[i] ) - - - keys = history.keys( pattern = "W*") - for key in keys: - if key in total: - self.assertEqual( history.iget( key , 5 ) , total.iget( key , 5 )) - - self.assertFalse( "WGPR:NOT_21_D" in history ) - self.assertTrue( "WGPR:NOT_21_D" in total ) - - self.assertEqual( total.iget( "WGPR:NOT_21_D", 5) , 0) # Default value - - def test_write(self): - with TestAreaContext("my_space") as area: - intersect_summary = EclSum( self.createTestPath( "Statoil/ECLIPSE/SummaryRestart/iter-1/NOR-2013A_R007-0") ) - self.assertIsNotNone(intersect_summary) - - write_location = os.path.join(os.getcwd(), "CASE") - intersect_summary.fwrite(ecl_case=write_location) - - reloaded_summary = EclSum(write_location) - self.assertEqual(intersect_summary.keys(), reloaded_summary.keys()) - - def test_ix_case(self): - intersect_summary = EclSum(self.createTestPath("Statoil/ECLIPSE/ix/summary/Create_Region_Around_Well")) - self.assertIsNotNone(intersect_summary) - - self.assertTrue( - "HWELL_PROD" in - [intersect_summary.smspec_node(key).wgname for key in intersect_summary.keys()] - ) - - eclipse_summary = EclSum(self.createTestPath("Statoil/ECLIPSE/ix/summary/ECL100/E100_CREATE_REGION_AROUND_WELL")) - self.assertIsNotNone(eclipse_summary) - - hwell_padder = lambda key : key if key.split(":")[-1] != "HWELL_PR" else key + "OD" - self.assertEqual( - intersect_summary.keys("WWCT*"), - map(hwell_padder, eclipse_summary.keys("WWCT*")) - ) - - def test_ix_write(self): - for data_set in [ - "Statoil/ECLIPSE/ix/summary/Create_Region_Around_Well", - "Statoil/ECLIPSE/ix/troll/IX_NOPH3_R04_75X75X1_grid2.SMSPEC" - ]: - - with TestAreaContext("my_space" + data_set.split("/")[-1]) as area: - intersect_summary = EclSum(self.createTestPath(data_set)) - self.assertIsNotNone(intersect_summary) - - write_location = os.path.join(os.getcwd(), "CASE") - intersect_summary.fwrite(ecl_case=write_location) - - reloaded_summary = EclSum(write_location) - self.assertEqual( - list(intersect_summary.keys()), - list(reloaded_summary.keys()) - ) - - def test_ix_caseII(self): - troll_summary = EclSum( self.createTestPath("Statoil/ECLIPSE/ix/troll/IX_NOPH3_R04_75X75X1_grid2.SMSPEC")) - self.assertIsNotNone(troll_summary) - self.assertTrue("WMCTL:Q21BH1" in list(troll_summary.keys())) diff --git a/ThirdParty/Ert/python/tests/ecl_tests/test_ecl_kw.py b/ThirdParty/Ert/python/tests/ecl_tests/test_ecl_kw.py index 19617aad8d..88d4fa9fb7 100644 --- a/ThirdParty/Ert/python/tests/ecl_tests/test_ecl_kw.py +++ b/ThirdParty/Ert/python/tests/ecl_tests/test_ecl_kw.py @@ -79,10 +79,8 @@ class KWTest(EclTest): name1 = "file1.txt" name2 = "file2.txt" kw = EclKW("TEST", len(data), data_type) - i = 0 - for d in data: + for (i,d) in enumerate(data): kw[i] = d - i += 1 file1 = cwrap.open(name1, "w") kw.fprintf_data(file1, fmt) diff --git a/ThirdParty/Ert/python/tests/ecl_tests/test_sum.py b/ThirdParty/Ert/python/tests/ecl_tests/test_sum.py index 811e7ec6db..c4dc3f46a5 100644 --- a/ThirdParty/Ert/python/tests/ecl_tests/test_sum.py +++ b/ThirdParty/Ert/python/tests/ecl_tests/test_sum.py @@ -67,7 +67,7 @@ def fgpt(days): def create_case(case = "CSV", restart_case = None, restart_step = -1, data_start = None): length = 100 - return createEclSum(case , [("FOPT", None , 0) , ("FOPR" , None , 0), ("FGPT" , None , 0)], + return createEclSum(case , [("FOPT", None , 0, "SM3") , ("FOPR" , None , 0, "SM3/DAY"), ("FGPT" , None , 0, "SM3")], sim_length_days = length, num_report_step = 10, num_mini_step = 10, @@ -82,12 +82,12 @@ class SumTest(EclTest): def test_mock(self): - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)]) + case = createEclSum("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("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)]) + case = createEclSum("CSV" , [("FOPT", None , 0, "SM3") , ("FOPR" , None , 0, "SM3/DAY")]) keys = case.keys() self.assertEqual( len(keys) , 2 ) self.assertIn( "FOPT" , keys ) @@ -107,10 +107,10 @@ class SumTest(EclTest): self.assertEqual( EclSum.varType( "WNEWTON") , EclSumVarType.ECL_SMSPEC_MISC_VAR ) self.assertEqual( EclSum.varType( "AARQ:4") , EclSumVarType.ECL_SMSPEC_AQUIFER_VAR ) - case = createEclSum("CSV" , [("FOPT", None , 0) , - ("FOPR" , None , 0), - ("AARQ" , None , 10), - ("RGPT" , None ,1)]) + case = createEclSum("CSV" , [("FOPT", None , 0, "SM3") , + ("FOPR" , None , 0, "SM3/DAY"), + ("AARQ" , None , 10, "???"), + ("RGPT" , None ,1, "SM3")]) node1 = case.smspec_node( "FOPT" ) self.assertEqual( node1.varType( ) , EclSumVarType.ECL_SMSPEC_FIELD_VAR ) @@ -133,7 +133,7 @@ class SumTest(EclTest): a = node1 < 1 def test_csv_export(self): - case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)]) + case = createEclSum("CSV" , [("FOPT", None , 0, "SM3") , ("FOPR" , None , 0, "SM3/DAY")]) sep = ";" with TestAreaContext("ecl/csv"): case.exportCSV( "file.csv" , sep = sep) @@ -147,7 +147,7 @@ class SumTest(EclTest): self.assertEqual( len(row) , 4 ) break - + self.assertEqual(case.unit("FOPT"), "SM3") with TestAreaContext("ecl/csv"): case.exportCSV( "file.csv" , keys = ["FOPT"] , sep = sep) @@ -270,6 +270,7 @@ class SumTest(EclTest): case2 = EclSum.load( "CSVX.SMSPEC" , "CSV.UNSMRY" ) self.assert_solve( case2 ) + self.assertEqual(case.unit("FOPR"), "SM3/DAY") def test_invalid(self): case = create_case() @@ -300,7 +301,7 @@ class SumTest(EclTest): def test_kw_vector(self): case1 = create_case() - case2 = createEclSum("CSV" , [("FOPR", None , 0) , ("FOPT" , None , 0), ("FWPT" , None , 0)], + case2 = createEclSum("CSV" , [("FOPR", None , 0, "SM3/DAY") , ("FOPT" , None , 0, "SM3"), ("FWPT" , None , 0, "SM3")], sim_length_days = 100, num_report_step = 10, num_mini_step = 10, @@ -366,6 +367,21 @@ class SumTest(EclTest): self.assertIn(key, ecl_sum_vector) + def test_first_last(self): + case = create_case() + with self.assertRaises(KeyError): + case.last_value("NO_SUCH_KEY") + last_fopt = case.last_value("FOPT") + values = case.get_values("FOPT") + self.assertEqual( last_fopt, values[-1]) + + with self.assertRaises(KeyError): + case.first_value("NO_SUCH_KEY") + + first_fopt = case.first_value("FOPT") + self.assertEqual(first_fopt, values[0]) + + def test_time_range(self): case = create_case() with self.assertRaises(ValueError): @@ -486,3 +502,61 @@ class SumTest(EclTest): case = EclSum("UNITS") self.assertEqual(case.unit_system, EclUnitTypeEnum.ECL_LAB_UNITS) + + + def test_numpy_vector(self): + case = create_case() + + with self.assertRaises(KeyError): + case.numpy_vector("NO_SUCH_KEY") + + numpy_vector = case.numpy_vector("FOPT") + self.assertEqual(len(numpy_vector), len(case)) + numpy_dates = case.numpy_dates + self.assertEqual( numpy_dates[0].tolist(), case.getDataStartTime()) + self.assertEqual( numpy_dates[-1].tolist(), case.getEndTime()) + + dates = case.dates + self.assertEqual( dates[0], case.getDataStartTime()) + self.assertEqual( dates[-1], case.getEndTime()) + + dates = [datetime.datetime(2000,1,1)] + case.dates + [datetime.datetime(2020,1,1)] + fopr = case.numpy_vector("FOPR", time_index = dates) + fopt = case.numpy_vector("FOPT", time_index = dates) + + + self.assertEqual(fopr[0], 0) + self.assertEqual(fopr[-1], 0) + + self.assertEqual(fopt[0], 0) + self.assertEqual(fopt[0], case.first_value("FOPT")) + self.assertEqual(fopt[-1], case.last_value("FOPT")) + + + + def test_pandas(self): + case = create_case() + dates = [datetime.datetime(2000,1,1)] + case.dates + [datetime.datetime(2020,1,1)] + frame = case.pandas_frame(column_keys=["FOPT", "FOPR"], time_index = dates) + + fopr = frame["FOPR"] + fopt = frame["FOPT"] + + self.assertEqual(fopr[0], 0) + self.assertEqual(fopr[-1], 0) + + self.assertEqual(fopt[0], 0) + self.assertEqual(fopt[0], case.first_value("FOPT")) + self.assertEqual(fopt[-1], case.last_value("FOPT")) + + + with self.assertRaises(ValueError): + frame = case.pandas_frame(column_keys=[]) + + with self.assertRaises(ValueError): + frame = case.pandas_frame(column_keys=["NO_KEY"]) + + frame = case.pandas_frame( ) + rows, columns = frame.shape + self.assertEqual(len(case.keys()), columns) + self.assertEqual(len(case), rows) diff --git a/ThirdParty/Ert/python/tests/geometry/CMakeLists.txt b/ThirdParty/Ert/python/tests/geometry/CMakeLists.txt deleted file mode 100644 index 1795decd10..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -set(TEST_SOURCES - __init__.py - test_convex_hull.py - test_cpolyline.py - test_cpolyline_collection.py - test_geometry_tools.py - test_intersection.py - test_point_in_polygon.py - test_polygon_slicing.py - test_polyline.py - test_surface.py - test_geo_pointset.py - test_geo_region.py -) - -add_python_package("python.tests.geometry" ${PYTHON_INSTALL_PREFIX}/tests/geometry "${TEST_SOURCES}" False) - -addPythonTest(tests.geometry.test_geo_pointset.GeoPointsetTest) -addPythonTest(tests.geometry.test_geo_region.GeoRegionTest) -addPythonTest(tests.geometry.test_surface.SurfaceTest) -addPythonTest(tests.geometry.test_polyline.PolylineTest) -addPythonTest(tests.geometry.test_intersection.IntersectionTest) -addPythonTest(tests.geometry.test_convex_hull.ConvexHullTest) -addPythonTest(tests.geometry.test_point_in_polygon.PointInPolygonTest) -addPythonTest(tests.geometry.test_polygon_slicing.PolygonSlicingTest) -addPythonTest(tests.geometry.test_cpolyline.CPolylineTest) -addPythonTest(tests.geometry.test_cpolyline_collection.CPolylineCollectionTest) -addPythonTest(tests.geometry.test_geometry_tools.GeometryToolsTest ) diff --git a/ThirdParty/Ert/python/tests/geometry/__init__.py b/ThirdParty/Ert/python/tests/geometry/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/tests/geometry/test_convex_hull.py b/ThirdParty/Ert/python/tests/geometry/test_convex_hull.py deleted file mode 100644 index e0c27305f6..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_convex_hull.py +++ /dev/null @@ -1,27 +0,0 @@ -from ecl.geo.geometry_tools import GeometryTools -from ecl.test.extended_testcase import ExtendedTestCase - - -class ConvexHullTest(ExtendedTestCase): - - def test_ccw(self): - p1 = (0, 0) - p2 = (1, 0) - p3 = (0, 1) - p4 = (0, 2) - - - self.assertTrue(GeometryTools.ccw(p1, p2, p3) > 0) # Counter-clockwise - self.assertTrue(GeometryTools.ccw(p1, p3, p2) < 0) # Clockwise - self.assertTrue(GeometryTools.ccw(p1, p3, p4) == 0) # Colinear - - - def test_convex_hull(self): - points = [(0, 0), (0, 1), (1, 1), (1, 0), (1, 1), (0.5, 0.5), (0.25, 0.25), (0.5, 1.25), (0.5, 0.75)] - result = GeometryTools.convexHull(points) - self.assertEqual(result, [(0, 0), (0, 1), (0.5, 1.25), (1, 1), (1, 0)]) - - - points = [(0, -0.5), (0, 0.5), (-0.5, 0), (0.5, 0), (0, 0), (0.5, 0.5)] - result = GeometryTools.convexHull(points) - self.assertEqual(result, [(-0.5, 0), (0, 0.5), (0.5, 0.5), (0.5, 0), (0, -0.5)]) \ No newline at end of file diff --git a/ThirdParty/Ert/python/tests/geometry/test_cpolyline.py b/ThirdParty/Ert/python/tests/geometry/test_cpolyline.py deleted file mode 100644 index 6439f15923..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_cpolyline.py +++ /dev/null @@ -1,171 +0,0 @@ -import math - -from ecl.geo import CPolyline , Polyline -from ecl.geo.xyz_io import XYZIo -from ecl.test import ExtendedTestCase , TestAreaContext - - -class CPolylineTest(ExtendedTestCase): - def setUp(self): - self.polyline1 = self.createTestPath("local/geometry/pol11.xyz") - self.polyline2 = self.createTestPath("local/geometry/pol8.xyz") - self.polyline3 = self.createTestPath("local/geometry/pol8_noend.xyz") - - - - def test_construction(self): - polyline = CPolyline() - self.assertEqual( len(polyline) , 0 ) - - with self.assertRaises(IOError): - CPolyline.createFromXYZFile( "Does/not/exist" ) - - p1 = CPolyline.createFromXYZFile( self.polyline1 ) - self.assertEqual( len(p1) , 13 ) - x,y = p1[-1] - self.assertEqual(x , 389789.263184) - self.assertEqual(y , 6605784.945099) - - p2 = CPolyline.createFromXYZFile( self.polyline2 ) - self.assertEqual( len(p2) , 20 ) - x,y = p2[-1] - self.assertEqual(x , 396056.314697) - self.assertEqual(y , 6605835.119461) - - p3 = CPolyline.createFromXYZFile( self.polyline3 ) - self.assertEqual( len(p3) , 20 ) - x,y = p3[-1] - self.assertEqual(x , 396056.314697) - self.assertEqual(y , 6605835.119461) - - - - def test_front(self): - polyline = CPolyline() - polyline.addPoint( 1 , 1 ) - polyline.addPoint( 0 , 0 , front = True ) - self.assertEqual( len(polyline) , 2 ) - - x,y = polyline[0] - self.assertEqual(x,0) - self.assertEqual(y,0) - - x,y = polyline[1] - self.assertEqual(x,1) - self.assertEqual(y,1) - - - def test_equal(self): - pl1 = CPolyline(name = "Poly1" , init_points = [(0,0) , (1,1) , (2,2)]) - pl2 = CPolyline(name = "Poly2" , init_points = [(0,0) , (1,1) , (2,2)]) - pl3 = CPolyline(init_points = [(0,0) , (1,1) , (2,3)]) - - self.assertEqual( pl1 , pl1 ) - self.assertEqual( pl1 , pl2 ) - self.assertFalse( pl1 == pl3 ) - - - def test_length(self): - polyline = CPolyline( init_points = [(0,1)]) - self.assertEqual( polyline.segmentLength() , 0 ) - - polyline = CPolyline( init_points = [(0,0) , (1,0) , (1,1) , (2,2)]) - self.assertEqual( polyline.segmentLength() , 2 + math.sqrt(2)) - - - def test_extend_to_bbox(self): - bbox = [(0,0) , (10,0) , (10,10) , (0,10)] - - polyline = CPolyline( init_points = [(11,11) , (13,13)]) - with self.assertRaises(ValueError): - polyline.extendToBBox( bbox , start = False ) - - - polyline = CPolyline( init_points = [(1,1) , (3,3)]) - - line1 = polyline.extendToBBox( bbox , start = True ) - self.assertEqual( line1 , CPolyline( init_points = [(1,1) , (0,0)])) - - line1 = polyline.extendToBBox( bbox , start = False ) - self.assertEqual( line1 , CPolyline( init_points = [(3,3) , (10,10)])) - - - - - def test_item(self): - polyline = CPolyline() - polyline.addPoint( 10 , 20 ) - self.assertEqual( len(polyline) , 1 ) - - with self.assertRaises(TypeError): - (x,y) = polyline["KEY"] - - with self.assertRaises(IndexError): - (x,y) = polyline[10] - - (x,y) = polyline[0] - self.assertEqual( x , 10 ) - self.assertEqual( y , 20 ) - - polyline.addPoint(20,20) - (x,y) = polyline[-1] - self.assertEqual( x , 20 ) - self.assertEqual( y , 20 ) - - - def test_cross_segment(self): - polyline = CPolyline( init_points = [(0,0), (1,0) , (1,1)]) - # - # x - # | - # | - # | - # x-------x - # - - self.assertTrue(polyline.segmentIntersects( (0.5 , 0.5) , (0.5 , -0.5))) - self.assertTrue(polyline.segmentIntersects( (0.5 , 0.5) , (1.5 , 0.5))) - - self.assertFalse(polyline.segmentIntersects( (0.5 , 0.5) , ( 0.5 , 1.5))) - self.assertFalse(polyline.segmentIntersects( (0.5 , 0.5) , (-0.5 , 0.5))) - self.assertFalse(polyline.segmentIntersects( (0.5 , 1.5) , ( 1.5 , 1.5))) - - self.assertTrue( polyline.segmentIntersects( (1.0 , 1.0) , ( 1.5 , 1.5))) - self.assertTrue( polyline.segmentIntersects( ( 1.5 , 1.5) , (1.0 , 1.0))) - self.assertTrue( polyline.segmentIntersects( ( 1 , 0) , (1.0 , 1.0))) - - - - def test_intersects(self): - polyline1 = CPolyline( init_points = [(0,0), (1,0) , (1,1)]) - polyline2 = CPolyline( init_points = [(0.50,0.50) , (1.50,0.50)]) - polyline3 = Polyline( init_points = [(0.50,0.50) , (1.50,0.50)]) - polyline4 = CPolyline( init_points = [(0.50,1.50) , (1.50,1.50)]) - - self.assertTrue( polyline1.intersects( polyline2 )) - self.assertTrue( polyline1.intersects( polyline3 )) - self.assertFalse( polyline1.intersects( polyline4 )) - - - def test_intersects2(self): - polyline = CPolyline( init_points = [(2,10),(2,100)]) - self.assertTrue( polyline.intersects( polyline )) - - - - def test_name(self): - p1 = CPolyline() - self.assertTrue( p1.getName() is None ) - - p2 = CPolyline( name = "Poly2" ) - self.assertEqual( p2.getName() , "Poly2") - - - def test_unzip(self): - pl = CPolyline( init_points = [(0,3) , (1,4) , (2,5)] ) - x,y = pl.unzip() - self.assertEqual(x , [0,1,2]) - self.assertEqual(y , [3,4,5]) - - - diff --git a/ThirdParty/Ert/python/tests/geometry/test_cpolyline_collection.py b/ThirdParty/Ert/python/tests/geometry/test_cpolyline_collection.py deleted file mode 100644 index 11ab6a63cd..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_cpolyline_collection.py +++ /dev/null @@ -1,133 +0,0 @@ -import gc - -from ecl.geo import CPolylineCollection , CPolyline -from ecl.geo.xyz_io import XYZIo -from ecl.test import ExtendedTestCase , TestAreaContext -from ecl.util import DoubleVector - -class CPolylineCollectionTest(ExtendedTestCase): - - def test_construction(self): - pc = CPolylineCollection() - self.assertEqual(len(pc) , 0) - - - def test_add_polyline(self): - pc = CPolylineCollection() - pl = pc.createPolyline( name = "TestP" ) - self.assertTrue( isinstance(pl , CPolyline)) - self.assertEqual(len(pc) , 1) - self.assertTrue( "TestP" in pc ) - - with self.assertRaises(IndexError): - pl = pc[2] - - p0 = pc[0] - self.assertTrue( p0 == pl ) - - with self.assertRaises(KeyError): - pn = pc["missing"] - - pn = pc["TestP"] - self.assertTrue( pn == pl ) - - px = CPolyline( name = "TestP") - with self.assertRaises(KeyError): - pc.addPolyline( px ) - self.assertEqual(len(pc) , 1) - - - p2 = CPolyline( name = "Poly2") - pc.addPolyline( p2 ) - - self.assertEqual( len(pc) , 2 ) - self.assertTrue( "Poly2" in pc ) - - l = [] - for p in pc: - l.append(p) - self.assertEqual( len(pc) , 2 ) - - - points = [(0,1) , (1,1)] - pc.addPolyline( points , name = "XYZ") - self.assertTrue( "XYZ" in pc ) - - - - - def create_collection(self): - collection = CPolylineCollection() - p1 = CPolyline( name = "POLY1" , init_points = [(0,10) , (1,11) , (2,12)]) - p2 = CPolyline( name = "POLY2" , init_points = [(0,100) , (10,110) , (20,120)]) - collection.addPolyline( p1 ) - collection.addPolyline( p2 ) - - tail = p1[-1] - self.assertEqual( tail , (2,12)) - self.assertEqual(p1.getName() , "POLY1") - - tail = p2[-1] - self.assertEqual( tail , (20,120)) - self.assertEqual(p2.getName() , "POLY2") - - return collection - - - def test_gc_polyline(self): - # This should test that the elements in the collection can be - # safely accessed, even after the polyline objects p1 and p2 - # from create_collection() have gone out of scope. - c = self.create_collection() - v = DoubleVector(initial_size = 10000) - - p1 = c[0] - tail = p1[-1] - self.assertEqual( tail , (2,12)) - self.assertEqual(p1.getName() , "POLY1") - - p2 = c[1] - tail = p2[-1] - self.assertEqual( tail , (20,120)) - self.assertEqual(p2.getName() , "POLY2") - - - def get_polyline(self): - collection = self.create_collection() - return collection[0] - - - def test_gc_collection(self): - p1 = self.get_polyline() - tail = p1[-1] - self.assertEqual( tail , (2,12)) - self.assertEqual( p1.getName() , "POLY1") - - def create_coll2(self): - coll1 = self.create_collection() - coll2 = coll1.shallowCopy() - coll1.addPolyline( CPolyline( name = "POLY3" , init_points = [(1,1) , (2,2) , (1,3) , (1,1)])) - - self.assertEqual(len(coll1) , 3) - self.assertTrue( "POLY3" in coll1 ) - - self.assertEqual(len(coll2) , 2) - self.assertFalse( "POLY3" in coll2 ) - - return coll2 - - - def test_shallow_copy(self): - coll2 = self.create_coll2() - self.assertEqual(len(coll2) , 2) - - p1 = coll2["POLY1"] - tail = p1[-1] - self.assertEqual( tail , (2,12)) - self.assertEqual(p1.getName() , "POLY1") - - p2 = coll2["POLY2"] - tail = p2[-1] - self.assertEqual( tail , (20,120)) - self.assertEqual(p2.getName() , "POLY2") - diff --git a/ThirdParty/Ert/python/tests/geometry/test_geo_pointset.py b/ThirdParty/Ert/python/tests/geometry/test_geo_pointset.py deleted file mode 100644 index 1d1c423f17..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_geo_pointset.py +++ /dev/null @@ -1,27 +0,0 @@ -from ecl.geo import GeoPointset, Surface -from ecl.test import ExtendedTestCase, TestAreaContext - - -class GeoPointsetTest(ExtendedTestCase): - - def test_init(self): - gp = GeoPointset() - self.assertEqual(0, len(gp)) - - def test_repr(self): - gp = GeoPointset() - self.assertTrue(repr(gp).startswith('GeoPointset')) - - def test_from_surface(self): - srf_path = self.createTestPath("local/geometry/surface/valid_ascii.irap") - srf = Surface(srf_path) - gp = GeoPointset.fromSurface(srf) - self.assertEqual(3871, len(srf)) - self.assertEqual(len(srf), len(gp)) - - def test_getitem(self): - srf_path = self.createTestPath("local/geometry/surface/valid_ascii.irap") - srf = Surface(srf_path) - gp = GeoPointset.fromSurface(srf) - for i in (561, 1105, 1729, 2465, 2821): - self.assertEqual(gp[i], srf[i]) diff --git a/ThirdParty/Ert/python/tests/geometry/test_geo_region.py b/ThirdParty/Ert/python/tests/geometry/test_geo_region.py deleted file mode 100644 index 949ced3128..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_geo_region.py +++ /dev/null @@ -1,88 +0,0 @@ -from ecl.geo import GeoRegion, GeoPointset, CPolyline, Surface -from ecl.test import ExtendedTestCase, TestAreaContext - - -class GeoRegionTest(ExtendedTestCase): - - def test_init(self): - pointset = GeoPointset() - georegion = GeoRegion(pointset) - self.assertEqual(0, len(georegion)) - - def test_repr(self): - pointset = GeoPointset() - georegion = GeoRegion(pointset) - self.assertTrue(repr(georegion).startswith('GeoRegion')) - - @staticmethod - def small_surface(): - ny,nx = 12,12 - xinc,yinc = 1, 1 - xstart,ystart = -1, -1 - angle = 0.0 - s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) - return Surface(*s_args) - - def test_select_polygon(self): - surface = self.small_surface() - pointset = GeoPointset.fromSurface(surface) - georegion = GeoRegion(pointset) - self.assertEqual(0, len(georegion)) - points = [(-0.1,2.0), (1.9,8.1), (6.1,8.1), (9.1,5), (7.1,0.9)] - polygon = CPolyline(name='test_polygon', init_points=points) - picked = 52 # https://www.futilitycloset.com/2013/04/24/picks-theorem/ - georegion.select_inside(polygon) - self.assertEqual(picked, len(georegion)) - georegion.deselect_inside(polygon) - self.assertEqual(0, len(georegion)) - georegion.select_outside(polygon) - self.assertEqual(len(surface) - picked, len(georegion)) - georegion.deselect_outside(polygon) - self.assertEqual(0, len(georegion)) - - georegion.select_inside(polygon) - georegion.select_outside(polygon) - self.assertEqual(len(surface), len(georegion)) - georegion.deselect_inside(polygon) - georegion.deselect_outside(polygon) - self.assertEqual(0, len(georegion)) - - georegion.select_inside(polygon) - self.assertEqual(picked, len(georegion)) - internal_square = [(2.5,2.5), (2.5,6.5), (6.5,6.5), (6.5,2.5)] - georegion.deselect_inside(CPolyline(init_points=internal_square)) - self.assertEqual(picked - 4*4, len(georegion)) # internal square is 4x4 - - - def test_select_halfspace(self): - surface = self.small_surface() - pointset = GeoPointset.fromSurface(surface) - georegion = GeoRegion(pointset) - self.assertEqual(0, len(georegion)) - line = [(-0.1,2.0), (1.9,8.1)] - picked = 118 - georegion.select_above(line) - self.assertEqual(picked, len(georegion)) - georegion.deselect_above(line) - self.assertEqual(0, len(georegion)) - georegion.select_below(line) - self.assertEqual(len(surface) - picked, len(georegion)) - georegion.deselect_below(line) - self.assertEqual(0, len(georegion)) - - georegion.select_above(line) - georegion.select_below(line) - self.assertEqual(len(surface), len(georegion)) - georegion.deselect_above(line) - georegion.deselect_below(line) - self.assertEqual(0, len(georegion)) - - - def test_raises(self): - surface = self.small_surface() - pointset = GeoPointset.fromSurface(surface) - georegion = GeoRegion(pointset) - with self.assertRaises(ValueError): - georegion.select_above(((2,), (1, 3))) - with self.assertRaises(ValueError): - georegion.select_above((('not-a-number', 2), (1, 3))) diff --git a/ThirdParty/Ert/python/tests/geometry/test_geometry_tools.py b/ThirdParty/Ert/python/tests/geometry/test_geometry_tools.py deleted file mode 100644 index 0656677ad6..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_geometry_tools.py +++ /dev/null @@ -1,80 +0,0 @@ -import math - -from ecl.geo import Polyline, GeometryTools , CPolyline -from ecl.geo.xyz_io import XYZIo -from ecl.test import ExtendedTestCase , TestAreaContext - - -class GeometryToolsTest(ExtendedTestCase): - - def test_distance(self): - p1 = (1,1) - p2 = (1,2,3) - with self.assertRaises(ValueError): - GeometryTools.distance( p1 , p2) - - with self.assertRaises(TypeError): - GeometryTools.distance( 1 , p2 ) - - p2 = (2,2) - self.assertEqual( GeometryTools.distance( p1 , p2) , math.sqrt(2)) - - p1 = (1,1,1) - p2 = (2,2,2) - self.assertEqual( GeometryTools.distance( p1 , p2) , math.sqrt(3)) - - - def test_join__polylines(self): - l1 = Polyline( init_points = [(0,1) , (1,1)]) - l2 = CPolyline( init_points = [(2,-1) , (2,0)]) - l3 = CPolyline( init_points = [(2,2) , (2,3)]) - l4 = Polyline( ) - l5 = CPolyline( init_points = [(0.5,0),(0.5,2)] ) - - with self.assertRaises( ValueError ): - GeometryTools.joinPolylines( l1 , l4 ) - - with self.assertRaises( ValueError ): - GeometryTools.joinPolylines( l4 , l1 ) - - self.assertIsNone( GeometryTools.joinPolylines( l1 , l5 )) - - self.assertEqual( GeometryTools.joinPolylines( l1 , l2 ) , [(1,1) , (2,0)] ) - - - def test_join_extend_polylines_onto(self): - l1 = Polyline( init_points = [(0,1) , (1,1)]) - l2 = CPolyline( init_points = [(2,0) , (2,2)]) - l3 = CPolyline( init_points = [(0.5 , 0) , (0.5 , 2)]) - l4 = Polyline( init_points = [(0,5) , (1,5)]) - l5 = Polyline( init_points = [(0,5)]) - - self.assertIsNone( GeometryTools.connectPolylines( l1 , l3 )) - - with self.assertRaises( ValueError ): - GeometryTools.connectPolylines( l1 , l5 ) - - with self.assertRaises( ValueError ): - GeometryTools.connectPolylines( l1 , l4 ) - - self.assertEqual( GeometryTools.connectPolylines( l1 , l2 ) , [(1,1) , (2,1)]) - - def test_ray_line_intersection(self): - p = GeometryTools.rayLineIntersection((0,0) , (1,0) , (5,-1),(5,1)) - self.assertEqual( p , (5,0)) - - self.assertIsNone( GeometryTools.rayLineIntersection((0,0) , (-1,0) , (5,-1),(5,1)) ) - self.assertIsNone( GeometryTools.rayLineIntersection((0,0) , (0,1) , (5,-1),(5,1)) ) - self.assertIsNone( GeometryTools.rayLineIntersection((0,0) , (0,-1) , (5,-1),(5,1)) ) - - p = GeometryTools.rayLineIntersection((0,0) , (1,1) , (5,-6),(5,6)) - self.assertEqual( p , (5,5)) - - - def test_nearest_point(self): - l1 = Polyline( init_points = [(0,0) , (10,0)]) - - p = GeometryTools.nearestPointOnPolyline( (5 , 5) , l1 ) - self.assertEqual( p , (5 , 0) ) - - diff --git a/ThirdParty/Ert/python/tests/geometry/test_intersection.py b/ThirdParty/Ert/python/tests/geometry/test_intersection.py deleted file mode 100644 index af78512e84..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_intersection.py +++ /dev/null @@ -1,47 +0,0 @@ -from ecl.geo import GeometryTools -from ecl.test.extended_testcase import ExtendedTestCase - - -class IntersectionTest(ExtendedTestCase): - - def test_intersection(self): - - p1 = (0.0, 0.0) - p2 = (10.0, 0.0) - p3 = (5.0, -5.0) - p4 = (5.0, 5.0) - - self.assertEqual(GeometryTools.lineIntersection(p1, p2, p3, p4), (5.0, 0.0)) - - p5 = (0.0, 5.0) - self.assertEqual(GeometryTools.lineIntersection(p1, p2, p3, p5), (2.5, 0)) - - - self.assertEqual(GeometryTools.lineIntersection((0.0, 0.0), (1.0, 1.0), (0.0, 1.0), (1.0, 0.0)), (0.5, 0.5)) - - - def test_coincident(self): - p1 = (0.0, 0.0) - p2 = (10.0, 10.0) - - self.assertIsNone( GeometryTools.lineIntersection(p1, p2, p1, p2) ) - - - def test_parallel(self): - p1 = (0.0, 0.0) - p2 = (10.0, 0.0) - - p3 = (0.0, 1.0) - p4 = (10.0, 1.0) - - self.assertIsNone(GeometryTools.lineIntersection(p1, p2, p3, p4)) - - - def test_intersection_outside_segments(self): - p1 = (0.0, 0.0) - p2 = (10.0, 0.0) - - p3 = (-1.0, -1.0) - p4 = (-1.0, 1.0) - - self.assertIsNone(GeometryTools.lineIntersection(p1, p2, p3, p4)) diff --git a/ThirdParty/Ert/python/tests/geometry/test_point_in_polygon.py b/ThirdParty/Ert/python/tests/geometry/test_point_in_polygon.py deleted file mode 100644 index 8faeb9ca5f..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_point_in_polygon.py +++ /dev/null @@ -1,60 +0,0 @@ -from ecl.geo.geometry_tools import GeometryTools -from ecl.geo.polyline import Polyline -from ecl.test.extended_testcase import ExtendedTestCase - - -class PointInPolygonTest(ExtendedTestCase): - - def test_point_in_polygon(self): - p1 = (0.5, 0.5) - p2 = (2, 2) - p3 = (1, 0.5) # on the edge - - poly1 = [(0, 0), (1, 0), (1, 1), (0, 1)] # Not explicitly closed - poly2 = [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)] # explicitly closed - - self.assertTrue(GeometryTools.pointInPolygon(p1, poly1)) - self.assertTrue(GeometryTools.pointInPolygon(p1, poly2)) - - self.assertFalse(GeometryTools.pointInPolygon(p2, poly1)) - self.assertFalse(GeometryTools.pointInPolygon(p2, poly2)) - - self.assertTrue(GeometryTools.pointInPolygon(p3, poly1)) - - - def test_point_in_polyline(self): - p1 = (0.5, 0.5) - p2 = (2, 2) - - poly = Polyline() - poly.addPoint(0, 0) - poly.addPoint(1, 0) - poly.addPoint(1, 1) - poly.addPoint(0, 1) - poly.addPoint(0, 0) - - self.assertTrue(GeometryTools.pointInPolygon(p1, poly)) - self.assertTrue(GeometryTools.pointInPolygon(p1, poly)) - - self.assertFalse(GeometryTools.pointInPolygon(p2, poly)) - self.assertFalse(GeometryTools.pointInPolygon(p2, poly)) - - - def test_point_in_strange_polygon(self): - p1 = (0.5, 0.51) - p2 = (0.5, 0.49) - - poly = [(0,0), (0, 1), (0.6, 0.5), (0.4, 0.5), (1, 1), (1, 0)] - - self.assertFalse(GeometryTools.pointInPolygon(p1, poly)) - self.assertTrue(GeometryTools.pointInPolygon(p2, poly)) - - - def test_point_in_polygon_with_3_element_points(self): - p1 = (0.5, 0.51, 0.2) - p2 = (0.5, 0.49, 0.1) - - poly = [(0,0,9), (0,1,9), (0.6,0.5), (0.4,0.5,9), (1,1), (1,0,9)] - - self.assertFalse(GeometryTools.pointInPolygon(p1, poly)) - self.assertTrue(GeometryTools.pointInPolygon(p2, poly)) \ No newline at end of file diff --git a/ThirdParty/Ert/python/tests/geometry/test_polygon_slicing.py b/ThirdParty/Ert/python/tests/geometry/test_polygon_slicing.py deleted file mode 100644 index e2493e6822..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_polygon_slicing.py +++ /dev/null @@ -1,139 +0,0 @@ -from math import sqrt -from ecl.geo.geometry_tools import GeometryTools -from ecl.test import ExtendedTestCase - - -class PolygonSlicingTest(ExtendedTestCase): - - 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)] - - sliced = GeometryTools.slicePolygon(edge , polygon) - expected = [(2,2),(2,1),(1,1),(1,5),(5,5),(5,4),(4,4),(2.0,4.0),(2,2)] - self.assertEqual(sliced, expected) - - - - def test_line_to_ray(self): - p0 = (0.0, 0.0) - p1 = (1.0, 1.0) - p2 = (1.0, 0.0) - - ray = GeometryTools.lineToRay(p0, p1) - self.assertEqual(ray, (1.0 / sqrt(2.0), 1.0 / sqrt(2.0))) - - ray = GeometryTools.lineToRay(p1, p0) - self.assertEqual(ray, (-1.0 / sqrt(2.0), -1.0 / sqrt(2.0))) - - ray = GeometryTools.lineToRay(p0, p2) - self.assertEqual(ray, (1.0, 0.0)) - - - def test_ray_line_intersection(self): - p0 = (0.0, 0.0) - p1 = (0.0, 1.0) - p2 = (1.0, 1.0) - p3 = (1.0, 0.0) - p5 = (2.0, 1.0) - - ray1 = GeometryTools.lineToRay(p0, p2) - ray2 = GeometryTools.lineToRay(p2, p0) - ray3 = GeometryTools.lineToRay(p0, p5) - - self.assertEqual((0.5, 0.5), GeometryTools.rayLineIntersection(p0, ray1, p1, p3)) - self.assertIsNone(GeometryTools.rayLineIntersection(p0, ray2, p1, p3)) #ray2 is ray1 reversed (no backwards intersections) - - self.assertEqual((1.0, 0.5), GeometryTools.rayLineIntersection(p0, ray3, p2, p3)) - self.assertIsNone(GeometryTools.rayLineIntersection(p0, ray3, p1, p2)) - - - - - def test_slicing_short_line_segment(self): - p0 = (0.0, 0.0) - p1 = (0.0, 1.0) - p2 = (1.0, 1.0) - p3 = (1.0, 0.0) - polygon = [p0, p1, p2, p3, p0] - lp0 = (0.2, 0.5) - lp1 = (0.4, 0.5) - line = [lp0, lp1] - - result = GeometryTools.slicePolygon(polygon, line) - - expected = [(0.0, 0.5), p1, p2, (1.0, 0.5), lp1, lp0, (0.0, 0.5)] - - self.assertEqual(result, expected) - - - def test_slicing_bendy_line_segments(self): - p0 = (0.0, 0.0) - p1 = (0.0, 1.0) - p2 = (1.0, 1.0) - p3 = (1.0, 0.0) - polygon = [p0, p1, p2, p3, p0] - - lp0 = (0.2, 0.5) - lp1 = (0.4, 0.5) - lp2 = (0.4, 0.3) - line = [lp0, lp1, lp2] - - expected = [(0.0, 0.5), p1, p2, p3, (0.4, 0.0), lp2, lp1, lp0, (0.0, 0.5)] - - result = GeometryTools.slicePolygon(polygon, line) - self.assertEqual(result, expected) - - line = [lp2, lp1, lp0] - result = GeometryTools.slicePolygon(polygon, line) - self.assertEqual(result, expected) - - - def test_slicing_same_segment(self): - p0 = (0.0, 0.0) - p1 = (0.0, 1.0) - p2 = (1.0, 1.0) - p3 = (1.0, 0.0) - polygon = [p0, p1, p2, p3, p0] - - lp0 = (0.2, 0.5) - lp1 = (0.4, 0.5) - lp2 = (0.4, 0.3) - lp3 = (0.2, 0.3) - - line = [lp0, lp1, lp2, lp3] - result = GeometryTools.slicePolygon(polygon, line) - expected = [(0.0, 0.5), (0.0, 0.3), lp3, lp2, lp1, lp0, (0.0, 0.5)] - self.assertEqual(result, expected) - - line = [lp3, lp2, lp1, lp0] - result = GeometryTools.slicePolygon(polygon, line) - expected = [(0.0, 0.3), (0.0, 0.5), lp0, lp1, lp2, lp3, (0.0, 0.3)] - self.assertEqual(result, expected) - - - def test_ray_polyline_intersections(self): - # /.\ - # . - # . - # (4)---------+----(3) - # /________:_____:_________ - # \ . | - # (1)--+----(2) - # | . - # | . - # (0) . - - - polygon = [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 2.0), (-1.0, 2.0)] - - p0 = (0.5, 0.0) - ray0 = (0.0, 1.0) - intersections0 = GeometryTools.rayPolygonIntersections(p0, ray0, polygon) - self.assertEqual(intersections0, [(1, (0.5, 1.0)), (3, (0.5, 2.0))]) - - - p1 = (1.5, 1.5) - ray1 = (-1.0, 0.0) - intersections1 = GeometryTools.rayPolygonIntersections(p1, ray1, polygon) - self.assertEqual(intersections1, [(2, (1, 1.5))]) diff --git a/ThirdParty/Ert/python/tests/geometry/test_polyline.py b/ThirdParty/Ert/python/tests/geometry/test_polyline.py deleted file mode 100644 index bd9e262cff..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_polyline.py +++ /dev/null @@ -1,193 +0,0 @@ - -from ecl.geo import Polyline, GeometryTools -from ecl.geo.xyz_io import XYZIo -from ecl.test import ExtendedTestCase , TestAreaContext - - -class PolylineTest(ExtendedTestCase): - def setUp(self): - self.polyline = self.createTestPath("local/geometry/pol11.xyz") - self.closed_polyline = self.createTestPath("local/geometry/pol8.xyz") - - def test_construction(self): - polyline = Polyline(name="test line") - - with self.assertRaises(IndexError): - polyline.isClosed() - - self.assertEqual(polyline.getName(), "test line") - - self.assertEqual(len(polyline), 0) - - polyline.addPoint(0, 0, 0) - self.assertEqual(len(polyline), 1) - - polyline.addPoint(1, 1, 0) - self.assertEqual(len(polyline), 2) - - polyline.addPoint(1, 1.5) - self.assertEqual(len(polyline), 3) - - self.assertEqual(polyline[0], (0, 0, 0)) - self.assertEqual(polyline[1], (1, 1, 0)) - self.assertEqual(polyline[2], (1, 1.5)) - - polyline.addPoint(0, 1, 0) - self.assertFalse(polyline.isClosed()) - - polyline.addPoint(0, 0, 0) - self.assertTrue(polyline.isClosed()) - - - - def test_construction_default(self): - with self.assertRaises(TypeError): - pl = Polyline( init_points = 1 ) - - with self.assertRaises(TypeError): - pl = Polyline( init_points = [1.23] ) - - pl = Polyline( init_points = [(1,0) , (1,1) , (1,2)]) - self.assertEqual( len(pl) , 3 ) - - - - - def test_iteration(self): - values = [(0, 0, 0), - (1, 0, 0), - (1, 1, 0), - (1, 1, 1)] - - polyline = Polyline(name="iteration line") - - for p in values: - polyline.addPoint(*p) - - for index, point in enumerate(polyline): - self.assertEqual(point, values[index]) - - - - def test_read_xyz_from_file(self): - with self.assertRaises(IOError): - XYZIo.readXYZFile("does/not/exist.xyz") - - polyline = XYZIo.readXYZFile(self.polyline) - - self.assertEqual(polyline.getName(), "pol11.xyz") - self.assertEqual(len(polyline), 13) - self.assertFalse(polyline.isClosed()) - self.assertEqual(polyline[0], (390271.843750, 6606121.334396, 1441.942627)) # first point - self.assertEqual(polyline[12], (389789.263184, 6605784.945099, 1446.627808)) # last point - - polyline = XYZIo.readXYZFile(self.closed_polyline) - - self.assertEqual(polyline.getName(), "pol8.xyz") - self.assertEqual(len(polyline), 21) - self.assertTrue(polyline.isClosed()) - self.assertEqual(polyline[0], (396202.413086, 6606091.935028, 1542.620972)) # first point - self.assertEqual(polyline[20], (396202.413086, 6606091.935028, 1542.620972)) # last point - - - def test_closed(self): - pl = Polyline( init_points = [(1,0) , (1,1) , (0,2)]) - self.assertFalse( pl.isClosed() ) - pl.addPoint( 1,0 ) - self.assertEqual( 4 , len(pl) ) - self.assertTrue( pl.isClosed() ) - - pl = Polyline( init_points = [(1,0) , (1,1) , (0,2)]) - self.assertFalse( pl.isClosed() ) - pl.assertClosed( ) - self.assertEqual( 4 , len(pl) ) - self.assertTrue( pl.isClosed() ) - - - def test_save(self): - with TestAreaContext("polyline/fwrite") as work_area: - p1 = Polyline( init_points = [(1,0) , (1,1) , (1,2)]) - p2 = Polyline( init_points = [(1,0) , (1,1) , (1,2)]) - self.assertTrue( p1 == p2 ) - - XYZIo.saveXYFile(p1 , "poly.xy") - - p2 = XYZIo.readXYFile("poly.xy") - self.assertTrue( p1 == p2 ) - - - def test_unzip(self): - p2 = Polyline( init_points = [(1,0) , (1,1) , (1,2)]) - p3 = Polyline( init_points = [(1,0,1) , (1,1,2) , (1,2,3)]) - (x,y) = p2.unzip() - self.assertEqual( x , [1,1,1]) - self.assertEqual( y , [0,1,2]) - - (x,y,z) = p3.unzip() - self.assertEqual( x , [1,1,1]) - self.assertEqual( y , [0,1,2]) - self.assertEqual( z , [1,2,3]) - - - with self.assertRaises(ValueError): - (x,y,z) = p2.unzip() - - with self.assertRaises(ValueError): - (x,y) = p3.unzip() - - - def test_intersection(self): - p1 = Polyline( init_points = [(0,0) , (1,0)]) - p2 = Polyline( init_points = [(0.5 , 0.5) , (0.5,-0.5)]) - p3 = Polyline( init_points = [(0,1) , (1,1)]) - - self.assertTrue(GeometryTools.polylinesIntersect( p1 , p2 )) - self.assertFalse( GeometryTools.polylinesIntersect( p2 , p3 )) - self.assertFalse( GeometryTools.polylinesIntersect( p1 , p3 )) - - self.assertTrue( p1.intersects(p2) ) - self.assertTrue( p2.intersects(p1) ) - - self.assertTrue( not p1.intersects(p3) ) - self.assertTrue( not p3.intersects(p1) ) - - - def test_add(self): - l1 = Polyline( init_points = [(-1,0.5) , (0.5, 0.5)]) - l2 = Polyline( init_points = [(-1,0.5) , (0.5, 0.5)]) - - l3 = l1 + l2 - self.assertEqual( len(l3) , 4 ) - self.assertEqual( l1[0] , l3[0] ) - self.assertEqual( l1[1] , l3[1] ) - self.assertEqual( l1[0] , l3[2] ) - self.assertEqual( l1[1] , l3[3] ) - - l4 = l1 - l4 += l2 - self.assertEqual(l3 , l4) - - - - def test_extend_to_edge(self): - bound = Polyline( init_points = [(0,0) , (1,0) , (1,1) , (0,1)] ) - l1 = Polyline( init_points = [(-1,0.5) , (0.5, 0.5)]) - l2 = Polyline( init_points = [(0.25,0.25) , (0.75, 0.75)]) - - # Bound is not closed - with self.assertRaises(AssertionError): - GeometryTools.extendToEdge( bound , l1 ) - - bound.assertClosed() - # l1 is not fully contained in bound - with self.assertRaises(ValueError): - GeometryTools.extendToEdge( bound , l1 ) - - l3 = GeometryTools.extendToEdge( bound , l2 ) - self.assertEqual( l3[0] , (0.00,0.00)) - self.assertEqual( l3[1] , (0.25,0.25)) - self.assertEqual( l3[2] , (0.75,0.75)) - self.assertEqual( l3[3] , (1.00,1.00)) - self.assertEqual( len(l3) , 4) - - diff --git a/ThirdParty/Ert/python/tests/geometry/test_surface.py b/ThirdParty/Ert/python/tests/geometry/test_surface.py deleted file mode 100644 index 995c34bcdb..0000000000 --- a/ThirdParty/Ert/python/tests/geometry/test_surface.py +++ /dev/null @@ -1,210 +0,0 @@ -import random -from ecl.geo import Surface -from ecl.test import ExtendedTestCase , TestAreaContext - - -class SurfaceTest(ExtendedTestCase): - def setUp(self): - self.surface_valid = self.createTestPath("local/geometry/surface/valid_ascii.irap") - self.surface_short = self.createTestPath("local/geometry/surface/short_ascii.irap") - self.surface_long = self.createTestPath("local/geometry/surface/long_ascii.irap") - self.surface_valid2 = self.createTestPath("local/geometry/surface/valid2_ascii.irap") - self.surface_small = self.createTestPath("local/geometry/surface/valid_small_ascii.irap") - - def test_xyz(self): - s = Surface(self.surface_valid2) - self.assertEqual(s.getXYZ(i=5,j=13), s.getXYZ(idx=642)) - x,y,z = s.getXYZ(i=5,j=13) - self.assertFloatEqual(464041.44804, x) - self.assertFloatEqual(7336966.309535, y) - self.assertFloatEqual(0.0051, z) - self.assertAlmostEqualList(s.getXYZ(i=6,j=13), s.getXYZ(idx=643)) - self.assertFloatEqual(-0.0006, s.getXYZ(i=6,j=13)[2]) # z value - - def test_create_new(self): - with self.assertRaises(ValueError): - s = Surface(None, 1, 1, 1) - with self.assertRaises(IOError): - s = Surface(50, 1, 1, 1) - - # values copied from irap surface_small - ny,nx = 20,30 - xinc,yinc = 50.0, 50.0 - xstart,ystart = 463325.5625, 7336963.5 - angle = -65.0 - s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) - s = Surface(*s_args) - self.assertEqual(ny*nx, len(s)) - self.assertEqual(nx, s.getNX()) - self.assertEqual(ny, s.getNY()) - small = Surface (self.surface_small) - self.assertTrue(small.headerEqual(s)) - valid = Surface (self.surface_valid) - self.assertFalse(valid.headerEqual(s)) - - self.assertNotEqual(s, small) - idx = 0 - for i in range(nx): - for j in range(ny): - s[idx] = small[idx] - idx += 1 - self.assertEqual(s, small) - - def test_create(self): - with self.assertRaises(IOError): - s = Surface("File/does/not/exist") - - with self.assertRaises(ValueError): - s = Surface(self.surface_short) - - with self.assertRaises(ValueError): - s = Surface(self.surface_long) - - s = Surface( self.surface_valid ) - - self.assertEqual( s.getNX( ) , 49 ) - self.assertEqual( s.getNY( ) , 79 ) - self.assertEqual( len(s) , 49*79 ) - - with self.assertRaises(IndexError): - v = s[49 * 79] - - with self.assertRaises(TypeError): - v = s["KEY"] - - self.assertEqual( s[0] , 0.0051 ) - self.assertEqual( s[-1] , -0.0014 ) - - with self.assertRaises(IndexError): - s[49*79] = 787 - - s[0] = 10 - self.assertEqual( s[0] , 10 ) - - s[-1] = 77 - self.assertEqual( s[len(s) - 1] , 77 ) - - - def test_write(self): - with TestAreaContext("surface/write"): - - s0 = Surface( self.surface_valid ) - s0.write( "new_surface.irap") - - s1 = Surface( "new_surface.irap") - self.assertTrue( s1 == s0 ) - - s0[0] = 99 - self.assertFalse( s1 == s0 ) - - - - def test_copy(self): - with TestAreaContext("surface/copy"): - s0 = Surface( self.surface_valid ) - s1 = s0.copy( ) - - self.assertTrue( s1 == s0 ) - s1[0] = 99 - self.assertFalse( s1 == s0 ) - del s0 - self.assertEqual( s1[0] , 99) - - s2 = s1.copy( copy_data = False ) - self.assertEqual( s2[0] , 0.0 ) - self.assertEqual( s2[10] , 0.0 ) - self.assertEqual( s2[100] , 0.0 ) - - - def test_header_equal(self): - s0 = Surface( self.surface_valid ) - s1 = Surface( self.surface_valid2 ) - s2 = s0.copy( ) - - self.assertTrue( s0.headerEqual( s0 )) - self.assertFalse( s0.headerEqual( s1 )) - self.assertTrue( s0.headerEqual( s2 )) - - - def test_ops(self): - s0 = Surface( self.surface_valid ) - s0.assign(1.0) - for v in s0: - self.assertEqual(v , 1.0) - - s0 += 1 - for v in s0: - self.assertEqual(v , 2.0) - - s0 *= 2 - for v in s0: - self.assertEqual(v , 4.0) - - s1 = s0 + 4 - for v in s1: - self.assertEqual(v , 8.0) - - s2 = Surface( self.surface_valid2 ) - with self.assertRaises(ValueError): - s3 = s1 + s2 - - s4 = s1 + s0 - for v in s4: - self.assertEqual(v , 12.0) - - s5 = s4 / 12 - for v in s5: - self.assertEqual(v , 1.0) - - - def test_ops2(self): - s0 = Surface( self.surface_small ) - surface_list = [] - for i in range(10): - s = s0.copy() - for j in range(len(s)): - s[j] = random.random() - surface_list.append(s) - - mean = s0.copy( copy_data = False ) - for s in surface_list: - mean += s - mean /= len(surface_list) - - std = s0.copy( copy_data = False ) - for s in surface_list: - std += (s - mean) * (s - mean) - std /= (len(surface_list) - 1) - - - def test_sqrt(self): - s0 = Surface( self.surface_small ) - s0.assign(4) - self.assertEqual(20*30, len(s0)) - s_sqrt = s0.sqrt( ) - for i in range(len(s0)): - self.assertEqual(s0[i] , 4) - self.assertEqual(s_sqrt[i] , 2) - s0.inplaceSqrt( ) - self.assertTrue( s0 == s_sqrt ) - - - def test_xy(self): - ny,nx = 20,30 - xinc,yinc = 50.0, 50.0 - xstart,ystart = 463325.5625, 7336963.5 - angle = 0 - s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) - s = Surface(*s_args) - - xy = s.getXY(0) - self.assertEqual((xstart, ystart), xy) - - xy = s.getXY(1) - self.assertEqual((xstart+xinc, ystart), xy) - - xy = s.getXY(nx) - self.assertEqual((xstart, ystart+yinc), xy) - - xy = s.getXY(-1) - self.assertEqual((xstart+xinc*(nx-1), ystart+yinc*(ny-1)), xy) diff --git a/ThirdParty/Ert/python/tests/global/CMakeLists.txt b/ThirdParty/Ert/python/tests/global/CMakeLists.txt deleted file mode 100644 index 957c12c570..0000000000 --- a/ThirdParty/Ert/python/tests/global/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(TEST_SOURCES - __init__.py - test_import.py - test_pylint.py -) - -add_python_package("python.tests.global" "${PYTHON_INSTALL_PREFIX}/tests/global" "${TEST_SOURCES}" False) - -addPythonTest(tests.global.test_import.ImportEcl) -addPythonTest(tests.global.test_pylint.LintErt) - - diff --git a/ThirdParty/Ert/python/tests/global/__init__.py b/ThirdParty/Ert/python/tests/global/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/tests/global/test_import.py b/ThirdParty/Ert/python/tests/global/test_import.py deleted file mode 100644 index fe0835809a..0000000000 --- a/ThirdParty/Ert/python/tests/global/test_import.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import os -import sys - - -from ecl.test import ImportTestCase - -class ImportEcl(ImportTestCase): - - def test_import_ecl(self): - self.assertTrue( self.import_package( "ecl" )) diff --git a/ThirdParty/Ert/python/tests/global/test_pylint.py b/ThirdParty/Ert/python/tests/global/test_pylint.py deleted file mode 100644 index bebe2f5f48..0000000000 --- a/ThirdParty/Ert/python/tests/global/test_pylint.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.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) - pass # temporarily disable linting due to monkey patching - - def test_lint_geo(self): - self.assertLinted('ecl/geo') - - def test_lint_util(self): - self.assertLinted('ecl/util') - - def test_lint_well(self): - self.assertLinted('ecl/well') diff --git a/ThirdParty/Ert/python/tests/install/test_install.py b/ThirdParty/Ert/python/tests/install/test_install.py deleted file mode 100644 index b43ab9b903..0000000000 --- a/ThirdParty/Ert/python/tests/install/test_install.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python -import sys - -# This is a small executable which is used to verify the install, -# Prior to calling this the environment must have been prepared to -# ensure that the newly installed versions are picked up - this can -# typically be achieved with the bash script bin/test_install which is -# generated during the configure process. - -from ecl.ecl import EclSum, EclGrid - - - diff --git a/ThirdParty/Ert/python/tests/legacy/CMakeLists.txt b/ThirdParty/Ert/python/tests/legacy/CMakeLists.txt deleted file mode 100644 index 1ccd83497b..0000000000 --- a/ThirdParty/Ert/python/tests/legacy/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -set(TEST_SOURCES - __init__.py - test_ecl.py - test_geo.py - test_well.py - test_util.py - test_test.py -) - -add_python_package("python.tests.legacy.ert" ${PYTHON_INSTALL_PREFIX}/tests/legacy "${TEST_SOURCES}" False) - -addPythonTest(tests.legacy.test_ecl.ErtLegacyEclTest) -addPythonTest(tests.legacy.test_geo.ErtLegacyGeoTest) -addPythonTest(tests.legacy.test_well.ErtLegacyWellTest) -addPythonTest(tests.legacy.test_util.ErtLegacyUtilTest) -addPythonTest(tests.legacy.test_test.ErtLegacyTestTest) diff --git a/ThirdParty/Ert/python/tests/legacy/__init__.py b/ThirdParty/Ert/python/tests/legacy/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/tests/legacy/test_ecl.py b/ThirdParty/Ert/python/tests/legacy/test_ecl.py deleted file mode 100644 index f90d3fd628..0000000000 --- a/ThirdParty/Ert/python/tests/legacy/test_ecl.py +++ /dev/null @@ -1,41 +0,0 @@ -from ert.ecl import EclFileEnum, EclFileFlagEnum, EclPhaseEnum, EclUnitTypeEnum , EclUtil -from ert.ecl import EclTypeEnum, EclDataType -from ert.ecl import EclSumVarType -from ert.ecl import EclSumTStep -from ert.ecl import EclSum #, EclSumVector, EclSumNode, EclSMSPECNode -from ert.ecl import EclSumKeyWordVector -from ert.ecl import EclPLTCell, EclRFTCell -from ert.ecl import EclRFT, EclRFTFile -from ert.ecl import FortIO, openFortIO -from ert.ecl import EclKW -from ert.ecl import Ecl3DKW -from ert.ecl import EclFileView -from ert.ecl import EclFile , openEclFile -from ert.ecl import Ecl3DFile -from ert.ecl import EclInitFile -from ert.ecl import EclRestartFile -from ert.ecl import EclGrid -from ert.ecl import EclRegion -from ert.ecl import EclSubsidence -from ert.ecl import phase_deltag, deltag -from ert.ecl import EclGrav -from ert.ecl import EclSumNode -from ert.ecl import EclSumVector -from ert.ecl import EclNPV , NPVPriceVector -from ert.ecl import EclCmp -from ert.ecl import EclGridGenerator - -from ert.ecl.faults import Layer -from ert.ecl.faults import FaultCollection -from ert.ecl.faults import Fault -from ert.ecl.faults import FaultLine -from ert.ecl.faults import FaultSegment , SegmentMap -from ert.ecl.faults import FaultBlock , FaultBlockCell -from ert.ecl.faults import FaultBlockLayer - - -from ecl.test import ExtendedTestCase - - -class ErtLegacyEclTest(ExtendedTestCase): - pass diff --git a/ThirdParty/Ert/python/tests/legacy/test_geo.py b/ThirdParty/Ert/python/tests/legacy/test_geo.py deleted file mode 100644 index 669b5ab9d6..0000000000 --- a/ThirdParty/Ert/python/tests/legacy/test_geo.py +++ /dev/null @@ -1,14 +0,0 @@ -from ert.geo import GeoPointset -from ert.geo import GeoRegion -from ert.geo import CPolyline -from ert.geo import CPolylineCollection -from ert.geo import Polyline -from ert.geo import XYZIo -from ert.geo import GeometryTools -from ert.geo import Surface - -from ecl.test import ExtendedTestCase - - -class ErtLegacyGeoTest(ExtendedTestCase): - pass diff --git a/ThirdParty/Ert/python/tests/legacy/test_test.py b/ThirdParty/Ert/python/tests/legacy/test_test.py deleted file mode 100644 index 40d0ef2b73..0000000000 --- a/ThirdParty/Ert/python/tests/legacy/test_test.py +++ /dev/null @@ -1,16 +0,0 @@ -from ert.test import TestRun -from ert.test import path_exists -from ert.test import ExtendedTestCase -from ert.test import SourceEnumerator -from ert.test import TestArea , TestAreaContext -from ert.test import TempArea , TempAreaContext -from ert.test import ErtTestRunner -from ert.test import PathContext -from ert.test import LintTestCase -from ert.test import ImportTestCase - -from ecl.test import ExtendedTestCase - - -class ErtLegacyTestTest(ExtendedTestCase): - pass diff --git a/ThirdParty/Ert/python/tests/legacy/test_util.py b/ThirdParty/Ert/python/tests/legacy/test_util.py deleted file mode 100644 index 712f12f00a..0000000000 --- a/ThirdParty/Ert/python/tests/legacy/test_util.py +++ /dev/null @@ -1,34 +0,0 @@ -from ert.util import Version -from ert.util import RngAlgTypeEnum, RngInitModeEnum, LLSQResultEnum -from ert.util import CTime -from ert.util import PermutationVector -from ert.util import VectorTemplate -from ert.util import DoubleVector -from ert.util import IntVector -from ert.util import BoolVector -from ert.util import TimeVector -from ert.util import StringList -from ert.util import RandomNumberGenerator -from ert.util import Matrix -from ert.util import quantile, quantile_sorted, polyfit -from ert.util import Log -from ert.util import LookupTable -from ert.util import Buffer -from ert.util import Hash, StringHash, DoubleHash, IntegerHash -from ert.util import UIReturn -from ert.util import ThreadPool -from ert.util import CThreadPool, startCThreadPool -from ert.util import installAbortSignals, updateAbortSignals -from ert.util import Profiler -from ert.util import ArgPack -from ert.util import PathFormat - -from ecl.test import ExtendedTestCase - -try: - from res.util import SubstitutionList -except ImportError: - pass - -class ErtLegacyUtilTest(ExtendedTestCase): - pass diff --git a/ThirdParty/Ert/python/tests/legacy/test_well.py b/ThirdParty/Ert/python/tests/legacy/test_well.py deleted file mode 100644 index 102b049739..0000000000 --- a/ThirdParty/Ert/python/tests/legacy/test_well.py +++ /dev/null @@ -1,13 +0,0 @@ -from ert.well import WellTypeEnum -from ert.well import WellConnectionDirectionEnum -from ert.well import WellConnection -from ert.well import WellSegment -from ert.well import WellState -from ert.well import WellTimeLine -from ert.well import WellInfo - -from ecl.test import ExtendedTestCase - - -class ErtLegacyWellTest(ExtendedTestCase): - pass diff --git a/ThirdParty/Ert/python/tests/share/CMakeLists.txt b/ThirdParty/Ert/python/tests/share/CMakeLists.txt deleted file mode 100644 index ef80c2d77d..0000000000 --- a/ThirdParty/Ert/python/tests/share/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -set(TEST_SOURCES - __init__.py - test_synthesizer.py -) - -add_python_package("python.tests.share" ${PYTHON_INSTALL_PREFIX}/tests/share "${TEST_SOURCES}" False) - -addPythonTest(share.test_synthesizer.SynthesizerTest) diff --git a/ThirdParty/Ert/python/tests/share/__init__.py b/ThirdParty/Ert/python/tests/share/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/tests/share/test_synthesizer.py b/ThirdParty/Ert/python/tests/share/test_synthesizer.py deleted file mode 100644 index f5863f5e91..0000000000 --- a/ThirdParty/Ert/python/tests/share/test_synthesizer.py +++ /dev/null @@ -1,50 +0,0 @@ -import sys -import os -from ecl.test import ExtendedTestCase - -try: - from synthesizer import OilSimulator -except ImportError as e: - share_lib_path = os.path.join(ExtendedTestCase.createSharePath("lib")) - - sys.path.insert(0, share_lib_path) - synthesizer_module = __import__("synthesizer") - OilSimulator = synthesizer_module.OilSimulator - sys.path.pop(0) - - -class SynthesizerTest(ExtendedTestCase): - - def test_oil_simulator(self): - sim = OilSimulator() - sim.addWell("OP1", seed=1) - sim.addBlock("6,6,6", seed=2) - - expected_values = [ - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0], - [0.3359771423145687, 0.3359771423145687, 0.25672494192349865, 0.25672494192349865, 0.010039005455891323, 0.010039005455891323, 0.029013112597713192, 0.7641143089523995, 0.3359771423145687, 0.25672494192349865, 0.010039005455891323, 0.7641143089523995, 0.029013112597713192, 0.8462347957619747], - [0.7252470407619624, 1.0612241830765312, 0.5175173529594699, 0.7742422948829686, 0.017973831236885583, 0.028012836692776905, 0.02418370085402209, 0.7135738912023045, 0.7252470407619624, 0.5175173529594699, 0.017973831236885583, 0.7135738912023045, 0.02418370085402209, 0.6888364145396828], - [0.7723163496234255, 1.8335405326999568, 0.5742386073607806, 1.3484809022437492, 0.11041673583737899, 0.1384295725301559, 0.12508507685507134, 0.7435277106858791, 0.7723163496234255, 0.5742386073607806, 0.11041673583737899, 0.7435277106858791, 0.12508507685507134, 0.6403046565762696], - [0.6038799675664164, 2.437420500266373, 0.6888868738548185, 2.037367776098568, 0.267892132439122, 0.4063217049692779, 0.3072960610203287, 1.140767885762087, 0.6038799675664164, 0.6888868738548185, 0.267892132439122, 1.140767885762087, 0.3072960610203287, 0.5205364945011657], - [0.23016535126253962, 2.6675858515289126, 0.721655666522216, 2.7590234426207836, 0.35552466124555465, 0.7618463662148325, 0.6070184801736589, 3.135379250454838, 0.23016535126253962, 0.721655666522216, 0.35552466124555465, 3.135379250454838, 0.6070184801736589, 0.4800677649914682], - [0.026293782934652718, 2.693879634463565, 0.7131990780527108, 3.4722225206734945, 0.6392372725163122, 1.4010836387311447, 0.8647254356377257, 7.131990780527107, 0.026293782934652718, 0.7131990780527108, 0.6392372725163122, 7.131990780527107, 0.8647254356377257, 0.3872974839053025], - [0.0, 2.693879634463565, 0.8676997908824122, 4.339922311555907, 0.8580356376693129, 2.2591192764004577, 0.8956197493411856, 8.676997908824122, 0.0, 0.8676997908824122, 0.8580356376693129, 8.676997908824122, 0.8956197493411856, 0.22557165737149715], - [0.10560669451549878, 2.799486328979064, 0.869082212788759, 5.209004524344666, 0.8903674796589355, 3.1494867560593933, 0.8939664328113363, 8.229423492288294, 0.10560669451549878, 0.869082212788759, 0.8903674796589355, 8.229423492288294, 0.8939664328113363, 0.1340241573819292], - [0.08615885630000791, 2.885645185279072, 0.44074890315982446, 5.64975342750449, 0.9425699260811738, 4.0920566821405675, 0.9040831722665535, 4.407489031598244, 0.08615885630000791, 0.44074890315982446, 0.9425699260811738, 4.407489031598244, 0.9040831722665535, 0.13404047971467026] - ] - - for report_step in range(10): - sim.step(scale=1.0 / 10.0) - - values = [sim.fopr(), sim.fopt(), sim.fgpr(), sim.fgpt(), sim.fwpr(), sim.fwpt(), sim.fwct(), sim.fgor(), - sim.opr("OP1"), sim.gpr("OP1"), sim.wpr("OP1"), sim.gor("OP1"), sim.wct("OP1"), sim.bpr("6,6,6")] - - self.assertAlmostEqual(values[0], values[8]) # fopr = opr:op1 - self.assertAlmostEqual(values[2], values[9]) # fgpr = gpr:op1 - self.assertAlmostEqual(values[4], values[10]) # fwpr = wpr:op1 - - self.assertAlmostEqual(sim.foip(), sim.ooip - sim.fopt()) - self.assertAlmostEqual(sim.fgip(), sim.goip - sim.fgpt()) - self.assertAlmostEqual(sim.fwip(), sim.woip - sim.fwpt()) - - self.assertAlmostEqualList(values, expected_values[report_step]) diff --git a/ThirdParty/Ert/python/tests/test_pylint.py b/ThirdParty/Ert/python/tests/test_pylint.py deleted file mode 100644 index 84e8ff6a63..0000000000 --- a/ThirdParty/Ert/python/tests/test_pylint.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (C) 2017 Statoil ASA, Norway. -# -# This file 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -from ecl.test import LintTestCase - -class LintErt(LintTestCase): - """Tests that no file in ert needs linting""" - - # Temporarily disabled due to monkey patching camel case - # 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) - - def test_lint_geo(self): - self.assertLinted('ecl/geo') - - def test_lint_util(self): - self.assertLinted('ecl/util') - - def test_lint_well(self): - self.assertLinted('ecl/well') diff --git a/ThirdParty/Ert/python/tests/util/CMakeLists.txt b/ThirdParty/Ert/python/tests/util/CMakeLists.txt deleted file mode 100644 index e2b75c8024..0000000000 --- a/ThirdParty/Ert/python/tests/util/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -set(TEST_SOURCES - __init__.py - test_ctime.py - test_cstring.py - test_hash.py - test_lookup_table.py - test_matrix.py - test_rng.py - test_stat.py - test_string_list.py - #test_substitution_list.py - test_thread_pool.py - test_cthread_pool.py - test_ui_return.py - test_vectors.py - test_version.py - test_work_area.py - test_path_context.py - test_path_fmt.py - test_arg_pack.py - test_spawn.py - test_log.py -) - -add_python_package("python.tests.util" ${PYTHON_INSTALL_PREFIX}/tests/util "${TEST_SOURCES}" False) - -addPythonTest(tests.util.test_ctime.CTimeTest) -addPythonTest(tests.util.test_cstring.CStringTest) -addPythonTest(tests.util.test_hash.HashTest) -addPythonTest(tests.util.test_lookup_table.LookupTableTest ) -addPythonTest(tests.util.test_matrix.MatrixTest ) -addPythonTest(tests.util.test_rng.RngTest ) -addPythonTest(tests.util.test_stat.StatTest ) -addPythonTest(tests.util.test_string_list.StringListTest) -addPythonTest(tests.util.test_vectors.UtilTest) -addPythonTest(tests.util.test_ui_return.UIReturnTest) -addPythonTest(tests.util.test_path_fmt.PathFmtTest) -addPythonTest(tests.util.test_work_area.WorkAreaTest) -addPythonTest(tests.util.test_version.VersionTest) -addPythonTest(tests.util.test_path_context.PathContextTest) -addPythonTest(tests.util.test_thread_pool.ThreadPoolTest) -addPythonTest(tests.util.test_cthread_pool.CThreadPoolTest) -addPythonTest(tests.util.test_arg_pack.ArgPackTest) -addPythonTest(tests.util.test_spawn.SpawnTest) -#addPythonTest(tests.util.test_substitution_list.SubstitutionListTest) -addPythonTest(tests.util.test_log.LogTest) diff --git a/ThirdParty/Ert/python/tests/util/__init__.py b/ThirdParty/Ert/python/tests/util/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/tests/util/test_arg_pack.py b/ThirdParty/Ert/python/tests/util/test_arg_pack.py deleted file mode 100644 index 2a73c39112..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_arg_pack.py +++ /dev/null @@ -1,35 +0,0 @@ -import ecl -from ecl.test import ExtendedTestCase -from ecl.util import ArgPack, StringList - -TEST_LIB = ecl.load("libecl") - - -class ArgPackTest(ExtendedTestCase): - def test_create(self): - arg = ArgPack() - self.assertEqual(len(arg), 0) - - arg.append(StringList()) - self.assertEqual(len(arg), 1) - - arg.append(3.14) - self.assertEqual(len(arg), 2) - - o = object() - with self.assertRaises(TypeError): - arg.append(o) - - def test_args(self): - arg = ArgPack(1, 2, 3) - self.assertEqual(len(arg), 3) - - def test_append_ptr(self): - arg = ArgPack(StringList()) - self.assertEqual(len(arg), 1) - - func = getattr(TEST_LIB, "test_argpack_is_stringlist") - func.restype = None - func.argtypes = [ArgPack] - - func(arg) diff --git a/ThirdParty/Ert/python/tests/util/test_cstring.py b/ThirdParty/Ert/python/tests/util/test_cstring.py deleted file mode 100644 index 12f8a58c50..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_cstring.py +++ /dev/null @@ -1,24 +0,0 @@ -import ecl -from cwrap import Prototype -from ecl.test.extended_testcase import ExtendedTestCase - -# Local copies so that the real ones don't get changed -class TestUtilPrototype(Prototype): - lib = ecl.load("libecl") - - def __init__(self, prototype, bind=False): - super(TestUtilPrototype, self).__init__(TestUtilPrototype.lib, prototype, bind=bind) - -alloc_string_copy = TestUtilPrototype("char* util_alloc_string_copy(char*)") - -class CStringTest(ExtendedTestCase): - - def test_get(self): - # this test can safely be deleted, as the type it used to test, - # cstring_obj, has been replaced with char* - s1 = "String123" - print('test_get.s1=' + s1) - s2 = alloc_string_copy(s1) - print('test_get.s2=' + s2) - self.assertEqual(s1, s2) - print('test_get.s1==s2: %s' % (s1 == s2)) diff --git a/ThirdParty/Ert/python/tests/util/test_cthread_pool.py b/ThirdParty/Ert/python/tests/util/test_cthread_pool.py deleted file mode 100644 index dd6b32b952..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_cthread_pool.py +++ /dev/null @@ -1,47 +0,0 @@ -import ctypes -import ecl -from ecl.test import ExtendedTestCase -from ecl.util import CThreadPool, startCThreadPool - -TEST_LIB = ecl.load("libecl") - - -class CThreadPoolTest(ExtendedTestCase): - def test_cfunc(self): - with self.assertRaises(TypeError): - func = CThreadPool.lookupCFunction("WRONG-TYPE", "no-this-does-not-exist") - - with self.assertRaises(AttributeError): - func = CThreadPool.lookupCFunction(TEST_LIB, "no-this-does-not-exist") - - def test_create(self): - pool = CThreadPool(32, start=True) - job = CThreadPool.lookupCFunction(TEST_LIB, "thread_pool_test_func1") - arg = ctypes.c_int(0) - - N = 256 - for i in range(N): - pool.addTask(job, ctypes.byref(arg)) - pool.join() - self.assertEqual(arg.value, N) - - def test_context(self): - N = 256 - arg = ctypes.c_int(0) - job = CThreadPool.lookupCFunction(TEST_LIB, "thread_pool_test_func1") - with startCThreadPool(16) as tp: - for i in range(N): - tp.addTask(job, ctypes.byref(arg)) - self.assertEqual(arg.value, N) - - def test_add_task_function(self): - pool = CThreadPool(32, start=True) - pool.addTaskFunction("testFunction", TEST_LIB, "thread_pool_test_func1") - - arg = ctypes.c_int(0) - task_count = 256 - for i in range(task_count): - pool.testFunction(ctypes.byref(arg)) - - pool.join() - self.assertEqual(arg.value, task_count) diff --git a/ThirdParty/Ert/python/tests/util/test_ctime.py b/ThirdParty/Ert/python/tests/util/test_ctime.py deleted file mode 100644 index 292a13153a..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_ctime.py +++ /dev/null @@ -1,131 +0,0 @@ -import time -from datetime import datetime, date - -from ecl.util import CTime - - -try: - from unittest2 import TestCase -except ImportError: - from unittest import TestCase - - -class CTimeTest(TestCase): - def test_creation(self): - t0 = CTime(0) - - t2 = CTime(datetime(1970, 1, 1)) - self.assertEqual(t0, t2) - - t3 = CTime(date(1970, 1, 1)) - self.assertEqual(t0, t3) - - with self.assertRaises(NotImplementedError): - CTime("string") - - def test_c_time(self): - delta = 0 - c_time = CTime(0) - py_time = datetime(1970, 1, 1) - - self.assertEqual(str(c_time), py_time.strftime("%Y-%m-%d %H:%M:%S%z")) - - date_time = CTime(py_time) - self.assertEqual(c_time, date_time) - - date_time_after = CTime(datetime(1970, 1, 1, 1, 0, 5)) - - self.assertTrue(date_time_after > date_time) - - def test_math(self): - c1 = CTime(date(2000, 1, 1)) - c2 = CTime(date(2000, 1, 1)) - c3 = CTime(date(2000, 1, 1)) - - c3 += c1 - self.assertTrue(isinstance(c3, CTime)) - - c4 = c1 * 1.0 - self.assertTrue(isinstance(c4, CTime)) - self.assertTrue(isinstance(c1 + c2, CTime)) - - self.assertEqual((c1 + c2) * 0.5, date(2000, 1, 1)) - - def test_comparison(self): - t0 = CTime(0) - t1 = CTime(0) - t2 = CTime(1) - - self.assertTrue(t0 == t1) - self.assertFalse(t0 != t1) - with self.assertRaises(TypeError): - t0 != 0.5 - - self.assertFalse(t0 < t1) - self.assertTrue(t0 < t2) - with self.assertRaises(TypeError): - t0 < 0.5 - - self.assertTrue(t0 <= t1) - self.assertTrue(t0 <= t2) - with self.assertRaises(TypeError): - t0 <= 0.5 - - self.assertFalse(t0 > t1) - self.assertFalse(t0 > t2) - with self.assertRaises(TypeError): - t0 > 0.5 - - self.assertTrue(t0 >= t1) - self.assertFalse(t0 >= t2) - with self.assertRaises(TypeError): - t0 >= 0.5 - - t3 = CTime(date(2050, 1, 1)) - t4 = CTime(date(2060, 1, 1)) - self.assertTrue(t1 < t3) - self.assertTrue(t3 < t4) - - t5 = CTime(t4) - self.assertTrue(t4 == t5) - - def test_range(self): - d1 = date(2000, 1, 1) - dt1 = datetime(2000, 1, 1, 0, 0, 0) - c1 = CTime(d1) - - d0 = date(1999, 1, 1) - dt0 = datetime(1999, 1, 1, 0, 0, 0) - c0 = CTime(d0) - - d2 = date(2001, 1, 1) - dt2 = datetime(2001, 1, 1, 0, 0, 0) - c2 = CTime(d2) - - self.assertTrue(d0 <= c1 < dt2) - self.assertTrue(c0 <= c1 < d2) - self.assertTrue(dt0 <= c1 < c2) - - self.assertFalse(d1 <= c0 < dt2) - self.assertFalse(c1 <= c0 < d2) - self.assertFalse(dt1 <= c0 < c2) - - self.assertTrue(d0 <= c0 < dt2) - self.assertTrue(c0 <= c0 < d2) - self.assertTrue(dt0 <= c0 < c2) - - self.assertFalse(d0 <= c2 < dt2) - self.assertFalse(c0 <= c2 < d2) - self.assertFalse(dt0 <= c2 < c2) - - self.assertTrue(d0 <= c2 <= dt2) - self.assertTrue(c0 <= c2 <= d2) - self.assertTrue(dt0 <= c2 <= c2) - - def test_conversion(self): - t = CTime(0) - - self.assertEqual(t.value(), 0) - self.assertEqual(t.ctime(), 0) - self.assertEqual(t.time(), time.gmtime(0)) - diff --git a/ThirdParty/Ert/python/tests/util/test_hash.py b/ThirdParty/Ert/python/tests/util/test_hash.py deleted file mode 100644 index 528d123ee4..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_hash.py +++ /dev/null @@ -1,68 +0,0 @@ -from ctypes import c_void_p - -from ecl.test import ExtendedTestCase -from ecl.util import Hash, StringHash, DoubleHash, IntegerHash - - -class HashTest(ExtendedTestCase): - def test_string_hash(self): - hash = StringHash() - - self.assertEqual(len(hash), 0) - - hash["hipp"] = "" - - self.assertEqual(len(hash), 1) - - with self.assertRaises(ValueError): - hash["hopp"] = 55 - - with self.assertRaises(KeyError): - hopp = hash["hopp"] - - self.assertTrue("hipp" in hash) - - self.assertEqual(list(hash.keys()), ["hipp"]) - - def test_int_hash(self): - hash = IntegerHash() - - with self.assertRaises(ValueError): - hash["one"] = "ein" - - with self.assertRaises(ValueError): - hash["one"] = 1.0 - - hash["two"] = 2 - - self.assertEqual(hash["two"], 2) - - def test_double_hash(self): - hash = DoubleHash() - - with self.assertRaises(ValueError): - hash["one"] = "ein" - - hash["two"] = 2 - hash["three"] = 3.0 - - self.assertEqual(hash["two"], 2) - self.assertEqual(hash["three"], 3.0) - - def test_c_void_p_hash(self): - hash = Hash() - - cp = c_void_p(512) - hash["1"] = cp - - self.assertEqual(hash["1"], cp.value) - - def test_for_in_hash(self): - hash = StringHash() - - hash["one"] = "one" - hash["two"] = "two" - hash["three"] = "three" - - for key in hash: - self.assertTrue(key in hash) diff --git a/ThirdParty/Ert/python/tests/util/test_log.py b/ThirdParty/Ert/python/tests/util/test_log.py deleted file mode 100644 index dba143dad9..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_log.py +++ /dev/null @@ -1,8 +0,0 @@ -from ecl.util.enums import MessageLevelEnum - -from ecl.test import ExtendedTestCase - -class LogTest(ExtendedTestCase): - - def test_enums(self): - self.assertEnumIsFullyDefined(MessageLevelEnum, "message_level_type", "lib/include/ert/util/log.h") diff --git a/ThirdParty/Ert/python/tests/util/test_lookup_table.py b/ThirdParty/Ert/python/tests/util/test_lookup_table.py deleted file mode 100644 index 9a0fdccdfe..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_lookup_table.py +++ /dev/null @@ -1,88 +0,0 @@ -try: - from unittest2 import TestCase -except ImportError: - from unittest import TestCase - -from ecl.util import LookupTable - - -class LookupTableTest(TestCase): - def test_lookup_table_no_values(self): - lookup = LookupTable() - - self.assertEqual(len(lookup), 0) - - with self.assertRaises(ValueError): - lookup.getMaxValue() - - with self.assertRaises(ValueError): - lookup.getMinValue() - - with self.assertRaises(ValueError): - lookup.getMaxArg() - - with self.assertRaises(ValueError): - lookup.getMinArg() - - with self.assertRaises(ValueError): - lookup.interp(0.25) - - def test_lookup_table_one_value(self): - lookup = LookupTable() - lookup.append(0, 0) - with self.assertRaises(ValueError): - lookup.interp(0.25) - - def test_lookup_table_min_and_max(self): - lookup = LookupTable() - - lookup.append(0.0, 0.0) - lookup.append(1.0, 10.0) - - self.assertEqual(lookup.getMaxValue(), 10.0) - self.assertEqual(lookup.getMinValue(), 0.0) - self.assertEqual(lookup.getMaxArg(), 1.0) - self.assertEqual(lookup.getMinArg(), 0.0) - self.assertEqual(len(lookup), 2) - - def test_lookup_out_of_bounds(self): - lookup = LookupTable() - - lookup.append(0.0, 0.0) - lookup.append(1.0, 10.0) - - self.assertEqual(lookup.interp(0), 0) - self.assertEqual(lookup.interp(1), 10) - - with self.assertRaises(ValueError): - lookup.interp(-1) - - with self.assertRaises(ValueError): - lookup.interp(2) - - lookup.setLowerLimit(-1) - self.assertEqual(lookup.interp(-0.25), -1) - - with self.assertRaises(ValueError): - lookup.interp(2) - - lookup.setUpperLimit(88) - self.assertEqual(lookup.interp(1.25), 88) - - def test_lookup_table_interpolation(self): - lookup = LookupTable() - - lookup.append(0.0, 0.0) - lookup.append(1.0, 10.0) - - self.assertEqual(lookup.interp(0.5), 5.0) - - def test_optional_arg(self): - lookup = LookupTable(lower_limit=-1, upper_limit=100) - - lookup.append(0.0, 0.0) - lookup.append(1.0, 10.0) - - self.assertEqual(lookup.interp(-1), -1.0) - self.assertEqual(lookup.interp(0.5), 5.0) - self.assertEqual(lookup.interp(2), 100.0) diff --git a/ThirdParty/Ert/python/tests/util/test_matrix.py b/ThirdParty/Ert/python/tests/util/test_matrix.py deleted file mode 100644 index d5d5205890..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_matrix.py +++ /dev/null @@ -1,247 +0,0 @@ -from ecl.util import Matrix , RandomNumberGenerator -from ecl.util.enums import RngAlgTypeEnum, RngInitModeEnum -from ecl.test import ExtendedTestCase, TestAreaContext - -class MatrixTest(ExtendedTestCase): - def test_matrix(self): - m = Matrix(2, 3) - - self.assertEqual(m.rows(), 2) - self.assertEqual(m.columns(), 3) - - self.assertEqual(m[(0, 0)], 0) - - m[(1, 1)] = 1.5 - self.assertEqual(m[(1, 1)], 1.5) - - m[1,0] = 5 - self.assertEqual(m[1, 0], 5) - - with self.assertRaises(TypeError): - m[5] = 5 - - with self.assertRaises(IndexError): - m[2, 0] = 0 - - with self.assertRaises(IndexError): - m[0, 3] = 0 - - def test_matrix_set(self): - m1 = Matrix(2,2) - m1.setAll(99) - self.assertEqual( 99 , m1[0,0] ) - self.assertEqual( 99 , m1[1,1] ) - m2 = Matrix(2,2 , value = 99) - self.assertEqual(m1,m2) - - - def test_matrix_random_init(self): - m = Matrix(10,10) - rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT) - m.randomInit( rng ) - - def test_matrix_copy_column(self): - m = Matrix(10,2) - rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT) - m.randomInit( rng ) - - with self.assertRaises(ValueError): - m.copyColumn(0,2) - - with self.assertRaises(ValueError): - m.copyColumn(2,0) - - with self.assertRaises(ValueError): - m.copyColumn(-2,0) - - m.copyColumn(1, 0) - for i in range(m.rows()): - self.assertEqual( m[i,0] , m[i,1] ) - - - def test_matrix_scale(self): - m = Matrix(2,2 , value = 1) - m.scaleColumn(0 , 2) - self.assertEqual(2 , m[0,0]) - self.assertEqual(2 , m[1,0]) - - m.setAll(1) - m.scaleRow(1 , 2 ) - self.assertEqual(2 , m[1,0]) - self.assertEqual(2 , m[1,1]) - - with self.assertRaises(IndexError): - m.scaleColumn(10 , 99) - - with self.assertRaises(IndexError): - m.scaleRow(10 , 99) - - - - - def test_matrix_equality(self): - m = Matrix(2, 2) - m[0, 0] = 2 - m[1, 1] = 4 - - s = Matrix(2, 3) - s[0, 0] = 2 - s[1, 1] = 4 - - self.assertNotEqual(m, s) - - r = Matrix(2, 2) - r[0, 0] = 2 - r[1, 1] = 3 - - self.assertNotEqual(m, r) - - r[1, 1] = 4 - - self.assertEqual(m, r) - - def test_str(self): - m = Matrix(2, 2) - s = "%s" % m - - m[0,0] = 0 - m[0,1] = 1 - m[1,0] = 2 - m[1,1] = 3 - - with TestAreaContext("matrix_fprint"): - with open("matrix.txt", "w") as f: - m.fprint( f ) - - with open("matrix.txt") as f: - l1 = [ float(x) for x in f.readline().split()] - l2 = [ float(x) for x in f.readline().split()] - - self.assertEqual( l1[0] , m[0,0]) - self.assertEqual( l1[1] , m[0,1]) - self.assertEqual( l2[0] , m[1,0]) - self.assertEqual( l2[1] , m[1,1]) - - - def test_copy_equal(self): - m1 = Matrix(2, 2) - m1[0,0] = 0 - m1[0,1] = 1 - m1[1,0] = 2 - m1[1,1] = 3 - - m2 = m1.copy( ) - self.assertTrue( m1 == m2 ) - - def test_sub_copy(self): - m1 = Matrix(3,3) - rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT) - m1.randomInit( rng ) - - with self.assertRaises(ValueError): - m2 = m1.subCopy( 0,0,4,2 ) - - with self.assertRaises(ValueError): - m2 = m1.subCopy( 0,0,2,4 ) - - with self.assertRaises(ValueError): - m2 = m1.subCopy( 4,0,1,1 ) - - with self.assertRaises(ValueError): - m2 = m1.subCopy( 0,2,1,2 ) - - - m2 = m1.subCopy( 0,0,2,2 ) - for i in range(2): - for j in range(2): - self.assertEqual( m1[i,j] , m2[i,j]) - - - def test_transpose(self): - m = Matrix(3,2) - m[0,0] = 0 - m[1,0] = 2 - m[2,0] = 4 - - m[0,1] = 1 - m[1,1] = 3 - m[2,1] = 5 - - mt = m.transpose( ) - - self.assertEqual(m[0,0] , 0) - self.assertEqual(m[1,0] , 2) - self.assertEqual(m[2,0] , 4) - - self.assertEqual(m[0,1] , 1) - self.assertEqual(m[1,1] , 3) - self.assertEqual(m[2,1] , 5) - - self.assertEqual( mt.rows() , m.columns()) - self.assertEqual( mt.columns() , m.rows()) - self.assertEqual(mt[0,0] , 0) - self.assertEqual(mt[1,0] , 1) - - self.assertEqual(mt[0,1] , 2) - self.assertEqual(mt[1,1] , 3) - - self.assertEqual(mt[0,2] , 4) - self.assertEqual(mt[1,2] , 5) - - m.transpose( inplace = True ) - self.assertEqual( m , mt ) - - - def test_matmul(self): - m1 = Matrix(3,3) - m2 = Matrix(2,2) - - with self.assertRaises(ValueError): - Matrix.matmul( m1 , m2 ) - - m = Matrix(3,2) - m[0,0] = 0 - m[1,0] = 2 - m[2,0] = 4 - - m[0,1] = 1 - m[1,1] = 3 - m[2,1] = 5 - - mt = m.transpose( ) - - m2 = Matrix.matmul( m , mt ) - - self.assertEqual( m2[0,0] , 1 ) - self.assertEqual( m2[1,1] , 13 ) - self.assertEqual( m2[2,2] , 41 ) - - - def test_csv(self): - m = Matrix(2, 2) - m[0, 0] = 2 - m[1, 1] = 4 - with TestAreaContext("matrix_csv"): - m.dumpCSV("matrix.csv") - - def test_identity(self): - m1 = Matrix.identity(1) - self.assertEqual(m1.rows(), 1) - self.assertEqual(m1.columns(), 1) - self.assertEqual(m1[0,0], 1) - - with self.assertRaises(ValueError): - Matrix.identity(0) - with self.assertRaises(ValueError): - Matrix.identity(-3) - - m = Matrix.identity(17) - self.assertEqual(m.rows(), 17) - self.assertEqual(m.columns(), 17) - for i in range(17): - for j in range(17): - elt = m[i, j] - if i == j: - self.assertEqual(elt, 1) - else: - self.assertEqual(elt, 0) diff --git a/ThirdParty/Ert/python/tests/util/test_path_context.py b/ThirdParty/Ert/python/tests/util/test_path_context.py deleted file mode 100644 index 8497e9d193..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_path_context.py +++ /dev/null @@ -1,49 +0,0 @@ -import os -from ecl.test import ExtendedTestCase, PathContext,TestAreaContext - - -class PathContextTest(ExtendedTestCase): - - def test_error(self): - with TestAreaContext("pathcontext"): - # Test failure on creating PathContext with an existing path - os.makedirs("path/1") - with self.assertRaises(OSError): - with PathContext("path/1"): - pass - - # Test failure on non-writable path - os.chmod("path/1", 0o0444) - with self.assertRaises(OSError): - with PathContext("path/1/subfolder"): - pass - os.chmod("path/1", 0o0744) - - # Test failure on creating PathContext with an existing file - with open("path/1/file", "w") as f: - f.write("xx") - with self.assertRaises(OSError): - with PathContext("path/1/file"): - pass - - - def test_chdir(self): - with PathContext("/tmp/pc"): - self.assertEqual( - os.path.realpath(os.getcwd()), - os.path.realpath("/tmp/pc") - ) - - def test_cleanup(self): - with TestAreaContext("pathcontext"): - os.makedirs("path/1") - - with PathContext("path/1/next/2/level"): - with open("../../file" , "w") as f: - f.write("Crap") - - self.assertTrue(os.path.isdir("path/1")) - self.assertTrue(os.path.isdir("path/1/next")) - self.assertFalse(os.path.isdir("path/1/next/2")) - - diff --git a/ThirdParty/Ert/python/tests/util/test_path_fmt.py b/ThirdParty/Ert/python/tests/util/test_path_fmt.py deleted file mode 100644 index 30adf3be51..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_path_fmt.py +++ /dev/null @@ -1,10 +0,0 @@ -import os -from ecl.test import ExtendedTestCase, TestAreaContext -from ecl.util import PathFormat - -class PathFmtTest(ExtendedTestCase): - - def test_create(self): - path_fmt = PathFormat("random/path/%d-%d") - self.assertIn('random/path', repr(path_fmt)) - self.assertTrue(str(path_fmt).startswith('PathFormat(')) diff --git a/ThirdParty/Ert/python/tests/util/test_rng.py b/ThirdParty/Ert/python/tests/util/test_rng.py deleted file mode 100644 index fdf0c2d60c..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_rng.py +++ /dev/null @@ -1,45 +0,0 @@ -from ecl.util.enums import RngAlgTypeEnum, RngInitModeEnum -from ecl.util.rng import RandomNumberGenerator -from ecl.test import ExtendedTestCase,TestAreaContext - - -class RngTest(ExtendedTestCase): - - def test_enums(self): - self.assertEnumIsFullyDefined(RngAlgTypeEnum, "rng_alg_type", "lib/include/ert/util/rng.h") - self.assertEnumIsFullyDefined(RngInitModeEnum, "rng_init_mode", "lib/include/ert/util/rng.h") - - def test_rng_default(self): - rng = RandomNumberGenerator() - self.assertIsInstance(rng.getDouble(), float) - - def test_rng_state(self): - rng = RandomNumberGenerator() - with self.assertRaises(ValueError): - rng.setState("12") - - rng.setState("0123456789ABCDEF") - val1 = rng.getInt() - val2 = rng.getInt() - - self.assertFalse( val1 == val2 ) - rng.setState("0123456789ABCDEF") - self.assertEqual( rng.getInt() , val1) - self.assertEqual( rng.getInt() , val2) - - - - def test_load_save(self): - rng = RandomNumberGenerator() - with self.assertRaises(IOError): - rng.loadState("does/not/exist") - - with TestAreaContext("rng_state") as t: - rng.saveState( "rng.txt" ) - t.sync() - val1 = rng.getInt() - val2 = rng.getInt() - rng.loadState( "rng.txt" ) - self.assertEqual( rng.getInt() , val1 ) - self.assertEqual( rng.getInt() , val2 ) - diff --git a/ThirdParty/Ert/python/tests/util/test_spawn.py b/ThirdParty/Ert/python/tests/util/test_spawn.py deleted file mode 100644 index c624ea3d6a..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_spawn.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import stat -import sys - -import ecl -from ecl.test.extended_testcase import ExtendedTestCase -from ecl.test.test_area import TestAreaContext - -from cwrap import Prototype - -class _TestSpawnPrototype(Prototype): - lib = ecl.load('libecl') - - def __init__(self, prototype, bind=True): - super(_TestSpawnPrototype, self).__init__(_TestSpawnPrototype.lib, prototype, bind=bind) - - -class SpawnTest(ExtendedTestCase): - _spawn = _TestSpawnPrototype("int util_spawn_blocking(char*, int, void*, char*, char*)", bind = False) - def createScript(self, name, stdout_string , stderr_string): - with open(name, "w") as f: - f.write("#!/usr/bin/env python\n") - f.write("import sys\n") - f.write("sys.stdout.write('%s')\n" % stdout_string) - f.write("sys.stdout.flush()\n") - f.write("sys.stderr.write('%s')\n" % stderr_string) - f.write("sys.stderr.flush()\n") - - mode = os.stat(name).st_mode - mode |= stat.S_IXUSR | stat.S_IXGRP - os.chmod(name, stat.S_IMODE(mode)) - - - - def test_spawn_redirect(self): - with TestAreaContext("spawn_test1", store_area=True) as test_area: - stdout_string = "stdout_redirect" - stderr_string = "stderr_redirect" - self.createScript("print.py",stdout_string, stderr_string) - status = self._spawn("print.py",0, None, "print.out", "print.err") - self.assertEqual(status , 0) - - sys.stderr.write("init stderr\n") - sys.stdout.write("init stdout\n") - sys.stderr.write("complete stderr\n") - sys.stdout.write("complete stdout\n") - - with open("print.out", "r") as f: - s = f.read() - self.assertEqual(s , stdout_string) - - with open("print.err", "r") as f: - s = f.read() - self.assertEqual(s , stderr_string) - - - - def test_spawn_noredirect(self): - with TestAreaContext("spawn_test2", store_area=True) as test_area: - self.createScript("print.py","stdout_no_redirect", "stderr_no_redirect") - status = self._spawn("print.py", 0, None, None , None) - self.assertEqual(status , 0) - diff --git a/ThirdParty/Ert/python/tests/util/test_stat.py b/ThirdParty/Ert/python/tests/util/test_stat.py deleted file mode 100644 index f1a79e9701..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_stat.py +++ /dev/null @@ -1,43 +0,0 @@ -from ecl.test import ExtendedTestCase -from ecl.util import DoubleVector, quantile, quantile_sorted, polyfit -from ecl.util.rng import RandomNumberGenerator - - -class StatTest(ExtendedTestCase): - def test_stat_quantiles(self): - rng = RandomNumberGenerator() - rng.setState("0123456789ABCDEF") - v = DoubleVector() - for i in range(100000): - v.append(rng.getDouble( )) - - self.assertAlmostEqual(quantile(v, 0.1), 0.1, 2) - self.assertAlmostEqual(quantile_sorted(v, 0.2), 0.2, 2) - self.assertAlmostEqual(quantile_sorted(v, 0.3), 0.3, 2) - self.assertAlmostEqual(quantile_sorted(v, 0.4), 0.4, 2) - self.assertAlmostEqual(quantile_sorted(v, 0.5), 0.5, 2) - - def test_polyfit(self): - x_list = DoubleVector() - y_list = DoubleVector() - S = DoubleVector() - - A = 7.25 - B = -4 - C = 0.025 - - x = 0 - dx = 0.1 - for i in range(100): - y = A + B * x + C * x * x - x_list.append(x) - y_list.append(y) - - x += dx - S.append(1.0) - - beta = polyfit(3, x_list, y_list, None) - - self.assertAlmostEqual(A, beta[0]) - self.assertAlmostEqual(B, beta[1]) - self.assertAlmostEqual(C, beta[2]) diff --git a/ThirdParty/Ert/python/tests/util/test_string_list.py b/ThirdParty/Ert/python/tests/util/test_string_list.py deleted file mode 100644 index a4076fe2c8..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_string_list.py +++ /dev/null @@ -1,159 +0,0 @@ -from __future__ import absolute_import, division, print_function, unicode_literals - -try: - from unittest2 import TestCase -except ImportError: - from unittest import TestCase - -from ecl.util import StringList - - -class StringListTest(TestCase): - def test_del(self): - s = StringList( initial = ["A", "list"] ) - internal_list_of_strings = s.strings - python_list_of_strings = list(s) - - self.assertEqual(internal_list_of_strings, python_list_of_strings) - - del s - - self.assertEqual(python_list_of_strings, ["A", "list"]) - - def test_iterate(self): - s = ["A", "list", "of", "strings"] - s1 = StringList(initial=s) - s2 = s1.strings - s3 = list(s1) - - for index in range(len(s1)): - self.assertEqual(s[index], s1[index]) - - for index in range(len(s2)): - self.assertEqual(s[index], s2[index]) - - for index in range(len(s3)): - self.assertEqual(s[index], s3[index]) - - - def test_pop( self ): - s = StringList(initial=["A", "list", "of", "strings"]) - s1 = s.pop() - self.assertTrue(len(s) == 3) - self.assertTrue(s1 == "strings") - - s1 = s.pop() - self.assertTrue(len(s) == 2) - self.assertTrue(s1 == "of") - - s1 = s.pop() - self.assertTrue(len(s) == 1) - self.assertTrue(s1 == "list") - - s1 = s.pop() - self.assertTrue(len(s) == 0) - self.assertTrue(s1 == "A") - - with self.assertRaises(IndexError): - s.pop() - - def test_last(self): - s = StringList(initial=["A", "list", "of", "strings"]) - self.assertEqual(s.last, "strings") - - with self.assertRaises(IndexError): - s.pop() - s.pop() - s.pop() - s.pop() - s.last - - - def test_in_and_not_in(self): - s = StringList(["A", "list", "of", "strings"]) - - self.assertTrue("A" in s) - self.assertTrue("Bjarne" not in s) - - def test_append(self): - s1 = StringList(["A", "B"]) - s1.append("C") - - s2 = StringList(["A","B","C"]) - self.assertEqual(s1, ["A", "B", "C"]) - self.assertEqual(s1, s2) - self.assertFalse(s1 == ["A","B","D"]) - self.assertFalse(s1 == ["A","B","C" , "D"]) - - pfx = 'StringList(size' # __repr__ - self.assertEqual(pfx, repr(s2)[:len(pfx)]) - - def test_append_not_string(self): - s = StringList() - s.append(10) - self.assertEqual( len(s) , 1) - self.assertEqual(s[0] , "10") - - - def test_negative_index(self): - s = StringList(["A", "B", "C"]) - - self.assertEqual(s[-1], "C") - self.assertEqual(s[-3], "A") - - with self.assertRaises(LookupError): - s = s[-4] - - def test_find_first(self): - s = StringList(["A", "B", "C"]) - - self.assertEqual(s.index("A"), 0) - self.assertEqual(s.index("B"), 1) - self.assertEqual(s.index("C"), 2) - self.assertEqual(s.index("D"), -1) - - - - def test_front_back(self): - s = StringList() - with self.assertRaises(LookupError): - s.front() - - with self.assertRaises(LookupError): - s.back() - - s.append("S1") - s.append("S2") - s.append("S3") - - self.assertEqual( "S1" , s.front() ) - self.assertEqual( "S3" , s.back() ) - - - def test_iadd(self): - s1 = StringList( initial = ["A","B","C"]) - with self.assertRaises(TypeError): - s3 = s1 + 10 - - - s2 = StringList( initial = ["A","B","C"]) - s3 = s1 + s2 - self.assertEqual( s3 , ["A","B","C","A","B","C"]) - - s1 += s2 - self.assertEqual( s1 , ["A","B","C","A","B","C"]) - with self.assertRaises(TypeError): - s3 += "b" - - - def test_ior(self): - s1 = StringList( initial = ["A","B","C"]) - s2 = StringList( initial = ["A","B","C"]) - - s3 = s1 | s2 - self.assertEqual( s3 , ["A","B","C"]) - s1 |= s2 - self.assertEqual( s1 , ["A","B","C"]) - - with self.assertRaises(TypeError): - s1 |= 26 diff --git a/ThirdParty/Ert/python/tests/util/test_thread_pool.py b/ThirdParty/Ert/python/tests/util/test_thread_pool.py deleted file mode 100644 index ffe620dcd6..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_thread_pool.py +++ /dev/null @@ -1,101 +0,0 @@ -import time -from ecl.util import ThreadPool -from ecl.util.thread_pool import Task -from ecl.test import ExtendedTestCase - - -class ThreadPoolTest(ExtendedTestCase): - - - def sleepTask(self, *args, **kwargs): - time.sleep(args[0]) - - def numberer(self, index, result): - result[index] = True - - def test_pool_creation(self): - pool = ThreadPool(4) - - self.assertEqual(4, pool.poolSize()) - - def noop(*args, **kwargs): - pass - - pool.addTask(noop) - self.assertEqual(1, pool.taskCount()) - - pool.addTask(noop, 1, 2, 3) - self.assertEqual(2, pool.taskCount()) - - pool.addTask(noop, 1, 2, 3, name="name", group="group", purpose="porpoise") - self.assertEqual(3, pool.taskCount()) - - self.assertEqual(pool.runningCount(), 0) - self.assertEqual(pool.doneCount(), 0) - - - def test_pool_execution(self): - pool = ThreadPool(4) - - result = {} - for index in range(10): - pool.addTask(self.numberer, index, result=result) - - pool.nonBlockingStart() - pool.join() - - for index in range(10): - self.assertTrue(index in result) - self.assertTrue(result[index]) - - self.assertFalse(pool.hasFailedTasks()) - - - - def test_pool_unbound_fail(self): - pool = ThreadPool(4) - - self.assertEqual(4, pool.poolSize()) - pool.addTask(ThreadPoolTest.numberer, 0, {}) - - pool.nonBlockingStart() - pool.join() - - self.assertTrue(pool.hasFailedTasks()) - - - def test_fill_pool(self): - pool = ThreadPool(4) - - for index in range(10): - pool.addTask(self.sleepTask, 2) - - pool.nonBlockingStart() - time.sleep(0.5) - self.assertEqual(pool.doneCount(), 0) - self.assertEqual(pool.runningCount(), 4) - - pool.join() - - - - def test_task(self): - def sleeping(): - time.sleep(1) - - task = Task(sleeping) - - self.assertFalse(task.hasStarted()) - self.assertFalse(task.isRunning()) - self.assertFalse(task.isDone()) - - task.start() - - self.assertTrue(task.hasStarted()) - self.assertTrue(task.isRunning()) - - task.join() - - self.assertFalse(task.isRunning()) - self.assertTrue(task.isDone()) - diff --git a/ThirdParty/Ert/python/tests/util/test_ui_return.py b/ThirdParty/Ert/python/tests/util/test_ui_return.py deleted file mode 100644 index 8b8da46025..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_ui_return.py +++ /dev/null @@ -1,69 +0,0 @@ -from ecl.test import ExtendedTestCase -from ecl.util import UIReturn -from ecl.util.enums import UIReturnStatusEnum - - -class UIReturnTest(ExtendedTestCase): - def test_create(self): - ui_return = UIReturn(UIReturnStatusEnum.UI_RETURN_OK) - self.assertTrue(ui_return) - - ui_return = UIReturn(UIReturnStatusEnum.UI_RETURN_FAIL) - self.assertFalse(ui_return) - - self.assertEqual(0, len(ui_return)) - - def test_help(self): - ui_return = UIReturn(UIReturnStatusEnum.UI_RETURN_OK) - self.assertEqual("", ui_return.help_text()) - - ui_return.add_help("Help1") - self.assertEqual("Help1", ui_return.help_text()) - - ui_return.add_help("Help2") - self.assertEqual("Help1 Help2", ui_return.help_text()) - - def test_error_raises_OK(self): - ui_return = UIReturn(UIReturnStatusEnum.UI_RETURN_OK) - with self.assertRaises(ValueError): - ui_return.add_error("Error1") - - with self.assertRaises(ValueError): - ui_return.last_error() - - with self.assertRaises(ValueError): - ui_return.first_error() - - def test_add_error(self): - ui_return = UIReturn(UIReturnStatusEnum.UI_RETURN_FAIL) - ui_return.add_error("Error1") - ui_return.add_error("Error2") - ui_return.add_error("Error3") - self.assertEqual(3, len(ui_return)) - - self.assertEqual("Error1", ui_return.first_error()) - self.assertEqual("Error3", ui_return.last_error()) - - def test_iget_error(self): - ui_return = UIReturn(UIReturnStatusEnum.UI_RETURN_FAIL) - ui_return.add_error("Error1") - ui_return.add_error("Error2") - ui_return.add_error("Error3") - - errorList = [] - for index in range(len(ui_return)): - errorList.append(ui_return.iget_error(index)) - self.assertEqual(errorList, ["Error1", "Error2", "Error3"]) - - with self.assertRaises(TypeError): - ui_return.iget_error("XX") - - ui_return = UIReturn(UIReturnStatusEnum.UI_RETURN_OK) - errorList = [] - for index in range(len(ui_return)): - errorList.append(ui_return.iget_error(index)) - self.assertEqual(errorList, []) - - def test_status_enum(self): - source_file_path = "lib/include/ert/util/ui_return.h" - self.assertEnumIsFullyDefined(UIReturnStatusEnum, "ui_return_status_enum", source_file_path) diff --git a/ThirdParty/Ert/python/tests/util/test_vectors.py b/ThirdParty/Ert/python/tests/util/test_vectors.py deleted file mode 100644 index 9b710567eb..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_vectors.py +++ /dev/null @@ -1,552 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'test_vectors.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - - -import copy -import datetime - -try: - from unittest2 import TestCase -except ImportError: - from unittest import TestCase - -from ecl.util import DoubleVector, IntVector, BoolVector, TimeVector, CTime, PermutationVector - -class UtilTest(TestCase): - def setUp(self): - pass - - def dotest_slicing(self, vec): - self.assertEqual(10, len(vec)) - self.assertEqual(vec[-1], vec[9]) - self.assertEqual(8, len(vec[:8])) - self.assertEqual(9, len(vec[1:])) - self.assertEqual(3, len(vec[1:8:3])) - odds = vec[1::2] - self.assertEqual(4, len(vec[1:8:2])) - for i in range(4): - self.assertEqual(vec[2*i + 1], odds[i]) - - def test_slicing(self): - dv = DoubleVector(initial_size=10) - for i in range(10): - dv[i] = 1.0 / (1+i) - self.dotest_slicing(dv) - iv = IntVector(initial_size=10) - for i in range(10): - iv[i] = i**3 - self.dotest_slicing(iv) - bv = BoolVector(initial_size=10) - for i in range(0,10,3): - bv[i] = True - self.dotest_slicing(bv) - tv = TimeVector(initial_size=10) - for i in range(10): - tv[i] = CTime(datetime.datetime(2016, 12, i+3, 0, 0, 0)) - self.dotest_slicing(tv) - - - - def test_double_vector(self): - v = DoubleVector() - - v[0] = 77.25 - v[1] = 123.25 - v[2] = 66.25 - v[3] = 56.25 - v[4] = 111.25 - v[5] = 99.25 - v[12] = 12 - - self.assertEqual(len(v), 13) - self.assertEqual(list(v), [v[0], v[1], v[2], v[3], v[4], v[5], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v[12]]) - - v.clear() - self.assertEqual(len(v), 0) - - v.clear() - - v[0] = 0.1 - v[1] = 0.2 - v[2] = 0.4 - v[3] = 0.8 - - v2 = v * 2 - - self.assertEqual(list(v2), [v[0] * 2, v[1] * 2, v[2] * 2, v[3] * 2]) - - v2 += v - self.assertEqual(list(v2), [v[0] * 3, v[1] * 3, v[2] * 3, v[3] * 3]) - - v2.assign(0.66) - self.assertEqual(list(v2), [0.66, 0.66, 0.66, 0.66]) - - v.assign(v2) - self.assertEqual(list(v), [0.66, 0.66, 0.66, 0.66]) - - v.clear() - v.setDefault(0.75) - self.assertEqual(v.getDefault(), 0.75) - v[2] = 0.0 - self.assertEqual(v[1], 0.75) - - def test_vector_operations_with_exceptions(self): - iv1 = IntVector() - iv1.append(1) - iv1.append(2) - iv1.append(3) - - iv2 = IntVector() - iv2.append(4) - iv2.append(5) - - dv1 = DoubleVector() - dv1.append(0.5) - dv1.append(0.75) - dv1.append(0.25) - - # Size mismatch - with self.assertRaises(ValueError): - iv3 = iv1 + iv2 - - # Size mismatch - with self.assertRaises(ValueError): - iv3 = iv1 * iv2 - - # Type mismatch - with self.assertRaises(TypeError): - iv1 += dv1 - - # Type mismatch - with self.assertRaises(TypeError): - iv1 *= dv1 - - def test_setitem_getitem(self): - primes = [2,3,5,7,11,13,17,19] - primep = [i in primes for i in range(20)] - b = BoolVector(initial_size = 20) - b[2] = True - b[3:8:2] = True - b[11::2] = True - self.assertTrue(b[15]) - self.assertTrue(b[-5]) - self.assertTrue(b[17]) - self.assertTrue(b[19]) - b[-5] = False - self.assertEqual(list(b), primep) - - def test_repr(self): - primes = [2,3,5,7,11,13,17,19] - b = BoolVector() - for i in primes: - b[i] = True - pfx = 'BoolVector(size = 20, content = "00110101000101000101")' - print(repr(b)) - self.assertEqual(pfx, repr(b)[:len(pfx)]) - b[30] = True - pfx = 'BoolVector(size = 31, content = "001101010...00000001")' - print(repr(b)) - self.assertEqual(pfx, repr(b)[:len(pfx)]) - - - def test_bool_vector(self): - b = BoolVector() - b.setDefault(True) - - b[4] = False - - self.assertEqual(list(b), [True, True, True, True, False]) - - def test_activeList(self): - active_list = IntVector.active_list("1,10,100-105") - self.assertTrue(len(active_list) == 8) - self.assertTrue(active_list[0] == 1) - self.assertTrue(active_list[2] == 100) - self.assertTrue(active_list[7] == 105) - self.assertEqual(active_list.count(100), 1) - active_list.append(100) - active_list.append(100) - self.assertEqual(active_list.count(100), 3) - - active_list = IntVector.active_list("1,10,100-105X") - self.assertFalse(active_list) - - def test_value_list(self): - list2 = IntVector.valueList("3,10-12,0,1") - self.assertTrue(len(list2) == 6) - expected = [3, 10, 11, 12, 0, 1] - for v1, v2 in zip(list2, expected): - self.assertEqual(v1, v2) - - def test_contains_int(self): - iv = IntVector() - iv[0] = 1 - iv[1] = 10 - iv[2] = 100 - iv[3] = 1000 - - self.assertTrue(1 in iv) - self.assertTrue(10 in iv) - self.assertTrue(88 not in iv) - self.assertTrue(99 not in iv) - - def test_activeMask(self): - active_list = BoolVector.createActiveMask("1 , 4 - 7 , 10") - self.assertTrue(len(active_list) == 11) - self.assertTrue(active_list[1]) - self.assertTrue(active_list[4]) - self.assertTrue(active_list[10]) - self.assertFalse(active_list[9]) - self.assertFalse(active_list[8]) - - self.assertEqual(6, active_list.count(True)) - - active_list = BoolVector.createActiveMask("1,4-7,10X") - self.assertFalse(active_list) - - def test_update_active_mask(self): - vec = BoolVector(False, 10) - - self.assertTrue(vec.updateActiveMask("1-2,5")) - self.assertTrue(vec[1]) - self.assertTrue(vec[2]) - self.assertTrue(vec[5]) - self.assertFalse(vec[4]) - - vec = BoolVector(False, 10) - - self.assertTrue(vec.updateActiveMask("1-5,2,3")) - self.assertTrue(vec[1]) - self.assertTrue(vec[2]) - self.assertTrue(vec[3]) - self.assertTrue(vec[4]) - self.assertTrue(vec[5]) - self.assertFalse(vec[0]) - self.assertFalse(vec[6]) - - vec = BoolVector(False, 10) - - self.assertTrue(vec.updateActiveMask("5,6,7,15")) - self.assertTrue(vec[5]) - self.assertTrue(vec[6]) - self.assertTrue(vec[7]) - self.assertFalse(vec[4]) - self.assertFalse(vec[8]) - self.assertEqual(len(vec), 16) - - def test_pop(self): - a = IntVector() - a.append(1) - a.append(2) - - self.assertEqual(a.pop(), 2) - self.assertEqual(len(a), 1) - self.assertEqual(a.pop(), 1) - self.assertEqual(len(a), 0) - with self.assertRaises(ValueError): - a.pop() - -#---- - - def test_shift(self): - a = IntVector() - a.append(1) - a.append(2) - a.append(3) - a.append(4) - a.append(5) - - with self.assertRaises(ValueError): - a >> -1 - - with self.assertRaises(ValueError): - a << -1 - - with self.assertRaises(ValueError): - a << -6 - - b = a << 2 - self.assertEqual(list(b), [3, 4, 5]) - - print(a) - a <<= 2 - print(a) - self.assertEqual(list(a), [3, 4, 5]) - - b = a >> 2 - self.assertEqual(list(b), [0, 0, 3, 4, 5]) - - a >>= 2 - self.assertEqual(list(a), [0, 0, 3, 4, 5]) - - def test_int_vector(self): - a = IntVector() - a.append(1) - a.append(2) - a.append(3) - a.append(4) - a.append(5) - - self.assertEqual(list(a), [1, 2, 3, 4, 5]) - - a.sort(reverse=True) - self.assertEqual(list(a), [5, 4, 3, 2, 1]) - - self.assertTrue(a.max(), 5) - self.assertTrue(a.min(), 1) - self.assertTrue(a.minIndex(), 4) - - self.assertEqual(a.maxIndex(reverse=True), 0) - self.assertEqual(a.maxIndex(reverse=False), 0) - - a[4] = 5 - self.assertTrue(a[4] == 5) - - a_plus_one = a + 1 - self.assertEqual(list(a_plus_one), [6, 5, 4, 3, 6]) - - sliced = a[0:3] - self.assertEqual(list(sliced), [5, 4, 3]) - - with self.assertRaises(IndexError): - item = a[6] - - copy_of_a = a.copy() - self.assertEqual(list(a), list(copy_of_a)) - - another_copy_of_a = copy_of_a.copy( ) - self.assertEqual(list(a), list(another_copy_of_a)) - -#--- - - def test_div(self): - v = IntVector() - v[0] = 100 - v[1] = 10 - v[2] = 1 - v /= 10 - - self.assertEqual(list(v), [10, 1, 0]) - - def test_true(self): - iv = IntVector() - self.assertFalse(iv) # Will invoke the __len__ function; could override with __nonzero__ - iv[0] = 1 - self.assertTrue(iv) - - def test_time_vector(self): - time_vector = TimeVector() - - time1 = CTime(datetime.datetime(2013, 8, 13, 0, 0, 0)) - time2 = CTime(datetime.datetime(2013, 8, 13, 1, 0, 0)) - - time_vector.setDefault(time2) - - time_vector.append(time1) - time_vector[2] = time2 - - self.assertEqual(time_vector[0], time1) - self.assertEqual(time_vector[1], time2) - self.assertEqual(time_vector[2], time2) - - tv1 = TimeVector(default_value=datetime.date(2000, 1, 1), initial_size=2) - self.assertEqual(tv1[0], datetime.date(2000, 1, 1)) - - tv2 = TimeVector() - tv2.append(time2) - print(tv2) - - def test_permutation_vector(self): - vector = DoubleVector() - - for i in range(5, 0, -1): - vector.append(i) - - permutation_vector = vector.permutationSort() - - for index, value in enumerate(range(5, 0, -1)): - self.assertEqual(vector[index], value) - - vector.permute(permutation_vector) - - for index, value in enumerate(range(1, 6)): - self.assertEqual(vector[index], value) - - def test_contains_time(self): - start = datetime.datetime(2010, 1, 1, 0, 0, 0) - end = datetime.datetime(2010, 2, 1, 0, 0, 0) - other = datetime.datetime(2010, 1, 15, 0, 0, 0) - - tv = TimeVector() - tv.append(start) - tv.append(end) - - self.assertTrue(start in tv) - self.assertTrue(end in tv) - self.assertTrue(other not in tv) - - def test_unique(self): - iv = IntVector() - iv.append(1) - iv.append(1) - iv.append(1) - iv.append(0) - iv.append(1) - iv.append(2) - iv.append(2) - iv.append(0) - iv.append(3) - iv.selectUnique() - self.assertEqual(len(iv), 4) - self.assertEqual(iv[0], 0) - self.assertEqual(iv[1], 1) - self.assertEqual(iv[2], 2) - self.assertEqual(iv[3], 3) - - def test_element_sum(self): - dv = DoubleVector() - iv = IntVector() - for i in range(10): - dv.append(i + 1) - iv.append(i + 1) - - self.assertEqual(dv.elementSum(), 55) - self.assertEqual(iv.elementSum(), 55) - - def test_time_vector_regular(self): - start = datetime.datetime(2010, 1, 1, 0, 0, 0) - end = datetime.datetime(2010, 2, 1, 0, 0, 0) - - with self.assertRaises(ValueError): - trange = TimeVector.createRegular(end, start, "1X") - - with self.assertRaises(TypeError): - trange = TimeVector.createRegular(start, end, "1X") - - with self.assertRaises(TypeError): - trange = TimeVector.createRegular(start, end, "1") - - with self.assertRaises(TypeError): - trange = TimeVector.createRegular(start, end, "X") - - with self.assertRaises(TypeError): - trange = TimeVector.createRegular(start, end, "1.5Y") - - trange = TimeVector.createRegular(start, end, "d") - trange = TimeVector.createRegular(start, end, "D") - trange = TimeVector.createRegular(start, end, "1d") - self.assertEqual(trange[0].datetime(), start) - self.assertEqual(trange[-1].datetime(), end) - date = start - delta = datetime.timedelta(days=1) - for t in trange: - self.assertEqual(t, date) - date += delta - - end = datetime.datetime(2010, 1, 10, 0, 0, 0) - trange = TimeVector.createRegular(start, end, "2d") - self.assertEqual(trange[-1].datetime(), datetime.datetime(2010, 1, 9, 0, 0, 0)) - self.assertEqual(5, len(trange)) - - end = datetime.datetime(2012, 1, 10, 0, 0, 0) - trange = TimeVector.createRegular(start, end, "3M") - self.assertTrue(trange[-1] == datetime.datetime(2012, 1, 1, 0, 0, 0)) - self.assertTrue(trange[1] == datetime.datetime(2010, 4, 1, 0, 0, 0)) - self.assertTrue(trange[2] == datetime.datetime(2010, 7, 1, 0, 0, 0)) - self.assertTrue(trange[3] == datetime.datetime(2010, 10, 1, 0, 0, 0)) - self.assertTrue(trange[4] == datetime.datetime(2011, 1, 1, 0, 0, 0)) - - start = datetime.datetime(1980, 1, 1, 0, 0, 0) - end = datetime.datetime(2020, 1, 1, 0, 0, 0) - trange = TimeVector.createRegular(start, end, "2Y") - for (y, t) in zip(xrange(1980, 2022, 2), trange): - self.assertTrue(t == datetime.datetime(y, 1, 1, 0, 0, 0)) - - trange = TimeVector.createRegular(start, datetime.date(2050, 1, 1), "1Y") - - def test_asList(self): - v = IntVector() - v[0] = 100 - v[1] = 10 - v[2] = 1 - - l = v.asList() - self.assertListEqual(l, [100, 10, 1]) - - def test_true_false(self): - v = IntVector(default_value=77) - self.assertFalse(v) - v[10] = 77 - self.assertTrue(v) - - v = DoubleVector(default_value=77) - self.assertFalse(v) - v[10] = 77 - self.assertTrue(v) - - def test_count_equal(self): - v = IntVector(default_value=77) - v[0] = 1 - v[10] = 1 - v[20] = 1 - self.assertEqual(v.countEqual(1), 3) - - v = DoubleVector(default_value=77) - v[0] = 1 - v[10] = 1 - v[20] = 1 - self.assertEqual(v.countEqual(1), 3) - - def range_test(self, v, a, b, d): - v.initRange(a, b, d) - r = range(a, b, d) - - self.assertEqual(len(v), len(r)) - for a, b in zip(v, r): - self.assertEqual(a, b) - - def create_range_test(self, v, a, b, d): - v = IntVector.createRange(a, b, d) - r = range(a, b, d) - - self.assertEqual(len(v), len(r)) - for a, b in zip(v, r): - self.assertEqual(a, b) - - def test_range(self): - v = IntVector() - v[10] = 99 - - with self.assertRaises(ValueError): - v.initRange(1, 2, 0) - - self.range_test(v, 0, 5, 1) - self.range_test(v, 0, 100, 3) - self.range_test(v, 0, 100, -3) - - self.create_range_test(v, 0, 5, 1) - self.create_range_test(v, 0, 100, 3) - self.create_range_test(v, 0, 100, -3) - - - - def test_perm_vector(self): - v = IntVector.createRange( 11 , 0 , -1 ) - perm = v.permutationSort( ) - self.assertEqual( perm[0] , 10 ) - self.assertEqual( perm[5] , 5 ) - self.assertEqual( perm[10] , 0 ) diff --git a/ThirdParty/Ert/python/tests/util/test_version.py b/ThirdParty/Ert/python/tests/util/test_version.py deleted file mode 100644 index fc8de22f6d..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_version.py +++ /dev/null @@ -1,110 +0,0 @@ -# Copyright (C) 2015 Statoil ASA, Norway. -# -# The file 'test_version.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. -import os.path - -import ecl -from ecl.test import ExtendedTestCase -from ecl.util import Version,EclVersion - - -class VersionTest(ExtendedTestCase): - def setUp(self): - pass - - def test_create(self): - v1 = Version(1, 8, 6) - self.assertFalse(v1.isDevelVersion()) - - self.assertEqual(v1.versionString(), "1.8.6") - self.assertEqual(v1.versionTuple(), (1, 8, 6)) - - v2 = Version(2, 0, "X") - self.assertTrue(v2.isDevelVersion()) - - def test_eq(self): - v1 = Version(1, 2, 3) - v2 = Version(1, 2, 3) - - self.assertTrue(v1 == v2) - self.assertEqual(v1, v2) - self.assertEqual(str(v1), str(v2)) - self.assertEqual(repr(v1), repr(v2)) - self.assertFalse(v1 != v2) - - v1 = Version(1, 2, "X") - v2 = Version(1, 2, "Y") - self.assertTrue(v1 != v2) - self.assertFalse(v1 == v2) - - v1 = Version(1, 2, "X") - v2 = Version(1, 2, 0) - self.assertTrue(v1 != v2) - self.assertFalse(v1 == v2) - - v1 = Version(1, 2, "X") - v2 = Version(1, 3, "X") - self.assertTrue(v1 != v2) - self.assertFalse(v1 == v2) - - v1 = Version(1, 2, "X") - v2 = (1, 3, "X") - self.assertTrue(v1 != v2) - self.assertFalse(v1 == v2) - - def test_ge(self): - v1 = Version(1, 2, 3) - v2 = Version(1, 2, 3) - v3 = (1, 2, 2) - - self.assertEqual(str(v1), str(v2)) - self.assertEqual(repr(v1), repr(v2)) - - self.assertTrue(v1 >= v2) - self.assertFalse(v1 < v2) - - self.assertTrue(v1 >= v3) - self.assertFalse(v1 < v3) - - v1 = Version(1, 2, "X") - v2 = Version(1, 1, 9) - self.assertTrue(v1 > v2) - - v2 = Version(1, 2, "X") - self.assertTrue(v1 >= v2) - - v2 = Version(1, 2, 0) - self.assertFalse(v1 >= v2) - - self.assertNotEqual(str(v1), str(v2)) - self.assertNotEqual(repr(v1), repr(v2)) - - - def test_current(self): - current = EclVersion( ) - 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() ) - - - def test_root_path(self): - self.assertTrue( os.path.isdir( os.path.join( ecl.root() , "ecl"))) - self.assertTrue( os.path.isfile( os.path.join( ecl.root() , "ecl", "__init__.py"))) - diff --git a/ThirdParty/Ert/python/tests/util/test_work_area.py b/ThirdParty/Ert/python/tests/util/test_work_area.py deleted file mode 100644 index 51403f817d..0000000000 --- a/ThirdParty/Ert/python/tests/util/test_work_area.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2014 Statoil ASA, Norway. -# -# The file 'test_work_area.py' 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ERT is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. -# -# See the GNU General Public License at -# for more details. - -import os.path -import os - -try: - from unittest2 import skipIf -except ImportError: - from unittest import skipIf - -from ecl.test import ExtendedTestCase , TestAreaContext, TempAreaContext - - -class WorkAreaTest(ExtendedTestCase): - - def test_full_path(self): - with TestAreaContext("TestArea") as test_area: - with open("test_file" , "w") as fileH: - fileH.write("Something") - - self.assertTrue( os.path.isfile( "test_file") ) - - with self.assertRaises(IOError): - full_path = test_area.getFullPath( "does/not/exists" ) - - with self.assertRaises(IOError): - full_path = test_area.getFullPath( "/already/absolute" ) - - full_path = test_area.getFullPath( "test_file" ) - self.assertTrue( os.path.isfile( full_path )) - self.assertTrue( os.path.isabs( full_path )) - - - def test_temp_area(self): - with TestAreaContext("TestArea") as test_area: - cwd = os.getcwd() - with open("file.txt" , "w") as f: - f.write("File") - - with TempAreaContext("TempArea") as temp_area: - self.assertEqual( cwd, os.getcwd()) - self.assertEqual( cwd, temp_area.get_cwd()) - temp_area.copy_file( "file.txt" ) - - self.assertTrue( os.path.isfile( os.path.join( temp_area.getPath( ) , "file.txt"))) - - os.mkdir("tmp") - os.chdir("tmp") - - self.assertEqual( os.getcwd() , os.path.join( cwd , "tmp")) - - - def test_IOError(self): - with TestAreaContext("TestArea") as test_area: - with self.assertRaises(IOError): - test_area.copy_file( "Does/not/exist" ) - - with self.assertRaises(IOError): - test_area.install_file( "Does/not/exist" ) - - with self.assertRaises(IOError): - test_area.copy_directory( "Does/not/exist" ) - - with self.assertRaises(IOError): - test_area.copy_parent_directory( "Does/not/exist" ) - - os.makedirs("path1/path2") - with open("path1/file.txt" , "w") as f: - f.write("File ...") - - with self.assertRaises(IOError): - test_area.copy_directory( "path1/file.txt" ) - - def test_sync(self): - with TestAreaContext("test_sync") as t: - with open("file.txt" , "w") as f: - f.write("content") - - t.sync() - self.assertTrue( os.path.isfile( "file.txt")) diff --git a/ThirdParty/Ert/python/tests/well/CMakeLists.txt b/ThirdParty/Ert/python/tests/well/CMakeLists.txt deleted file mode 100644 index b9efe79dca..0000000000 --- a/ThirdParty/Ert/python/tests/well/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -set(TEST_SOURCES - __init__.py - test_ecl_well.py - test_ecl_well2.py - test_ecl_well3.py -) - -add_python_package("python.tests.well" ${PYTHON_INSTALL_PREFIX}/tests/well "${TEST_SOURCES}" False) - -if (STATOIL_TESTDATA_ROOT) - addPythonTest(tests.well.test_ecl_well.EclWellTest LABELS StatoilData) - addPythonTest(tests.well.test_ecl_well2.EclWellTest2 LABELS StatoilData) - addPythonTest(tests.well.test_ecl_well3.EclWellTest3 LABELS StatoilData) -endif() diff --git a/ThirdParty/Ert/python/tests/well/__init__.py b/ThirdParty/Ert/python/tests/well/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ThirdParty/Ert/python/tests/well/test_ecl_well.py b/ThirdParty/Ert/python/tests/well/test_ecl_well.py deleted file mode 100644 index ed3aad2c47..0000000000 --- a/ThirdParty/Ert/python/tests/well/test_ecl_well.py +++ /dev/null @@ -1,446 +0,0 @@ -import datetime -from ecl.ecl import EclGrid, EclFile, EclFileFlagEnum -from ecl.test import ExtendedTestCase -from ecl.util.ctime import CTime -from ecl.well import WellInfo, WellConnection, WellTypeEnum, WellConnectionDirectionEnum, WellSegment - - -class EclWellTest(ExtendedTestCase): - ALL_WELLS = ['E5H', 'G1H', 'M41', 'J41', 'D10H', 'P41', 'L41', 'M42', 'S41', 'S13H', 'Q12HT2', 'O41', 'L11H', 'Q21H', - 'E6CH', 'D4Y1H', 'D4Y2H', 'I13Y1H', 'Q21AY1H', 'F5AH', 'O14Y4HT2', 'K24Y1H', 'K24Y3H', 'S21H', 'N11H', - 'L23Y1H', 'D7AY1H', 'S21AHT2', 'H2AH', 'S21AHT3', 'L23Y6H', 'N11AH', 'N11BY1H', 'X23Y2H', 'N22Y3HT3', - 'G1BY1HT2', 'Q21BY1H', 'Q21BY2T2', 'A08', 'A37', 'P24Y4H', 'A11', 'A33', 'P21BY1H', 'H6BY2H', 'M24AH', - 'TOGIB2H', 'TOGIB3H', 'TOGIB4H', 'TOGIB5H', 'TOGIB6H', 'TAP21', 'D1AH', 'D1BYH', 'D2H', 'D2AYH', 'D4YH', - 'D5AH', 'D6H', 'D7H', 'D7AYH', 'D8AH', 'D8BYH', 'E1AH', 'E1BYH', 'E3YH', 'E4H', 'E5AH', 'E6BH', 'E6DYH', - '31/2-T1', 'F1AH', 'F1BYH', 'F4AHT2', 'F5H', 'F5BYH', 'F6AH', 'F6BYH', '2B3H', 'G1AHT2', 'G1BYH', 'G3H', - 'G3AYH', 'G4AH', 'G4BYH', 'G6HT2', 'G6AYH', '31/5-T1', 'H1AH', 'H2BYH', 'H2HT2', 'H3ABH', 'H3CYH', 'H4HT2', - 'H5AHT2', 'H6AH', 'H6BYH', 'Z1H', 'Z2H', 'I11AH', 'I12AYH', 'I13YH', 'I14AHT2', 'I14BYH', 'I21AHT2', - 'I21BYH', 'I22AH', 'I23AH', 'I32YH', 'J11AH', 'J12H', 'J13H', 'J13AYH', 'J14H', 'J14AYH', 'J21YH', 'J22YH', - 'J22AYH', 'J23AH', 'J24HT2', 'J24AYH', 'K11YH', 'K12AH', 'K12BYH', 'K13AH', 'K14AYH', 'K21AYH', 'K22AH', - 'K23AH', 'K24YH', 'L11AH', 'L11BYH', 'L12Y', 'L13H', 'L13AYH', 'L14YH', 'L21AYH', 'L22AYH', 'L23YH', - 'L24AYH', 'M11H', 'M12H', 'M13YH', 'M14AHT2', 'M14BYH', 'M21H', 'M22H', 'M23AH', 'M24YH', 'N11BYH', - 'N12HT2', 'N13H', 'N14AH', 'N21YH', 'N22YH', 'N23AYH', 'N24YH', 'O11H', 'O11AYH', 'O12AH', 'O13AH', - 'O13BYH', 'O14YH', 'O21YH', 'O23YH', 'O26YH', 'P11YH', 'P11AYH', 'P12H', 'P13AHT2', 'P13BYH', 'P14AHT2', - 'P14BYH', 'P21AYH', 'P21BYH', 'P22AYH', 'P23YH', 'P24YH', 'P24Y1H', 'Q11AHT2', 'Q11BYH', 'Q12AH', 'Q12BH', - 'Q13AH', 'Q14H', 'Q14AYH', 'Q21AYH', 'Q21BH1', 'Q21BH2', 'S11HT3', 'S12H', 'S13AH', 'S14AH', 'S14BYH', - 'S21BYH', 'S22AH', 'S23HT2', 'S23AYH', 'S24YH', 'S31H', 'X11AH', 'X11BYH', 'X12H', 'X12AH', 'X13YH', - 'X14AYH', 'X21H', 'X22H', 'X22AYH', 'X23YH', 'X24AH', 'Y11AH', 'Y11BYH', 'Y12YH', 'Y13AH', 'Y13BYH', - 'Y14AYH', 'Y21YH', 'Y22YH', 'Y23AHT2', 'Y23CYH', 'Y24AH'] - - - @classmethod - def setUpClass(cls): - EclWellTest.__well_info = None - EclWellTest.__well_info_with_no_well_segments = None - - - def getWellInfoWithNoWellSegments(self): - """ @rtype: WellInfo """ - if EclWellTest.__well_info_with_no_well_segments is None: - grid_path = self.createTestPath("Statoil/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.EGRID") - rst_path_1 = self.createTestPath("Statoil/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.X0135") - - grid = EclGrid(grid_path) - - rst_file = EclFile(rst_path_1, EclFileFlagEnum.ECL_FILE_CLOSE_STREAM) - - EclWellTest.__well_info_with_no_well_segments = WellInfo(grid, rst_file, False) - - - return EclWellTest.__well_info_with_no_well_segments - - def getWellInfo(self): - """ @rtype: WellInfo """ - if EclWellTest.__well_info is None: - grid_path = self.createTestPath("Statoil/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.EGRID") - rst_path_1 = self.createTestPath("Statoil/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.X0135") - - grid = EclGrid(grid_path) - - rst_file = EclFile(rst_path_1, EclFileFlagEnum.ECL_FILE_CLOSE_STREAM) - - EclWellTest.__well_info = WellInfo(grid, rst_file) - - - return EclWellTest.__well_info - - - def test_no_such_well(self): - grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") - rst_path1 = self.createTestPath("nosuch/path/ECLIPSE.X001") - rst_path2 = self.createTestPath("nosuch/path/ECLIPSE.X002") - grid = EclGrid(grid_path) - with self.assertRaises(IOError): - _ = WellInfo(grid, rst_path1) - with self.assertRaises(IOError): - _ = WellInfo(grid, [rst_path1, rst_path2]) - - def test_construction(self): - grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") - rst_path_1 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0011") - rst_path_2 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0022") - rst_path_3 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0035") - rst_path_4 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0061") - - grid = EclGrid(grid_path) - - def checkWellInfo(well_info, well_count, report_step_count): - self.assertEqual(len(well_info), well_count) - - for index, well_time_line in enumerate(well_info): - self.assertEqual(len(well_time_line), report_step_count[index]) - - 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)) - 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]) - checkWellInfo(well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2]) - - well_info = WellInfo(grid, [EclFile(rst_path_1), EclFile(rst_path_2), rst_path_3, EclFile(rst_path_4)]) - checkWellInfo(well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3]) - - - well_info = WellInfo(grid) - well_info.addWellFile(rst_path_1, True) - - checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1]) - - well_info.addWellFile(EclFile(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) - checkWellInfo(well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2]) - - well_info.addWellFile(rst_path_4, True) - checkWellInfo(well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3]) - - - - def test_well_type_enum(self): - source_file_path = "lib/include/ert/ecl_well/well_conn.h" - # The header file has duplicated symbols, so the simple test fails. - # self.assertEnumIsFullyDefined(WellTypeEnum, "well_type_enum", source_file_path) - - - def test_well_connection_direction_enum(self): - source_file_path = "lib/include/ert/ecl_well/well_conn.h" - self.assertEnumIsFullyDefined(WellConnectionDirectionEnum, "well_conn_dir_enum", source_file_path) - - - def test_well_info(self): - well_info = self.getWellInfo() - self.assertEqual(len(well_info), 222) - - all_well_names = well_info.allWellNames() - - self.assertEqual(len(well_info), len(all_well_names)) - self.assertEqual(EclWellTest.ALL_WELLS, all_well_names) - - for well_name in all_well_names: - self.assertTrue(well_name in well_info) - - self.assertEqual(well_info[0], well_info[all_well_names[0]]) - self.assertEqual(well_info[1], well_info[all_well_names[1]]) - self.assertEqual(well_info[221], well_info[all_well_names[221]]) - - self.assertNotEqual(well_info[0], well_info[1]) - - well_time_lines = [wtl for wtl in well_info] - self.assertEqual(len(well_time_lines), len(well_info)) - - with self.assertRaises(IndexError): - err = well_info[222] - - with self.assertRaises(KeyError): - err = well_info["Well"] - - - - - def test_well_time_line(self): - well_info = self.getWellInfo() - - for well_time_line in well_info: - self.assertEqual(len(well_time_line), 1) - - well_states = set() - for well_name in EclWellTest.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)) - - # testing name and repr - info = self.getWellInfo() - wtl = info['G6HT2'] - self.assertEqual('G6HT2', wtl.getName()) - rep = repr(wtl) - print(rep) - pfx = 'WellTimeLine(' - self.assertEqual(pfx, rep[:len(pfx)]) - - # testing __getitem__ and its well state - ws = wtl[0] - self.assertTrue(ws.isOpen()) - self.assertEqual(ws.wellType(), WellTypeEnum.ECL_WELL_PRODUCER) - self.assertTrue(ws.isMultiSegmentWell()) - pfx = 'WellState(' - self.assertEqual(pfx, repr(ws)[:len(pfx)]) - - - def test_well_state(self): - well_info = self.getWellInfo() - - sim_time = CTime(datetime.date(2000, 1, 1)) - 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} - - segments = set() - branches = set() - connections = set() - connections_count = 0 - - for index, well_name in enumerate(EclWellTest.ALL_WELLS): - well_time_line = well_info[well_name] - well_state = well_time_line[0] - - self.assertEqual(well_state.name(), well_name) - well_number = well_state.wellNumber() - self.assertEqual(well_number, index) - - self.assertEqual(well_state.reportNumber(), 135) - self.assertEqual(well_state.simulationTime(), sim_time) - - open_states[well_state.isOpen()] += 1 - msw_states[well_state.isMultiSegmentWell()] += 1 - - well_types[well_state.wellType()] += 1 - - self.assertTrue(well_state.hasGlobalConnections()) - global_connections = well_state.globalConnections() - connections_count += len(global_connections) - connections.update(global_connections) - - # branches.add(well_state.branches()) - # segments.add(well_state.segments()) - - self.assertEqual(open_states[True], 53) - self.assertEqual(open_states[False], 169) - - 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(len(connections), connections_count) - - - - def test_well_segments(self): - well_info = self.getWellInfo() - - well_name = "X22AYH" - well_time_line = well_info[well_name] - well_state = well_time_line[0] - - segments = well_state.segments() - - branch_ids = [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, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, - 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55] - - outlet_ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 1, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, - 52, 53, 54, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 45, 47, 48, 49, 50, 51, - 52, 53, 54, 55] - - depths = [1554.0, 1557.505, 1557.506, 1557.50540469, 1557.75140469, 1558.24240469, 1558.24240469, 1557.75340469, - 1557.50740469, 1557.50658613, 1557.50628848, 1557.50584678, 1557.50384678, 1557.50484678, 1557.50402823, - 1557.50380498, 1557.50454913, 1557.50425147, 1557.50325147, 1557.50273057, 1557.50473057, 1557.50373057, - 1557.5038794, 1557.5048794, 1557.50398643, 1557.50406085, 1557.50606085, 1557.50670767, 1557.635, 1557.509, - 1557.504, 1557.503, 1557.502, 1557.50242878, 1557.50542878, 1557.50505671, 1557.50602409, 1557.50602409, - 1557.50402409, 1557.50485764, 1557.50563489, 1557.50543796, 1557.50643796, 1557.50843796, 1557.50799148, - 1557.50709851, 1557.50665427, 1557.50865427, 1557.50943383, 1557.50543383, 1557.50443383, 1557.50495473, - 1557.504285, 1557.50473149, 1557.50442009, 1557.505, 1557.506, 1557.50540469, 1557.75140469, 1558.24240469, - 1558.24240469, 1557.75340469, 1557.50740469, 1557.50658613, 1557.50628848, 1557.50584678, 1557.50384678, - 1557.50484678, 1557.50402823, 1557.50380498, 1557.50454913, 1557.50425147, 1557.50325147, 1557.50273057, - 1557.50473057, 1557.50373057, 1557.5038794, 1557.5048794, 1557.50398643, 1557.50406085, 1557.50606085, - 1557.50670767, 1557.635, 1557.509, 1557.504, 1557.503, 1557.502, 1557.50242878, 1557.50542878, 1557.50505671, - 1557.50602409, 1557.50602409, 1557.50402409, 1557.50485764, 1557.50563489, 1557.50543796, 1557.50643796, - 1557.50799148, 1557.50799148, 1557.50665427, 1557.50865427, 1557.50943383, 1557.50543383, 1557.50443383, - 1557.50495473, 1557.504285, 1557.50473149, 1557.50442009] - - lengths = [1853.483, 525.634, 89.101, 148.227, 105.066, 70.981, 50.194, 71.215, 129.929, 141.712, 141.239, 108.247, - 200.032, 116.122, 141.525, 141.983, 112.622, 72.694, 105.195, 149.555, 128.22, 83.537, 112.533, 155.336, - 86.552, 71.427, 129.949, 92.347, 210.312, 58.0, 218.375, 111.0, 250.925, 76.233, 72.565, 127.481, 97.987, - 75.648, 121.119, 129.137, 188.157, 109.433, 142.914, 84.9, 47.458, 57.507, 55.704, 211.767, 121.219, - 143.23, 145.666, 146.044, 88.195, 72.891, 58.92, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, - 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, - 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] - - total_lengths = [1853.483, 2379.117, 2468.218, 2616.445, 2721.511, 2792.492, 2842.686, 2913.901, 3043.83, 3185.542, - 3326.781, 3435.028, 3635.06, 3751.182, 3892.707, 4034.69, 4147.312, 4220.006, 4325.201, 4474.756, - 4602.976, 4686.513, 4799.046, 4954.382, 5040.934, 5112.361, 5242.31, 5334.657, 2063.795, 2121.795, - 2340.17, 2451.17, 2702.095, 2778.328, 2850.893, 2978.374, 3076.361, 3152.009, 3273.128, 3402.265, - 3590.422, 3699.855, 3842.769, 3927.669, 3975.127, 4032.634, 4088.338, 4300.105, 4421.324, 4564.554, - 4710.22, 4856.264, 4944.459, 5017.35, 5076.27, 2379.217, 2468.318, 2616.545, 2721.611, 2792.592, - 2842.786, 2914.001, 3043.93, 3185.642, 3326.881, 3435.128, 3635.16, 3751.282, 3892.807, 4034.79, - 4147.412, 4220.106, 4325.301, 4474.856, 4603.076, 4686.613, 4799.146, 4954.482, 5041.034, 5112.461, - 5242.41, 5334.757, 2063.895, 2121.895, 2340.27, 2451.27, 2702.195, 2778.428, 2850.993, 2978.474, - 3076.461, 3152.109, 3273.228, 3402.365, 3590.522, 3699.955, 3842.869, 3975.227, 3975.227, 4088.438, - 4300.205, 4421.424, 4564.654, 4710.32, 4856.364, 4944.559, 5017.45, 5076.37] - - link_count = 0 - main_stem = {True: 0, False: 0} - nearest_wellhead = {True: 0, False: 0} - for index, segment in enumerate(segments): - assert isinstance(segment, WellSegment) - self.assertEqual(segment.id(), index + 1) - link_count += segment.linkCount() - self.assertEqual(segment.branchId(), branch_ids[index]) - self.assertEqual(segment.outletId(), outlet_ids[index]) - - self.assertTrue(segment.isActive()) - main_stem[segment.isMainStem()] += 1 - nearest_wellhead[segment.isNearestWellHead()] += 1 - - self.assertFloatEqual(segment.depth(), depths[index]) - self.assertFloatEqual(segment.length(), lengths[index]) - self.assertFloatEqual(segment.totalLength(), total_lengths[index]) - - if index == 0: - self.assertEqual(segment.diameter(), 0.0) - else: - self.assertEqual(segment.diameter(), 0.159) - - - self.assertEqual(main_stem[True], 28) - self.assertEqual(main_stem[False], 80) - - self.assertEqual(nearest_wellhead[True], 1) - self.assertEqual(nearest_wellhead[False], 107) - - self.assertEqual(link_count, 53) - - - - def test_well_connections(self): - well_info = self.getWellInfo() - - well_name = "H6BY2H" - well_connections_ijk = [(33, 157, 9), (32, 157, 9), (32, 157, 51), (32, 157, 52), - (32, 157, 53), (32, 157, 54), (32, 157, 55), (32, 157, 56), - (32, 157, 57), (31, 157, 57), (31, 158, 57), (31, 158, 56), - (30, 158, 56), (29, 158, 56), (29, 157, 56), (28, 157, 56), - (28, 158, 56), (28, 158, 55), (27, 158, 55), (27, 158, 54), - (26, 158, 54), (26, 158, 53), (25, 158, 53), (24, 158, 53), - (23, 158, 53), (23, 158, 54), (22, 158, 54), (21, 158, 54), - (20, 158, 54), (20, 158, 55), (19, 158, 55), (19, 158, 54), - (18, 158, 54), (17, 158, 54), (16, 158, 54), (16, 158, 55), - (15, 158, 55), (15, 158, 54), (15, 158, 53), (14, 158, 54), - (13, 158, 54), (13, 158, 55), (12, 158, 55), (12, 157, 55)] - - well_connection_factors = [3022.45092773, 171.561004639, 237.263000488, 135.57800293, 177.925994873, 289.058990479, - 1081.09997559, 1575.79101562, 3679.54907227, 2865.51489258, 3999.2199707, 14205.3300781, - 1864.43005371, 1296.47302246, 3.40599989891, 2012.7199707, 2656.25390625, 4144.21923828, - 6.22700023651, 96.4029998779, 0.144999995828, 80.81199646, 114.416999817, 97.5159988403, - 26.8530006409, 0.12800000608, 34238.15625, 34493.7070312, 2618.16894531, 31999.1992188, - 27874.6191406, 7343.23681641, 35418.1679688, 34612.6523438, 3486.13500977, 15446.3691406, - 65.4499969482, 8687.91113281, 13238.8037109, 5644.90380859, 7499.49707031, 12863.5292969, - 12277.4716797, 19404.5488281] - - well_time_line = well_info[well_name] - well_state = well_time_line[0] - - self.assertFalse(well_state.isMultiSegmentWell()) - - self.assertTrue(well_state.hasGlobalConnections()) - global_connections = well_state.globalConnections() - - for index, connection in enumerate(global_connections): - assert isinstance(connection, WellConnection) - self.assertTrue(connection.isOpen()) - self.assertEqual(connection.ijk(), well_connections_ijk[index]) - self.assertFalse(connection.isMultiSegmentWell()) - self.assertEqual(connection.segmentId(), -999) - self.assertFalse(connection.isFractureConnection()) - self.assertTrue(connection.isMatrixConnection()) - self.assertFloatEqual(connection.connectionFactor(), well_connection_factors[index]) - self.assertEqual(connection.direction(), WellConnectionDirectionEnum.well_conn_dirX) - - self.assertNotEqual(global_connections[0], global_connections[1]) - self.assertEqual(global_connections[0], global_connections[0]) - - - def test_well_connections_msw(self): - well_info = self.getWellInfo() - - well_name = "X22AYH" - well_time_line = well_info[well_name] - well_state = well_time_line[0] - - segment_ids = [56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108] - - self.assertTrue(well_state.isMultiSegmentWell()) - - self.assertTrue(well_state.hasGlobalConnections()) - global_connections = well_state.globalConnections() - - self.assertEqual(len(global_connections), len(segment_ids)) - - for index, connection in enumerate(global_connections): - assert isinstance(connection, WellConnection) - self.assertTrue(connection.isOpen()) - self.assertTrue(connection.isMultiSegmentWell()) - self.assertEqual(connection.segmentId(), segment_ids[index]) - self.assertFalse(connection.isFractureConnection()) - self.assertTrue(connection.isMatrixConnection()) - self.assertEqual(connection.direction(), WellConnectionDirectionEnum.well_conn_dirY) - - - def test_well_connections_msw_do_not_load_segments(self): - well_info = self.getWellInfoWithNoWellSegments() - - well_name = "X22AYH" - well_time_line = well_info[well_name] - well_state = well_time_line[0] - - segment_ids = [56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108] - - self.assertTrue(well_state.isMultiSegmentWell()) - self.assertFalse(well_state.hasSegmentData()) - - self.assertTrue(well_state.hasGlobalConnections()) - global_connections = well_state.globalConnections() - - self.assertEqual(len(global_connections), len(segment_ids)) - - for index, connection in enumerate(global_connections): - assert isinstance(connection, WellConnection) - self.assertTrue(connection.isOpen()) - self.assertTrue(connection.isMultiSegmentWell()) - self.assertEqual(connection.segmentId(), segment_ids[index]) - self.assertFalse(connection.isFractureConnection()) - self.assertTrue(connection.isMatrixConnection()) - self.assertEqual(connection.direction(), WellConnectionDirectionEnum.well_conn_dirY) diff --git a/ThirdParty/Ert/python/tests/well/test_ecl_well2.py b/ThirdParty/Ert/python/tests/well/test_ecl_well2.py deleted file mode 100644 index 52797e2bfa..0000000000 --- a/ThirdParty/Ert/python/tests/well/test_ecl_well2.py +++ /dev/null @@ -1,43 +0,0 @@ -import datetime -import os.path - -from ecl.ecl import EclGrid, EclFile, EclFileFlagEnum -from ecl.test import ExtendedTestCase -from ecl.util.ctime import CTime -from ecl.well import WellInfo, WellConnection, WellTypeEnum, WellConnectionDirectionEnum, WellSegment - - - -class EclWellTest2(ExtendedTestCase): - grid = None - - - def getGrid(self): - if EclWellTest2.grid is None: - EclWellTest2.grid = EclGrid( self.createTestPath("Statoil/ECLIPSE/Troll/Ref2014/T07-4A-W2014-06.EGRID")) - - return EclWellTest2.grid - - - def checkWell(self , rst_file): - segment_length = [2660 , 20 , 121 , 1347.916 , 20.585 , 56.249 , 115.503 , 106.978 , 47.124 , 279.529, - 128.534 , 165.33 , 59.97 , 936.719 ] - - well_info = WellInfo( self.getGrid() , self.createTestPath( os.path.join("Statoil/ECLIPSE/Troll/Ref2014" , rst_file ))) - well_time_line = well_info["F4BYH"] - for well_state in well_time_line: - self.assertTrue( well_state.isMultiSegmentWell() ) - self.assertTrue( well_state.hasSegmentData() ) - - for index,length in enumerate(segment_length): - segment = well_state.igetSegment(index) - self.assertFloatEqual( segment.length() , length ) - - - - - def testWell(self): - self.checkWell("T07-4A-W2014-06.X0695") - self.checkWell("T07-4A-W2014-06.X0709") - self.checkWell("T07-4A-W2014-06.UNRST") - diff --git a/ThirdParty/Ert/python/tests/well/test_ecl_well3.py b/ThirdParty/Ert/python/tests/well/test_ecl_well3.py deleted file mode 100644 index 66283d261e..0000000000 --- a/ThirdParty/Ert/python/tests/well/test_ecl_well3.py +++ /dev/null @@ -1,48 +0,0 @@ -import datetime -import os.path - -from ecl.ecl import EclGrid, EclFile, EclSum -from ecl.test import ExtendedTestCase -from ecl.util.ctime import CTime -from ecl.well import WellInfo, WellConnection, WellTypeEnum, WellConnectionDirectionEnum, WellSegment - - -class EclWellTest3(ExtendedTestCase): - grid = None - - def test_rates(self): - grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") - rst_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") - sum_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") - - grid = EclGrid(grid_path) - well_info = WellInfo(grid, rst_path) - sum = EclSum(sum_path) - - for wtl in well_info: - for well_state in wtl: - # print "%03d %g %g " % (R , well_state.oilRate(), sum.get_from_report( "WOPR:%s" % well , R)) - if wtl.getName() == "OP_4": - pass - # print well_state.oilRate(), well_state.waterRate(), well_state.gasRate(), well_state.volumeRate() - # print well_state.oilRateSI(), well_state.waterRateSI(), well_state.gasRateSI(), well_state.volumeRateSI() - self.assertEqual(well_state.oilRate(), well_state.oilRateSI()) - self.assertEqual(well_state.waterRate(), well_state.waterRateSI()) - self.assertEqual(well_state.gasRate(), well_state.gasRateSI()) - self.assertEqual(well_state.volumeRate(), well_state.volumeRateSI()) - # print sum.get_from_report("WOPR:%s" % wtl.getName(), 1) - # print sum.get_from_report( "WWPR:%s" % wtl.getName(), 30 ) - - for conn in well_state.globalConnections(): - # print conn.gasRate(), conn.waterRate(), conn.oilRate() - # print conn.gasRateSI(), conn.waterRateSI(), conn.oilRateSI() - self.assertEqual(conn.gasRate(), conn.gasRateSI()) - self.assertEqual(conn.waterRate(), conn.waterRateSI()) - self.assertEqual(conn.oilRate(), conn.oilRateSI()) - self.assertEqual(conn.volumeRate(), conn.volumeRateSI()) - # - # print sum.get_from_report("WGPR:%s" % wtl.getName(), 30) - # - # self.assertFloatEqual(well_state.oilRate(), sum.get_from_report("WOPR:%s" % wtl.getName(), 30)) - # self.assertFloatEqual(well_state.waterRate(), sum.get_from_report("WWPR:%s" % wtl.getName(), 30)) - # self.assertFloatEqual(well_state.gasRate(), sum.get_from_report("WGPR:%s" % wtl.getName(), 30)) diff --git a/ThirdParty/Ert/python/tests/well_tests/test_ecl_well.py b/ThirdParty/Ert/python/tests/well_tests/test_ecl_well.py index 8f12c67354..1d7d2ee32f 100644 --- a/ThirdParty/Ert/python/tests/well_tests/test_ecl_well.py +++ b/ThirdParty/Ert/python/tests/well_tests/test_ecl_well.py @@ -446,3 +446,10 @@ class EclWellTest(EclTest): self.assertFalse(connection.isFractureConnection()) self.assertTrue(connection.isMatrixConnection()) self.assertEqual(connection.direction(), WellConnectionDirectionEnum.well_conn_dirY) + + + def test_load_broken_direction(self): + grid_path = self.createTestPath("Statoil/ECLIPSE/icon-invalid-value/R6_HM2016B_FFP_BASE.EGRID") + rst_path = self.createTestPath("Statoil/ECLIPSE/icon-invalid-value/R6_HM2016B_FFP_BASE.UNRST") + grid = EclGrid(grid_path) + well_info = WellInfo(grid, rst_path) diff --git a/ThirdParty/Ert/redhat/ert.ecl.spec b/ThirdParty/Ert/redhat/ert.ecl.spec deleted file mode 100644 index 9aabf2ff86..0000000000 --- a/ThirdParty/Ert/redhat/ert.ecl.spec +++ /dev/null @@ -1,108 +0,0 @@ -# -# spec file for package ert.ecl -# - -%define tag final2 - -Name: ert.ecl -Version: 2015.10 -Release: 0 -Summary: ERT - Ensemble based Reservoir Tool - ECL library -License: GPL-3+ -Group: Development/Libraries/C and C++ -Url: http://ert.nr.no -Source0: https://github.com/OPM/%{name}/archive/release/%{version}/%{tag}.tar.gz#/%{name}-%{version}.tar.gz -BuildRequires: lapack-devel zlib-devel iputils -BuildRequires: gcc -%{?!el6:BuildRequires: python-devel numpy} -%{?el6:BuildRequires: cmake28 devtoolset-3-toolchain} -%{?!el6:BuildRequires: cmake} -BuildRoot: %{_tmppath}/%{name}-%{version}-build -Requires: libert.ecl1 = %{version} - -%description -ERT - Ensemble based Reservoir Tool is a tool for managing en ensemble -of reservoir models. The initial motivation for creating ERT was a as -tool to do assisted history matching with Ensemble Kalman Filter -(EnKF). - -%package -n libert.ecl1 -Summary: ERT - Ensemble based Reservoir Tool - ECL library -Group: System/Libraries - -%{?!el6: -%package -n python-ert.ecl -Summary: ERT - Ensemble based Reservoir Tool - Python bindings -Group: Python/Libraries -Requires: libert.ecl1 python-cwrap - -%description -n python-ert.ecl -ERT - Ensemble based Reservoir Tool is a tool for managing en ensemble -of reservoir models. The initial motivation for creating ERT was a as -tool to do assisted history matching with Ensemble Kalman Filter -(EnKF). This package contains the Python bindings. - -%package -n python-cwrap -Summary: Simplify ctypes based wrapping of C code. -Group: Python/Libraries - -%description -n python-cwrap -Package to simplify ctypes based wrapping of C code. -} - -%description -n libert.ecl1 -ERT - Ensemble based Reservoir Tool is a tool for managing en ensemble -of reservoir models. The initial motivation for creating ERT was a as -tool to do assisted history matching with Ensemble Kalman Filter -(EnKF). - -%package devel -Summary: Development and header files for libert.ecl -Group: Development/Libraries/C and C++ -Requires: %{name} = %{version} -Requires: lapack-devel -Requires: libert.ecl1 = %{version} - -%description devel -This package contains the development and header files for ert.ecl - -%prep -%setup -q -n ert-release-%{version}-%{tag} - -%build -%{?el6:scl enable devtoolset-3 bash} -DESTDIR=${RPM_BUILD_ROOT} %{?el6:cmake28} %{?!el6:cmake} -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%{_prefix} -DBUILD_ECL_SUMMARY=1 %{?el6:-DBUILD_PYTHON=0} %{?el6:-DCMAKE_CXX_COMPILER=/opt/rh/devtoolset-3/root/usr/bin/g++ -DCMAKE_C_COMPILER=/opt/rh/devtoolset-3/root/usr/bin/gcc -DCMAKE_Fortran_COMPILER=/opt/rh/devtoolset-3/root/usr/bin/gfortran} -make - -%install -make install DESTDIR=${RPM_BUILD_ROOT} - -%clean -rm -rf %{buildroot} - -%post -n libert.ecl1 -p /sbin/ldconfig - -%postun -n libert.ecl1 -p /sbin/ldconfig - -%files -%doc README - -%files -n libert.ecl1 -%defattr(-,root,root,-) -%{_libdir}/*.so.* -%{_bindir}/* - -%files devel -%defattr(-,root,root,-) -%{_libdir}/*.so -%{_includedir}/* - -%{?!el6: -%files -n python-ert.ecl -%defattr(-,root,root,-) -/usr/lib/python2.7/site-packages/ert/* - -%files -n python-cwrap -%defattr(-,root,root,-) -/usr/lib/python2.7/site-packages/cwrap/* -} diff --git a/ThirdParty/Ert/requirements.txt b/ThirdParty/Ert/requirements.txt index 4622ca5be8..4d44c49dca 100644 --- a/ThirdParty/Ert/requirements.txt +++ b/ThirdParty/Ert/requirements.txt @@ -1,2 +1,3 @@ cwrap numpy +pandas diff --git a/patches/fix-synthetic-odb-cases.patch b/patches/fix-synthetic-odb-cases.patch index 050a7e882d..cbdcc000d9 100644 --- a/patches/fix-synthetic-odb-cases.patch +++ b/patches/fix-synthetic-odb-cases.patch @@ -4,13 +4,13 @@ Date: Thu, 4 Jan 2018 20:29:09 +0100 Subject: [PATCH] #2317 Apply fix for synthetic odb files --- - ThirdParty/Ert/lib/ecl/ecl_rsthead.c | 10 ++++++++-- + ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -diff --git a/ThirdParty/Ert/lib/ecl/ecl_rsthead.c b/ThirdParty/Ert/lib/ecl/ecl_rsthead.c +diff --git a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h index e8d9cef..2993b1e 100644 ---- a/ThirdParty/Ert/lib/ecl/ecl_rsthead.c -+++ b/ThirdParty/Ert/lib/ecl/ecl_rsthead.c +--- a/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h ++++ b/ThirdParty/Ert/lib/include/ert/ecl/ecl_rsthead.h @@ -88,7 +88,10 @@ ecl_rsthead_type * ecl_rsthead_alloc_from_kw( int report_step , const ecl_kw_typ // The only derived quantity rsthead->sim_time = rsthead_date( rsthead->day , rsthead->month , rsthead->year );