diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index c2bf28e0a3..ddcc0fd193 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -155,7 +155,7 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigActiveCellInfo* activeCellIn const ecl_grid_type* subGrid = ecl_grid_get_cell_lgr1(localEclGrid, localCellIdx); if (subGrid != NULL) { - int subGridFileIndex = ecl_grid_get_grid_nr(subGrid); + int subGridFileIndex = ecl_grid_get_lgr_nr(subGrid); CVF_ASSERT(subGridFileIndex > 0); cell.setSubGrid(static_cast(mainGrid->gridByIndex(subGridFileIndex))); } diff --git a/ThirdParty/Ert/.gitignore b/ThirdParty/Ert/.gitignore new file mode 100644 index 0000000000..14df4ceb91 --- /dev/null +++ b/ThirdParty/Ert/.gitignore @@ -0,0 +1,23 @@ +*.o +*.so +.svn/ +*/.svn/ +*.pyc +*~ + +# /devel/libenkf/src/ +/devel/libenkf/src/.faultlist + +# /develbranch/libenkf/src/ +/develbranch/libenkf/src/.faultlist + +# Ignore build catalog +/build + +# Ignore pdf from tex-test +/devel/libert_util/tests/data/latex_OK.pdf +# Ignore Statoil test data +/devel/test-data/Statoil + +# Ignore the ert_local python file which is needed to run some python tests +/devel/python/python/ert/ecl/ecl_local.py diff --git a/ThirdParty/Ert/README b/ThirdParty/Ert/README index 5718e9c9d8..684da78e00 100644 --- a/ThirdParty/Ert/README +++ b/ThirdParty/Ert/README @@ -207,57 +207,45 @@ in the devel/python/docs directory and in the Python classes themselves. -5. Testing +5. Test -The ERT is very weak on tests, but that is being improved. There are two different -categories of tests: - - CMake tests: CMake has a system for adding and running tests, and - these can be invoked with the command 'make test' after the - normal build process has completed, or alternatively the - 'ctest' test-runner which allows more options on which tests to run. +The ert codebase has a small but increasing test coverage. The tests +are typically located in a per-library subdirectory tests/. The test +framework is based on ctest which basically works like this: - Python test: The python directory devel/python/test has several - python unittests. These tests test both the Python wrappers - and the underlying C code and serve as quite good integration - tests. Read the content of devel/python/test/README carfully - before you invoke the Python tests, you might have to update - the local_(csh|bash) scripts to reflect your build output - path. + 1. In the CMakeLists.txt file testing is enabled with + ENABLE_TESTING(). + 2. Tests are added with: -5.1 Test data & labels + add_test( test_name test_executable arg1 arg2 arg3 ... ) -Unfortunately a large fraction of the test data is based on Statoil -internal data, and is not available on GitHub. All the tests which are -based on Statoil internal test data are labeled with the label -'Statoil', and using the 'ctest' program you can use the -L and -LE -options to include/exclude tests based on their label. + If the executable exits with status 0 the test has passed, + otherwise it has failed. The executable run by the test can + typically be an executable built as part of the solution, but can + in principle be an arbitrary executable like a dedicated test + runner or e.g. the Python interpreter. - ctest -L Statoil # Run all the tests with the 'Statoil' label - ctest -LE Statoil # Run all the tests without the 'Statoil' label +5.1 Test of C code -The argument to the -L and -LE options are regular expressions, -i.e. in the case above all tests which have a label matching the -regexp 'Statoil' will be run. A test can only have one single label, -but due to to the regexp mechanism we can create a 'list-like' -structure by chaining labels together; by convention the label -elements are joined with ':'. In the example +The main part of the testing infrastructure is small C applications +which are added like this: - set_property( TEST test_name PROPERTY LABELS Statoil:Python ) + add_executable( test_exe test_source.c ) + target_link_libraries( test_exe lib ) + add_test( test_name ${EXECUTABLE_OUTPUT_PATH}/test_exe commandline_arg1 commandline_arg2 ) -the labels 'Statoil' and 'Python' are applied to the test. The labels -in use are: +Where the two first lines create the test executable in the normal +way, and the last line adds it as a test. - Statoil: This indicates that the test makes use of Statoil internal - test data, and will fail if the Statoil test data have not - been made available according to the description in - devel/test-data/README.txt +5.2 Test of Python Code - Python: This indicates that the test is a Python unittest, and the - Python interpreter will be the test runner for the test. +In devel/python/test there are several files with Python tests, these +files are executable files and they are invoked directly from the +commandline. A limited number of the tests have been integrated in the +ctest system. -5.2 Test names +5.3 Test names The tests in the cmake build system follow the naming convention of the library which functionality they are testing - i.e. all tests in @@ -269,5 +257,45 @@ can be used to include and exclude tests based on their name ctest -E ecl # Run all tests NOT matching the regexp 'ecl' -The python tests are not yet integrated into this convention.... - +5.4 Test labels + +Using the cmake set_property() function it is possible to assigne +labels to the test, and the -L and -LE options to ctest can be used to +limit which tests to run. A test can only have one label; in the +current ctest setup different labels are combined into one composite +label with a ":" separator, i.e. + + set_property( TEST test_xxx PROPERTY LABELS StatoilData:Python) + +will set the 'StatoilData' and 'Python' properties on test_xxx. The +labels currently maintained in the ert test setup are: + + StatoilData: This implies that the test makes use of Statoil + internal data. If you are in Statoil/Bergen you can see more + details in file devel/test-data/README for how to make this data + available. + + If you are not in Statoil/Bergen you must pass the option: "-EL + StatoilData" to ctest to skip all the tests which require + Statoil data. + + StatoilBuild: There is one python test which makes use of Statoil + internal configuration data, this test is labeled with + StatoilBuild. If you want to run this test you must set the + cmake option ECL_LOCAL_TARGET to point to a file which contains + some local configuration settings, e.g. where the ECLIPSE binary + is installed. + + Python: This label is used to indicate that we are talking about a + Python test. + + LSF: This labels indicates that the test needs a working LSF + environment to run. + + + + ctest -L Statoil # Run all tests labeled with Statoil - both + # StatoilData and StatoilBuild + + ctest -EL "Statoil|LSF" # Exclude all tests labeled with Statoil or LSF. + diff --git a/ThirdParty/Ert/devel/.gitignore b/ThirdParty/Ert/devel/.gitignore deleted file mode 100644 index 6d908bcd9a..0000000000 --- a/ThirdParty/Ert/devel/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/lib/ -ert_build_config.h -*_vector.[ch] diff --git a/ThirdParty/Ert/devel/CMakeLists.txt b/ThirdParty/Ert/devel/CMakeLists.txt index 4f60f3925c..f1f4687c25 100644 --- a/ThirdParty/Ert/devel/CMakeLists.txt +++ b/ThirdParty/Ert/devel/CMakeLists.txt @@ -22,21 +22,24 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(ERT_WINDOWS TRUE) add_definitions( -DERT_WINDOWS ) +# This symbol must be defined to support large (> 2GB) files on windows. + add_definitions( -DWINDOWS_LFS ) endif() - +# Treat warnings as errors if not on Windows if (ERT_WINDOWS) set( CMAKE_C_FLAGS "-O2" ) set( CMAKE_CXX_FLAGS "-O2" ) else() - set( CMAKE_C_FLAGS "-g -O2 -Wall -Wno-unknown-pragmas -std=gnu99 " ) - set( CMAKE_CXX_FLAGS "-g -O2 -Wall" ) + set( CMAKE_C_FLAGS "-std=gnu99 -g -O2 -Wall -Wno-unknown-pragmas " ) + set( CMAKE_CXX_FLAGS "-g -Wall -O2 ") endif() - include(cmake/ert_check.cmake) include(cmake/ert_find.cmake) include(cmake/Modules/UseMultiArch.cmake) +include(cmake/ert_link.cmake) + set( INSTALL_GROUP "" CACHE STRING "Group to install as - blank to install as current group") set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) @@ -46,15 +49,9 @@ if (MSVC) set( LIBRARY_TYPE STATIC ) set( SHARED_LIB OFF ) else() - if (INSTALL_ERT) set( LIBRARY_TYPE SHARED ) set( SHARED_LIB ON ) - else() - set( LIBRARY_TYPE STATIC ) - set( SHARED_LIB OFF ) - endif(INSTALL_ERT) -endif(MSVC) - +endif() if (MSVC) diff --git a/ThirdParty/Ert/devel/cmake/ert_check.cmake b/ThirdParty/Ert/devel/cmake/ert_check.cmake index 04bdca9f22..7f0cf3e77f 100644 --- a/ThirdParty/Ert/devel/cmake/ert_check.cmake +++ b/ThirdParty/Ert/devel/cmake/ert_check.cmake @@ -1,3 +1,8 @@ +check_function_exists( fseeko HAVE_FSEEKO ) +if (HAVE_HFSEEKO) + add_definitions( -DHAVE_FSEEKO ) +endif() + check_function_exists( regexec HAVE_REGEXP ) if (HAVE_REGEXP) add_definitions( -DHAVE_REGEXP ) @@ -84,6 +89,16 @@ if (HAVE_OPENDIR) add_definitions( -DHAVE__USLEEP ) endif() +# Checking based on compiling. Some of the code generates warnings, so we just cut down to bare-bone compiler flags. + +set( CMAKE_C_FLAGS_main ${CMAKE_C_FLAGS} ) +set( CMAKE_CXX_FLAGS_main ${CMAKE_CXX_FLAGS} ) + +if (NOT ERT_WINDOWS) + set( CMAKE_C_FLAGS "-std=gnu99" ) + set( CMAKE_CXX_FLAGS "") +endif() + try_compile( HAVE_ISFINITE ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_isfinite.c ) if (HAVE_ISFINITE) add_definitions( -DHAVE_ISFINITE ) @@ -110,3 +125,5 @@ if (ISREG_POSIX) add_definitions( -DHAVE_ISREG ) endif() +set( CMAKE_C_FLAGS ${CMAKE_C_FLAGS_main} ) +set( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_main} ) diff --git a/ThirdParty/Ert/devel/cmake/ert_link.cmake b/ThirdParty/Ert/devel/cmake/ert_link.cmake new file mode 100644 index 0000000000..8664a76564 --- /dev/null +++ b/ThirdParty/Ert/devel/cmake/ert_link.cmake @@ -0,0 +1,14 @@ +if (CMAKE_COMPILER_IS_GNUCC) + option (USE_RUNPATH "Embed original dependency paths in installed library" OFF) + if (USE_RUNPATH) + set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + endif (USE_RUNPATH) +else() + set(USE_RUNPATH OFF) +endif() + + +macro( add_runpath target ) + set_target_properties( ${target} PROPERTIES LINK_FLAGS -Wl,--enable-new-dtags) +endmacro() \ No newline at end of file diff --git a/ThirdParty/Ert/devel/libanalysis/src/CMakeLists.txt b/ThirdParty/Ert/devel/libanalysis/src/CMakeLists.txt index 2346c6e9f0..32706738ef 100644 --- a/ThirdParty/Ert/devel/libanalysis/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libanalysis/src/CMakeLists.txt @@ -10,7 +10,9 @@ if (NEED_LIBDL) target_link_libraries( analysis dl ) endif() - +if (USE_RUNPATH) + add_runpath( analysis ) +endif() # List of modules set( CMAKE_SHARED_MODULE_PREFIX "" ) diff --git a/ThirdParty/Ert/devel/libconfig/CMakeLists.txt b/ThirdParty/Ert/devel/libconfig/CMakeLists.txt index da0dfb169f..6d8bd6b946 100644 --- a/ThirdParty/Ert/devel/libconfig/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libconfig/CMakeLists.txt @@ -1,2 +1,4 @@ add_subdirectory( src ) -add_subdirectory( tests ) +if (BUILD_TESTS) + add_subdirectory( tests ) +endif() diff --git a/ThirdParty/Ert/devel/libconfig/src/CMakeLists.txt b/ThirdParty/Ert/devel/libconfig/src/CMakeLists.txt index 555a39c4cd..6bac305ba7 100644 --- a/ThirdParty/Ert/devel/libconfig/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libconfig/src/CMakeLists.txt @@ -5,6 +5,9 @@ add_library( config ${LIBRARY_TYPE} ${source_files} ) set_target_properties( config PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( config ert_util ) +if (USE_RUNPATH) + add_runpath( config ) +endif() if (INSTALL_ERT) install(TARGETS config DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ThirdParty/Ert/devel/libconfig/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libconfig/tests/CMakeLists.txt index c877ff0679..d6854e88cf 100644 --- a/ThirdParty/Ert/devel/libconfig/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libconfig/tests/CMakeLists.txt @@ -1,44 +1,44 @@ add_executable( config_append_test config_append_test.c ) -target_link_libraries( config_append_test config ) +target_link_libraries( config_append_test config test_util ) add_executable( config_node_test config_node_test.c ) -target_link_libraries( config_node_test config ) +target_link_libraries( config_node_test config test_util ) add_executable( config_typeOK config_typeOK.c ) -target_link_libraries( config_typeOK config ) +target_link_libraries( config_typeOK config test_util ) add_executable( config_typeFail config_typeFail.c ) -target_link_libraries( config_typeFail config ) +target_link_libraries( config_typeFail config test_util ) add_executable( config_path_elm config_path_elm.c ) -target_link_libraries( config_path_elm config ) +target_link_libraries( config_path_elm config test_util ) add_executable( config_root_path config_root_path.c ) -target_link_libraries( config_root_path config ) +target_link_libraries( config_root_path config test_util ) add_executable( config_include_test config_include_test.c) -target_link_libraries( config_include_test config) +target_link_libraries( config_include_test config test_util ) add_executable( config_content_node config_content_node.c) -target_link_libraries( config_content_node config) +target_link_libraries( config_content_node config test_util ) add_executable( config_content_item config_content_item.c) -target_link_libraries( config_content_item config) +target_link_libraries( config_content_item config test_util ) add_executable( config_argc config_argc.c) -target_link_libraries( config_argc config) +target_link_libraries( config_argc config test_util ) add_executable( config_error config_error.c) -target_link_libraries( config_error config) +target_link_libraries( config_error config test_util ) add_test( config_error ${EXECUTABLE_OUTPUT_PATH}/config_error ) add_executable( config_config config_config.c) -target_link_libraries( config_config config) +target_link_libraries( config_config config test_util ) add_test( config_config ${EXECUTABLE_OUTPUT_PATH}/config_config ) add_executable( config_schema_item config_schema_item.c) -target_link_libraries( config_schema_item config) +target_link_libraries( config_schema_item config test_util ) add_test( config_schema_item ${EXECUTABLE_OUTPUT_PATH}/config_schema_item ) add_test( config_typeOK ${EXECUTABLE_OUTPUT_PATH}/config_typeOK ${CMAKE_CURRENT_SOURCE_DIR}/data/type_testOK ) diff --git a/ThirdParty/Ert/devel/libconfig/tests/config_path_elm.c b/ThirdParty/Ert/devel/libconfig/tests/config_path_elm.c index 0cd949bdcd..f1d759214b 100644 --- a/ThirdParty/Ert/devel/libconfig/tests/config_path_elm.c +++ b/ThirdParty/Ert/devel/libconfig/tests/config_path_elm.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -29,17 +30,19 @@ int main(int argc , char ** argv) { #ifdef ERT_LINUX - const char * root = "/tmp/root"; const char * rel_path = "rel/path"; - const char * abs_path = "/tmp/root/rel/path"; const char * rel_true = "rel/path/XXX"; - const char * abs_true = "/tmp/root/rel/path/XXX"; const char * path_true1 = "rel/path/XXX"; - const char * path_true2 = "/tmp/root/rel/path/XXX"; + #endif - - util_make_path( root ); + test_work_area_type * work_area = test_work_area_alloc( "config_path_elm" , true ); + const char * root = test_work_area_get_cwd( work_area ); + char * abs_path = util_alloc_filename( root , "rel/path" , NULL); + char * abs_true = util_alloc_filename( root , "rel/path/XXX" , NULL); + char * path_true2 = util_alloc_filename( root , "rel/path/XXX" , NULL); + + chdir( test_work_area_get_original_cwd( work_area )); config_root_path_type * root_path = config_root_path_alloc( root ); { config_path_elm_type * path_elm = config_path_elm_alloc( root_path , rel_path ); @@ -54,7 +57,6 @@ int main(int argc , char ** argv) { config_path_elm_free( path_elm ); } - printf("test1 OK \n"); { config_path_elm_type * path_elm = config_path_elm_alloc( root_path , abs_path ); @@ -67,7 +69,6 @@ int main(int argc , char ** argv) { config_path_elm_free( path_elm ); } - printf("test2 OK \n"); config_root_path_free( root_path ); chdir( root ); @@ -85,7 +86,6 @@ int main(int argc , char ** argv) { config_path_elm_free( path_elm ); } - printf("test3 OK \n"); exit(0); } diff --git a/ThirdParty/Ert/devel/libconfig/tests/config_root_path.c b/ThirdParty/Ert/devel/libconfig/tests/config_root_path.c index cd7a1fde9c..c23af67b29 100644 --- a/ThirdParty/Ert/devel/libconfig/tests/config_root_path.c +++ b/ThirdParty/Ert/devel/libconfig/tests/config_root_path.c @@ -32,13 +32,13 @@ int main(int argc , char ** argv) { { config_root_path_type * root_path = config_root_path_alloc( NULL ); - if (!test_string_equal( config_root_path_get_abs_path( root_path ) , cwd )) + if (!test_check_string_equal( config_root_path_get_abs_path( root_path ) , cwd )) test_error_exit("abs:path:%s expeceted:%s \n",config_root_path_get_abs_path( root_path ) , cwd ); - if (!test_string_equal( config_root_path_get_input_path( root_path ) , NULL )) + if (!test_check_string_equal( config_root_path_get_input_path( root_path ) , NULL )) test_error_exit("input:path:%s expeceted:%s \n",config_root_path_get_input_path( root_path ) , NULL ); - if (!test_string_equal( config_root_path_get_rel_path( root_path ) , NULL )) + if (!test_check_string_equal( config_root_path_get_rel_path( root_path ) , NULL )) test_error_exit("rel:path:%s expeceted:%s \n",config_root_path_get_rel_path( root_path ) , NULL ); @@ -62,10 +62,10 @@ int main(int argc , char ** argv) { config_root_path_type * root_path1 = config_root_path_alloc( input_path ); config_root_path_type * root_path2 = config_root_path_alloc( rel_path ); - if (!test_string_equal( config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2 ))) + if (!test_check_string_equal( config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2 ))) test_error_exit("Rel: %s != %s \n",config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2)); - if (!test_string_equal( config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 ))) + if (!test_check_string_equal( config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 ))) test_error_exit("Abs: %s != %s \n",config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 )); config_root_path_free( root_path1 ); diff --git a/ThirdParty/Ert/devel/libecl/CMakeLists.txt b/ThirdParty/Ert/devel/libecl/CMakeLists.txt index 90b94538d4..faca95eb2b 100644 --- a/ThirdParty/Ert/devel/libecl/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl/CMakeLists.txt @@ -1,10 +1,5 @@ add_subdirectory( src ) -#if (BUILD_APPLICATIONS OR BUILD_ECL_SUMMARY) -# add_subdirectory( applications ) -#endif() add_subdirectory( applications ) -if (BUILD_TESTS) - add_subdirectory( tests ) -endif() +add_subdirectory( tests ) diff --git a/ThirdParty/Ert/devel/libecl/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libecl/applications/CMakeLists.txt index 864aeaf500..131e33900d 100644 --- a/ThirdParty/Ert/devel/libecl/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl/applications/CMakeLists.txt @@ -35,7 +35,10 @@ if (BUILD_APPLICATIONS) foreach(prog ${program_list}) target_link_libraries( ${prog} ecl ert_util ) - + if (USE_RUNPATH) + add_runpath( ${prog} ) + endif() + #----------------------------------------------------------------- set (destination ${CMAKE_INSTALL_PREFIX}/bin) if (INSTALL_ERT) @@ -52,6 +55,9 @@ if (BUILD_ENS_PLOT) include_directories( ${PLPLOT_HEADER} ) add_executable( ens_plot.x ens_plot.c ) target_link_libraries( ens_plot.x plot ecl) + if (USE_RUNPATH) + add_runpath( ens_plot.x ) + endif() set (destination ${CMAKE_INSTALL_PREFIX}/bin) if (INSTALL_ERT) @@ -68,6 +74,9 @@ endif() if (BUILD_ECL_SUMMARY) add_executable( ecl_summary view_summary.c ) target_link_libraries( ecl_summary ecl) + if (USE_RUNPATH) + add_runpath( ecl_summary ) + endif() set (destination ${CMAKE_INSTALL_PREFIX}/bin) if (INSTALL_ERT) diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_file_kw.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_file_kw.h index c6f5781404..e2f10ea252 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_file_kw.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_file_kw.h @@ -25,6 +25,8 @@ extern "C" { #include +#include + #include #include @@ -35,7 +37,7 @@ typedef struct inv_map_struct inv_map_type; ecl_file_kw_type * inv_map_get_file_kw( inv_map_type * inv_map , const ecl_kw_type * ecl_kw ); void inv_map_free( inv_map_type * map ); - ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , long offset); + ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , offset_type offset); void ecl_file_kw_free( ecl_file_kw_type * file_kw ); void ecl_file_kw_free__( void * arg ); ecl_kw_type * ecl_file_kw_get_kw( ecl_file_kw_type * file_kw , fortio_type * fortio, inv_map_type * inv_map); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid.h index ee007e3b08..124692ce9d 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid.h @@ -30,9 +30,10 @@ extern "C" { #include #include #include +#include #define ECL_GRID_GLOBAL_GRID "Global" // used as key in hash tables over grids. - +#define ECL_GRID_MAINGRID_LGR_NR 0 typedef double (block_function_ftype) ( const double_vector_type *); typedef struct ecl_grid_struct ecl_grid_type; @@ -77,6 +78,10 @@ extern "C" { int ecl_grid_get_global_index3(const ecl_grid_type * , int , int , int ); int ecl_grid_get_global_index1A(const ecl_grid_type * ecl_grid , int active_index); int ecl_grid_get_global_index1F(const ecl_grid_type * ecl_grid , int active_fracture_index); + + const int_vector_type * ecl_grid_get_nnc_index_list( ecl_grid_type * grid ); + const nnc_info_type * ecl_grid_get_cell_nnc_info3( const ecl_grid_type * grid , int i , int j , int k); + const nnc_info_type * ecl_grid_get_cell_nnc_info1( const ecl_grid_type * grid , int global_index); ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * zcorn_kw , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , const ecl_kw_type * mapaxes_kw ); ecl_grid_type * ecl_grid_alloc_GRDECL_data(int , int , int , const float * , const float * , const int * , const float * mapaxes); @@ -85,7 +90,7 @@ extern "C" { ecl_grid_type * ecl_grid_load_case( const char * case_input ); ecl_grid_type * ecl_grid_alloc_rectangular( int nx , int ny , int nz , double dx , double dy , double dz , const int * actnum); ecl_grid_type * ecl_grid_alloc_regular( int nx, int ny , int nz , const double * ivec, const double * jvec , const double * kvec , const int * actnum); - + bool ecl_grid_exists( const char * case_input ); char * ecl_grid_alloc_case_filename( const char * case_input ); @@ -132,17 +137,19 @@ extern "C" { void ecl_grid_dump(const ecl_grid_type * grid , FILE * stream); void ecl_grid_dump_ascii(const ecl_grid_type * grid , bool active_only , FILE * stream); - + /* lgr related functions */ const ecl_grid_type * ecl_grid_get_cell_lgr3(const ecl_grid_type * grid , int i, int j , int k); const ecl_grid_type * ecl_grid_get_cell_lgr1A(const ecl_grid_type * grid , int active_index); const ecl_grid_type * ecl_grid_get_cell_lgr1(const ecl_grid_type * grid , int global_index ); int ecl_grid_get_num_lgr(const ecl_grid_type * main_grid ); - int ecl_grid_get_grid_nr( const ecl_grid_type * ecl_grid ); - ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid , int lgr_nr); + int ecl_grid_get_lgr_nr( const ecl_grid_type * ecl_grid ); + ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid , int lgr_index); + ecl_grid_type * ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type * main_grid, int lgr_nr); ecl_grid_type * ecl_grid_get_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); bool ecl_grid_has_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); - const char * ecl_grid_iget_lgr_name( const ecl_grid_type * ecl_grid , int lgr_nr); + const char * ecl_grid_iget_lgr_name( const ecl_grid_type * ecl_grid , int lgr_index); + const char * ecl_grid_get_lgr_name( const ecl_grid_type * ecl_grid , int lgr_nr); stringlist_type * ecl_grid_alloc_lgr_name_list(const ecl_grid_type * ecl_grid); int ecl_grid_get_parent_cell1( const ecl_grid_type * grid , int global_index); int ecl_grid_get_parent_cell3( const ecl_grid_type * grid , int i , int j , int k); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_kw_magic.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_kw_magic.h index ece8f6ecf8..7c664549eb 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_kw_magic.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_kw_magic.h @@ -232,6 +232,7 @@ extern "C" { #define CONORAT_KW "CONORAT" /* Oil ... */ #define CONPRES_KW "CONPRES" /* Pressure ... */ #define CONLENST_KW "CONLENST" /* Length along MSW well */ +#define CONLENEN_KW "CONLENEN" /* Length to connection end for MSW well */ #define CONVTUB_KW "CONVTUB" /* Volumetric flow at tubing head conditions. */ #define CONOTUB_KW "CONOTUB" /* Volumetric oil flow at tubing head conditions. */ #define CONGTUB_KW "CONGTUB" /* Volumetric gas flow at tubing head conditions. */ @@ -269,7 +270,20 @@ extern "C" { the second element will be the name of the parent. */ #define MAPUNITS_KW "MAPUNITS" #define GRIDUNIT_KW "GRIDUNIT" - + +#define NNCHEAD_KW "NNCHEAD" /*Non-neighbour connection header*/ +#define NNC1_KW "NNC1" /*Upstream cell numbers for non-neighbour connections*/ +#define NNC2_KW "NNC2" /*Downstream cell numbers for non-neighbour connections*/ +#define NNCL_KW "NNCL" /*Cell numbers for LGR cells that are connected to global grid cells*/ +#define NNCG_KW "NNCG" /*Cell numbers for global cells connected to LGR cells*/ +#define NNCHEAD_NUMNNC_INDEX 0 /*Item 1 in non-neighbour connection header: number of NNCs. Only present for main grid*/ +#define NNCHEAD_LGR_INDEX 1 /*Item 2 in non-neighbour connection header: LGR number (0 for global grid)*/ +#define NNCHEADA_KW "NNCHEADA" /*Header for NNC's between two amalgamated LGRs*/ +#define NNA1_KW "NNA1" /*Cell numbers in connecting local grid ILOC1*/ +#define NNA2_KW "NNA2" /*Cell numbers in connecting local grid ILOC2*/ +#define NNCHEADA_ILOC1_INDEX 0 /*ILOC1: Index of first LGR*/ +#define NNCHEADA_ILOC2_INDEX 1 /*ILOC2: Index of second LGR*/ +#define NNA_NUMNNC_INDEX 0 /*Item 1 in NNA1 or NNA2 is number of NNCs*/ /* EGRID keywords */ #define LGR_PARENT_KW "LGRPARNT" /* The name of the parent for an LGR. */ @@ -282,7 +296,7 @@ extern "C" { #define ENDGRID_KW "ENDGRID" #define ENDLGR_KW "ENDLGR" #define CORSNUM_KW "CORSNUM" - + /* GRID keywords */ #define GRIDHEAD_KW "GRIDHEAD" /* Header information for GRID files. */ #define COORD_KW "COORD" /* Header information for one cell in GRID file. */ @@ -298,7 +312,7 @@ extern "C" { #define GRIDHEAD_NZ_INDEX 3 #define GRIDHEAD_LGR_INDEX 4 #define GRIDHEAD_SIZE 100 - + /* Observe that these indices are one value lower than the values used in the ecl_smspec file. */ #define DIMENS_NX_INDEX 0 diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_cell.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_cell.h index 4d8ad0754b..a38b89edea 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_cell.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_cell.h @@ -42,6 +42,7 @@ UTIL_IS_INSTANCE_HEADER( ecl_rft_cell ); double grat , double wrat , double connection_start, + double connection_end, double flowrate, double oil_flowrate, double gas_flowrate, @@ -67,6 +68,7 @@ UTIL_IS_INSTANCE_HEADER( ecl_rft_cell ); double ecl_rft_cell_get_grat( const ecl_rft_cell_type * cell ); double ecl_rft_cell_get_orat( const ecl_rft_cell_type * cell ); double ecl_rft_cell_get_connection_start( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_connection_end( const ecl_rft_cell_type * cell ); double ecl_rft_cell_get_flowrate( const ecl_rft_cell_type * cell ); double ecl_rft_cell_get_oil_flowrate( const ecl_rft_cell_type * cell ); double ecl_rft_cell_get_gas_flowrate( const ecl_rft_cell_type * cell ); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_smspec.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_smspec.h index c37575eea1..bf32c70799 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_smspec.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_smspec.h @@ -87,7 +87,7 @@ typedef struct ecl_smspec_struct ecl_smspec_type; const smspec_node_type * ecl_smspec_get_block_var_node(const ecl_smspec_type * ecl_smspec , const char * block_var , int block_nr); int ecl_smspec_get_block_var_params_index(const ecl_smspec_type * ecl_smspec , const char * block_var , int block_nr); bool ecl_smspec_has_block_var(const ecl_smspec_type * ecl_smspec , const char * block_var , int block_nr); - + const smspec_node_type * ecl_smspec_get_block_var_node_ijk(const ecl_smspec_type * ecl_smspec , const char * block_var , int i , int j , int k); int ecl_smspec_get_block_var_params_index_ijk(const ecl_smspec_type * ecl_smspec , const char * block_var , int i , int j , int k); bool ecl_smspec_has_block_var_ijk(const ecl_smspec_type * ecl_smspec , const char * block_var , int i , int j , int k); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum.h index e31572f7ca..a5f51aafef 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum.h @@ -202,6 +202,9 @@ typedef struct ecl_sum_struct ecl_sum_type; bool ecl_sum_is_oil_producer( const ecl_sum_type * ecl_sum , const char * well); char * ecl_sum_alloc_well_key( const ecl_sum_type * ecl_sum , const char * keyword , const char * wgname); + bool ecl_sum_report_step_equal( const ecl_sum_type * ecl_sum1 , const ecl_sum_type * ecl_sum2); + bool ecl_sum_report_step_compatible( const ecl_sum_type * ecl_sum1 , const ecl_sum_type * ecl_sum2); + UTIL_IS_INSTANCE_HEADER( ecl_sum ); #ifdef __cplusplus diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_data.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_data.h index 496eecb00b..047800dc1c 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_data.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_data.h @@ -83,6 +83,8 @@ typedef struct ecl_sum_data_struct ecl_sum_data_type ; int ecl_sum_data_iget_report_end( const ecl_sum_data_type * data , int report_step ); int ecl_sum_data_iget_report_start( const ecl_sum_data_type * data , int report_step ); ecl_sum_tstep_type * ecl_sum_data_add_new_tstep( ecl_sum_data_type * data , int report_step , double sim_days); + 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); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_tstep.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_tstep.h index ba37173cd8..94dc7e32e4 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_tstep.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_tstep.h @@ -51,6 +51,7 @@ typedef struct ecl_sum_tstep_struct ecl_sum_tstep_type; void ecl_sum_tstep_iset( ecl_sum_tstep_type * tstep , int index , float value); void ecl_sum_tstep_set_from_node( ecl_sum_tstep_type * tstep , const smspec_node_type * smspec_node , float value); void ecl_sum_tstep_set_from_key( ecl_sum_tstep_type * tstep , const char * gen_key , float value); + bool ecl_sum_tstep_sim_time_equal( const ecl_sum_tstep_type * tstep1 , const ecl_sum_tstep_type * tstep2 ); UTIL_SAFE_CAST_HEADER( ecl_sum_tstep ); UTIL_SAFE_CAST_HEADER_CONST( ecl_sum_tstep ); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/fortio.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/fortio.h index 87fdcfaa3d..99e0b68b7f 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/fortio.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/fortio.h @@ -26,6 +26,8 @@ extern "C" { #include #include +#include + typedef enum { FORTIO_NOENTRY = 0, /* File does not exists at all - application error. */ FORTIO_EOF = 1, /* The file / record is empty */ @@ -66,8 +68,8 @@ typedef struct fortio_struct fortio_type; void fortio_rewind(const fortio_type *fortio); const char * fortio_filename_ref(const fortio_type * ); bool fortio_fmt_file(const fortio_type *); - long fortio_ftell( const fortio_type * fortio ); - int fortio_fseek( fortio_type * fortio , long offset , int whence); + offset_type fortio_ftell( const fortio_type * fortio ); + int fortio_fseek( fortio_type * fortio , offset_type offset , int whence); int fortio_fileno( fortio_type * fortio ); bool fortio_fclose_stream( fortio_type * fortio ); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_index_list.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_index_list.h new file mode 100644 index 0000000000..f18860f893 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_index_list.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_index_list.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 __NNC_INDEX_LIST_H__ +#define __NNC_INDEX_LIST_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + typedef struct nnc_index_list_struct nnc_index_list_type; + + UTIL_IS_INSTANCE_HEADER(nnc_index_list); + + nnc_index_list_type * nnc_index_list_alloc(); + void nnc_index_list_free( nnc_index_list_type * index_list ); + void nnc_index_list_add_index(nnc_index_list_type * index_list , int index); + const int_vector_type * nnc_index_list_get_list(nnc_index_list_type * index_list); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_info.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_info.h new file mode 100644 index 0000000000..a27057b4e7 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_info.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_info.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 __NNC_INFO_H__ +#define __NNC_INFO_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include + + typedef struct nnc_info_struct nnc_info_type; + + UTIL_IS_INSTANCE_HEADER(nnc_info); + + nnc_info_type * nnc_info_alloc(int lgr_nr); + void nnc_info_free( nnc_info_type * nnc_info ); + void nnc_info_add_nnc(nnc_info_type * nnc_info, int lgr_nr, int global_cell_number); + + const int_vector_type * nnc_info_iget_index_list(const nnc_info_type * nnc_info, int lgr_index); + nnc_vector_type * nnc_info_iget_vector( const nnc_info_type * nnc_info , int lgr_index); + + const int_vector_type * nnc_info_get_index_list(const nnc_info_type * nnc_info, int lgr_nr); + nnc_vector_type * nnc_info_get_vector( const nnc_info_type * nnc_info , int lgr_nr); + + const int_vector_type * nnc_info_get_self_index_list(const nnc_info_type * nnc_info); + nnc_vector_type * nnc_info_get_self_vector( const nnc_info_type * nnc_info ); + + int nnc_info_get_lgr_nr(const nnc_info_type * nnc_info ); + int nnc_info_get_size( const nnc_info_type * nnc_info ); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_vector.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_vector.h new file mode 100644 index 0000000000..bd4ac59de1 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_vector.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_vector.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 __NNC_VECTOR_H__ +#define __NNC_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + typedef struct nnc_vector_struct nnc_vector_type; + + UTIL_IS_INSTANCE_HEADER(nnc_vector); + + nnc_vector_type * nnc_vector_alloc(int lgr_nr); + void nnc_vector_free( nnc_vector_type * nnc_vector ); + void nnc_vector_add_nnc(nnc_vector_type * nnc_vector, int global_cell_number); + const int_vector_type * nnc_vector_get_index_list(const nnc_vector_type * nnc_vector); + int nnc_vector_get_lgr_nr(const nnc_vector_type * nnc_vector ); + void nnc_vector_free__(void * arg); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/smspec_node.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/smspec_node.h index 725376e9ca..27e44f8416 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/smspec_node.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/smspec_node.h @@ -61,6 +61,8 @@ typedef enum {ECL_SMSPEC_INVALID_VAR = 0 , char * smspec_alloc_group_key( const char * join_string , const char * keyword , const char * wgname); char * smspec_alloc_well_key( const char * join_string , const char * keyword , const char * wgname); char * smspec_alloc_region_key( const char * join_string , const char * keyword , int num); + char * smspec_alloc_region_2_region_r1r2_key( const char * join_string , const char * keyword , int r1, int r2); + char * smspec_alloc_region_2_region_num_key( const char * join_string , const char * keyword , int num); char * smspec_alloc_segment_key( const char * join_string , const char * keyword , const char * wgname , int num); char * smspec_alloc_block_num_key( const char * join_string , const char * keyword , int num); char * smspec_alloc_local_well_key( const char * join_string , const char * keyword , const char * lgr_name , const char * wgname); diff --git a/ThirdParty/Ert/devel/libecl/src/CMakeLists.txt b/ThirdParty/Ert/devel/libecl/src/CMakeLists.txt index 92a66c89ac..67195441ec 100644 --- a/ThirdParty/Ert/devel/libecl/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl/src/CMakeLists.txt @@ -2,14 +2,17 @@ include_directories( ext ) file(GLOB ext_source "ext/*.c" ) file(GLOB ext_header "ext/*.h" ) -set( source_files ecl_rsthead.c ecl_sum_tstep.c ecl_rst_file.c ecl_init_file.c ecl_grid_cache.c smspec_node.c ecl_kw_grdecl.c ecl_file_kw.c ecl_grav.c ecl_grav_calc.c ecl_smspec.c ecl_sum_data.c ecl_util.c ecl_kw.c ecl_sum.c fortio.c ecl_rft_file.c ecl_rft_node.c ecl_rft_cell.c ecl_grid.c ecl_coarse_cell.c ecl_box.c ecl_io_config.c ecl_file.c ecl_region.c point.c tetrahedron.c ecl_subsidence.c ecl_grid_dims.c grid_dims.c ecl_grav_common.c ${ext_source}) +set( source_files ecl_rsthead.c ecl_sum_tstep.c ecl_rst_file.c ecl_init_file.c ecl_grid_cache.c smspec_node.c ecl_kw_grdecl.c ecl_file_kw.c ecl_grav.c ecl_grav_calc.c ecl_smspec.c ecl_sum_data.c ecl_util.c ecl_kw.c ecl_sum.c fortio.c ecl_rft_file.c ecl_rft_node.c ecl_rft_cell.c ecl_grid.c ecl_coarse_cell.c ecl_box.c ecl_io_config.c ecl_file.c ecl_region.c point.c tetrahedron.c ecl_subsidence.c ecl_grid_dims.c grid_dims.c nnc_info.c ecl_grav_common.c nnc_vector.c nnc_index_list.c ${ext_source}) -set( header_files ecl_rsthead.h ecl_sum_tstep.h ecl_rst_file.h ecl_init_file.h smspec_node.h ecl_grid_cache.h ecl_kw_grdecl.h ecl_file_kw.h ecl_grav.h ecl_grav_calc.h ecl_endian_flip.h ecl_smspec.h ecl_sum_data.h ecl_util.h ecl_kw.h ecl_sum.h fortio.h ecl_rft_file.h ecl_rft_node.h ecl_rft_cell.h ecl_box.h ecl_coarse_cell.h ecl_grid.h ecl_io_config.h ecl_file.h ecl_region.h ecl_kw_magic.h ecl_subsidence.h ecl_grid_dims.h grid_dims.h ${ext_header} ecl_grav_common.h) +set( header_files ecl_rsthead.h ecl_sum_tstep.h ecl_rst_file.h ecl_init_file.h smspec_node.h ecl_grid_cache.h ecl_kw_grdecl.h ecl_file_kw.h ecl_grav.h ecl_grav_calc.h ecl_endian_flip.h ecl_smspec.h ecl_sum_data.h ecl_util.h ecl_kw.h ecl_sum.h fortio.h ecl_rft_file.h ecl_rft_node.h ecl_rft_cell.h ecl_box.h ecl_coarse_cell.h ecl_grid.h ecl_io_config.h ecl_file.h ecl_region.h ecl_kw_magic.h ecl_subsidence.h ecl_grid_dims.h grid_dims.h nnc_info.h nnc_vector.h ${ext_header} ecl_grav_common.h nnc_index_list.h) add_library( ecl ${LIBRARY_TYPE} ${source_files} ) set_target_properties( ecl PROPERTIES VERSION 1.0 SOVERSION 1.0 ) +if (USE_RUNPATH) + add_runpath( ecl ) +endif() #----------------------------------------------------------------- set( OPENMP OFF ) diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_file.c b/ThirdParty/Ert/devel/libecl/src/ecl_file.c index c2baf8d43b..9c60277efc 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_file.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_file.c @@ -823,7 +823,7 @@ static void ecl_file_scan( ecl_file_type * ecl_file ) { fortio_fseek( ecl_file->fortio , 0 , SEEK_SET ); { ecl_kw_type * work_kw = ecl_kw_alloc_new("WORK-KW" , 0 , ECL_INT_TYPE , NULL); - long current_offset; + offset_type current_offset; while (true) { current_offset = fortio_ftell( ecl_file->fortio ); if (ecl_kw_fread_header( work_kw , ecl_file->fortio )) { diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_file_kw.c b/ThirdParty/Ert/devel/libecl/src/ecl_file_kw.c index ad2dbd382f..3ca6f42f48 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_file_kw.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_file_kw.c @@ -56,7 +56,7 @@ struct inv_map_struct { struct ecl_file_kw_struct { UTIL_TYPE_ID_DECLARATION; - long file_offset; + offset_type file_offset; ecl_type_enum ecl_type; int kw_size; char * header; @@ -135,7 +135,7 @@ UTIL_IS_INSTANCE_FUNCTION( ecl_file_kw , ECL_FILE_KW_TYPE_ID ) -static ecl_file_kw_type * ecl_file_kw_alloc__( const char * header , ecl_type_enum ecl_type , int size , long offset) { +static ecl_file_kw_type * ecl_file_kw_alloc__( const char * header , ecl_type_enum ecl_type , int size , offset_type offset) { ecl_file_kw_type * file_kw = util_malloc( sizeof * file_kw ); UTIL_TYPE_ID_INIT( file_kw , ECL_FILE_KW_TYPE_ID ); @@ -160,7 +160,7 @@ static ecl_file_kw_type * ecl_file_kw_alloc__( const char * header , ecl_type_en access the ecl_file_kw instances. */ -ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , long offset ) { +ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , offset_type offset ) { return ecl_file_kw_alloc__( ecl_kw_get_header( ecl_kw ) , ecl_kw_get_type( ecl_kw ) , ecl_kw_get_size( ecl_kw ) , offset ); } diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_grid.c b/ThirdParty/Ert/devel/libecl/src/ecl_grid.c index cde1086863..b9613ea387 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_grid.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_grid.c @@ -39,7 +39,8 @@ #include #include #include - +#include +#include /* If openmp is enabled the main loop in ecl_grid_init_GRDECL_data is @@ -358,6 +359,73 @@ */ +/* + About nnc + --------- + + When loading a grid file the various NNC related keywords are read + in to assemble information of the NNC. The NNC information is + organized as follows: + + 1. The field nnc_index_list is a thin wrapper around a int_vector + instance which will return a sorted list of indicies of cells + which have attached NNC information. + + 2. For cells with NNC's attached the information is kept in a + nnc_info_type structure. For a particular cell the nnc_info + structure keeps track of which other cells this particular cell + is connected to, on a per grid (i.e. LGR) basis. + + In the nnc_info structure the different grids are identified + through the lgr_nr. + + + + Example usage: + -------------- + + ecl_grid_type * grid = ecl_grid_alloc("FILE.EGRID"); + + // Get a int_vector instance with all the cells which have nnc info + // attached. + const int_vector_type * cells_with_nnc = ecl_grid_get_nnc_index_list( grid ); + + // Iterate over all the cells with nnc info: + for (int i=0; i < int_vector_size( cells_with_nnc ); i++) { + int cell_index = int_vector_iget( cells_with_nnc , i); + const nnc_info_type * nnc_info = ecl_grid_get_nnc_info1( grid , cell_index); + + // Get all the nnc connections from @cell_index to other cells in the same grid + { + const int_vector_type * nnc_list = nnc_info_get_self_index_list( nnc_info ); + for (int j=0; j < int_vector_size( nnc_list ); j++) + printf("Cell[%d] -> %d in the same grid \n",cell_index , int_vector_iget(nnc_list , j)); + } + + + { + for (int lgr_index=0; lgr_index < nnc_info_get_size( nnc_info ); lgr_index++) { + nnc_vector_type * nnc_vector = nnc_info_iget_vector( nnc_info , lgr_index ); + int lgr_nr = nnc_vector_get_lgr_nr( nnc_vector ); + if (lgr_nr != nnc_info_get_lgr_nr( nnc_info )) { + const int_vector_type * nnc_list = nnc_vector_get_index_list( nnc_vector ); + for (int j=0; j < int_vector_size( nnc_list ); j++) + printf("Cell[%d] -> %d in lgr:%d/%s \n",cell_index , int_vector_iget(nnc_list , j) , lgr_nr , ecl_grid_get_lgr_name(ecl_grid , lgr_nr)); + } + } + } + } + + + Dual porosity and nnc: In ECLIPSE the connection between the matrix + properties and the fracture properties in a cell is implemented as a + nnc where the fracture cell has global index in the range [nx*ny*nz, + 2*nz*ny*nz). In ert we we have not implemented this double covering + in the case of dual porosity models, and therefor NNC involving + fracture cells are not considered. +*/ + + /* about tetraheder decomposition @@ -467,6 +535,7 @@ struct ecl_cell_struct { int host_cell; /* the global index of the host cell for an lgr cell, set to -1 for normal cells. */ int coarse_group; /* The index of the coarse group holding this cell -1 for non-coarsened cells. */ int cell_flags; + nnc_info_type * nnc_info; /* Non-neighbour connection info*/ }; @@ -476,7 +545,8 @@ struct ecl_cell_struct { struct ecl_grid_struct { UTIL_TYPE_ID_DECLARATION; - int grid_nr; /* this corresponds to item 4 in gridhead - 0 for the main grid. */ + int lgr_nr; /* EGRID files: corresponds to item 4 in gridhead - 0 for the main grid. + GRID files: 0 for the main grid, then 1 -> number of LGRs in order read from file*/ char * name; /* the name of the file for the main grid - name of the lgr for lgrs. */ int ny,nz,nx; int size; /* == nx*ny*nz */ @@ -488,6 +558,7 @@ struct ecl_grid_struct { int * fracture_index_map; /* For fractures: this a list of nx*ny*nz elements, where value -1 means inactive cell .*/ int * inv_fracture_index_map; /* For fractures: this is list of total_active elements - which point back to the index_map. */ + nnc_index_list_type * nnc_index_list; #ifdef LARGE_CELL_MALLOC ecl_cell_type * cells; @@ -506,9 +577,10 @@ struct ecl_grid_struct { /* the two fields below are for *storing* lgr grid instances. observe that these fields will be NULL for lgr grids, i.e. grids with - grid_nr > 0. + lgr_nr > 0. */ - vector_type * LGR_list; /* a vector of ecl_grid instances for lgr's - the index corresponds to the grid_nr. */ + vector_type * LGR_list; /* a vector of ecl_grid instances for LGRs - the index corresponds to the order LGRs are read from file*/ + int_vector_type * lgr_index_map; /* a vector that maps LGR-nr for EGRID files to index into the LGR_list.*/ hash_type * LGR_hash; /* a hash of pointers to ecl_grid instances - for name based lookup of lgr. */ int parent_box[6]; /* integers i1,i2, j1,j2, k1,k2 of the parent grid region containing this lgr. the indices are inclusive - zero offset */ /* not used yet .. */ @@ -826,6 +898,8 @@ static void ecl_cell_init( ecl_cell_type * cell , bool init_valid) { if (init_valid) cell->cell_flags = CELL_FLAG_VALID; + + cell->nnc_info = NULL; } @@ -1122,6 +1196,14 @@ static void ecl_grid_taint_cells( ecl_grid_type * ecl_grid ) { static void ecl_grid_free_cells( ecl_grid_type * grid ) { + + int i; + for (i=0; i < grid->size; i++) { + ecl_cell_type * cell = ecl_grid_get_cell( grid , i ); + if (cell->nnc_info) + nnc_info_free(cell->nnc_info); + } + #ifndef LARGE_CELL_MALLOC int i; for (i=0; i < grid->size; i++) { @@ -1162,7 +1244,7 @@ static void ecl_grid_alloc_cells( ecl_grid_type * grid , bool init_valid) { is performed. */ -static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int dualp_flag , int nx , int ny , int nz, int grid_nr , bool init_valid) { +static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int dualp_flag , int nx , int ny , int nz, int lgr_nr, bool init_valid) { ecl_grid_type * grid = util_malloc(sizeof * grid ); UTIL_TYPE_ID_INIT(grid , ECL_GRID_ID); grid->total_active = 0; @@ -1171,7 +1253,7 @@ static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int du grid->ny = ny; grid->nz = nz; grid->size = nx*ny*nz; - grid->grid_nr = grid_nr; + grid->lgr_nr = lgr_nr; grid->global_grid = global_grid; grid->coarsening_active = false; @@ -1182,8 +1264,9 @@ static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int du grid->index_map = NULL; grid->fracture_index_map = NULL; grid->inv_fracture_index_map = NULL; + grid->nnc_index_list = nnc_index_list_alloc( ); ecl_grid_alloc_cells( grid , init_valid ); - + if (global_grid != NULL) { /* this is an lgr instance, and we inherit the global grid @@ -1206,21 +1289,22 @@ static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int du } - grid->block_dim = 0; - grid->values = NULL; - if (grid_nr == 0) { /* this is the main grid */ - grid->LGR_list = vector_alloc_new(); - vector_append_ref( grid->LGR_list , grid ); /* adding a 'self' pointer as first inistance - without destructor! */ - grid->LGR_hash = hash_alloc(); + grid->block_dim = 0; + grid->values = NULL; + if (ECL_GRID_MAINGRID_LGR_NR == lgr_nr) { /* this is the main grid */ + grid->LGR_list = vector_alloc_new(); + grid->lgr_index_map = int_vector_alloc(0,0); + grid->LGR_hash = hash_alloc(); } else { - grid->LGR_list = NULL; - grid->LGR_hash = NULL; + grid->LGR_list = NULL; + grid->lgr_index_map = NULL; + grid->LGR_hash = NULL; } - grid->name = NULL; - grid->parent_name = NULL; - grid->parent_grid = NULL; - grid->children = hash_alloc(); - grid->coarse_cells = vector_alloc_new(); + grid->name = NULL; + grid->parent_name = NULL; + grid->parent_grid = NULL; + grid->children = hash_alloc(); + grid->coarse_cells = vector_alloc_new(); return grid; } @@ -1322,12 +1406,12 @@ static void ecl_grid_set_cell_GRID(ecl_grid_type * ecl_grid , int coords_size , /* - The grid_nr > 0 test essentially checks if this is a LGR; if - this test applies we either have bug - or a GRID file with LGRs - and only 4/5 elements in the coords keywords. In the latter - case we must start using the LGRILG keyword. + The ECL_GRID_MAINGRID_LGR_NR != ecl_grid->lgr_nr test checks if + this is a LGR; if this test applies we either have bug - or a + GRID file with LGRs and only 4/5 elements in the coords keywords. + In the latter case we must start using the LGRILG keyword. */ - if ((ecl_grid->grid_nr > 0) && (coords_size != 7)) + if ((ECL_GRID_MAINGRID_LGR_NR != ecl_grid->lgr_nr) && (coords_size != 7)) util_abort("%s: Need 7 element coords keywords for LGR - or reimplement to use LGRILG keyword.\n",__func__); switch(coords_size) { @@ -1699,13 +1783,9 @@ static void ecl_grid_init_mapaxes( ecl_grid_type * ecl_grid , const float * mapa static void ecl_grid_add_lgr( ecl_grid_type * main_grid , ecl_grid_type * lgr_grid) { - int next_grid_nr = vector_get_size( main_grid->LGR_list ); - if (next_grid_nr != lgr_grid->grid_nr) - util_abort("%s: index based insertion of lgr grid failed. next_grid_nr:%d lgr->grid_nr:%d \n",__func__ , next_grid_nr , lgr_grid->grid_nr); - { - vector_append_owned_ref( main_grid->LGR_list , lgr_grid , ecl_grid_free__); - hash_insert_ref( main_grid->LGR_hash , lgr_grid->name , lgr_grid); - } + vector_append_owned_ref( main_grid->LGR_list , lgr_grid , ecl_grid_free__); + int_vector_iset(main_grid->lgr_index_map, lgr_grid->lgr_nr, vector_get_size(main_grid->LGR_list)-1); + hash_insert_ref( main_grid->LGR_hash , lgr_grid->name , lgr_grid); } @@ -1764,7 +1844,7 @@ static void ecl_grid_set_lgr_name_EGRID(ecl_grid_type * lgr_grid , const ecl_fil 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. */ 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); + 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)); if (strlen( parent ) > 0) @@ -1795,7 +1875,7 @@ static void ecl_grid_set_lgr_name_GRID(ecl_grid_type * lgr_grid , const ecl_file if ((strlen(parent) == 0) || (strcmp(parent , GLOBAL_STRING ) == 0)) free( parent ); - else + else lgr_grid->parent_name = parent; } } @@ -1893,9 +1973,9 @@ void ecl_grid_init_GRDECL_data(ecl_grid_type * ecl_grid , const float * zcorn , static ecl_grid_type * ecl_grid_alloc_GRDECL_data__(ecl_grid_type * global_grid , int dualp_flag , int nx , int ny , int nz , const float * zcorn , const float * coord , const int * actnum, const float * mapaxes, const int * corsnum, - int grid_nr) { + int lgr_nr) { - ecl_grid_type * ecl_grid = ecl_grid_alloc_empty(global_grid , dualp_flag , nx,ny,nz,grid_nr,true); + ecl_grid_type * ecl_grid = ecl_grid_alloc_empty(global_grid , dualp_flag , nx,ny,nz,lgr_nr,true); if (mapaxes != NULL) ecl_grid_init_mapaxes( ecl_grid , mapaxes ); @@ -1930,15 +2010,14 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_kw__(ecl_grid_type * global_grid , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , /* Can be NULL */ const ecl_kw_type * mapaxes_kw , /* Can be NULL */ - const ecl_kw_type * corsnum_kw , /* Can be NULL */ - int grid_nr) { - - int gtype, nx,ny,nz; + const ecl_kw_type * corsnum_kw) { /* Can be NULL */ + int gtype, nx,ny,nz, lgr_nr; gtype = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_TYPE_INDEX); nx = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_NX_INDEX); ny = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_NY_INDEX); nz = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_NZ_INDEX); + lgr_nr = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_LGR_INDEX); /* The code used to have this test: @@ -1951,7 +2030,7 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_kw__(ecl_grid_type * global_grid , if (gtype != GRIDHEAD_GRIDTYPE_CORNERPOINT) util_abort("%s: gtype:%d fatal error when loading grid - must have corner point grid - aborting\n",__func__ , gtype ); - + { const float * mapaxes_data = NULL; const int * actnum_data = NULL; @@ -1974,7 +2053,7 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_kw__(ecl_grid_type * global_grid , actnum_data, mapaxes_data, corsnum_data, - grid_nr); + lgr_nr); } } @@ -1983,7 +2062,7 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_kw__(ecl_grid_type * global_grid , If you create/load ecl_kw instances for the various fields, this function can be used to create a GRID instance, without going through a GRID/EGRID file. Does not support LGR or coarsening - hierarchies. + hierarchies. */ ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , @@ -1991,10 +2070,10 @@ ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , /* Can be NULL */ const ecl_kw_type * mapaxes_kw ) { /* Can be NULL */ - + ecl_kw_type * gridhead_kw = ecl_grid_alloc_gridhead_kw( nx , ny , nz , 0); - ecl_grid_type * ecl_grid = ecl_grid_alloc_GRDECL_kw__(NULL , FILEHEAD_SINGLE_POROSITY , gridhead_kw , zcorn_kw , coord_kw , actnum_kw , mapaxes_kw , NULL , 0); + ecl_grid_type * ecl_grid = ecl_grid_alloc_GRDECL_kw__(NULL , FILEHEAD_SINGLE_POROSITY , gridhead_kw , zcorn_kw , coord_kw , actnum_kw , mapaxes_kw , NULL); ecl_kw_free( gridhead_kw ); return ecl_grid; @@ -2002,6 +2081,126 @@ ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , + + + +static void ecl_grid_init_cell_nnc_info(ecl_grid_type * ecl_grid, int global_index) { + ecl_cell_type * grid_cell = ecl_grid_get_cell(ecl_grid, global_index); + + if (!grid_cell->nnc_info) + grid_cell->nnc_info = nnc_info_alloc(ecl_grid->lgr_nr); +} + + +/* + This function populates nnc_info for cells with non neighbour connections + */ +static void ecl_grid_init_nnc_cells( ecl_grid_type * grid1, ecl_grid_type * grid2, const ecl_kw_type * keyword1, const ecl_kw_type * keyword2) { + + int * grid1_nnc_cells = ecl_kw_get_int_ptr(keyword1); + int * grid2_nnc_cells = ecl_kw_get_int_ptr(keyword2); + int nnc_count = ecl_kw_get_size(keyword2); + + int i; + for (i = 0; i < nnc_count; i++) { + int grid1_cell_index = grid1_nnc_cells[i] -1; + int grid2_cell_index = grid2_nnc_cells[i] -1; + + + /* + In the ECLIPSE output format grids with dual porosity are (to some + extent ...) modeled as two independent grids stacked on top of + eachother, where the fracture cells have global index in the range + [nx*ny*nz, 2*nx*ny*nz). + + The physical connection between the matrix and the fractures in + cell nr c is modelled as an nnc: cell[c] -> cell[c + nx*ny*nz]. In + the ert ecl library we only have cells in the range [0,nx*ny*nz), + and fracture is a property of a cell, we therefor do not include + nnc connections involving fracture cells (i.e. cell_index >= + nx*ny*nz). + */ + if ((FILEHEAD_SINGLE_POROSITY != grid1->dualp_flag) && + ((grid1_cell_index >= grid1->size) || + (grid2_cell_index >= grid2->size))) + break; + + + ecl_grid_init_cell_nnc_info(grid1, grid1_cell_index); + ecl_grid_init_cell_nnc_info(grid2, grid2_cell_index); + + { + ecl_cell_type * grid1_cell = ecl_grid_get_cell(grid1, grid1_cell_index); + ecl_cell_type * grid2_cell = ecl_grid_get_cell(grid2, grid2_cell_index); + + //Add the non-neighbour connection in both directions + nnc_info_add_nnc(grid1_cell->nnc_info, grid2->lgr_nr, grid2_cell_index); + nnc_info_add_nnc(grid2_cell->nnc_info, grid1->lgr_nr, grid1_cell_index); + + nnc_index_list_add_index( grid1->nnc_index_list , grid1_cell_index ); + nnc_index_list_add_index( grid2->nnc_index_list , grid2_cell_index ); + } + } +} + + +/* + This function reads the non-neighbour connection data from file and initializes the grid structure with the the nnc data +*/ +static void ecl_grid_init_nnc(ecl_grid_type * main_grid, ecl_file_type * ecl_file) { + int num_nnchead_kw = ecl_file_get_num_named_kw( ecl_file , NNCHEAD_KW ); + int num_nncg_kw = ecl_file_get_num_named_kw( ecl_file , NNCG_KW ); + + int i; + for (i = 0; i < num_nnchead_kw; i++) { + ecl_kw_type * nnchead_kw = ecl_file_iget_named_kw( ecl_file , NNCHEAD_KW , i); + int lgr_nr = ecl_kw_iget_int(nnchead_kw, NNCHEAD_LGR_INDEX); + ecl_kw_type * keyword1 = NULL; + ecl_kw_type * keyword2 = NULL; + + if (ECL_GRID_MAINGRID_LGR_NR == lgr_nr) { + keyword1 = ecl_file_iget_named_kw( ecl_file , NNC1_KW , i); + keyword2 = ecl_file_iget_named_kw( ecl_file , NNC2_KW , i); + } else { + int nnc_lgr_index = (num_nnchead_kw == num_nncg_kw) ? i : i-1; //Subtract 1 if no nnc data for main grid + keyword1 = ecl_file_iget_named_kw( ecl_file , NNCL_KW , nnc_lgr_index); + keyword2 = ecl_file_iget_named_kw( ecl_file , NNCG_KW , nnc_lgr_index); + } + + { + ecl_grid_type * grid = (lgr_nr > 0) ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid; + ecl_grid_init_nnc_cells(grid, main_grid, keyword1, keyword2); + } + } +} + +/* + This function reads the non-neighbour connection data for amalgamated LGRs (that is, non-neighbour + connections between two LGRs) and initializes the grid structure with the nnc data. + */ +static void ecl_grid_init_nnc_amalgamated(ecl_grid_type * main_grid, ecl_file_type * ecl_file) { + int num_nncheada_kw = ecl_file_get_num_named_kw( ecl_file , NNCHEADA_KW ); + + int i; + for (i = 0; i < num_nncheada_kw; i++) { + ecl_kw_type * nncheada_kw = ecl_file_iget_named_kw( ecl_file , NNCHEADA_KW , i); + int lgr_nr1 = ecl_kw_iget_int(nncheada_kw, NNCHEADA_ILOC1_INDEX); + int lgr_nr2 = ecl_kw_iget_int(nncheada_kw, NNCHEADA_ILOC2_INDEX); + + ecl_grid_type * lgr_grid1 = ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr1); + ecl_grid_type * lgr_grid2 = ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr2); + + ecl_kw_type * nna1_kw = ecl_file_iget_named_kw( ecl_file , NNA1_KW , i); + ecl_kw_type * nna2_kw = ecl_file_iget_named_kw( ecl_file , NNA2_KW , i); + + ecl_grid_init_nnc_cells( lgr_grid1 ,lgr_grid2, nna1_kw, nna2_kw); + + } +} + + + + /** Creating a grid based on a EGRID file is a three step process: @@ -2045,7 +2244,7 @@ static ecl_grid_type * ecl_grid_alloc_EGRID__( ecl_grid_type * main_grid , const corsnum_kw = ecl_file_iget_named_kw( ecl_file , CORSNUM_KW , 0); } - + { ecl_grid_type * ecl_grid = ecl_grid_alloc_GRDECL_kw__( main_grid , @@ -2055,10 +2254,9 @@ static ecl_grid_type * ecl_grid_alloc_EGRID__( ecl_grid_type * main_grid , const coord_kw , actnum_kw , mapaxes_kw , - corsnum_kw , - grid_nr ); - - if (grid_nr > 0) ecl_grid_set_lgr_name_EGRID(ecl_grid , ecl_file , grid_nr); + corsnum_kw ); + + if (ECL_GRID_MAINGRID_LGR_NR != grid_nr) ecl_grid_set_lgr_name_EGRID(ecl_grid , ecl_file , grid_nr); return ecl_grid; } } @@ -2091,6 +2289,10 @@ static ecl_grid_type * ecl_grid_alloc_EGRID(const char * grid_file) { } } main_grid->name = util_alloc_string_copy( grid_file ); + + ecl_grid_init_nnc(main_grid, ecl_file); + ecl_grid_init_nnc_amalgamated(main_grid, ecl_file); + ecl_file_close( ecl_file ); return main_grid; } @@ -2106,7 +2308,7 @@ static ecl_grid_type * ecl_grid_alloc_GRID_data__(ecl_grid_type * global_grid , if (dualp_flag != FILEHEAD_SINGLE_POROSITY) nz = nz / 2; { - ecl_grid_type * grid = ecl_grid_alloc_empty( global_grid , dualp_flag , nx , ny , nz , grid_nr , false); + ecl_grid_type * grid = ecl_grid_alloc_empty( global_grid , dualp_flag , nx , ny , nz , grid_nr, false); if (mapaxes != NULL) ecl_grid_init_mapaxes( grid , mapaxes ); @@ -2344,7 +2546,7 @@ static ecl_grid_type * ecl_grid_alloc_GRID(const char * grid_file) { */ 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 * grid = ecl_grid_alloc_empty(NULL , FILEHEAD_SINGLE_POROSITY , nx , ny , nz , 0,true); + ecl_grid_type * grid = ecl_grid_alloc_empty(NULL , FILEHEAD_SINGLE_POROSITY , nx , ny , nz , 0, true); const double offset[3] = {0,0,0}; int k,j,i; @@ -2950,13 +3152,15 @@ void ecl_grid_free(ecl_grid_type * grid) { double_vector_free( grid->values[i] ); free( grid->values ); } - if (grid->grid_nr == 0) { /* This is the main grid. */ + if (ECL_GRID_MAINGRID_LGR_NR == grid->lgr_nr) { /* This is the main grid. */ vector_free( grid->LGR_list ); + int_vector_free( grid->lgr_index_map); hash_free( grid->LGR_hash ); } if (grid->coord_kw != NULL) ecl_kw_free( grid->coord_kw ); + nnc_index_list_free( grid->nnc_index_list ); vector_free( grid->coarse_cells ); hash_free( grid->children ); util_safe_free( grid->parent_name ); @@ -3044,10 +3248,10 @@ grid_dims_type ecl_grid_iget_dims( const ecl_grid_type * grid , int grid_nr) { grid_dims_type dims; const ecl_grid_type * lgr; - if (grid_nr == 0) + if (grid_nr == 0) lgr = grid; else - lgr = ecl_grid_iget_lgr( grid , grid_nr - 1 ); + lgr = ecl_grid_iget_lgr(grid, grid_nr - 1); dims.nx = lgr->nx; dims.ny = lgr->ny; @@ -3369,6 +3573,25 @@ double ecl_grid_get_cell_thickness3( const ecl_grid_type * grid , int i , int j } +const int_vector_type * ecl_grid_get_nnc_index_list( ecl_grid_type * grid ) { + return nnc_index_list_get_list( grid->nnc_index_list ); +} + + +const nnc_info_type * ecl_grid_get_cell_nnc_info1( const ecl_grid_type * grid , int global_index) { + const ecl_cell_type * cell = ecl_grid_get_cell( grid , global_index); + return cell->nnc_info; +} + + + +const nnc_info_type * ecl_grid_get_cell_nnc_info3( const ecl_grid_type * grid , int i , int j , int k) { + const int global_index = ecl_grid_get_global_index3(grid , i,j,k); + return ecl_grid_get_cell_nnc_info1(grid, global_index); +} + + + /*****************************************************************/ /* Functions to query whether a cell is active or not. */ @@ -3413,7 +3636,7 @@ double ecl_grid_cell_invalid1A(const ecl_grid_type * grid , int active_index) { /* Functions for LGR query/lookup/... */ static void __assert_main_grid(const ecl_grid_type * ecl_grid) { - if (ecl_grid->grid_nr != 0) + if (ecl_grid->lgr_nr != ECL_GRID_MAINGRID_LGR_NR) util_abort("%s: tried to get LGR grid from another LGR_grid - only main grid can be used as first input \n",__func__); } @@ -3472,20 +3695,37 @@ bool ecl_grid_have_coarse_cells( const ecl_grid_type * main_grid ) { */ int ecl_grid_get_num_lgr(const ecl_grid_type * main_grid ) { __assert_main_grid( main_grid ); - return vector_get_size( main_grid->LGR_list ) - 1; + return vector_get_size( main_grid->LGR_list ); } /** - The lgr_nr has zero offset, not counting the main grid, i.e. - - ecl_grid_iget_lgr( ecl_grid , 0); - - will return the first LGR - and fail HARD if there are no LGR's. + The lgr_index has zero offset + ecl_grid_iget_lgr( ecl_grid , 0); will return the first lgr + ecl_grid_iget_lgr( ecl_grid , 1); will return the second lgr + The method will fail HARD if lgr_index is out of bounds. */ -ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid, int lgr_nr) { +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_nr + 1); + return vector_iget( main_grid->LGR_list , lgr_index); +} + +/* + This function returns the lgr with the given lgr_nr. The lgr_nr is + the fourth element in the GRIDHEAD for EGRID files. The lgr nr is + equal to the grid nr if the grid's are consecutive numbered and + read from file in increasing lgr nr order. + + This method can only be used for EGRID files. For GRID files the + lgr_nr is 0 for all grids. +*/ + +ecl_grid_type * ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type * main_grid, int lgr_nr) { + __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); + } } @@ -3527,7 +3767,7 @@ const ecl_grid_type * ecl_grid_get_cell_lgr1A(const ecl_grid_type * grid , int a Will return the global grid for a lgr. If the input grid is indeed a global grid itself the function will return NULL. */ -const ecl_grid_type * ecl_grid_get_global_grid( const ecl_grid_type * grid ) { + const ecl_grid_type * ecl_grid_get_global_grid( const ecl_grid_type * grid ) { return grid->global_grid; } @@ -3545,36 +3785,40 @@ 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_nr) { +const char * ecl_grid_iget_lgr_name( const ecl_grid_type * ecl_grid , int lgr_index) { __assert_main_grid( ecl_grid ); - if (lgr_nr < (vector_get_size( ecl_grid->LGR_list ) - 1)) { - const ecl_grid_type * lgr = vector_iget( ecl_grid->LGR_list , lgr_nr + 1); + if (lgr_index < (vector_get_size( ecl_grid->LGR_list ))) { + const ecl_grid_type * lgr = vector_iget( ecl_grid->LGR_list , lgr_index); return lgr->name; } else return NULL; } +const char * ecl_grid_get_lgr_name( const ecl_grid_type * ecl_grid , int lgr_nr) { + __assert_main_grid( ecl_grid ); + { + int lgr_index = int_vector_iget( ecl_grid->lgr_index_map , lgr_nr ); + return ecl_grid_iget_lgr_name( ecl_grid , lgr_index ); + } +} + /*****************************************************************/ /** - This function returns the grid_nr field of the field; this is just - the occurence number in the grid file. Starting with 0 at the main + This function returns the lgr_nr field of the grid; for GRID files, this + is just the occurence number in the grid file. Starting with 0 at the main grid, and then increasing consecutively through the lgr sections. - - Observe that there is A MAJOR POTENTIAL for confusion with the - ecl_grid_iget_lgr() function, the latter does not refer to the main - grid and returns the first lgr section (which has grid_nr == 1) for - input argument 0. + For EGRID files, this is the LGR number (fourth element in the + gridhead). */ -int ecl_grid_get_grid_nr( const ecl_grid_type * ecl_grid ) { - return ecl_grid->grid_nr; +int ecl_grid_get_lgr_nr( const ecl_grid_type * ecl_grid ) { + return ecl_grid->lgr_nr; } - const char * ecl_grid_get_name( const ecl_grid_type * ecl_grid ) { return ecl_grid->name; } @@ -3613,7 +3857,7 @@ void ecl_grid_summarize(const ecl_grid_type * ecl_grid) { printf(" Origo X................: %10.2f \n",ecl_grid->origo[0]); printf(" Origo Y................: %10.2f \n",ecl_grid->origo[1]); - if (ecl_grid->grid_nr == 0) { + if (ECL_GRID_MAINGRID_LGR_NR == ecl_grid->lgr_nr) { int grid_nr; for (grid_nr=1; grid_nr < vector_get_size( ecl_grid->LGR_list ); grid_nr++) { printf("\n"); @@ -3954,7 +4198,7 @@ bool ecl_grid_test_lgr_consistency( const ecl_grid_type * ecl_grid ) { static void ecl_grid_dump__(const ecl_grid_type * grid , FILE * stream) { - util_fwrite_int( grid->grid_nr , stream ); + util_fwrite_int( grid->lgr_nr , stream ); util_fwrite_string( grid->name , stream ); util_fwrite_int( grid->nx , stream ); util_fwrite_int( grid->nz , stream ); @@ -3975,7 +4219,7 @@ static void ecl_grid_dump__(const ecl_grid_type * grid , FILE * stream) { static void ecl_grid_dump_ascii__(const ecl_grid_type * grid , bool active_only , FILE * stream) { - fprintf(stream , "Grid nr : %d\n",grid->grid_nr); + fprintf(stream , "Grid nr : %d\n",grid->lgr_nr); fprintf(stream , "Grid name : %s\n",grid->name); fprintf(stream , "nx : %6d\n",grid->nx); fprintf(stream , "ny : %6d\n",grid->ny); @@ -4007,15 +4251,21 @@ static void ecl_grid_dump_ascii__(const ecl_grid_type * grid , bool active_only 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__(grid, 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 ); + } } void ecl_grid_dump_ascii(const 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_const( grid->LGR_list , i) , active_only , stream ); + ecl_grid_dump_ascii__( grid , active_only , stream ); + { + int i; + for (i = 0; i < vector_get_size( grid->LGR_list ); i++) + ecl_grid_dump_ascii__( vector_iget_const( grid->LGR_list , i) , active_only , stream ); + } } @@ -4180,6 +4430,8 @@ void ecl_grid_fwrite_GRID( const ecl_grid_type * grid , const char * filename) { if (grid->coarsening_active) coords_size = 7; + ecl_grid_fwrite_GRID__( grid , coords_size , fortio ); + { int grid_nr; for (grid_nr = 0; grid_nr < vector_get_size( grid->LGR_list ); grid_nr++) { @@ -4591,7 +4843,7 @@ static void ecl_grid_fwrite_EGRID__( ecl_grid_type * grid , fortio_type * fortio } } - ecl_grid_fwrite_gridhead_kw( grid->nx , grid->ny , grid->nz , grid->grid_nr , fortio); + ecl_grid_fwrite_gridhead_kw( grid->nx , grid->ny , grid->nz , grid->lgr_nr , fortio); /* Writing main grid data */ { { @@ -4637,6 +4889,8 @@ static void ecl_grid_fwrite_EGRID__( ecl_grid_type * grid , fortio_type * fortio void ecl_grid_fwrite_EGRID( ecl_grid_type * grid , const char * filename) { bool fmt_file = false; fortio_type * fortio = fortio_open_writer( filename , fmt_file , ECL_ENDIAN_FLIP ); + + ecl_grid_fwrite_EGRID__( grid , fortio ); { int grid_nr; for (grid_nr = 0; grid_nr < vector_get_size( grid->LGR_list ); grid_nr++) { diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_kw.c b/ThirdParty/Ert/devel/libecl/src/ecl_kw.c index 85432ec2c3..296d03f20f 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_kw.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_kw.c @@ -2374,7 +2374,7 @@ void ecl_kw_inplace_update_file(const ecl_kw_type * ecl_kw , const char * filena /******************************************************************/ bool ecl_kw_is_kw_file(FILE * stream , bool fmt_file ) { - const long int init_pos = ftell(stream); + const long int init_pos = util_ftell(stream); bool kw_file; { @@ -2394,7 +2394,7 @@ bool ecl_kw_is_kw_file(FILE * stream , bool fmt_file ) { ecl_kw_free(ecl_kw); } - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return kw_file; } @@ -2403,7 +2403,7 @@ bool ecl_kw_is_kw_file(FILE * stream , bool fmt_file ) { bool ecl_kw_is_grdecl_file(FILE * stream) { - const long int init_pos = ftell(stream); + const long int init_pos = util_ftell(stream); bool grdecl_file; bool at_eof = false; util_fskip_chars(stream , " \r\n\t" , &at_eof); /* Skipping intial space */ @@ -2427,7 +2427,7 @@ bool ecl_kw_is_grdecl_file(FILE * stream) { } while (c == ' '); } } - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return grdecl_file; } diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_kw_grdecl.c b/ThirdParty/Ert/devel/libecl/src/ecl_kw_grdecl.c index 1fb0f3bb5a..cc6d71c29a 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_kw_grdecl.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_kw_grdecl.c @@ -71,7 +71,7 @@ bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { - long start_pos = ftell( stream ); + long start_pos = util_ftell( stream ); long current_pos; char next_kw[256]; @@ -83,14 +83,14 @@ bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { { while (true) { char c; - if (ftell(stream) == 0) + if (util_ftell(stream) == 0) /* We are at the very beginning of the file. Can just jump out of the loop. */ break; - fseek( stream , -1 , SEEK_CUR ); + util_fseek( stream , -1 , SEEK_CUR ); c = fgetc( stream ); if (c == '\n') { /* @@ -98,7 +98,7 @@ bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { have not reached any !isspace() characters on the way and can go back to start_pos and read from there. */ - fseek( stream , start_pos , SEEK_SET ); + util_fseek( stream , start_pos , SEEK_SET ); break; } @@ -111,25 +111,25 @@ bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { util_fskip_lines( stream , 1 ); break; } - fseek( stream , -2 , SEEK_CUR ); + util_fseek( stream , -2 , SEEK_CUR ); } } while (true) { - current_pos = ftell( stream ); + current_pos = util_ftell( stream ); if (fscanf(stream , "%s" , next_kw) == 1) { if ((next_kw[0] == next_kw[1]) && (next_kw[0] == ECL_COMMENT_CHAR)) // This is a comment line - skip it. util_fskip_lines( stream , 1 ); else { // This is a valid keyword i.e. a non-commented out string; return true. - fseek( stream , current_pos , SEEK_SET ); + util_fseek( stream , current_pos , SEEK_SET ); return true; } } else { // EOF reached - return False. - fseek( stream , start_pos , SEEK_SET ); + util_fseek( stream , start_pos , SEEK_SET ); return false; } } @@ -167,17 +167,17 @@ char * ecl_kw_grdecl_alloc_next_header( FILE * stream ) { */ static bool ecl_kw_grdecl_fseek_kw__(const char * kw , FILE * stream) { - long init_pos = ftell( stream ); + long init_pos = util_ftell( stream ); while (true) { if (ecl_kw_grdecl_fseek_next_kw( stream )) { char next_kw[256]; fscanf( stream , "%s" , next_kw); if (strcmp( kw , next_kw ) == 0) { - fseek( stream , -strlen(next_kw) , SEEK_CUR); + util_fseek( stream , -strlen(next_kw) , SEEK_CUR); return true; } } else { - fseek( stream , init_pos , SEEK_SET); + util_fseek( stream , init_pos , SEEK_SET); return false; } } @@ -274,13 +274,13 @@ bool ecl_kw_grdecl_fseek_kw(const char * kw , bool rewind , FILE * stream) { if (ecl_kw_grdecl_fseek_kw__(kw , stream)) return true; /* OK - we found the kw between current file pos and EOF. */ else if (rewind) { - long int init_pos = ftell(stream); + long int init_pos = util_ftell(stream); - fseek(stream , 0L , SEEK_SET); + util_fseek(stream , 0L , SEEK_SET); if (ecl_kw_grdecl_fseek_kw__( kw , stream )) /* Try again from the beginning of the file. */ return true; else - fseek(stream , init_pos , SEEK_SET); /* Could not find it - reposition to initial position. */ + util_fseek(stream , init_pos , SEEK_SET); /* Could not find it - reposition to initial position. */ } /* OK: If we are here - that means that we failed to find the kw. */ diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_rft_cell.c b/ThirdParty/Ert/devel/libecl/src/ecl_rft_cell.c index eab980b2f6..1891855d2e 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_rft_cell.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_rft_cell.c @@ -66,6 +66,7 @@ struct plt_data_struct { double wrat; double grat; double connection_start; + double connection_end; double flowrate; double oil_flowrate; double gas_flowrate; @@ -95,7 +96,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 flowrate , double oil_flowrate , double gas_flowrate , double water_flowrate) { + 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 ); UTIL_TYPE_ID_INIT( data , PLT_DATA_TYPE_ID ); @@ -103,6 +104,7 @@ static UTIL_IS_INSTANCE_FUNCTION( rft_data , RFT_DATA_TYPE_ID) data->grat = grat; data->wrat = wrat; data->connection_start = connection_start; + data->connection_end = connection_end; data->flowrate = flowrate; data->oil_flowrate = oil_flowrate; data->gas_flowrate = gas_flowrate; @@ -161,6 +163,7 @@ ecl_rft_cell_type * ecl_rft_cell_alloc_PLT( int i , double grat , double wrat, double connection_start, + double connection_end, double flowrate , double oil_flowrate , double gas_flowrate , @@ -168,7 +171,7 @@ ecl_rft_cell_type * ecl_rft_cell_alloc_PLT( int i , ecl_rft_cell_type * cell = ecl_rft_cell_alloc_common( i , j , k , depth , pressure ); - cell->data = plt_data_alloc( orat , grat , wrat , connection_start , flowrate , oil_flowrate , gas_flowrate , water_flowrate); + cell->data = plt_data_alloc( orat , grat , wrat , connection_start , connection_end , flowrate , oil_flowrate , gas_flowrate , water_flowrate); return cell; } @@ -282,6 +285,13 @@ double ecl_rft_cell_get_connection_start( const ecl_rft_cell_type * cell ) { return ECL_RFT_CELL_INVALID_VALUE; } +double ecl_rft_cell_get_connection_end( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->connection_end; + else + return ECL_RFT_CELL_INVALID_VALUE; +} double ecl_rft_cell_get_flowrate( const ecl_rft_cell_type * cell ) { const plt_data_type * data = plt_data_try_cast_const( cell->data ); @@ -345,7 +355,7 @@ int ecl_rft_cell_cmp( const ecl_rft_cell_type * cell1 , const ecl_rft_cell_type else if (val1 == val2) return 0; else - return 0; + return 1; } diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_rft_node.c b/ThirdParty/Ert/devel/libecl/src/ecl_rft_node.c index 07f60948b3..090f4ba05c 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_rft_node.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_rft_node.c @@ -170,22 +170,31 @@ static void ecl_rft_node_init_PLT_cells( ecl_rft_node_type * rft_node , const ec const float * gas_flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONGTUB_KW , 0)); const float * water_flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONWTUB_KW , 0)); const float * connection_start = NULL; + const float * connection_end = NULL; - /* This keyword is ONLY present if we are dealing with a MSW well. */ + /* The keywords CONLENST_KW and CONLENEN_KW are ONLY present if we are dealing with a MSW well. */ if (ecl_file_has_kw( rft , CONLENST_KW)) connection_start = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONLENST_KW , 0)); + + if (ecl_file_has_kw( rft , CONLENEN_KW)) + connection_end = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONLENEN_KW , 0)); { int c; for ( c = 0; c < ecl_kw_get_size( conipos ); c++) { ecl_rft_cell_type * cell; double cs = 0; + double ce = 0; + if (connection_start) cs = connection_start[c]; + + if (connection_end) + ce = connection_end[c]; /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ cell = ecl_rft_cell_alloc_PLT( i[c] -1 , j[c] -1 , k[c] -1 , - depth[c] , P[c] , OR[c] , GR[c] , WR[c] , cs , flowrate[c] , oil_flowrate[c] , gas_flowrate[c] , water_flowrate[c]); + depth[c] , P[c] , OR[c] , GR[c] , WR[c] , cs , ce, flowrate[c] , oil_flowrate[c] , gas_flowrate[c] , water_flowrate[c]); ecl_rft_node_append_cell( rft_node , cell ); } } diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_smspec.c b/ThirdParty/Ert/devel/libecl/src/ecl_smspec.c index 3201750c50..1519207f3f 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_smspec.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_smspec.c @@ -485,6 +485,7 @@ static ecl_smspec_var_type ecl_smspec_identify_special_var( const char * var ) { ecl_smspec_var_type ecl_smspec_identify_var_type(const char * var) { ecl_smspec_var_type var_type = ecl_smspec_identify_special_var( var ); + int str_length = strlen(var); if (var_type == ECL_SMSPEC_INVALID_VAR) { switch(var[0]) { case('A'): @@ -521,10 +522,13 @@ ecl_smspec_var_type ecl_smspec_identify_var_type(const char * var) { var_type = ECL_SMSPEC_NETWORK_VAR; break; case('R'): - if (var[2] == 'F') - var_type = ECL_SMSPEC_REGION_2_REGION_VAR; - else + if (((3 == str_length) && var[2] == 'F') || + ((4 == str_length) && var[3] == 'F')) { + var_type = ECL_SMSPEC_REGION_2_REGION_VAR; + } + else { var_type = ECL_SMSPEC_REGION_VAR; + } break; case('S'): var_type = ECL_SMSPEC_SEGMENT_VAR; @@ -649,7 +653,7 @@ static void ecl_smspec_install_gen_keys( ecl_smspec_type * smspec , smspec_node_ hash_insert_ref(smspec->gen_var_index , gen_key1 , smspec_node); } - /* Insert the (optional) extra mapping for block related variables: */ + /* Insert the (optional) extra mapping for block related variables and region_2_region variables: */ { const char * gen_key2 = smspec_node_get_gen_key2( smspec_node ); if (gen_key2 != NULL) @@ -751,6 +755,8 @@ static void ecl_smspec_install_special_keys( ecl_smspec_type * ecl_smspec , smsp break; case(ECL_SMSPEC_SEGMENT_VAR): break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + break; default: util_abort("%: Internal error - should never be here ?? \n",__func__); break; @@ -778,6 +784,9 @@ bool ecl_smspec_needs_wgname( ecl_smspec_var_type var_type ) { case(ECL_SMSPEC_REGION_VAR): return false; break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + return false; + break; case(ECL_SMSPEC_MISC_VAR): return false; break; @@ -821,6 +830,9 @@ bool ecl_smspec_needs_num( ecl_smspec_var_type var_type ) { case(ECL_SMSPEC_REGION_VAR): return true; break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + return true; + break; case(ECL_SMSPEC_MISC_VAR): return false; break; diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_sum.c b/ThirdParty/Ert/devel/libecl/src/ecl_sum.c index d9282726f7..126b81def6 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_sum.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_sum.c @@ -1183,6 +1183,20 @@ bool ecl_sum_is_oil_producer( const ecl_sum_type * ecl_sum , const char * well) +bool ecl_sum_report_step_equal( const ecl_sum_type * ecl_sum1 , const ecl_sum_type * ecl_sum2) { + if (ecl_sum1 == ecl_sum2) + return true; + else + return ecl_sum_data_report_step_equal( ecl_sum1->data , ecl_sum2->data ); +} + + +bool ecl_sum_report_step_compatible( const ecl_sum_type * ecl_sum1 , const ecl_sum_type * ecl_sum2) { + if (ecl_sum1 == ecl_sum2) + return true; + else + return ecl_sum_data_report_step_compatible( ecl_sum1->data , ecl_sum2->data ); +} diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_sum_data.c b/ThirdParty/Ert/devel/libecl/src/ecl_sum_data.c index 09d4e684cc..73b1e87a1c 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_sum_data.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_sum_data.c @@ -204,7 +204,7 @@ - +#define INVALID_MINISTEP_NR -1 struct ecl_sum_data_struct { @@ -255,8 +255,8 @@ static void ecl_sum_data_clear_index( ecl_sum_data_type * data ) { data->last_report_step = -1024 * 1024; data->days_start = 0; data->sim_length = -1; - data->first_ministep = -1; - data->last_ministep = -1; + data->first_ministep = INVALID_MINISTEP_NR; + data->last_ministep = INVALID_MINISTEP_NR; data->index_valid = false; time_interval_reopen( data->sim_time ); } @@ -268,8 +268,8 @@ ecl_sum_data_type * ecl_sum_data_alloc(ecl_smspec_type * smspec) { data->smspec = smspec; data->__min_time = 0; - data->report_first_index = int_vector_alloc( 0 , -1 ); /* This -1 value is hard-wired around in the place - not good. */ - data->report_last_index = int_vector_alloc( 0 , -1 ); + data->report_first_index = int_vector_alloc( 0 , INVALID_MINISTEP_NR ); + data->report_last_index = int_vector_alloc( 0 , INVALID_MINISTEP_NR ); data->sim_time = time_interval_alloc_open(); ecl_sum_data_clear_index( data ); @@ -545,7 +545,7 @@ static int ecl_sum_data_get_index_from_sim_time( const ecl_sum_data_type * data { int low_index = 0; int high_index = vector_get_size( data->data ); - int internal_index = -1; + int internal_index = INVALID_MINISTEP_NR; while (internal_index < 0) { @@ -1043,7 +1043,7 @@ bool ecl_sum_data_has_report_step(const ecl_sum_data_type * data , int report_st /** Returns the last index included in report step @report_step. Observe that if the dataset does not include @report_step at all, - the function will return -1; this must be checked for in the + the function will return INVALID_MINISTEP_NR; this must be checked for in the calling scope. */ @@ -1056,7 +1056,7 @@ int ecl_sum_data_iget_report_end( const ecl_sum_data_type * data , int report_st /** Returns the first index included in report step @report_step. Observe that if the dataset does not include @report_step at all, - the function will return -1; this must be checked for in the + the function will return INVALID_MINISTEP_NR; this must be checked for in the calling scope. */ @@ -1349,3 +1349,52 @@ int ecl_sum_data_get_length( const ecl_sum_data_type * data ) { return vector_get_size( data->data ); } + +bool ecl_sum_data_report_step_equal( const ecl_sum_data_type * data1 , const ecl_sum_data_type * data2) { + bool equal = true; + if (int_vector_size( data1->report_last_index ) == int_vector_size(data2->report_last_index)) { + int i; + for (i = 0; i < int_vector_size( data1->report_last_index ); i++) { + int time_index1 = int_vector_iget( data1->report_last_index , i ); + int time_index2 = int_vector_iget( data2->report_last_index , i ); + + if ((time_index1 != INVALID_MINISTEP_NR) && (time_index2 != INVALID_MINISTEP_NR)) { + const ecl_sum_tstep_type * ministep1 = ecl_sum_data_iget_ministep( data1 , time_index1 ); + const ecl_sum_tstep_type * ministep2 = ecl_sum_data_iget_ministep( data2 , time_index2 ); + + if (!ecl_sum_tstep_sim_time_equal( ministep1 , ministep2)) { + equal = false; + break; + } + } else if (time_index1 != time_index2) { + equal = false; + break; + } + } + } else + equal = false; + + return equal; +} + + +bool ecl_sum_data_report_step_compatible( const ecl_sum_data_type * data1 , const ecl_sum_data_type * data2) { + bool compatible = true; + int min_size = util_int_min( int_vector_size( data1->report_last_index ) , int_vector_size( data2->report_last_index)); + int i; + for (i = 0; i < min_size; i++) { + int time_index1 = int_vector_iget( data1->report_last_index , i ); + int time_index2 = int_vector_iget( data2->report_last_index , i ); + + if ((time_index1 != INVALID_MINISTEP_NR) && (time_index2 != INVALID_MINISTEP_NR)) { + const ecl_sum_tstep_type * ministep1 = ecl_sum_data_iget_ministep( data1 , time_index1 ); + const ecl_sum_tstep_type * ministep2 = ecl_sum_data_iget_ministep( data2 , time_index2 ); + + if (!ecl_sum_tstep_sim_time_equal( ministep1 , ministep2)) { + compatible = false; + break; + } + } + } + return compatible; +} diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_sum_tstep.c b/ThirdParty/Ert/devel/libecl/src/ecl_sum_tstep.c index 49dab11754..e982a24106 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_sum_tstep.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_sum_tstep.c @@ -289,3 +289,10 @@ void ecl_sum_tstep_set_from_key( ecl_sum_tstep_type * tstep , const char * gen_k } +bool ecl_sum_tstep_sim_time_equal( const ecl_sum_tstep_type * tstep1 , const ecl_sum_tstep_type * tstep2 ) { + if (tstep1->sim_time == tstep2->sim_time) + return true; + else + return false; +} + diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_util.c b/ThirdParty/Ert/devel/libecl/src/ecl_util.c index 92f3dde9c5..f28fb9abce 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_util.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_util.c @@ -1215,16 +1215,16 @@ time_t ecl_util_get_start_date(const char * data_file) { util_abort("%s: sorry - could not find START in DATA file %s \n",__func__ , data_file); { - long int start_pos = ftell( stream ); + long int start_pos = util_ftell( stream ); int buffer_size; /* Look for terminating '/' */ if (!parser_fseek_string( parser , stream , "/" , false , true)) util_abort("%s: sorry - could not find \"/\" termination of START keyword in data_file: \n",__func__ , data_file); - buffer_size = (ftell(stream) - start_pos) ; + buffer_size = (util_ftell(stream) - start_pos) ; buffer = util_calloc( buffer_size + 1 , sizeof * buffer ); - fseek( stream , start_pos , SEEK_SET); + util_fseek( stream , start_pos , SEEK_SET); util_fread( buffer , sizeof * buffer , buffer_size ,stream , __func__); buffer[buffer_size] = '\0'; } @@ -1257,16 +1257,16 @@ int ecl_util_get_num_cpu(const char * data_file) { char * buffer; if (parser_fseek_string( parser , stream , "PARALLEL" , true , true)) { /* Seeks case insensitive. */ - long int start_pos = ftell( stream ); + long int start_pos = util_ftell( stream ); int buffer_size; /* Look for terminating '/' */ if (!parser_fseek_string( parser , stream , "/" , false , true)) util_abort("%s: sorry - could not find \"/\" termination of PARALLEL keyword in data_file: \n",__func__ , data_file); - buffer_size = (ftell(stream) - start_pos) ; + buffer_size = (util_ftell(stream) - start_pos) ; buffer = util_calloc( buffer_size + 1 , sizeof * buffer ); - fseek( stream , start_pos , SEEK_SET); + util_fseek( stream , start_pos , SEEK_SET); util_fread( buffer , sizeof * buffer , buffer_size ,stream , __func__); buffer[buffer_size] = '\0'; @@ -1277,14 +1277,15 @@ int ecl_util_get_num_cpu(const char * data_file) { for (i=0; i < stringlist_get_size( tokens ); i++) { item = util_realloc_string_copy( item , stringlist_iget( tokens , i )); util_strupr( item ); - if ( util_string_equal( item , "DISTRIBUTED" )) { + if (( util_string_equal( item , "DISTRIBUTED" )) || + ( util_string_equal( item , "DIST" ))) { num_cpu = atoi( stringlist_iget( tokens , i - 1)); break; } } free( item ); stringlist_free( tokens ); - } + } free( buffer ); } diff --git a/ThirdParty/Ert/devel/libecl/src/fortio.c b/ThirdParty/Ert/devel/libecl/src/fortio.c index cece604fbd..fd27c6ca71 100644 --- a/ThirdParty/Ert/devel/libecl/src/fortio.c +++ b/ThirdParty/Ert/devel/libecl/src/fortio.c @@ -119,7 +119,7 @@ static bool __read_int(FILE * stream , int * value, bool endian_flip) { static bool fortio_is_fortran_stream__(FILE * stream , bool endian_flip) { const bool strict_checking = true; /* True: requires that *ALL* records in the file are fortran formatted */ - long init_pos = ftell(stream); + offset_type init_pos = util_ftell(stream); bool is_fortran_stream = false; int header , tail; bool cont; @@ -128,7 +128,7 @@ static bool fortio_is_fortran_stream__(FILE * stream , bool endian_flip) { cont = false; if (__read_int(stream , &header , endian_flip)) { if (header >= 0) { - if (fseek(stream , header , SEEK_CUR) == 0) { + if (util_fseek(stream , (offset_type) header , SEEK_CUR) == 0) { if (__read_int(stream , &tail , endian_flip)) { cont = true; /* @@ -155,7 +155,7 @@ static bool fortio_is_fortran_stream__(FILE * stream , bool endian_flip) { } } } while (cont); - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return is_fortran_stream; } @@ -423,7 +423,7 @@ void fortio_fclose(fortio_type *fortio) { bool fortio_is_fortio_file(fortio_type * fortio) { FILE * stream = fortio->stream; - int init_pos = ftell(stream); + offset_type init_pos = fortio_ftell(fortio); int elm_read; bool is_fortio_file = false; elm_read = fread(&fortio->active_header , sizeof(fortio->active_header) , 1 , fortio->stream); @@ -433,7 +433,7 @@ bool fortio_is_fortio_file(fortio_type * fortio) { if (fortio->endian_flip_header) util_endian_flip_vector(&fortio->active_header , sizeof fortio->active_header , 1); - if (fseek(stream , fortio->active_header , SEEK_CUR) == 0) { + if (fortio_fseek(fortio , (offset_type) fortio->active_header , SEEK_CUR) == 0) { if (fread(&trailer , sizeof(fortio->active_header) , 1 , fortio->stream) == 1) { if (fortio->endian_flip_header) util_endian_flip_vector(&trailer , sizeof trailer , 1); @@ -444,7 +444,7 @@ bool fortio_is_fortio_file(fortio_type * fortio) { } } - fseek(stream , init_pos , SEEK_SET); + fortio_fseek(fortio , init_pos , SEEK_SET); return is_fortio_file; } @@ -527,7 +527,7 @@ void fortio_fread_buffer(fortio_type * fortio, char * buffer , int buffer_size) int fortio_fskip_record(fortio_type *fortio) { int record_size = fortio_init_read(fortio); - fseek(fortio->stream , record_size , SEEK_CUR); + fortio_fseek(fortio , (offset_type) record_size , SEEK_CUR); fortio_complete_read(fortio); return record_size; } @@ -624,7 +624,7 @@ static fortio_status_type fortio_check_record( FILE * stream , bool endian_flip if (endian_flip) util_endian_flip_vector(&header , sizeof header , 1); - if (fseek( stream , header , SEEK_CUR ) != 0) + if (util_fseek( stream , (offset_type) header , SEEK_CUR ) != 0) /* The fseek() failed - i.e. the data section was not sufficiently long. */ status = FORTIO_MISSING_DATA; else { @@ -697,13 +697,13 @@ fortio_status_type fortio_check_file( const char * filename , bool endian_flip) } -long fortio_ftell( const fortio_type * fortio ) { - return ftell( fortio->stream ); +offset_type fortio_ftell( const fortio_type * fortio ) { + return util_ftell( fortio->stream ); } -int fortio_fseek( fortio_type * fortio , long offset , int whence) { - int fseek_return = fseek( fortio->stream , offset , whence ); +int fortio_fseek( fortio_type * fortio , offset_type offset , int whence) { + int fseek_return = util_fseek( fortio->stream , offset , whence ); /* if fseek_return != 0 -> util_abort(). */ @@ -723,6 +723,6 @@ FILE * fortio_get_FILE(const fortio_type *fortio) { return fortio- int fortio_get_record_size(const fortio_type *fortio) { return fortio->active_header; } //bool fortio_endian_flip(const fortio_type *fortio) { return fortio->endian_flip_header; } bool fortio_fmt_file(const fortio_type *fortio) { return fortio->fmt_file; } -void fortio_rewind(const fortio_type *fortio) { rewind(fortio->stream); } +void fortio_rewind(const fortio_type *fortio) { util_rewind(fortio->stream); } const char * fortio_filename_ref(const fortio_type * fortio) { return (const char *) fortio->filename; } diff --git a/ThirdParty/Ert/devel/libecl/src/nnc_index_list.c b/ThirdParty/Ert/devel/libecl/src/nnc_index_list.c new file mode 100644 index 0000000000..73c6401924 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/src/nnc_index_list.c @@ -0,0 +1,73 @@ + +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_index_list.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 NNC_INDEX_LIST_TYPE_ID 87225078 + + +struct nnc_index_list_struct { + UTIL_TYPE_ID_DECLARATION; + int_vector_type *index_list; + int lgr_nr; + bool sorted; +}; + + +UTIL_IS_INSTANCE_FUNCTION( nnc_index_list , NNC_INDEX_LIST_TYPE_ID ) + + + +nnc_index_list_type * nnc_index_list_alloc() { + nnc_index_list_type * nnc_index_list = util_malloc( sizeof * nnc_index_list ); + UTIL_TYPE_ID_INIT(nnc_index_list , NNC_INDEX_LIST_TYPE_ID); + nnc_index_list->index_list = int_vector_alloc(0 , 0 ); + nnc_index_list->sorted = true; + return nnc_index_list; +} + + +void nnc_index_list_free( nnc_index_list_type * nnc_index_list ) { + int_vector_free( nnc_index_list->index_list ); + free( nnc_index_list ); +} + + +const int_vector_type * nnc_index_list_get_list( nnc_index_list_type * nnc_index_list) { + if (!nnc_index_list->sorted) + int_vector_select_unique( nnc_index_list->index_list ); + + nnc_index_list->sorted = true; + return nnc_index_list->index_list; +} + + + +void nnc_index_list_add_index( nnc_index_list_type * nnc_index_list , int index) { + nnc_index_list->sorted = false; + int_vector_append( nnc_index_list->index_list , index ); +} diff --git a/ThirdParty/Ert/devel/libecl/src/nnc_info.c b/ThirdParty/Ert/devel/libecl/src/nnc_info.c new file mode 100644 index 0000000000..a6b745cbc6 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/src/nnc_info.c @@ -0,0 +1,128 @@ + +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_info.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 NNC_INFO_TYPE_ID 675415078 + + +struct nnc_info_struct { + UTIL_TYPE_ID_DECLARATION; + vector_type * lgr_list; /*List of int vector * for nnc connections for LGRs*/ + int_vector_type * lgr_index_map; /* A vector that maps LGR-nr to index into the LGR_list.*/ + int lgr_nr; /* The lgr_nr of the cell holding this nnc_info structure. */ +}; + + +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 ); + 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); + nnc_info->lgr_nr = lgr_nr; + return nnc_info; +} + +void nnc_info_free( nnc_info_type * nnc_info ) { + vector_free(nnc_info->lgr_list); + int_vector_free(nnc_info->lgr_index_map); + free (nnc_info); +} + +nnc_vector_type * nnc_info_get_vector( const nnc_info_type * nnc_info , int lgr_nr) { + int lgr_index = int_vector_safe_iget( nnc_info->lgr_index_map , lgr_nr ); + if (-1 == lgr_index) + return NULL; + else + return 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 ); +} + + +nnc_vector_type * nnc_info_get_self_vector( const nnc_info_type * nnc_info ) { + return nnc_info_get_vector( nnc_info , nnc_info->lgr_nr ); +} + + +static void nnc_info_assert_vector( nnc_info_type * nnc_info , int lgr_nr ) { + nnc_vector_type * nnc_vector = nnc_info_get_vector( nnc_info , lgr_nr); + if (!nnc_vector) { + nnc_vector = nnc_vector_alloc( lgr_nr ); + vector_append_owned_ref( nnc_info->lgr_list , nnc_vector , nnc_vector_free__ ); + int_vector_iset( nnc_info->lgr_index_map , lgr_nr , vector_get_size( nnc_info->lgr_list ) - 1 ); + } +} + + + + + +void nnc_info_add_nnc(nnc_info_type * nnc_info, int lgr_nr, int global_cell_number) { + nnc_info_assert_vector( nnc_info , lgr_nr ); + { + nnc_vector_type * nnc_vector = nnc_info_get_vector( nnc_info , lgr_nr ); + nnc_vector_add_nnc( nnc_vector , global_cell_number ); + } +} + + +const int_vector_type * nnc_info_get_index_list(const nnc_info_type * nnc_info, int lgr_nr) { + nnc_vector_type * nnc_vector = nnc_info_get_vector( nnc_info , lgr_nr ); + if (nnc_vector) + return nnc_vector_get_index_list( nnc_vector ); + else + return NULL; +} + + +const int_vector_type * nnc_info_iget_index_list(const nnc_info_type * nnc_info, int lgr_index) { + nnc_vector_type * nnc_vector = nnc_info_iget_vector( nnc_info , lgr_index ); + return nnc_vector_get_index_list( nnc_vector ); +} + + + +const int_vector_type * nnc_info_get_self_index_list(const nnc_info_type * nnc_info) { + return nnc_info_get_index_list( nnc_info , nnc_info->lgr_nr ); +} + + + +int nnc_info_get_lgr_nr( const nnc_info_type * nnc_info ) { + return nnc_info->lgr_nr; +} + + +int nnc_info_get_size( const nnc_info_type * nnc_info ) { + return vector_get_size( nnc_info->lgr_list ); +} diff --git a/ThirdParty/Ert/devel/libecl/src/nnc_vector.c b/ThirdParty/Ert/devel/libecl/src/nnc_vector.c new file mode 100644 index 0000000000..921ada21ab --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/src/nnc_vector.c @@ -0,0 +1,76 @@ + +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_vector.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 NNC_VECTOR_TYPE_ID 875615078 + + +struct nnc_vector_struct { + UTIL_TYPE_ID_DECLARATION; + int_vector_type *nnc_index_list; + int lgr_nr; +}; + + +UTIL_IS_INSTANCE_FUNCTION( nnc_vector , NNC_VECTOR_TYPE_ID ) +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 ); + UTIL_TYPE_ID_INIT(nnc_vector , NNC_VECTOR_TYPE_ID); + nnc_vector->nnc_index_list = int_vector_alloc(0, 0); + nnc_vector->lgr_nr = lgr_nr; + return nnc_vector; +} + +void nnc_vector_free( nnc_vector_type * nnc_vector ) { + int_vector_free( nnc_vector->nnc_index_list ); + free( nnc_vector ); +} + + +void nnc_vector_free__(void * arg) { + nnc_vector_type * nnc_vector = nnc_vector_safe_cast( arg ); + nnc_vector_free( nnc_vector ); +} + + +void nnc_vector_add_nnc(nnc_vector_type * nnc_vector, int global_cell_number) { + int_vector_append( nnc_vector->nnc_index_list , global_cell_number ); +} + + +const int_vector_type * nnc_vector_get_index_list(const nnc_vector_type * nnc_vector) { + return nnc_vector->nnc_index_list; +} + + +int nnc_vector_get_lgr_nr( const nnc_vector_type * nnc_vector ) { + return nnc_vector->lgr_nr; +} diff --git a/ThirdParty/Ert/devel/libecl/src/smspec_node.c b/ThirdParty/Ert/devel/libecl/src/smspec_node.c index 20b0f70ce5..1c85b371be 100644 --- a/ThirdParty/Ert/devel/libecl/src/smspec_node.c +++ b/ThirdParty/Ert/devel/libecl/src/smspec_node.c @@ -53,7 +53,7 @@ struct smspec_node_struct { UTIL_TYPE_ID_DECLARATION; char * gen_key1; /* The main composite key, i.e. WWCT:OP3 for this element. */ - char * gen_key2; /* Some of the ijk based elements will have both a xxx:i,j,k and a xxx:num key. Mostly NULL. */ + char * gen_key2; /* Some of the ijk based elements will have both a xxx:i,j,k and a xxx:num key. Some of the region_2_region elements will have both a xxx:num and a xxx:r2-r2 key. Mostly NULL. */ ecl_smspec_var_type var_type; /* The variable type */ char * wgname; /* The value of the WGNAMES vector for this element. */ char * keyword; /* The value of the KEYWORDS vector for this elements. */ @@ -89,6 +89,8 @@ struct smspec_node_struct { #define ECL_SUM_KEYFMT_GROUP "%s%s%s" #define ECL_SUM_KEYFMT_WELL "%s%s%s" #define ECL_SUM_KEYFMT_REGION "%s%s%d" +#define ECL_SUM_KEYFMT_REGION_2_REGION_R1R2 "%s%s%d-%d" +#define ECL_SUM_KEYFMT_REGION_2_REGION_NUM "%s%s%d" #define ECL_SUM_KEYFMT_SEGMENT "%s%s%s%s%d" #define ECL_SUM_KEYFMT_LOCAL_WELL "%s%s%s%s%s" @@ -119,6 +121,23 @@ char * smspec_alloc_region_key( const char * join_string , const char * keyword num ); } +char * smspec_alloc_region_2_region_r1r2_key( const char * join_string , const char * keyword , int r1, int r2) { + return util_alloc_sprintf(ECL_SUM_KEYFMT_REGION_2_REGION_R1R2, + keyword, + join_string, + r1, + r2); +} + +char * smspec_alloc_region_2_region_num_key( const char * join_string , const char * keyword , int num) { + return util_alloc_sprintf(ECL_SUM_KEYFMT_REGION_2_REGION_NUM, + keyword , + join_string , + num); +} + + + char * smspec_alloc_block_ijk_key( const char * join_string , const char * keyword , int i , int j , int k) { return util_alloc_sprintf(ECL_SUM_KEYFMT_BLOCK_IJK , keyword, @@ -308,10 +327,11 @@ static void smspec_node_set_flags( smspec_node_type * smspec_node) { file. */ { - if (smspec_node->var_type == ECL_SMSPEC_COMPLETION_VAR || - smspec_node->var_type == ECL_SMSPEC_SEGMENT_VAR || - smspec_node->var_type == ECL_SMSPEC_REGION_VAR || - smspec_node->var_type == ECL_SMSPEC_BLOCK_VAR || + if (smspec_node->var_type == ECL_SMSPEC_COMPLETION_VAR || + smspec_node->var_type == ECL_SMSPEC_SEGMENT_VAR || + smspec_node->var_type == ECL_SMSPEC_REGION_VAR || + smspec_node->var_type == ECL_SMSPEC_REGION_2_REGION_VAR || + smspec_node->var_type == ECL_SMSPEC_BLOCK_VAR || smspec_node->var_type == ECL_SMSPEC_AQUIFER_VAR) smspec_node->need_nums = true; else @@ -354,7 +374,7 @@ smspec_node_type * smspec_node_alloc_new(int params_index, float default_value) node->keyword = NULL; node->lgr_name = NULL; node->lgr_ijk = NULL; - + smspec_node_set_invalid_flags( node ); return node; // This is NOT usable } @@ -446,9 +466,18 @@ static void smspec_node_set_gen_keys( smspec_node_type * smspec_node , const cha // KEYWORD:NUM smspec_node->gen_key1 = smspec_alloc_region_key( key_join_string , smspec_node->keyword , smspec_node->num); break; - case(ECL_SMSPEC_SEGMENT_VAR): - // KEYWORD:WGNAME:NUM - smspec_node->gen_key1 = smspec_alloc_segment_key( key_join_string , smspec_node->keyword , smspec_node->wgname , smspec_node->num); + case (ECL_SMSPEC_SEGMENT_VAR): + // KEYWORD:WGNAME:NUM + smspec_node->gen_key1 = smspec_alloc_segment_key( key_join_string , smspec_node->keyword , smspec_node->wgname , smspec_node->num); + break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + // KEYWORDS:RXF:NUM and RXF:R1-R2 + smspec_node->gen_key1 = smspec_alloc_region_2_region_num_key( key_join_string , smspec_node->keyword , smspec_node->num); + { + int r1 = smspec_node->num % 32768; + int r2 = ((smspec_node->num-r1) / 32768)-10; + smspec_node->gen_key2 = smspec_alloc_region_2_region_r1r2_key( key_join_string , smspec_node->keyword , r1, r2); + } break; case(ECL_SMSPEC_MISC_VAR): // KEYWORD @@ -549,7 +578,7 @@ bool smspec_node_init( smspec_node_type * smspec_node, initOK = false; break; case(ECL_SMSPEC_SEGMENT_VAR): - if (wgnameOK) { + if (wgnameOK && num >= 0) { smspec_node_set_wgname( smspec_node , wgname ); smspec_node_set_num( smspec_node , grid_dims , num ); } else @@ -563,6 +592,10 @@ bool smspec_node_init( smspec_node_type * smspec_node, /* Region variable : NUM */ smspec_node_set_num( smspec_node , grid_dims , num ); break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + /* Region 2 region variable : NUM */ + smspec_node_set_num( smspec_node , grid_dims , num ); + break; case(ECL_SMSPEC_BLOCK_VAR): /* A block variable : NUM*/ smspec_node_set_num( smspec_node , grid_dims , num ); diff --git a/ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt index 42c8765bf9..402ccc319a 100644 --- a/ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt @@ -1,123 +1,11 @@ -add_executable( ecl_coarse_test ecl_coarse_test.c ) -target_link_libraries( ecl_coarse_test ecl ) -add_test( ecl_coarse_test ${EXECUTABLE_OUTPUT_PATH}/ecl_coarse_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 ) +if (BUILD_TESTS) + include( tests.cmake ) +endif() +# The ecl_win64 application is not built as a proper test integrated +# into the CTEST system. Should be invoked manually on Windows. +if (ERT_WINDOWS) + add_executable( ecl_lfs ecl_lfs.c ) + target_link_libraries( ecl_lfs ecl ert_util ) +endif() -add_executable( ecl_restart_test ecl_restart_test.c ) -target_link_libraries( ecl_restart_test ecl ) -add_test( ecl_restart_test ${EXECUTABLE_OUTPUT_PATH}/ecl_restart_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ) - - -add_executable( ecl_grid_lgr_name ecl_grid_lgr_name.c ) -target_link_libraries( ecl_grid_lgr_name ecl ) -set_target_properties( ecl_grid_lgr_name PROPERTIES COMPILE_FLAGS "-Werror") -add_test( ecl_grid_lgr_name ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_lgr_name ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID) - -add_executable( ecl_region ecl_region.c ) -target_link_libraries( ecl_region ecl ) -add_test( ecl_region ${EXECUTABLE_OUTPUT_PATH}/ecl_region ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) - - -add_executable( ecl_grid_case ecl_grid_case.c ) -target_link_libraries( ecl_grid_case ecl ) -add_test( ecl_grid_case ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_case ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) - - -add_executable( ecl_lgr_test ecl_lgr_test.c ) -target_link_libraries( ecl_lgr_test ecl ) -add_test( ecl_lgr_test1 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID) -add_test( ecl_lgr_test2 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.GRID) -add_test( ecl_lgr_test3 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID ) - - -add_executable( ecl_grid_simple ecl_grid_simple.c ) -target_link_libraries( ecl_grid_simple ecl ) -add_test( ecl_grid_simple ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_simple ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) - - -add_executable( ecl_grid_dims ecl_grid_dims.c ) -target_link_libraries( ecl_grid_dims ecl ) - -add_test( ecl_grid_dims0 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ) -add_test( ecl_grid_dims1 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT ) -add_test( ecl_grid_dims2 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT) -add_test( ecl_grid_dims3 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) -add_test( ecl_grid_dims4 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ) -add_test( ecl_grid_dims5 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID - ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.INIT ) - - - - - -add_executable( ecl_kw_grdecl ecl_kw_grdecl.c ) -target_link_libraries( ecl_kw_grdecl ecl ) -add_test( ecl_kw_grdecl ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_grdecl ) - -add_executable( ecl_kw_equal ecl_kw_equal.c ) -target_link_libraries( ecl_kw_equal ecl ) -add_test( ecl_kw_equal ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_equal ) - - -add_executable( ecl_dualp ecl_dualp.c ) -target_link_libraries( ecl_dualp ecl ) -add_test( ecl_dualp ${EXECUTABLE_OUTPUT_PATH}/ecl_dualp ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 ) - -add_executable( ecl_util_month_range ecl_util_month_range.c ) -target_link_libraries( ecl_util_month_range ecl ) -add_test( ecl_util_month_range ${EXECUTABLE_OUTPUT_PATH}/ecl_util_month_range ) - -add_executable( ecl_sum_test ecl_sum_test.c ) -target_link_libraries( ecl_sum_test ecl ) -add_test( ecl_sum_test ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) - -add_executable( ecl_fortio ecl_fortio.c ) -target_link_libraries( ecl_fortio ecl ) -add_test( ecl_fortio ${EXECUTABLE_OUTPUT_PATH}/ecl_fortio ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ) - -add_executable( ecl_file ecl_file.c ) -target_link_libraries( ecl_file ecl ) -add_test( ecl_file ${EXECUTABLE_OUTPUT_PATH}/ecl_file ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ECLIPSE.UNRST) - -add_executable( ecl_fmt ecl_fmt.c ) -target_link_libraries( ecl_fmt ecl ) -add_test( ecl_fmt ${EXECUTABLE_OUTPUT_PATH}/ecl_fmt ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.DATA) - - -add_executable( ecl_rsthead ecl_rsthead.c ) -target_link_libraries( ecl_rsthead ecl ) -add_test( ecl_rsthead ${EXECUTABLE_OUTPUT_PATH}/ecl_rsthead ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST - ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUALPORO.X0005 ) - -add_executable( ecl_rft ecl_rft.c ) -target_link_libraries( ecl_rft ecl ) -add_test( ecl_rft_rft ${EXECUTABLE_OUTPUT_PATH}/ecl_rft ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT RFT) -add_test( ecl_rft_plt ${EXECUTABLE_OUTPUT_PATH}/ecl_rft ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/RFT/TEST1_1A.RFT PLT) - -add_executable( ecl_rft_cell ecl_rft_cell.c ) -target_link_libraries( ecl_rft_cell ecl ) -add_test( ecl_rft_cell ${EXECUTABLE_OUTPUT_PATH}/ecl_rft_cell ) - - -set_property( TEST ecl_fmt PROPERTY LABELS StatoilData ) -set_property( TEST ecl_coarse_test PROPERTY LABELS StatoilData ) -set_property( TEST ecl_restart_test PROPERTY LABELS StatoilData ) -set_property( TEST ecl_lgr_test1 PROPERTY LABELS StatoilData ) -set_property( TEST ecl_lgr_test2 PROPERTY LABELS StatoilData ) -set_property( TEST ecl_lgr_test3 PROPERTY LABELS StatoilData ) -set_property( TEST ecl_grid_lgr_name PROPERTY LABELS StatoilData ) -set_property( TEST ecl_grid_simple PROPERTY LABELS StatoilData ) -set_property( TEST ecl_dualp PROPERTY LABELS StatoilData ) -set_property( TEST ecl_sum_test PROPERTY LABELS StatoilData ) -set_property( TEST ecl_fortio PROPERTY LABELS StatoilData) -set_property( TEST ecl_grid_dims1 PROPERTY LABELS StatoilData ) -set_property( TEST ecl_grid_dims2 PROPERTY LABELS StatoilData ) -set_property( TEST ecl_grid_dims3 PROPERTY LABELS StatoilData ) -set_property( TEST ecl_grid_dims4 PROPERTY LABELS StatoilData ) -set_property( TEST ecl_grid_dims5 PROPERTY LABELS StatoilData ) -set_property( TEST ecl_file PROPERTY LABELS StatoilData) -set_property( TEST ecl_rsthead PROPERTY LABELS StatoilData) -set_property( TEST ecl_region PROPERTY LABELS StatoilData) -set_property( TEST ecl_grid_case PROPERTY LABELS StatoilData) -set_property( TEST ecl_rft_rft PROPERTY LABELS StatoilData) -set_property( TEST ecl_rft_plt PROPERTY LABELS StatoilData) diff --git a/ThirdParty/Ert/devel/libecl/tests/data/num_cpu1 b/ThirdParty/Ert/devel/libecl/tests/data/num_cpu1 new file mode 100644 index 0000000000..0f2473552d --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/data/num_cpu1 @@ -0,0 +1,2 @@ +PARALLEL + 4 DISTRIBUTED/ diff --git a/ThirdParty/Ert/devel/libecl/tests/data/num_cpu2 b/ThirdParty/Ert/devel/libecl/tests/data/num_cpu2 new file mode 100644 index 0000000000..663a393104 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/data/num_cpu2 @@ -0,0 +1,2 @@ +PARALLEL +4 'DIST'/ diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_file.c b/ThirdParty/Ert/devel/libecl/tests/ecl_file.c index ef36d2f082..8a7abfa59d 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_file.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_file.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -103,9 +104,12 @@ void test_close_stream1(const char * src_file , const char * target_file ) { void test_writable(const char * src_file ) { - util_copy_file( src_file , "/tmp/ECL.UNRST" ); + test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable" , true); + char * fname = util_split_alloc_filename( src_file ); + + test_work_area_copy_file( work_area , src_file ); { - ecl_file_type * ecl_file = ecl_file_open( "/tmp/ECL.UNRST" , ECL_FILE_WRITABLE); + ecl_file_type * ecl_file = ecl_file_open( fname , ECL_FILE_WRITABLE); ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); ecl_kw_type * swat0 = ecl_kw_alloc_copy( swat ); test_assert_true( ecl_kw_equal( swat , swat0 )); @@ -114,26 +118,30 @@ void test_writable(const char * src_file ) { test_assert_true( ecl_file_writable( ecl_file )); ecl_file_close( ecl_file ); - ecl_file = ecl_file_open( "/tmp/ECL.UNRST" , 0); + ecl_file = ecl_file_open( fname , 0); swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 )); } - util_unlink_existing( "/tmp/ECL.UNRST" ); + test_work_area_free( work_area ); } int main( int argc , char ** argv) { - const char * src_file = argv[1]; - const char * filename = argv[2]; - char * target_file = util_alloc_filename("/tmp" , filename , NULL ); + const char * target_file = argv[2]; - test_flags( src_file ); - test_loadall(src_file , target_file ); - test_close_stream1( src_file , target_file ); - test_close_stream2( src_file , target_file ); - test_writable( src_file ); - util_unlink_existing( target_file ); - + { + test_work_area_type * work_area = test_work_area_alloc("ecl_file" , true); + + test_work_area_install_file( work_area , src_file ); + test_flags( src_file ); + test_loadall(src_file , target_file ); + + test_close_stream1( src_file , target_file); + test_close_stream2( src_file , target_file); + test_writable( src_file ); + + test_work_area_free( work_area ); + } exit(0); } diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c b/ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c index fafa15b40c..482915f4a3 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c @@ -20,21 +20,22 @@ #include #include +#include #include #include -void test_content( const char * src_file , bool fmt_file ) { - char * base_name , *path; - char * target_file; - bool fmt; - util_alloc_file_components( src_file , &path , &base_name , NULL); - target_file = util_alloc_filename( "/tmp" , base_name , NULL ); - util_copy_file( src_file , target_file); - - test_assert_true( ecl_util_fmt_file( target_file , &fmt )); - test_assert_bool_equal( fmt , fmt_file ); - unlink( target_file ); +void test_content( test_work_area_type * work_area , const char * src_file , bool fmt_file ) { + test_work_area_install_file( work_area , src_file ); + { + char * base_name; + bool fmt; + util_alloc_file_components( src_file , NULL , &base_name , NULL); + util_copy_file( src_file , base_name ); + + test_assert_true( ecl_util_fmt_file( base_name , &fmt )); + test_assert_bool_equal( fmt , fmt_file ); + } } @@ -43,11 +44,11 @@ void test_content( const char * src_file , bool fmt_file ) { void test_small( ) { bool fmt; - FILE * stream = util_fopen("/tmp/small.txt" , "w"); + FILE * stream = util_fopen("small.txt" , "w"); fprintf(stream , "Some bytes\n"); fclose( stream ); - test_assert_false( ecl_util_fmt_file( "/tmp/small.txt" , &fmt )); + test_assert_false( ecl_util_fmt_file( "small.txt" , &fmt )); } @@ -55,29 +56,32 @@ void test_small( ) { int main(int argc , char ** argv) { - const char * binary_file = argv[1]; - const char * text_file = argv[2]; + test_work_area_type * work_area = test_work_area_alloc( "ecl_fmt" , true); + { + const char * binary_file = argv[1]; + const char * text_file = argv[2]; - bool fmt_file; + bool fmt_file; - test_assert_true( ecl_util_fmt_file( binary_file , &fmt_file )); - test_assert_false( fmt_file ); + test_assert_true( ecl_util_fmt_file( binary_file , &fmt_file )); + test_assert_false( fmt_file ); - test_assert_true( ecl_util_fmt_file( text_file , &fmt_file )); - test_assert_true( fmt_file ); + test_assert_true( ecl_util_fmt_file( text_file , &fmt_file )); + test_assert_true( fmt_file ); - test_assert_true( ecl_util_fmt_file( "TEST.EGRID" , &fmt_file )); - test_assert_false( fmt_file ); + test_assert_true( ecl_util_fmt_file( "TEST.EGRID" , &fmt_file )); + test_assert_false( fmt_file ); - test_assert_true( ecl_util_fmt_file( "TEST.FEGRID" , &fmt_file )); - test_assert_true( fmt_file ); + test_assert_true( ecl_util_fmt_file( "TEST.FEGRID" , &fmt_file )); + test_assert_true( fmt_file ); - test_assert_false(ecl_util_fmt_file( "TEST_DOES_NOT_EXIST" , &fmt_file )); - - test_content( binary_file , false ); - test_content( text_file , true ); - test_small( ); + test_assert_false(ecl_util_fmt_file( "TEST_DOES_NOT_EXIST" , &fmt_file )); + test_content( work_area , binary_file , false ); + test_content( work_area , text_file , true ); + test_small( ); + } + test_work_area_free( work_area ); exit(0); } diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c b/ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c index 4dc9f76a7c..a7eb31ad99 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -79,10 +80,15 @@ int main( int argc , char ** argv) { test_existing_read( file ); test_not_existing_read( ); - test_write( "/tmp/file.x" , true ); - test_write( "/tmp/path/does/not/exist" , false ); test_open_close_read( file ); test_wrapper( file ); + test_write( "/tmp/path/does/not/exist" , false ); + { + test_work_area_type * work_area = test_work_area_alloc("ecl_fortio.write" , true ); + util_make_path("path"); + test_write( "path/file.x" , true ); + test_work_area_free( work_area ); + } exit(0); } diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_get_num_cpu_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_get_num_cpu_test.c new file mode 100644 index 0000000000..92d18884c4 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_get_num_cpu_test.c @@ -0,0 +1,33 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'ecl_get_num_cpu_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 + + +int main(int argc , char ** argv) { + const char * filename1 = argv[1]; + const char * filename2 = argv[2]; + int num_cpu = 4; + test_assert_int_equal(ecl_util_get_num_cpu(filename1), num_cpu); + test_assert_int_equal(ecl_util_get_num_cpu(filename2), num_cpu); + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_kw_grdecl.c b/ThirdParty/Ert/devel/libecl/tests/ecl_kw_grdecl.c index 5b68d278eb..a18d168131 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_kw_grdecl.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_kw_grdecl.c @@ -20,6 +20,8 @@ #include #include +#include + #include int main(int argc , char ** argv) { @@ -30,6 +32,7 @@ int main(int argc , char ** argv) { ecl_kw_iset_int(ecl_kw , i , i ); { + test_work_area_type * work_area = test_work_area_alloc("ecl_kw_grdecl" , true); FILE * stream = util_fopen( "FILE.grdecl" , "w"); ecl_kw_fprintf_grdecl(ecl_kw , stream ); @@ -62,7 +65,7 @@ int main(int argc , char ** argv) { ecl_kw_free( ecl_kw2 ); } fclose( stream ); - + test_work_area_free( work_area ); } ecl_kw_free( ecl_kw ); diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_lfs.c b/ThirdParty/Ert/devel/libecl/tests/ecl_lfs.c new file mode 100644 index 0000000000..871b7bfa0a --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_lfs.c @@ -0,0 +1,91 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_win64.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) { + int num_kw = 1000; // Total file size should roughly exceed 2GB + int kw_size = 600000; + ecl_kw_type * kw = ecl_kw_alloc("KW" , kw_size , ECL_INT_TYPE ); + rng_type * rng = rng_alloc( MZRAN , INIT_DEFAULT ); + int i; + offset_type file_size; + for (i=0; i < kw_size; i++) + ecl_kw_iset_int( kw , i , rng_get_int( rng , 912732 )); + + { + fortio_type * fortio = fortio_open_writer( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP); + for (i = 0; i < num_kw; i++) { + printf("Writing keyword %d/%d to file:LARGE_FILE.UNRST \n",i+1 , num_kw ); + ecl_kw_fwrite( kw , fortio ); + } + fortio_fclose( fortio ); + } + + /*{ + fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP); + for (i = 0; i < num_kw - 1; i++) { + printf("SKipping keyword %d/%d from file:LARGE_FILE.UNRST \n",i+1 , num_kw ); + ecl_kw_fskip( fortio ); + } + { + ecl_kw_type * file_kw = ecl_kw_fread_alloc( fortio ); + if (ecl_kw_equal( kw , file_kw )) + printf("Keyword read back from file correctly :-) \n"); + else + printf("Fatal error - keyword different on return ...\n"); + ecl_kw_free( file_kw ); + } + fortio_fclose( fortio ); + } + */ + file_size = util_file_size( "LARGE_FILE.UNRST" ); + printf("File size: %lld \n",file_size); + { + fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP); + printf("Seeking to file end: "); + fortio_fseek( fortio , file_size , SEEK_SET); + fortio_fclose( fortio ); + printf("Seek OK \n"); + } + + + printf("Doing ecl_file_open(..)\n"); + { + ecl_file_type * file = ecl_file_open( "LARGE_FILE.UNRST" , 0); + ecl_kw_type * file_kw = ecl_file_iget_named_kw( file , "KW" , num_kw - 1); + if (ecl_kw_equal( kw , file_kw )) + printf("Keyword read back from file correctly :-) \n"); + else + printf("Fatal error - keyword different on return ...\n"); + ecl_file_close( file ); + } + + remove( "LARGE_FILE.UNRST" ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_lgr_name.c b/ThirdParty/Ert/devel/libecl/tests/ecl_lgr_name.c new file mode 100644 index 0000000000..6ce84cc4db --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_lgr_name.c @@ -0,0 +1,44 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_lgr_name.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 + + +int main( int argc , char ** argv) { + ecl_grid_type * grid = ecl_grid_alloc( argv[1] ); + + int num_lgr = ecl_grid_get_num_lgr( grid ); + int lgr_index; + for (lgr_index = 0; lgr_index < num_lgr; lgr_index++) { + ecl_grid_type * lgr_from_index = ecl_grid_iget_lgr( grid, lgr_index ); + int lgr_nr = ecl_grid_get_lgr_nr( lgr_from_index); + ecl_grid_type * lgr_from_nr = ecl_grid_get_lgr_from_lgr_nr( grid , lgr_nr); + + test_assert_ptr_equal( lgr_from_index , lgr_from_nr ); + + test_assert_string_equal( ecl_grid_get_lgr_name( grid , lgr_nr) , ecl_grid_iget_lgr_name( grid , lgr_index)); + printf("Grid[%d:%d] : %s \n",lgr_index , lgr_nr , ecl_grid_iget_lgr_name( grid , lgr_index )); + } + ecl_grid_free( grid ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list.c new file mode 100644 index 0000000000..64c60819af --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list.c @@ -0,0 +1,103 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_index_list.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 + + +void test_create() { + nnc_index_list_type * index_list = nnc_index_list_alloc(); + test_assert_true( nnc_index_list_is_instance( index_list )); + { + const int_vector_type * list = nnc_index_list_get_list( index_list ); + test_assert_int_equal( 0 , int_vector_size( list )); + } + nnc_index_list_free( index_list ); +} + + +void test_content() { + nnc_index_list_type * index_list = nnc_index_list_alloc(); + + nnc_index_list_add_index( index_list , 0 ); + nnc_index_list_add_index( index_list , 1 ); + nnc_index_list_add_index( index_list , 2 ); + nnc_index_list_add_index( index_list , 3 ); + + { + const int_vector_type * list = nnc_index_list_get_list( index_list ); + test_assert_int_equal( 4 , int_vector_size( list )); + + test_assert_int_equal( 0 , int_vector_iget( list , 0)); + test_assert_int_equal( 1 , int_vector_iget( list , 1)); + test_assert_int_equal( 2 , int_vector_iget( list , 2)); + test_assert_int_equal( 3 , int_vector_iget( list , 3)); + + } + nnc_index_list_free( index_list ); +} + + +void test_sort_unique() { + nnc_index_list_type * index_list = nnc_index_list_alloc(); + + nnc_index_list_add_index( index_list , 3 ); + nnc_index_list_add_index( index_list , 1 ); + nnc_index_list_add_index( index_list , 2 ); + nnc_index_list_add_index( index_list , 0 ); + + { + const int_vector_type * list = nnc_index_list_get_list( index_list ); + test_assert_int_equal( 4 , int_vector_size( list )); + + test_assert_int_equal( 0 , int_vector_iget( list , 0)); + test_assert_int_equal( 1 , int_vector_iget( list , 1)); + test_assert_int_equal( 2 , int_vector_iget( list , 2)); + test_assert_int_equal( 3 , int_vector_iget( list , 3)); + + } + nnc_index_list_add_index( index_list , 3 ); + nnc_index_list_add_index( index_list , 1 ); + nnc_index_list_add_index( index_list , 2 ); + nnc_index_list_add_index( index_list , 0 ); + { + const int_vector_type * list = nnc_index_list_get_list( index_list ); + test_assert_int_equal( 4 , int_vector_size( list )); + + test_assert_int_equal( 0 , int_vector_iget( list , 0)); + test_assert_int_equal( 1 , int_vector_iget( list , 1)); + test_assert_int_equal( 2 , int_vector_iget( list , 2)); + test_assert_int_equal( 3 , int_vector_iget( list , 3)); + + } + nnc_index_list_free( index_list ); +} + + + +int main( int argc , char ** argv) { + test_create(); + test_content(); + test_sort_unique(); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list_grid.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list_grid.c new file mode 100644 index 0000000000..65645a5f2a --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list_grid.c @@ -0,0 +1,60 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_index_list_grid.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 + + + +int main( int argc , char ** argv) { + const char * egrid_file = argv[1]; + + ecl_grid_type * grid = ecl_grid_alloc( egrid_file ); + ecl_file_type * gfile = ecl_file_open( egrid_file , 0 ); + const ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw( gfile , "NNC1" ,0 ); + const ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw( gfile , "NNC2" ,0 ); + const int_vector_type * index_list = ecl_grid_get_nnc_index_list( grid ); + + { + int_vector_type * nnc = int_vector_alloc(0,0); + + int_vector_set_many( nnc , 0 , ecl_kw_get_ptr( nnc1_kw ) , ecl_kw_get_size( nnc1_kw )); + int_vector_append_many( nnc , ecl_kw_get_ptr( nnc2_kw ) , ecl_kw_get_size( nnc2_kw )); + int_vector_select_unique( nnc ); + test_assert_int_equal( int_vector_size( index_list ) , int_vector_size( nnc )); + + { + int i; + for (i=0; i < int_vector_size( nnc ); i++) + test_assert_int_equal( int_vector_iget( nnc , i ) - 1 , int_vector_iget(index_list , i )); + } + int_vector_free( nnc ); + } + + ecl_file_close( gfile ); + ecl_grid_free( grid ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_info_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_info_test.c new file mode 100644 index 0000000000..af5acb5456 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_info_test.c @@ -0,0 +1,66 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_info_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 +#include +#include + + +int main(int argc , char ** argv) { + int lgr_nr = 77; + nnc_info_type * nnc_info = nnc_info_alloc(lgr_nr); + + test_assert_int_equal( lgr_nr , nnc_info_get_lgr_nr( nnc_info )); + test_assert_true(nnc_info_is_instance(nnc_info)); + test_assert_not_NULL(nnc_info); + + nnc_info_add_nnc(nnc_info, 1, 110); + nnc_info_add_nnc(nnc_info, 1, 111); + + const nnc_vector_type * nnc_vector = nnc_info_get_vector( nnc_info , 1); + const int_vector_type * nnc_cells = nnc_info_get_index_list(nnc_info, 1); + test_assert_int_equal(int_vector_size(nnc_cells), 2); + test_assert_ptr_equal( nnc_cells , nnc_vector_get_index_list( nnc_vector )); + + + const nnc_vector_type * nnc_vector_null = nnc_info_get_vector( nnc_info , 2); + const int_vector_type * nnc_cells_null = nnc_info_get_index_list(nnc_info, 2); + test_assert_NULL(nnc_cells_null); + test_assert_NULL(nnc_vector_null); + + const nnc_vector_type * nnc_vector_self = nnc_info_get_self_vector( nnc_info ); + const nnc_vector_type * nnc_vector_77 = nnc_info_get_vector( nnc_info , lgr_nr ); + test_assert_ptr_equal( nnc_vector_77 , nnc_vector_self ); + + const int_vector_type * nnc_cells_77 = nnc_info_get_index_list(nnc_info, lgr_nr); + const int_vector_type * nnc_cells_self = nnc_info_get_self_index_list(nnc_info); + test_assert_ptr_equal( nnc_cells_77 , nnc_cells_self ); + + + test_assert_int_equal( 1 , nnc_info_get_size( nnc_info )); + test_assert_ptr_equal( nnc_info_get_vector( nnc_info , 1 ) , nnc_info_iget_vector( nnc_info , 0 )); + nnc_info_free(nnc_info); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_test.c new file mode 100644 index 0000000000..ed8d8e53aa --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_test.c @@ -0,0 +1,341 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_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 +#include + + +void test_nnc_global_grid( const char * grid_filename ) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + + const int data[] = {2675, 5235, 7795, 10355, 12915, 15475, 18035, 20595, 23155, 25715, 28275, 30835, 33395}; + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 114); + test_assert_not_NULL( nnc_info ); + test_assert_int_equal( ecl_grid_get_lgr_nr( ecl_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + ecl_grid_free(ecl_grid); +} + +void test_nnc_dual_poro(const char * grid_filename ) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + ecl_grid_free(ecl_grid); +} + +void test_nnc_lgr( const char * grid_filename ) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + + //Global grid + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 125132); + test_assert_not_NULL( nnc_info ); + test_assert_int_equal( ecl_grid_get_lgr_nr( ecl_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), 1); + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, 0), 151053); + + //LGR + const int data[] = {126394, 126305}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0); + test_assert_not_NULL( lgr_grid ); + + const nnc_info_type * lgr_nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 2017-1); + test_assert_not_NULL( lgr_nnc_info ); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( lgr_nnc_info )); + + const int_vector_type * lgr_nnc_cell_number_vec = nnc_info_get_index_list(lgr_nnc_info, 0); + test_assert_not_NULL(lgr_nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(lgr_nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(lgr_nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(lgr_nnc_cell_number_vec, i), data[i]); + + ecl_grid_free(ecl_grid); +} + + + +void test_nnc_multiple_lgr( const char * grid_filename) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + + { + //Global grid, check NNC for cell with global index 736 + int data[] = {11957, 20336, 3528, 6321, 9114, 11907, 20286}; + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 736); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( ecl_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) { + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + } + + //Check grid name + test_assert_string_equal(ecl_grid_get_name(ecl_grid), grid_filename); + } + + { + //Global grid, check NNC for cell with global index 138291 + int data[] = {141035, 143828, 141085, 143878}; + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 138291); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( ecl_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) { + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + } + } + + + { + //LGR nr 1, cell global index 0: check NNCs to main grid + int data[] = {29012, 26220}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0); + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 0); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i = 0; + for (; i < int_vector_size(nnc_cell_number_vec); ++i) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + //Check name + test_assert_string_equal(ecl_grid_get_name(lgr_grid), "LG006023"); + } + + + { + //LGR nr 1, cell global index 0: check NNCs to grid with lgr nr 20 + int data[] = {12}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0); + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 0); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 20); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i = 0; + for (; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + } + + + + + { + //LGR nr 3, check NNC for cell with global index 8 + int data[] = {20681, 23474, 26267, 37440}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 2); + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 8); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + //Check LGR name + test_assert_string_equal(ecl_grid_get_name(lgr_grid), "LG005024"); + } + + { + //LGR nr 99, check NNC for cell with global index 736 + int data[] = {126671, 79142}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 98-1); //Subtract 1: LGR nr 98 is not present in the test file. LGRs are numbered 1-97 and 99-110 in test file. + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 736); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + //Check LGR name + test_assert_string_equal(ecl_grid_get_name(lgr_grid), "LG008021"); + } + + { + //LGR nr 110, cell with global index 271: Check NNCs to global grid + int data[] = {20191, 22983}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 109-1); //Subtract 1: LGR nr 98 is not present in the test file. LGRs are numbered 1-97 and 99-110 in test file. + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 271); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + //Check LGR name + test_assert_string_equal(ecl_grid_get_name(lgr_grid), "LG003014"); + } + + { + //LGR nr 110, cell with global index 271: Check NNCs to lgr nr 109 + int data[] = {275}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 109-1); //Subtract 1: LGR nr 98 is not present in the test file. LGRs are numbered 1-97 and 99-110 in test file. + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 271); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 109); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + } + + + { + //Test global versus ijk indexing + const nnc_info_type * nnc_info1 = ecl_grid_get_cell_nnc_info1(ecl_grid, 736); + test_assert_not_NULL(nnc_info1); + + int i = 0; + int j = 0; + int k = 0; + + ecl_grid_get_ijk1(ecl_grid, 736, &i, &j, &k); + + const nnc_info_type * nnc_info2 = ecl_grid_get_cell_nnc_info3(ecl_grid, i, j, k); + test_assert_not_NULL(nnc_info2); + + test_assert_ptr_equal(nnc_info1, nnc_info2); + } + + ecl_grid_free(ecl_grid); +} + + +void test_nnc_amalgamated_lgrs(const char * grid_filename) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + + + //Get the NNC info for cell with global index 0 in LGR nr 1 + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0); + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 0); + test_assert_not_NULL(nnc_info); + + //Get the connections that this cell has to LGR 20 + const int_vector_type * nnc_lgr_20 = nnc_info_get_index_list(nnc_info, 20); + test_assert_not_NULL(nnc_lgr_20); + + test_assert_int_equal(int_vector_size(nnc_lgr_20), 1); + test_assert_int_equal(int_vector_iget(nnc_lgr_20, 0), 12); + + ecl_grid_free(ecl_grid); +} + + + + +int main(int argc , char ** argv) { + const char * EGRID_file1 = argv[1]; + const char * EGRID_file2 = argv[2]; + const char * EGRID_file3 = argv[3]; + const char * EGRID_file4 = argv[4]; + + test_nnc_global_grid( EGRID_file1 ); + test_nnc_lgr( EGRID_file2 ); + test_nnc_multiple_lgr( EGRID_file3 ); + test_nnc_amalgamated_lgrs(EGRID_file3); + test_nnc_dual_poro( EGRID_file4 ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_vector.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_vector.c new file mode 100644 index 0000000000..d12cbeda03 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_vector.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_vector.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 + + +int main(int argc , char ** argv) { + int lgr_nr = 100; + nnc_vector_type * vector = nnc_vector_alloc( lgr_nr ); + + test_assert_true( nnc_vector_is_instance( vector )); + test_assert_int_equal( lgr_nr , nnc_vector_get_lgr_nr( vector )); + + nnc_vector_add_nnc( vector , 100 ); + nnc_vector_add_nnc( vector , 200 ); + nnc_vector_add_nnc( vector , 300 ); + + { + const int_vector_type * index_list = nnc_vector_get_index_list( vector ); + + test_assert_int_equal( 3 , int_vector_size( index_list )); + test_assert_int_equal( 100 , int_vector_iget( index_list , 0 )); + test_assert_int_equal( 200 , int_vector_iget( index_list , 1 )); + test_assert_int_equal( 300 , int_vector_iget( index_list , 2 )); + } + + nnc_vector_free( vector ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_region2region_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_region2region_test.c new file mode 100644 index 0000000000..98694d278b --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_region2region_test.c @@ -0,0 +1,70 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'ecl_region2region.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 has_r2r_key(const ecl_sum_type* ecl_sum) { + test_assert_true(ecl_sum_has_key( ecl_sum , "RGF:393217" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RGF:1-2" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "ROF:524291" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RWF:393222" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RWF:6-2" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "ROF:3-6" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RNLF:458753" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RNLF:1-4" )); +} + +void get_unit(const ecl_sum_type* ecl_sum) { + test_assert_string_equal(ecl_sum_get_unit( ecl_sum , "RGF:1-2" ), "GFLOW"); + test_assert_string_equal(ecl_sum_get_unit( ecl_sum , "ROF:3-6" ), "OFLOW"); + test_assert_string_equal(ecl_sum_get_unit( ecl_sum , "RWF:6-2" ), "WFLOW"); + test_assert_string_equal(ecl_sum_get_unit( ecl_sum , "RNLF:1-4" ), "NLFLOW"); +} + +void get_var_params_index(const ecl_sum_type* ecl_sum) { + test_assert_int_equal(ecl_sum_get_general_var_params_index( ecl_sum , "RGF:1-2"), 21917); + test_assert_int_equal(ecl_sum_get_general_var_params_index( ecl_sum , "ROF:3-6"), 21918); + test_assert_int_equal(ecl_sum_get_general_var_params_index( ecl_sum, "RWF:6-2"), 21919); + test_assert_int_equal(ecl_sum_get_general_var_params_index( ecl_sum, "RNLF:1-4"), 21920); +} + +int main(int argc , char ** argv) { + + const char * headerfile = argv[1]; + + ecl_sum_type * ecl_sum = ecl_sum_fread_alloc_case( headerfile , ":"); + + if (ecl_sum) { + has_r2r_key(ecl_sum); + get_unit(ecl_sum); + get_var_params_index(ecl_sum); + } + else + test_error_exit("ecl_region2region_test: Test file not read correctly"); + + + if (ecl_sum) + ecl_sum_free( ecl_sum ); + + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_rft.c b/ThirdParty/Ert/devel/libecl/tests/ecl_rft.c index 88c0bad336..5a71d86bc5 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_rft.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_rft.c @@ -36,10 +36,10 @@ void test_rft( const char * rft_file ) { test_assert_int_equal( 14 , ecl_rft_node_get_size( rft_node )); test_assert_false( ecl_rft_node_is_MSW( rft_node )); - test_assert_double_equal( 259.146 , ecl_rft_node_iget_pressure( rft_node , 0 )); - test_assert_double_equal( 0.0580598 , ecl_rft_node_iget_soil( rft_node , 0 )); - test_assert_double_equal( 0.940477 , ecl_rft_node_iget_swat( rft_node , 0 )); - test_assert_double_equal( 0.00146271 , ecl_rft_node_iget_sgas( rft_node , 0 )); + test_assert_double_equal( 260.6111 , ecl_rft_node_iget_pressure( rft_node , 0 )); + test_assert_double_equal( 0.0581993 , ecl_rft_node_iget_soil( rft_node , 0 )); + test_assert_double_equal( 0.9405648 , ecl_rft_node_iget_swat( rft_node , 0 )); + test_assert_double_equal( 0.00123579 , ecl_rft_node_iget_sgas( rft_node , 0 )); { int i,j,k; @@ -67,9 +67,26 @@ void test_rft( const char * rft_file ) { } -// Have no such case yet ... void test_plt_msw( const char * plt_file ) { + ecl_rft_file_type * plt = ecl_rft_file_alloc( plt_file ); + ecl_rft_node_type * plt_node = ecl_rft_file_iget_node( plt , 11 ); + test_assert_true( ecl_rft_node_is_PLT( plt_node )); + test_assert_true( ecl_rft_node_is_MSW( plt_node )); + test_assert_int_equal( 22 , ecl_rft_node_get_size( plt_node )); + ecl_rft_node_inplace_sort_cells( plt_node ); + { + int i; + for (i=1; i < ecl_rft_node_get_size( plt_node ); i++) { + const ecl_rft_cell_type * prev_cell = ecl_rft_node_iget_cell( plt_node , i - 1); + const ecl_rft_cell_type * this_cell = ecl_rft_node_iget_cell( plt_node , i ); + + test_assert_true( ecl_rft_cell_get_connection_start( prev_cell ) < ecl_rft_cell_get_connection_start( this_cell )); + test_assert_true( ecl_rft_cell_get_connection_end( prev_cell ) < ecl_rft_cell_get_connection_end( this_cell )); + } + } + + ecl_rft_file_free( plt ); } diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_rft_cell.c b/ThirdParty/Ert/devel/libecl/tests/ecl_rft_cell.c index 0c37cf48d0..19328a7087 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_rft_cell.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_rft_cell.c @@ -68,6 +68,7 @@ void test_rft_cell() { test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_wrat( cell )); test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_flowrate( cell )); test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_connection_start( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_connection_end( cell )); test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_oil_flowrate( cell )); test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_gas_flowrate( cell )); test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_water_flowrate( cell )); @@ -97,11 +98,12 @@ void test_plt_cell() { const double wrat = 0.45; const double flowrate = 100.0; const double connection_start = 891; + const double connection_end = 979; const double oil_flowrate = 0.891; const double gas_flowrate = 7771; const double water_flowrate = 77614; - ecl_rft_cell_type * cell = ecl_rft_cell_alloc_PLT(i,j,k,depth,pressure,orat,grat,wrat,connection_start,flowrate,oil_flowrate , gas_flowrate , water_flowrate); + ecl_rft_cell_type * cell = ecl_rft_cell_alloc_PLT(i,j,k,depth,pressure,orat,grat,wrat,connection_start,connection_end, flowrate,oil_flowrate , gas_flowrate , water_flowrate); test_assert_int_equal( i , ecl_rft_cell_get_i( cell )); test_assert_int_equal( j , ecl_rft_cell_get_j( cell )); @@ -122,6 +124,7 @@ void test_plt_cell() { test_assert_double_equal( grat , ecl_rft_cell_get_grat( cell )); test_assert_double_equal( wrat , ecl_rft_cell_get_wrat( cell )); test_assert_double_equal( connection_start, ecl_rft_cell_get_connection_start( cell )); + test_assert_double_equal( connection_end, ecl_rft_cell_get_connection_end( cell )); test_assert_double_equal(flowrate , ecl_rft_cell_get_flowrate( cell )); test_assert_double_equal(oil_flowrate , ecl_rft_cell_get_oil_flowrate( cell )); diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_compatible.c b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_compatible.c new file mode 100644 index 0000000000..e76932c528 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_compatible.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_sum_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) { + const char * case1 = argv[1]; + const char * case2 = argv[2]; + const char * compatible_string = argv[3]; + bool compatible; + ecl_sum_type * ecl_sum1 = ecl_sum_fread_alloc_case( case1 , ":"); + ecl_sum_type * ecl_sum2 = ecl_sum_fread_alloc_case( case2 , ":"); + + test_assert_true( ecl_sum_is_instance( ecl_sum1 )); + test_assert_true( ecl_sum_is_instance( ecl_sum2 )); + test_assert_true( ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum1) ); + test_assert_true( util_sscanf_bool( compatible_string , &compatible )); + + test_assert_true( ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum1) ); + test_assert_true( ecl_sum_report_step_compatible( ecl_sum2 , ecl_sum2) ); + test_assert_bool_equal( compatible , ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum2 )); + + ecl_sum_free( ecl_sum1 ); + ecl_sum_free( ecl_sum2 ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_equal.c b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_equal.c new file mode 100644 index 0000000000..86465c7bf5 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_equal.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_sum_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) { + const char * case1 = argv[1]; + const char * case2 = argv[2]; + const char * equal_string = argv[3]; + bool equal; + ecl_sum_type * ecl_sum1 = ecl_sum_fread_alloc_case( case1 , ":"); + ecl_sum_type * ecl_sum2 = ecl_sum_fread_alloc_case( case2 , ":"); + + test_assert_true( ecl_sum_is_instance( ecl_sum1 )); + test_assert_true( ecl_sum_is_instance( ecl_sum2 )); + test_assert_true( ecl_sum_report_step_equal( ecl_sum1 , ecl_sum1) ); + test_assert_true( util_sscanf_bool( equal_string , &equal )); + + test_assert_true( ecl_sum_report_step_equal( ecl_sum1 , ecl_sum1) ); + test_assert_true( ecl_sum_report_step_equal( ecl_sum2 , ecl_sum2) ); + test_assert_bool_equal( equal , ecl_sum_report_step_equal( ecl_sum1 , ecl_sum2 )); + + ecl_sum_free( ecl_sum1 ); + ecl_sum_free( ecl_sum2 ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_sum_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_test.c index a383cfa2ec..af33502b9b 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_sum_test.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_test.c @@ -60,14 +60,16 @@ void test_is_oil_producer( const ecl_sum_type * ecl_sum) { + int main( int argc , char ** argv) { - const char * casename = argv[1]; - - ecl_sum_type * ecl_sum = ecl_sum_fread_alloc_case( casename , ":"); - - test_time_range( ecl_sum ); - test_days( ecl_sum ); - test_is_oil_producer(ecl_sum); + const char * case1 = argv[1]; + ecl_sum_type * ecl_sum1 = ecl_sum_fread_alloc_case( case1 , ":"); + + test_assert_true( ecl_sum_is_instance( ecl_sum1 )); + test_time_range( ecl_sum1 ); + test_days( ecl_sum1 ); + test_is_oil_producer(ecl_sum1); + ecl_sum_free( ecl_sum1 ); exit(0); } diff --git a/ThirdParty/Ert/devel/libecl/tests/tests.cmake b/ThirdParty/Ert/devel/libecl/tests/tests.cmake new file mode 100644 index 0000000000..d122914436 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/tests.cmake @@ -0,0 +1,175 @@ +add_executable( ecl_coarse_test ecl_coarse_test.c ) +target_link_libraries( ecl_coarse_test ecl test_util ) +add_test( ecl_coarse_test ${EXECUTABLE_OUTPUT_PATH}/ecl_coarse_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 ) + + +add_executable( ecl_restart_test ecl_restart_test.c ) +target_link_libraries( ecl_restart_test ecl test_util ) +add_test( ecl_restart_test ${EXECUTABLE_OUTPUT_PATH}/ecl_restart_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ) + + +add_executable( ecl_grid_lgr_name ecl_grid_lgr_name.c ) +target_link_libraries( ecl_grid_lgr_name ecl test_util ) +set_target_properties( ecl_grid_lgr_name PROPERTIES COMPILE_FLAGS "-Werror") +add_test( ecl_grid_lgr_name ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_lgr_name ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID) + +add_executable( ecl_region ecl_region.c ) +target_link_libraries( ecl_region ecl test_util ) +add_test( ecl_region ${EXECUTABLE_OUTPUT_PATH}/ecl_region ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) + +add_executable( ecl_region2region ecl_region2region_test.c ) +target_link_libraries( ecl_region2region ecl test_util ) +add_test( ecl_region2region ${EXECUTABLE_OUTPUT_PATH}/ecl_region2region ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/R2R/R2R.SMSPEC ) + +add_executable( ecl_grid_case ecl_grid_case.c ) +target_link_libraries( ecl_grid_case ecl test_util ) +add_test( ecl_grid_case ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_case ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) + + +add_executable( ecl_lgr_test ecl_lgr_test.c ) +target_link_libraries( ecl_lgr_test ecl test_util ) +add_test( ecl_lgr_test1 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID) +add_test( ecl_lgr_test2 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.GRID) +add_test( ecl_lgr_test3 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID ) + + +add_executable( ecl_grid_simple ecl_grid_simple.c ) +target_link_libraries( ecl_grid_simple ecl test_util ) +add_test( ecl_grid_simple ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_simple ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) + + +add_executable( ecl_grid_dims ecl_grid_dims.c ) +target_link_libraries( ecl_grid_dims ecl test_util ) + +add_test( ecl_grid_dims0 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ) +add_test( ecl_grid_dims1 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT ) +add_test( ecl_grid_dims2 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT) +add_test( ecl_grid_dims3 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) +add_test( ecl_grid_dims4 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ) +add_test( ecl_grid_dims5 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.INIT ) + + +add_executable( ecl_nnc_test ecl_nnc_test.c ) +target_link_libraries( ecl_nnc_test ecl test_util ) +add_test (ecl_nnc_test ${EXECUTABLE_OUTPUT_PATH}/ecl_nnc_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID ) +add_executable( ecl_nnc_info_test ecl_nnc_info_test.c ) +target_link_libraries( ecl_nnc_info_test ecl test_util ) +add_test (ecl_nnc_info_test ${EXECUTABLE_OUTPUT_PATH}/ecl_nnc_info_test ) + + +add_executable( ecl_kw_grdecl ecl_kw_grdecl.c ) +target_link_libraries( ecl_kw_grdecl ecl test_util ) +add_test( ecl_kw_grdecl ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_grdecl ) + +add_executable( ecl_kw_equal ecl_kw_equal.c ) +target_link_libraries( ecl_kw_equal ecl test_util ) +add_test( ecl_kw_equal ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_equal ) + + +add_executable( ecl_dualp ecl_dualp.c ) +target_link_libraries( ecl_dualp ecl test_util ) +add_test( ecl_dualp ${EXECUTABLE_OUTPUT_PATH}/ecl_dualp ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 ) + +add_executable( ecl_util_month_range ecl_util_month_range.c ) +target_link_libraries( ecl_util_month_range ecl test_util ) +add_test( ecl_util_month_range ${EXECUTABLE_OUTPUT_PATH}/ecl_util_month_range ) + +add_executable( ecl_sum_test ecl_sum_test.c ) +target_link_libraries( ecl_sum_test ecl test_util ) +add_test( ecl_sum_test ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) + +add_executable( ecl_sum_report_step_equal ecl_sum_report_step_equal.c ) +target_link_libraries( ecl_sum_report_step_equal ecl test_util ) +add_test( ecl_sum_report_step_equal1 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE FALSE) +add_test( ecl_sum_report_step_equal2 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE TRUE) +add_test( ecl_sum_report_step_equal3 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/extraMinistep/ECLIPSE TRUE) +add_test( ecl_sum_report_step_equal4 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/short/ECLIPSE FALSE) +add_test( ecl_sum_report_step_equal5 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/enkf/ECLIPSE FALSE) +add_test( ecl_sum_report_step_equal6 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre2/SNORRE2 FALSE) + +add_executable( ecl_sum_report_step_compatible ecl_sum_report_step_compatible.c ) +target_link_libraries( ecl_sum_report_step_compatible ecl test_util ) +add_test( ecl_sum_report_step_compatible1 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE FALSE) +add_test( ecl_sum_report_step_compatible2 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE TRUE) +add_test( ecl_sum_report_step_compatible3 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/extraMinistep/ECLIPSE TRUE) +add_test( ecl_sum_report_step_compatible4 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/short/ECLIPSE TRUE) +add_test( ecl_sum_report_step_compatible5 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/enkf/ECLIPSE TRUE) +add_test( ecl_sum_report_step_compatible6 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre2/SNORRE2 FALSE) + +add_executable( ecl_fortio ecl_fortio.c ) +target_link_libraries( ecl_fortio ecl test_util ) +add_test( ecl_fortio ${EXECUTABLE_OUTPUT_PATH}/ecl_fortio ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ) + +add_executable( ecl_file ecl_file.c ) +target_link_libraries( ecl_file ecl test_util ) +add_test( ecl_file ${EXECUTABLE_OUTPUT_PATH}/ecl_file ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ECLIPSE.UNRST) + +add_executable( ecl_fmt ecl_fmt.c ) +target_link_libraries( ecl_fmt ecl test_util ) +add_test( ecl_fmt ${EXECUTABLE_OUTPUT_PATH}/ecl_fmt ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.DATA) + + +add_executable( ecl_rsthead ecl_rsthead.c ) +target_link_libraries( ecl_rsthead ecl test_util ) +add_test( ecl_rsthead ${EXECUTABLE_OUTPUT_PATH}/ecl_rsthead ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUALPORO.X0005 ) + +add_executable( ecl_rft ecl_rft.c ) +target_link_libraries( ecl_rft ecl test_util ) +add_test( ecl_rft_rft ${EXECUTABLE_OUTPUT_PATH}/ecl_rft ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT RFT) +add_test( ecl_rft_plt ${EXECUTABLE_OUTPUT_PATH}/ecl_rft ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/RFT/TEST1_1A.RFT PLT) +add_test( ecl_rft_plt ${EXECUTABLE_OUTPUT_PATH}/ecl_rft ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/RFT/RFT2.RFT MSW-PLT) + +add_executable( ecl_rft_cell ecl_rft_cell.c ) +target_link_libraries( ecl_rft_cell ecl test_util ) +add_test( ecl_rft_cell ${EXECUTABLE_OUTPUT_PATH}/ecl_rft_cell ) + +add_executable( ecl_get_num_cpu ecl_get_num_cpu_test.c ) +target_link_libraries( ecl_get_num_cpu ecl test_util ) +add_test( ecl_get_num_cpu ${EXECUTABLE_OUTPUT_PATH}/ecl_get_num_cpu ${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu1 ${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu2) + + + +set_property( TEST ecl_fmt PROPERTY LABELS StatoilData ) +set_property( TEST ecl_coarse_test PROPERTY LABELS StatoilData ) +set_property( TEST ecl_restart_test PROPERTY LABELS StatoilData ) +set_property( TEST ecl_lgr_test1 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_lgr_test2 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_lgr_test3 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_lgr_name PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_simple PROPERTY LABELS StatoilData ) +set_property( TEST ecl_dualp PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_test PROPERTY LABELS StatoilData ) + +set_property( TEST ecl_sum_report_step_equal1 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal2 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal3 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal4 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal5 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal6 PROPERTY LABELS StatoilData ) + +set_property( TEST ecl_sum_report_step_compatible1 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible2 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible3 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible4 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible5 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible6 PROPERTY LABELS StatoilData ) + +set_property( TEST ecl_fortio PROPERTY LABELS StatoilData) +set_property( TEST ecl_grid_dims1 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_dims2 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_dims3 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_dims4 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_dims5 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_nnc_test PROPERTY LABELS StatoilData ) +set_property( TEST ecl_file PROPERTY LABELS StatoilData) +set_property( TEST ecl_rsthead PROPERTY LABELS StatoilData) +set_property( TEST ecl_region PROPERTY LABELS StatoilData) +set_property( TEST ecl_region2region PROPERTY LABELS StatoilData) +set_property( TEST ecl_grid_case PROPERTY LABELS StatoilData) +set_property( TEST ecl_rft_rft PROPERTY LABELS StatoilData) +set_property( TEST ecl_rft_plt PROPERTY LABELS StatoilData) diff --git a/ThirdParty/Ert/devel/libecl_well/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libecl_well/applications/CMakeLists.txt index 578a9d2901..9015221393 100644 --- a/ThirdParty/Ert/devel/libecl_well/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl_well/applications/CMakeLists.txt @@ -1,9 +1,11 @@ -add_executable( well_info_test well_info_test.c ) add_executable( segment_info segment_info.c ) - -set(program_list well_info_test segment_info ) +set(program_list segment_info ) foreach(prog ${program_list}) target_link_libraries( ${prog} ecl_well ecl) + if (USE_RUNPATH) + add_runpath( ${prog} ) + endif() + #----------------------------------------------------------------- diff --git a/ThirdParty/Ert/devel/libecl_well/applications/segment_info.c b/ThirdParty/Ert/devel/libecl_well/applications/segment_info.c index 712802ece0..fa720032cc 100644 --- a/ThirdParty/Ert/devel/libecl_well/applications/segment_info.c +++ b/ThirdParty/Ert/devel/libecl_well/applications/segment_info.c @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -46,7 +45,6 @@ int main(int argc , char ** argv) { const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 ); const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( rst_file , ZWEL_KW , 0 ); - test_install_SIGNALS(); { int well_nr; for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) { @@ -79,7 +77,7 @@ int main(int argc , char ** argv) { printf("Branch : %d \n",well_segment_get_branch_id( segment )); printf("Connections : ["); { - well_conn_collection_type * connections = well_segment_get_global_connections( segment ); + const well_conn_collection_type * connections = well_segment_get_global_connections( segment ); if (connections) { int ic; for (ic = 0; ic < well_conn_collection_get_size( connections ); ic++) { diff --git a/ThirdParty/Ert/devel/libecl_well/applications/well_info_test.c b/ThirdParty/Ert/devel/libecl_well/applications/well_info_test.c deleted file mode 100644 index 2ecfa829cd..0000000000 --- a/ThirdParty/Ert/devel/libecl_well/applications/well_info_test.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'well_info_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 -#include -#include -#include - -#include -#include -#include -#include - -int main( int argc , char ** argv) { - signal(SIGSEGV , util_abort_signal); /* Segmentation violation, i.e. overwriting memory ... */ - 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.*/ - signal(SIGABRT , util_abort_signal); /* Signal abort. */ - { - well_info_type * well_info = well_info_alloc( NULL ); - int i; - for (i=1; i < argc; i++) { - printf("Loading file: %s \n",argv[i]); - well_info_load_rstfile( well_info , argv[i]); - } - - // List all wells: - { - int iwell; - for (iwell = 0; iwell < well_info_get_num_wells( well_info ); iwell++) { - well_ts_type * well_ts = well_info_get_ts( well_info , well_info_iget_well_name( well_info , iwell)); - well_state_type * well_state = well_ts_get_last_state( well_ts ); - - well_state_summarize( well_state , stdout ); - printf("\n"); - } - } - well_info_free( well_info ); - exit(1); - - // Look at the timeseries for one well: - { - well_ts_type * well_ts = well_info_get_ts( well_info , well_info_iget_well_name( well_info , 0)); - int i; - for (i =0; i < well_ts_get_size( well_ts ); i++) { - well_state_type * well_state = well_ts_iget_state( well_ts , i ); - - printf("Well:%s report:%04d state:",well_state_get_name( well_state ), well_state_get_report_nr( well_state )); - if (well_state_is_open( well_state )) - printf("OPEN\n"); - else - printf("CLOSED\n"); - } - } - - // Look at one well_state: - { - well_state_type * well_state = well_info_iiget_state( well_info , 0 , 0 ); - printf("Well:%s report:%04d \n",well_state_get_name( well_state ), well_state_get_report_nr( well_state )); - { - const well_conn_type ** connections = well_state_get_connections( well_state , 0 ); - printf("Branches: %d \n",well_state_get_num_branches( well_state )); - printf("num_connections: %d \n",well_state_get_num_connections( well_state , 0 )); - { - int iconn; - for (iconn = 0; iconn < well_state_get_num_connections( well_state , 0 ); iconn++) { - const well_conn_type * conn = connections[ iconn ]; - printf("Connection:%02d i=%3d j=%3d k=%3d State:",iconn , well_conn_get_i( conn ) , well_conn_get_j( conn ) , well_conn_get_k( conn )); - if (well_conn_open( conn ) ) - printf("Open\n"); - else - printf("Closed\n"); - } - } - } - } - well_info_free( well_info ); - } -} diff --git a/ThirdParty/Ert/devel/libecl_well/src/CMakeLists.txt b/ThirdParty/Ert/devel/libecl_well/src/CMakeLists.txt index 19b908b75c..88d84809de 100644 --- a/ThirdParty/Ert/devel/libecl_well/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl_well/src/CMakeLists.txt @@ -13,6 +13,10 @@ include_directories( ${libgeometry_src_path} ) add_library( ecl_well ${LIBRARY_TYPE} ${source_files} ) set_target_properties( ecl_well PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( ecl_well ecl ) +if (USE_RUNPATH) + add_runpath( ecl_well ) +endif() + #----------------------------------------------------------------- if (INSTALL_ERT) diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_state.c b/ThirdParty/Ert/devel/libecl_well/src/well_state.c index 0f792c7b10..1620d4935f 100644 --- a/ThirdParty/Ert/devel/libecl_well/src/well_state.c +++ b/ThirdParty/Ert/devel/libecl_well/src/well_state.c @@ -336,16 +336,16 @@ static void well_state_add_LGR_connections( well_state_type * well_state , const // Go through all the LGRs and add connections; both in the bulk // grid and as wellhead. int num_lgr = ecl_grid_get_num_lgr( grid ); - int lgr_nr; - for (lgr_nr = 0; lgr_nr < num_lgr; lgr_nr++) { + int lgr_index; + for (lgr_index = 0; lgr_index < num_lgr; lgr_index++) { ecl_file_push_block( ecl_file ); // <-------------------------// { // - ecl_file_subselect_block( ecl_file , LGR_KW , lgr_nr ); // + ecl_file_subselect_block( ecl_file , LGR_KW , lgr_index ); // { // Restrict the file view - const char * grid_name = ecl_grid_iget_lgr_name( grid , lgr_nr ); // + const char * grid_name = ecl_grid_iget_lgr_name( grid , lgr_index ); // int well_nr = well_state_get_lgr_well_nr( well_state , ecl_file ); // to one LGR block. if (well_nr >= 0) // - well_state_add_connections__( well_state , ecl_file , grid_name , lgr_nr + 1, well_nr ); // + well_state_add_connections__( well_state , ecl_file , grid_name , lgr_index + 1, well_nr ); // } // } // ecl_file_pop_block( ecl_file ); // <-------------------------// diff --git a/ThirdParty/Ert/devel/libecl_well/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libecl_well/tests/CMakeLists.txt index 7c47c45ef9..9460918d2f 100644 --- a/ThirdParty/Ert/devel/libecl_well/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl_well/tests/CMakeLists.txt @@ -1,29 +1,29 @@ add_executable( well_conn_collection well_conn_collection.c ) -target_link_libraries( well_conn_collection ecl_well ) +target_link_libraries( well_conn_collection ecl_well test_util ) set_target_properties( well_conn_collection PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_conn_collection ${EXECUTABLE_OUTPUT_PATH}/well_conn_collection ) add_executable( well_branch_collection well_branch_collection.c ) -target_link_libraries( well_branch_collection ecl_well ) +target_link_libraries( well_branch_collection ecl_well test_util ) set_target_properties( well_branch_collection PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_branch_collection ${EXECUTABLE_OUTPUT_PATH}/well_branch_collection ) add_executable( well_conn well_conn.c ) -target_link_libraries( well_conn ecl_well ) +target_link_libraries( well_conn ecl_well test_util ) set_target_properties( well_conn PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_conn ${EXECUTABLE_OUTPUT_PATH}/well_conn ) add_executable( well_state well_state.c ) -target_link_libraries( well_state ecl_well ) +target_link_libraries( well_state ecl_well test_util ) set_target_properties( well_state PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_state ${EXECUTABLE_OUTPUT_PATH}/well_state ) add_executable( well_state_load well_state_load.c ) -target_link_libraries( well_state_load ecl_well ) +target_link_libraries( well_state_load ecl_well test_util ) set_target_properties( well_state_load PROPERTIES COMPILE_FLAGS "-Werror") add_executable( well_state_load_missing_RSEG well_state_load_missing_RSEG.c ) -target_link_libraries( well_state_load_missing_RSEG ecl_well ) +target_link_libraries( well_state_load_missing_RSEG ecl_well test_util ) set_target_properties( well_state_load_missing_RSEG PROPERTIES COMPILE_FLAGS "-Werror") @@ -50,40 +50,40 @@ add_test( well_state_load_missing_RSEG2 ${EXECUTABLE_OUTPUT_PATH}/well_state_loa add_executable( well_segment well_segment.c ) -target_link_libraries( well_segment ecl_well ) +target_link_libraries( well_segment ecl_well test_util ) set_target_properties( well_segment PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_segment ${EXECUTABLE_OUTPUT_PATH}/well_segment ) add_executable( well_segment_conn well_segment_conn.c ) -target_link_libraries( well_segment_conn ecl_well ) +target_link_libraries( well_segment_conn ecl_well test_util ) set_target_properties( well_segment_conn PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_segment_conn ${EXECUTABLE_OUTPUT_PATH}/well_segment_conn ) add_executable( well_segment_load well_segment_load.c ) -target_link_libraries( well_segment_load ecl_well ) +target_link_libraries( well_segment_load ecl_well test_util ) set_target_properties( well_segment_load PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_segment_load ${EXECUTABLE_OUTPUT_PATH}/well_segment_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/MSWcase/MSW_CASE.X0021) add_executable( well_segment_branch_conn_load well_segment_branch_conn_load.c ) -target_link_libraries( well_segment_branch_conn_load ecl_well ) +target_link_libraries( well_segment_branch_conn_load ecl_well test_util ) set_target_properties( well_segment_branch_conn_load PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_segment_branch_conn_load ${EXECUTABLE_OUTPUT_PATH}/well_segment_branch_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/MSWcase/MSW_CASE.X0021) add_executable( well_info well_info.c ) -target_link_libraries( well_info ecl_well ) +target_link_libraries( well_info ecl_well test_util ) set_target_properties( well_info PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_info ${EXECUTABLE_OUTPUT_PATH}/well_info ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) add_executable( well_segment_collection well_segment_collection.c ) -target_link_libraries( well_segment_collection ecl_well ) +target_link_libraries( well_segment_collection ecl_well test_util ) set_target_properties( well_segment_collection PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_segment_collection ${EXECUTABLE_OUTPUT_PATH}/well_segment_collection ) add_executable( well_conn_load well_conn_load.c ) -target_link_libraries( well_conn_load ecl_well ) +target_link_libraries( well_conn_load ecl_well test_util ) set_target_properties( well_conn_load PROPERTIES COMPILE_FLAGS "-Werror") add_test( well_conn_load1 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.X0030 F) add_test( well_conn_load2 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.X0021 F) @@ -93,18 +93,18 @@ add_test( well_conn_load5 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOU add_test( well_conn_load6 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003 F) add_executable( well_ts well_ts.c ) -target_link_libraries( well_ts ecl_well ) +target_link_libraries( well_ts ecl_well test_util ) add_test( well_ts ${EXECUTABLE_OUTPUT_PATH}/well_ts ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/CO2case/BASE_CASE ) add_executable( well_dualp well_dualp.c ) -target_link_libraries( well_dualp ecl_well ) +target_link_libraries( well_dualp ecl_well test_util ) add_test( well_dualp ${EXECUTABLE_OUTPUT_PATH}/well_dualp ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUALPORO.X0005 ) add_executable( well_lgr_load well_lgr_load.c ) -target_link_libraries( well_lgr_load ecl_well ) +target_link_libraries( well_lgr_load ecl_well test_util ) add_test( well_lgr_load1 ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003) add_test( well_lgr_load2 ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.X0016) diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_state_load_missing_RSEG.c b/ThirdParty/Ert/devel/libecl_well/tests/well_state_load_missing_RSEG.c new file mode 100644 index 0000000000..b0a7e4071e --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_state_load_missing_RSEG.c @@ -0,0 +1,67 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_state_load_missing_RSEG.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 + + +int main(int argc , char ** argv) { + test_install_SIGNALS(); + { + const char * grid_file = argv[1]; + const char * rst_file_name = argv[2]; + + ecl_grid_type * grid = ecl_grid_alloc( grid_file ); + ecl_file_type * rst_file = ecl_file_open( rst_file_name , 0); + ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file ); + const char * well_name = "WELL"; + int report_nr = 100; + time_t valid_from = -1; + bool open = false; + well_type_enum type = GAS_INJECTOR; + int global_well_nr = 0; + + for (global_well_nr = 0; global_well_nr < header->nwells; global_well_nr++) { + well_state_type * well_state = well_state_alloc(well_name , global_well_nr , open , type , report_nr , valid_from); + test_assert_true( well_state_is_instance( well_state) ); + well_state_add_connections( well_state , grid , rst_file , 0 ); + well_state_add_MSW( well_state , rst_file , global_well_nr ); + + { + const well_segment_collection_type * segments = well_state_get_segments( well_state ); + + if (!ecl_file_has_kw( rst_file , RSEG_KW )) + test_assert_int_equal( 0 , well_segment_collection_get_size( segments )); + + } + well_state_free( well_state ); + } + } + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/CMakeLists.txt b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/CMakeLists.txt index e4b996c246..dfb31fc396 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/CMakeLists.txt @@ -31,6 +31,9 @@ set_source_files_properties( main.c PROPERTIES COMPILE_DEFINITIONS "COMPILE_TIME add_executable( ert ${src_list} ) target_link_libraries( ert enkf sched rms ecl config plot job_queue analysis ert_util ) +if (USE_RUNPATH) + add_runpath( ert ) +endif() if (ERT_INSTALL_PREFIX) set (destination ${CMAKE_INSTALL_PREFIX}/${ERT_INSTALL_PREFIX}/bin) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_analysis.c b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_analysis.c index 6ab512c6a7..6a75b3c5dc 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_analysis.c +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_analysis.c @@ -65,6 +65,17 @@ void enkf_tui_analysis_analyze_selected__(void * arg) { } } +void enkf_tui_analysis_scale_observation_std__(void * arg) { + enkf_main_type * enkf_main = enkf_main_safe_cast(arg); + + double scale_factor = enkf_tui_util_scanf_double_with_lower_limit("Global scaling factor", PROMPT_LEN, 0); + + if (enkf_main_have_obs(enkf_main)) { + enkf_obs_type * observations = enkf_main_get_obs(enkf_main); + enkf_obs_scale_std(observations, scale_factor); + } +} + /** @@ -228,19 +239,26 @@ void enkf_tui_analysis_menu(void * arg) { arg_pack_type * arg_pack = arg_pack_alloc(); arg_pack_append_ptr( arg_pack , enkf_main ); arg_pack_append_ptr( arg_pack , menu ); - + { - enkf_tui_analysis_update_title( enkf_main , menu ); - menu_add_item(menu , "Analyze one step manually" , "aA" , enkf_tui_analysis_analyze__ , enkf_main , NULL); - menu_add_item(menu , "Analyze interval manually" , "iI" , enkf_tui_analysis_smooth__ , enkf_main , NULL); - menu_add_item(menu , "Analyze selected steps manually" , "nN" , enkf_tui_analysis_analyze_selected__ , enkf_main , NULL); - menu_add_separator( menu ); - menu_add_item(menu , "Select analysis module" , "sS" , enkf_tui_analysis_select_module__ , arg_pack , NULL); - menu_add_item(menu , "List available modules" , "lL" , enkf_tui_analysis_list_modules__ , enkf_main , NULL); - menu_add_item(menu , "Modify analysis module parameters" , "mM" , enkf_tui_analysis_update_module__ , enkf_main , NULL); - menu_add_item(menu , "Reload current module (external only)" , "rR" , enkf_tui_analysis_reload_module__ , enkf_main , NULL); + enkf_tui_analysis_update_title(enkf_main, menu); + menu_add_item(menu, "Analyze one step manually", "aA", enkf_tui_analysis_analyze__, enkf_main, NULL); + menu_add_item(menu, "Analyze interval manually", "iI", enkf_tui_analysis_smooth__, enkf_main, NULL); + menu_add_item(menu, "Analyze selected steps manually", "nN", enkf_tui_analysis_analyze_selected__, enkf_main, NULL); + menu_add_separator(menu); + { + menu_item_type * item = menu_add_item(menu, "Global scaling of uncertainty", "gG", enkf_tui_analysis_scale_observation_std__, enkf_main, NULL); + if (!enkf_main_have_obs(enkf_main)) { + menu_item_disable(item); + } + } + menu_add_separator(menu); + menu_add_item(menu, "Select analysis module", "sS", enkf_tui_analysis_select_module__, arg_pack, NULL); + menu_add_item(menu, "List available modules", "lL", enkf_tui_analysis_list_modules__, enkf_main, NULL); + menu_add_item(menu, "Modify analysis module parameters", "mM", enkf_tui_analysis_update_module__, enkf_main, NULL); + menu_add_item(menu, "Reload current module (external only)", "rR", enkf_tui_analysis_reload_module__, enkf_main, NULL); } menu_run(menu); menu_free(menu); - arg_pack_free( arg_pack ); + arg_pack_free(arg_pack); } diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.c b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.c index 8a1ec81d51..36ccaa82b5 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.c +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.c @@ -20,9 +20,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include +#include /** diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.h b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.h index 8060aa0ad0..f87730e8a7 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.h +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.h @@ -18,7 +18,7 @@ #ifndef __ENKF_INTER_MAIN_H__ #define __ENKF_INTER_MAIN_H__ -#include +#include void enkf_tui_main_menu(void * arg); diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.h b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.h index b7b0a88aaf..8fe6895b4b 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.h +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.h @@ -23,7 +23,7 @@ extern "C" { #endif -#include +#include void enkf_tui_plot_RFT_sim_all_MD( void * arg); void enkf_tui_plot_RFT_sim_all_TVD( void * arg); diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.c b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.c index 2bfaa24736..d89e507240 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.c +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.c @@ -434,6 +434,19 @@ bool enkf_tui_util_sscanf_active_list( bool_vector_type * iactive , const char * } } +/** + The limit is not inclusive +*/ +double enkf_tui_util_scanf_double_with_lower_limit(const char * prompt , int prompt_len , double min_value) { + double value; + char * new_prompt = util_alloc_sprintf("%s (greater than %g)" , prompt , min_value ); + do { + value = util_scanf_double(new_prompt , prompt_len); + } while (value <= min_value); + free(new_prompt); + return value; +} + /*****************************************************************/ diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.h b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.h index 49245e18f0..5298e09d81 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.h +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.h @@ -41,6 +41,6 @@ char * enkf_tui_util_scanf_report_step_as_char(int , cons void enkf_tui_util_msg(const char * , ...); int enkf_tui_util_scanf_int_with_default(const char * prompt , int prompt_len , bool * default_used); int enkf_tui_util_scanf_int_with_default_return_to_menu(const char * prompt , int prompt_len , bool * default_used); - +double enkf_tui_util_scanf_double_with_lower_limit(const char * prompt , int prompt_len , double min_value); bool enkf_tui_util_sscanf_active_list( bool_vector_type * iactive , const char * select_string , int ens_size ); #endif diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/block_obs.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/block_obs.h index 81698a58b9..3316d518a7 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/block_obs.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/block_obs.h @@ -70,6 +70,11 @@ int block_obs_get_size(const block_obs_type * ); void block_obs_iget(const block_obs_type * block_obs, int , double * , double * ); void block_obs_iget_ijk(const block_obs_type * block_obs , int block_nr , int * i , int * j , int * k); +void block_obs_scale_std(block_obs_type * block_obs, double scale_factor); +void block_obs_scale_std__(void * block_obs, double scale_factor); + + + VOID_FREE_HEADER(block_obs); VOID_GET_OBS_HEADER(block_obs); UTIL_IS_INSTANCE_HEADER(block_obs); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/config_keys.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/config_keys.h index e8f9c452d9..9386cc114e 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/config_keys.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/config_keys.h @@ -140,6 +140,7 @@ extern "C" { #define RERUN_START_KEY "RERUN_START" #define RSH_COMMAND_KEY "RSH_COMMAND" #define RSH_HOST_KEY "RSH_HOST" +#define RUNPATH_FILE_KEY "RUNPATH_FILE" #define RUNPATH_KEY "RUNPATH" #define ITER_RUNPATH_KEY "ITER_RUNPATH" #define RERUN_PATH_KEY "RERUN_PATH" diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_main.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_main.h index 7e1c04305b..81708ac754 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_main.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_main.h @@ -69,6 +69,7 @@ extern "C" { char * enkf_main_alloc_mount_point( const enkf_main_type * enkf_main , const char * case_path); const char * enkf_main_get_current_fs( const enkf_main_type * enkf_main ); void enkf_main_user_select_fs(enkf_main_type * enkf_main , const char * case_path ); + bool enkf_main_fs_exists(const enkf_main_type * enkf_main, const char * input_case); void enkf_main_set_eclbase( enkf_main_type * enkf_main , const char * eclbase_fmt); void enkf_main_set_data_file( enkf_main_type * enkf_main , const char * data_file ); void enkf_main_set_user_config_file( enkf_main_type * enkf_main , const char * user_config_file ); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_obs.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_obs.h index 02bbbb1ed9..dd5265664e 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_obs.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_obs.h @@ -45,6 +45,7 @@ extern "C" { void enkf_obs_free( enkf_obs_type * enkf_obs); obs_vector_type * enkf_obs_get_vector(const enkf_obs_type * , const char * ); + void enkf_obs_add_obs_vector(enkf_obs_type * enkf_obs, const char * key, const obs_vector_type * vector); void enkf_obs_load(enkf_obs_type * enkf_obs, const history_type * history , @@ -80,6 +81,7 @@ extern "C" { stringlist_type * enkf_obs_alloc_matching_keylist(const enkf_obs_type * enkf_obs , const char * input_string); time_t enkf_obs_iget_obs_time(enkf_obs_type * enkf_obs , int report_step); void enkf_obs_fprintf_config( const enkf_obs_type * enkf_obs , FILE * stream); + void enkf_obs_scale_std(enkf_obs_type * enkf_obs, double scale_factor); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/gen_obs.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/gen_obs.h index e10d5d0e60..7e6cfdb99d 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/gen_obs.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/gen_obs.h @@ -29,6 +29,10 @@ typedef struct gen_obs_struct gen_obs_type; gen_obs_type * gen_obs_alloc(gen_data_config_type * config , const char * obs_key , const char * , double , double , const char * , const char * , const char * ); void gen_obs_user_get_with_data_index(const gen_obs_type * gen_obs , const char * index_key , double * value , double * std , bool * valid); +void gen_obs_scale_std(gen_obs_type * gen_obs, double std_multiplier ); +void gen_obs_scale_std__(void * gen_obs, double std_multiplier ); + + VOID_CHI2_HEADER(gen_obs); UTIL_IS_INSTANCE_HEADER(gen_obs); VOID_FREE_HEADER(gen_obs); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/obs_vector.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/obs_vector.h new file mode 100644 index 0000000000..fc381374e0 --- /dev/null +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/obs_vector.h @@ -0,0 +1,104 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'obs_vector.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 __OBS_VECTOR_H__ +#define __OBS_VECTOR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + + typedef void (obs_free_ftype) (void *); + typedef void (obs_get_ftype) (const void * , obs_data_type * , int , const active_list_type * ); + typedef void (obs_meas_ftype) (const void * , const void *, node_id_type , meas_data_type * , const active_list_type * ); + typedef void (obs_user_get_ftype) (void * , const char * , double * , double * , bool *); + typedef void (obs_scale_std_ftype) (void * , double ); + typedef double (obs_chi2_ftype) (const void * , const void *, node_id_type ); + + typedef enum { GEN_OBS = 1, + SUMMARY_OBS = 2, + BLOCK_OBS = 3} obs_impl_type; + + typedef struct obs_vector_struct obs_vector_type; + + + void obs_vector_clear_nodes( obs_vector_type * obs_vector ); + void obs_vector_del_node(obs_vector_type * obs_vector , int index); + void obs_vector_free(obs_vector_type * ); + int obs_vector_get_num_active(const obs_vector_type * ); + bool obs_vector_iget_active(const obs_vector_type * , int ); + void obs_vector_iget_observations(const obs_vector_type * , int , obs_data_type * , const active_list_type * active_list); + void obs_vector_measure(const obs_vector_type * , enkf_fs_type * fs, state_enum state , int report_step , const enkf_state_type * , meas_data_type * , const active_list_type * active_list); + const char * obs_vector_get_state_kw(const obs_vector_type * ); + obs_impl_type obs_vector_get_impl_type(const obs_vector_type * ); + int obs_vector_get_active_report_step(const obs_vector_type * ); + void obs_vector_user_get(const obs_vector_type * obs_vector , const char * index_key , int report_step , double * value , double * std , bool * valid); + int obs_vector_get_next_active_step(const obs_vector_type * , int ); + void * obs_vector_iget_node(const obs_vector_type * , int ); + obs_vector_type * obs_vector_alloc_from_GENERAL_OBSERVATION(const conf_instance_type * , const history_type * , const ensemble_config_type * ); + void obs_vector_load_from_SUMMARY_OBSERVATION(obs_vector_type * obs_vector , const conf_instance_type * , const history_type * , ensemble_config_type * ); + bool obs_vector_load_from_HISTORY_OBSERVATION(obs_vector_type * obs_vector , const conf_instance_type * , const history_type * , ensemble_config_type * , double std_cutoff ); + obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_type * , const ecl_grid_type * grid , const ecl_sum_type * refcase , const history_type *, ensemble_config_type * ); + void obs_vector_set_config_node(obs_vector_type * , const enkf_config_node_type * ); + obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key , enkf_config_node_type * config_node, int num_reports); + void obs_vector_scale_std(obs_vector_type * obs_vector, double std_multiplier); + void obs_vector_install_node(obs_vector_type * obs_vector , int obs_index , void * node ); + + double obs_vector_chi2(const obs_vector_type * , enkf_fs_type * , node_id_type node_id); + + void obs_vector_ensemble_chi2(const obs_vector_type * obs_vector , + enkf_fs_type * fs, + bool_vector_type * valid , + int step1 , int step2 , + int iens1 , int iens2 , + state_enum load_state , + double ** chi2); + + double obs_vector_total_chi2(const obs_vector_type * , enkf_fs_type * , int , state_enum ); + void obs_vector_ensemble_total_chi2(const obs_vector_type * , enkf_fs_type * , int , state_enum , double * ); + enkf_config_node_type * obs_vector_get_config_node(obs_vector_type * ); + const char * obs_vector_get_obs_key( const obs_vector_type * obs_vector); + + UTIL_SAFE_CAST_HEADER(obs_vector); + VOID_FREE_HEADER(obs_vector); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/qc_module.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/qc_module.h index cacf78b946..e4fec2d135 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/qc_module.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/qc_module.h @@ -39,7 +39,7 @@ extern "C" { void qc_module_init( qc_module_type * qc_module , const config_type * config); void qc_module_export_runpath_list( const qc_module_type * qc_module ); void qc_module_add_config_items( config_type * config ); - void qc_module_set_runpath_list_file( qc_module_type * qc_module , const char * filename); + void qc_module_set_runpath_list_file( qc_module_type * qc_module , const char * path, const char * filename); const char * qc_module_get_runpath_list_file( qc_module_type * qc_module); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/summary_obs.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/summary_obs.h index 52ed9699bf..b446800aab 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/summary_obs.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/summary_obs.h @@ -80,6 +80,8 @@ summary_obs_type * summary_obs_alloc_from_SUMMARY_OBSERVATION( void summary_obs_set(summary_obs_type * , double , double ); +void summary_obs_scale_std(summary_obs_type * summary_obs, double std_multiplier ); +void summary_obs_scale_std__(void * summary_obs, double std_multiplier ); VOID_FREE_HEADER(summary_obs); VOID_GET_OBS_HEADER(summary_obs); diff --git a/ThirdParty/Ert/devel/libenkf/src/CMakeLists.txt b/ThirdParty/Ert/devel/libenkf/src/CMakeLists.txt index 24dcedbcdf..ba08fa8437 100644 --- a/ThirdParty/Ert/devel/libenkf/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libenkf/src/CMakeLists.txt @@ -2,7 +2,6 @@ set( source_files ert_report.c time_map.c rng_config.c trans_func.c enkf_types.c set( header_files ert_report.h time_map.h rng_config.h enkf_analysis.h enkf_fs_type.h trans_func.h enkf_obs.h obs_data.h enkf_config_node.h block_obs.h field_config.h field.h enkf_macros.h ecl_static_kw.h enkf_state.h enkf_util.h enkf_main.h enkf_node.h enkf_fs.h gen_kw_config.h gen_kw.h enkf_types.h fs_driver.h meas_data.h summary_obs.h summary_config.h summary_config.h gen_data_config.h gen_data.h gen_common.h gen_obs.h enkf_sched.h fs_types.h enkf_serialize.h plain_driver.h ecl_config.h ensemble_config.h model_config.h site_config.h active_list.h obs_vector.h field_trans.h plain_driver.h local_ministep.h container.h local_updatestep.h local_config.h analysis_config.h misfit_ensemble.h misfit_ensemble_typedef.h misfit_ts.h misfit_member.h data_ranking.h ranking_table.h ranking_common.h misfit_ranking.h block_fs_driver.h field_common.h gen_kw_common.h gen_data_common.h plot_config.h ert_template.h member_config.h enkf_defaults.h container_config.h local_dataset.h local_obsset.h surface.h surface_config.h local_context.h enkf_plot_data.h enkf_plot_member.h qc_module.h ert_report_list.h enkf_plot_arg.h runpath_list.h ert_workflow_list.h analysis_iter_config.h ecl_refcase_list.h) - add_library( enkf ${LIBRARY_TYPE} ${source_files} ) set_target_properties( enkf PROPERTIES VERSION 1.0 SOVERSION 1.0 ) @@ -12,6 +11,10 @@ set_target_properties( enkf PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( enkf ecl sched analysis rms plot config job_queue ) +if (USE_RUNPATH) + add_runpath( enkf ) +endif() + #----------------------------------------------------------------- if (INSTALL_ERT) install(TARGETS enkf DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ThirdParty/Ert/devel/libenkf/src/block_obs.c b/ThirdParty/Ert/devel/libenkf/src/block_obs.c index d8ec61f638..7515399bb6 100644 --- a/ThirdParty/Ert/devel/libenkf/src/block_obs.c +++ b/ThirdParty/Ert/devel/libenkf/src/block_obs.c @@ -356,6 +356,20 @@ int block_obs_get_size(const block_obs_type * block_obs) { return block_obs->size; } +void block_obs_scale_std(block_obs_type * block_obs, double scale_factor) { + for (int i = 0; i < block_obs->size; i++) { + if (block_obs->point_list[i] != NULL) { + point_obs_type * point_observation = block_obs->point_list[i]; + point_observation->std = point_observation->std * scale_factor; + } + } +} + +void block_obs_scale_std__(void * block_obs, double scale_factor) { + block_obs_type * observation = block_obs_safe_cast(block_obs); + block_obs_scale_std(observation, scale_factor); +} + /*****************************************************************/ diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_main.c b/ThirdParty/Ert/devel/libenkf/src/enkf_main.c index 2fc1be833d..8ddebb290a 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_main.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_main.c @@ -2261,22 +2261,20 @@ void enkf_main_update_node( enkf_main_type * enkf_main , const char * key ) { } - - - -/** - When the case has changed it is essential to invalidate the meta - information in the enkf_nodes, otherwise the nodes might reuse old - data (from a previous case). -*/ - -static void enkf_main_invalidate_cache( enkf_main_type * enkf_main ) { - int ens_size = enkf_main_get_ensemble_size( enkf_main ); - int iens; - for (iens = 0; iens < ens_size; iens++) - enkf_state_invalidate_cache( enkf_main->ensemble[iens] ); -} - +// NOTE KF 20130628: This is commented out, because I don't think it is used, but we'll give it some time +// +///** +// When the case has changed it is essential to invalidate the meta +// information in the enkf_nodes, otherwise the nodes might reuse old +// data (from a previous case). +//*/ +// +//static void enkf_main_invalidate_cache( enkf_main_type * enkf_main ) { +// int ens_size = enkf_main_get_ensemble_size( enkf_main ); +// int iens; +// for (iens = 0; iens < ens_size; iens++) +// enkf_state_invalidate_cache( enkf_main->ensemble[iens] ); +//} void enkf_main_create_fs( enkf_main_type * enkf_main , const char * fs_path) { @@ -2386,7 +2384,8 @@ void enkf_main_set_fs( enkf_main_type * enkf_main , enkf_fs_type * fs , const ch enkf_main_link_current_fs__( enkf_main , case_path); enkf_main->current_fs_case = util_realloc_string_copy( enkf_main->current_fs_case , case_path); enkf_main_gen_data_special( enkf_main ); - enkf_main_add_subst_kw( enkf_main , "CASE" , enkf_main->current_fs_case , "Current case" , true ); + enkf_main_add_subst_kw( enkf_main , "ERT-CASE" , enkf_main->current_fs_case , "Current case" , true ); + enkf_main_add_subst_kw( enkf_main , "ERTCASE" , enkf_main->current_fs_case , "Current case" , true ); } } @@ -2468,7 +2467,15 @@ const char * enkf_main_get_current_fs( const enkf_main_type * enkf_main ) { return enkf_main->current_fs_case; } +bool enkf_main_fs_exists(const enkf_main_type * enkf_main, const char * input_case){ + bool exists = false; + char * new_mount_point = enkf_main_alloc_mount_point( enkf_main , input_case); + if(enkf_fs_exists( new_mount_point )) + exists = true; + free( new_mount_point ); + return exists; +} void enkf_main_user_select_fs(enkf_main_type * enkf_main , const char * input_case ) { @@ -2835,7 +2842,6 @@ enkf_main_type * enkf_main_bootstrap(const char * _site_config, const char * _mo enkf_main_rng_init( enkf_main ); /* Must be called before the ensmeble is created. */ enkf_main_init_subst_list( enkf_main ); ert_workflow_list_init( enkf_main->workflow_list , config , enkf_main->logh ); - enkf_main_init_qc( enkf_main , config ); enkf_main_init_data_kw( enkf_main , config ); analysis_config_load_internal_modules( enkf_main->analysis_config ); @@ -2851,6 +2857,8 @@ enkf_main_type * enkf_main_bootstrap(const char * _site_config, const char * _mo ecl_config_get_last_history_restart( enkf_main->ecl_config ), ecl_config_get_sched_file(enkf_main->ecl_config) , ecl_config_get_refcase( enkf_main->ecl_config )); + + enkf_main_init_qc( enkf_main , config ); enkf_main_update_num_cpu( enkf_main ); { const config_content_item_type * pred_item = config_get_content_item( config , SCHEDULE_PREDICTION_FILE_KEY ); diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_main_jobs.c b/ThirdParty/Ert/devel/libenkf/src/enkf_main_jobs.c index 513e6f165b..b993d5f99a 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_main_jobs.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_main_jobs.c @@ -58,7 +58,7 @@ void * enkf_main_smoother_JOB( void * self , const stringlist_type * args ) { int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc( 0 , true ); bool rerun = true; - const char * target_case = "AUTO-SMOOTHER"; + const char * target_case = stringlist_iget( args , 0 ); bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_run_smoother( enkf_main , target_case , rerun); @@ -75,3 +75,15 @@ void * enkf_main_create_reports_JOB(void * self , const stringlist_type * args ) return NULL; } +void * enkf_main_scale_obs_std_JOB(void * self, const stringlist_type * args ) { + enkf_main_type * enkf_main = enkf_main_safe_cast( self ); + + double scale_factor; + util_sscanf_double(stringlist_iget(args, 0), &scale_factor); + + if (enkf_main_have_obs(enkf_main)) { + enkf_obs_type * observations = enkf_main_get_obs(enkf_main); + enkf_obs_scale_std(observations, scale_factor); + } + return NULL; +} diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_obs.c b/ThirdParty/Ert/devel/libenkf/src/enkf_obs.c index f95cc2340a..7c0d65907b 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_obs.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_obs.c @@ -46,7 +46,7 @@ The observation system ---------------------- -The observation system in the EnKF code is a three leayer system. At +The observation system in the EnKF code is a three layer system. At the the top is the enkf_obs_type. The enkf_main object contains one enkf_obs instance which has internalized ALL the observation data. In enkf_obs the the data is internalized in a hash table, where the keys @@ -59,7 +59,7 @@ be NULL, if the observation is not active at this report step. In addition the obs_vector contains function pointers to manipulate the observation data at the lowest level. -At the lowest level we have spsesific observation instances, +At the lowest level we have specific observation instances, field_obs, summary_obs and gen_obs. These instances contain the actual data. @@ -484,7 +484,7 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , conf_instance_type * enkf_conf = conf_instance_alloc_from_file(enkf_conf_class, "enkf_conf", config_file); if(conf_instance_validate(enkf_conf) == false) - util_abort("Can not proceed with this configuration.\n"); + util_abort("Can not proceed with this configuration.\n"); if (enkf_obs->config_file != NULL) /* Clear current instance, observe that this function */ hash_clear( enkf_obs->obs_hash ); /* will reload even if it is called repeatedly with the */ @@ -503,9 +503,13 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , config_node = ensemble_config_add_summary( ensemble_config , obs_key , LOAD_FAIL_WARN ); if (config_node != NULL) { - obs_vector = obs_vector_alloc( SUMMARY_OBS , obs_key , ensemble_config_get_node( ensemble_config , obs_key ) , enkf_obs->obs_time , last_report); + obs_vector = obs_vector_alloc( SUMMARY_OBS , obs_key , ensemble_config_get_node( ensemble_config , obs_key ), last_report); if (obs_vector != NULL) { - if (obs_vector_load_from_HISTORY_OBSERVATION(obs_vector , hist_obs_conf , enkf_obs->history , ensemble_config , std_cutoff )) + if (obs_vector_load_from_HISTORY_OBSERVATION(obs_vector , + hist_obs_conf , + enkf_obs->history , + ensemble_config, + std_cutoff )) enkf_obs_add_obs_vector(enkf_obs, obs_key, obs_vector); else { fprintf(stderr,"** Could not load historical data for observation:%s - ignored\n",obs_key); @@ -536,7 +540,7 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , config_node = ensemble_config_add_summary( ensemble_config , sum_key , LOAD_FAIL_WARN ); if (config_node != NULL) { - obs_vector = obs_vector_alloc( SUMMARY_OBS , obs_key , ensemble_config_get_node( ensemble_config , sum_key ) , enkf_obs->obs_time , last_report); + obs_vector = obs_vector_alloc( SUMMARY_OBS , obs_key , ensemble_config_get_node( ensemble_config , sum_key ), last_report); if (obs_vector != NULL) { obs_vector_load_from_SUMMARY_OBSERVATION(obs_vector , sum_obs_conf , enkf_obs->history , ensemble_config); enkf_obs_add_obs_vector(enkf_obs, obs_key, obs_vector); @@ -557,7 +561,7 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , { const char * obs_key = stringlist_iget(block_obs_keys, block_obs_nr); const conf_instance_type * block_obs_conf = conf_instance_get_sub_instance_ref(enkf_conf, obs_key); - obs_vector_type * obs_vector = obs_vector_alloc_from_BLOCK_OBSERVATION(block_obs_conf , grid , refcase , enkf_obs->history , ensemble_config , enkf_obs->obs_time); + obs_vector_type * obs_vector = obs_vector_alloc_from_BLOCK_OBSERVATION(block_obs_conf , grid , refcase , enkf_obs->history ,ensemble_config); if (obs_vector != NULL) enkf_obs_add_obs_vector(enkf_obs, obs_key, obs_vector); } @@ -575,7 +579,7 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , const char * obs_key = stringlist_iget(block_obs_keys, block_obs_nr); const conf_instance_type * gen_obs_conf = conf_instance_get_sub_instance_ref(enkf_conf, obs_key); - obs_vector_type * obs_vector = obs_vector_alloc_from_GENERAL_OBSERVATION(gen_obs_conf , enkf_obs->history , ensemble_config , enkf_obs->obs_time); + obs_vector_type * obs_vector = obs_vector_alloc_from_GENERAL_OBSERVATION(gen_obs_conf , enkf_obs->history , ensemble_config); if (obs_vector != NULL) enkf_obs_add_obs_vector(enkf_obs, obs_key, obs_vector); } @@ -1052,7 +1056,17 @@ const obs_vector_type * enkf_obs_user_get_vector(const enkf_obs_type * obs , con return vector; } - - /*****************************************************************/ +void enkf_obs_scale_std(enkf_obs_type * enkf_obs, double scale_factor) { + + hash_iter_type * observation_vector_iterator = enkf_obs_alloc_iter(enkf_obs); + + while (!hash_iter_is_complete(observation_vector_iterator)) { + obs_vector_type * current_obs_vector = hash_iter_get_next_value(observation_vector_iterator); + obs_vector_scale_std(current_obs_vector, scale_factor); + } + + hash_iter_free(observation_vector_iterator); +} + diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_state.c b/ThirdParty/Ert/devel/libenkf/src/enkf_state.c index c0d15b6c7c..3453705a68 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_state.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_state.c @@ -752,7 +752,8 @@ static bool enkf_state_internalize_dynamic_results(enkf_state_type * enkf_state if (ecl_config_active( ecl_config )) { bool eclipse_load = enkf_state_internalize_dynamic_eclipse_results( enkf_state , fs , model_config , loadOK, interactive , msg_list); - fprintf(stderr , "** Warning: could not load ECLIPSE summary data from %s - this will probably fail later ...\n" , enkf_state->run_info->run_path); + if (!eclipse_load) + fprintf(stderr , "** Warning: could not load ECLIPSE summary data from %s - this will probably fail later ...\n" , enkf_state->run_info->run_path); return eclipse_load; } else return false; diff --git a/ThirdParty/Ert/devel/libenkf/src/gen_kw.c b/ThirdParty/Ert/devel/libenkf/src/gen_kw.c index 8759dc5ae7..2a58c09aea 100644 --- a/ThirdParty/Ert/devel/libenkf/src/gen_kw.c +++ b/ThirdParty/Ert/devel/libenkf/src/gen_kw.c @@ -260,7 +260,7 @@ bool gen_kw_fload(gen_kw_type * gen_kw , const char * filename) { if (!readOK) { int counter = 0; readOK = true; - fseek( stream , 0 , SEEK_SET ); + util_fseek( stream , 0 , SEEK_SET ); while ((counter < size) && readOK) { char key[128]; diff --git a/ThirdParty/Ert/devel/libenkf/src/gen_obs.c b/ThirdParty/Ert/devel/libenkf/src/gen_obs.c index ec080e4c0f..0e05394fe5 100644 --- a/ThirdParty/Ert/devel/libenkf/src/gen_obs.c +++ b/ThirdParty/Ert/devel/libenkf/src/gen_obs.c @@ -330,11 +330,6 @@ void gen_obs_get_observations(gen_obs_type * gen_obs , obs_data_type * obs_data, - - - - - /** In general the gen_obs observation vector can be smaller than the gen_data field it is observing, i.e. we can have a situation like @@ -368,11 +363,11 @@ void gen_obs_get_observations(gen_obs_type * gen_obs , obs_data_type * obs_data, The function gen_obs_user_get_with_data_index() will do the translation from data based indexing to observation based indexing, i.e. - gen_obs_user_get_with_data_index("obs_key:4") + gen_obs_user_get_with_data_index("4") will do an inverse lookup of the '4' and further call - gen_obs_user_get("obs_key:2") + gen_obs_user_get("2") */ @@ -416,6 +411,18 @@ void gen_obs_user_get_with_data_index(const gen_obs_type * gen_obs , const char } } +void gen_obs_scale_std(gen_obs_type * gen_obs, double std_multiplier) { + for (int i = 0; i < gen_obs->obs_size; i++) { + gen_obs->obs_std[i] *= std_multiplier; + } +} + +void gen_obs_scale_std__(void * gen_obs, double std_multiplier) { + gen_obs_type * observation = gen_obs_safe_cast(gen_obs); + gen_obs_scale_std(observation, std_multiplier); +} + + diff --git a/ThirdParty/Ert/devel/libenkf/src/local_config.c b/ThirdParty/Ert/devel/libenkf/src/local_config.c index 9bd4a995b9..64b143ca55 100644 --- a/ThirdParty/Ert/devel/libenkf/src/local_config.c +++ b/ThirdParty/Ert/devel/libenkf/src/local_config.c @@ -60,12 +60,13 @@ ministep to the updatestep, otherwise it will not be able to do anything. -CREATE_MINISTEP [NAME_OF_MINISTEP] ----------------------------------- +CREATE_MINISTEP [NAME_OF_MINISTEP OBSSET_NAME] +----------------------------------------------- This function will create a new ministep with the name -'NAME_OF_MINISTEP'. The ministep is then ready for adding data and -observation keys. Before the ministep will be used you must attach it -to an updatestep with the ATTACH_MINISTEP command +'NAME_OF_MINISTEP'. The ministep will be based on the observation +set given by OBSSET_NAME (which must be created first).The ministep +is then ready for adding data. Before the ministep can be used you +must attach it to an updatestep with the ATTACH_MINISTEP command CREATE_DATASET [NAME_OF_DATASET] -------------------------------- diff --git a/ThirdParty/Ert/devel/libenkf/src/obs_vector.c b/ThirdParty/Ert/devel/libenkf/src/obs_vector.c new file mode 100644 index 0000000000..7d32b64f84 --- /dev/null +++ b/ThirdParty/Ert/devel/libenkf/src/obs_vector.c @@ -0,0 +1,959 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'obs_vector.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. +*/ + +/** + See the overview documentation of the observation system in enkf_obs.c +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define OBS_VECTOR_TYPE_ID 120086 + +struct obs_vector_struct { + UTIL_TYPE_ID_DECLARATION; + obs_free_ftype *freef; /* Function used to free an observation node. */ + obs_get_ftype *get_obs; /* Function used to build the 'd' vector. */ + obs_meas_ftype *measure; /* Function used to measure on the state, and add to to the S matrix. */ + obs_user_get_ftype *user_get; /* Function to get an observation based on KEY:INDEX input from user.*/ + obs_chi2_ftype *chi2; /* Function to evaluate chi-squared for an observation. */ + obs_scale_std_ftype *scale_std; /* Function to scale the standard deviation with a given factor */ + + vector_type * nodes; + char * obs_key; /* The key this observation vector has in the enkf_obs layer. */ + enkf_config_node_type * config_node; /* The config_node of the node type we are observing - shared reference */ + obs_impl_type obs_type; + int num_active; /* The total number of timesteps where this observation is active (i.e. nodes[ ] != NULL) */ +}; + + +UTIL_IS_INSTANCE_FUNCTION(obs_vector , OBS_VECTOR_TYPE_ID) +UTIL_SAFE_CAST_FUNCTION(obs_vector , OBS_VECTOR_TYPE_ID) + +/*****************************************************************/ + + +static int __conf_instance_get_restart_nr(const conf_instance_type * conf_instance, const char * obs_key , const history_type * history , int size) { + int obs_restart_nr = -1; /* To shut up compiler warning. */ + + if(conf_instance_has_item(conf_instance, "RESTART")) { + obs_restart_nr = conf_instance_get_item_value_int(conf_instance, "RESTART"); + if(obs_restart_nr > size) + util_abort("%s: Observation %s occurs at restart %i, but history file has only %i restarts.\n", __func__, obs_key, obs_restart_nr, size); + } else if(conf_instance_has_item(conf_instance, "DATE")) { + time_t obs_date = conf_instance_get_item_value_time_t(conf_instance, "DATE" ); + obs_restart_nr = history_get_restart_nr_from_time_t( history , obs_date ); + } else if (conf_instance_has_item(conf_instance, "DAYS")) { + double days = conf_instance_get_item_value_double(conf_instance, "DAYS"); + obs_restart_nr = history_get_restart_nr_from_days( history , days ); + } else + util_abort("%s: Internal error. Invalid conf_instance?\n", __func__); + + return obs_restart_nr; +} + + + +/*****************************************************************/ + + +static void obs_vector_resize(obs_vector_type * vector , int new_size) { + int current_size = vector_get_size( vector->nodes ); + int i; + + for (i=current_size; i < new_size; i++) + vector_append_ref( vector->nodes , NULL); + +} + + +obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key , enkf_config_node_type * config_node, int num_reports) { + obs_vector_type * vector = util_malloc(sizeof * vector ); + + UTIL_TYPE_ID_INIT( vector , OBS_VECTOR_TYPE_ID); + vector->freef = NULL; + vector->measure = NULL; + vector->get_obs = NULL; + vector->user_get = NULL; + vector->chi2 = NULL; + vector->scale_std = NULL; + + switch (obs_type) { + case(SUMMARY_OBS): + vector->freef = summary_obs_free__; + vector->measure = summary_obs_measure__; + vector->get_obs = summary_obs_get_observations__; + vector->user_get = summary_obs_user_get__; + vector->chi2 = summary_obs_chi2__; + vector->scale_std = summary_obs_scale_std__; + break; + case(BLOCK_OBS): + vector->freef = block_obs_free__; + vector->measure = block_obs_measure__; + vector->get_obs = block_obs_get_observations__; + vector->user_get = block_obs_user_get__; + vector->chi2 = block_obs_chi2__; + vector->scale_std = block_obs_scale_std__; + break; + case(GEN_OBS): + vector->freef = gen_obs_free__; + vector->measure = gen_obs_measure__; + vector->get_obs = gen_obs_get_observations__; + vector->user_get = gen_obs_user_get__; + vector->chi2 = gen_obs_chi2__; + vector->scale_std = gen_obs_scale_std__; + break; + default: + util_abort("%s: internal error - obs_type:%d not recognized \n",__func__ , obs_type); + } + + vector->obs_type = obs_type; + vector->config_node = config_node; + vector->obs_key = util_alloc_string_copy( obs_key ); + vector->num_active = 0; + vector->nodes = vector_alloc_new(); + obs_vector_resize(vector , num_reports + 1); /* +1 here ?? Ohh - these +/- problems. */ + + return vector; +} + +obs_impl_type obs_vector_get_impl_type(const obs_vector_type * obs_vector) { + return obs_vector->obs_type; +} + + +/** + This is the key for the enkf_node which this observation is + 'looking at'. I.e. if this observation is an RFT pressure + measurement, this function will return "PRESSURE". +*/ + +const char * obs_vector_get_state_kw(const obs_vector_type * obs_vector) { + return enkf_config_node_get_key( obs_vector->config_node ); +} + + +enkf_config_node_type * obs_vector_get_config_node(obs_vector_type * obs_vector) { + return obs_vector->config_node; +} + + + +void obs_vector_free(obs_vector_type * obs_vector) { + vector_free( obs_vector->nodes ); + free(obs_vector->obs_key); + free(obs_vector); +} + + +static void obs_vector_assert_node_type( const obs_vector_type * obs_vector , const void * node ) { + bool type_OK; + switch (obs_vector->obs_type) { + case(SUMMARY_OBS): + type_OK = summary_obs_is_instance( node ); + break; + case(BLOCK_OBS): + type_OK = block_obs_is_instance( node ); + break; + case(GEN_OBS): + type_OK = gen_obs_is_instance( node ); + break; + default: + util_abort("%s: Error in type check: \n",__func__); + type_OK = false; + } + if (!type_OK) + util_abort("%s: Type mismatch when trying to add observation node to observation vector \n",__func__); +} + + + + +void obs_vector_del_node(obs_vector_type * obs_vector , int index) { + if (vector_iget_const( obs_vector->nodes , index ) != NULL) { + vector_iset_ref( obs_vector->nodes , index , NULL); /* Clear current content. */ + obs_vector->num_active--; + } +} + +/** + This function will clear (and free) all the summary_obs / gen_obs / + field_obs instances which have been installed in the vector; + however the vector itself is retained with keys, function pointers + and so on. +*/ + +void obs_vector_clear_nodes( obs_vector_type * obs_vector ) { + vector_clear( obs_vector->nodes ); + obs_vector->num_active = 0; +} + + + +void obs_vector_install_node(obs_vector_type * obs_vector , int index , void * node) { + obs_vector_assert_node_type( obs_vector , node ); + { + if (vector_iget_const( obs_vector->nodes , index ) == NULL) + obs_vector->num_active++; + + vector_iset_owned_ref( obs_vector->nodes , index , node , obs_vector->freef ); + } +} + +/** + Observe that @summary_key is the key used to look up the + corresponding simulated value in the ensemble, and not the + observation key - the two can be different. +*/ + +static void obs_vector_add_summary_obs( obs_vector_type * obs_vector , int obs_index , const char * summary_key , const char * obs_key , double value , double std , const char * auto_corrf_name , double auto_corrf_param) { + summary_obs_type * summary_obs = summary_obs_alloc( summary_key , obs_key , value , std , auto_corrf_name , auto_corrf_param); + obs_vector_install_node( obs_vector , obs_index , summary_obs ); +} + + +/*****************************************************************/ + +int obs_vector_get_num_active(const obs_vector_type * vector) { + return vector->num_active; +} + + +/** + IFF - only one - report step is active this function will return + that report step. If more than report step is active, the function + is ambiguous, and will fail HARD. Check with get_num_active first! +*/ + +int obs_vector_get_active_report_step(const obs_vector_type * vector) { + if (vector->num_active == 1) { + int active_step = -1; + int i; + for (i=0; i < vector_get_size(vector->nodes); i++) { + void * obs_node = vector_iget( vector->nodes , i); + if (obs_node != NULL) { + if (active_step >= 0) + util_abort("%s: internal error - mismatch in obs_vector->nodes and obs_vector->num_active \n",__func__); + active_step = i; + } + } + if (active_step < 0) + util_abort("%s: internal error - mismatch in obs_vector->nodes and obs_vector->num_active \n",__func__); + + return active_step; + } else { + util_abort("%s: when calling this function the number of active report steps MUST BE 1 - you had: %d \n",__func__ , vector->num_active); + return 0; /* Comiler shut up. */ + } +} + + + +bool obs_vector_iget_active(const obs_vector_type * vector, int index) { + /* We accept this ... */ + if (index >= vector_get_size( vector->nodes )) + return false; + + { + void * obs_data = vector_iget( vector->nodes , index ); + if (obs_data != NULL) + return true; + else + return false; + } +} + + +/* + Will happily return NULL if index is not active. +*/ +void * obs_vector_iget_node(const obs_vector_type * vector, int index) { + return vector_iget( vector->nodes , index ); +} + + +void obs_vector_user_get(const obs_vector_type * obs_vector , const char * index_key , int report_step , double * value , double * std , bool * valid) { + void * obs_node = obs_vector_iget_node( obs_vector , report_step ); + obs_vector->user_get(obs_node , index_key , value , std , valid); +} + +/* + This function returns the next active (i.e. node != NULL) report + step, starting with 'prev_step + 1'. If no more active steps are + found, it will return -1. +*/ + +int obs_vector_get_next_active_step(const obs_vector_type * obs_vector , int prev_step) { + if (prev_step >= (vector_get_size(obs_vector->nodes) - 1)) + return -1; + else { + int size = vector_get_size( obs_vector->nodes ); + int next_step = prev_step + 1; + while (( next_step < size) && (obs_vector_iget_node(obs_vector , next_step) == NULL)) + next_step++; + + if (next_step == size) + return -1; /* No more active steps. */ + else + return next_step; + } +} + + +/*****************************************************************/ +/** + All the obs_vector_load_from_XXXX() functions can safely return + NULL, in which case no observation is added to enkf_obs observation + hash table. +*/ + + +void obs_vector_load_from_SUMMARY_OBSERVATION(obs_vector_type * obs_vector , const conf_instance_type * conf_instance , const history_type * history, ensemble_config_type * ensemble_config) { + if(!conf_instance_is_of_class(conf_instance, "SUMMARY_OBSERVATION")) + util_abort("%s: internal error. expected \"SUMMARY_OBSERVATION\" instance, got \"%s\".\n", + __func__, conf_instance_get_class_name_ref(conf_instance) ); + + { + double obs_value = conf_instance_get_item_value_double(conf_instance, "VALUE" ); + double obs_error = conf_instance_get_item_value_double(conf_instance, "ERROR" ); + double min_error = conf_instance_get_item_value_double(conf_instance, "ERROR_MIN"); + const char * error_mode = conf_instance_get_item_value_ref( conf_instance, "ERROR_MODE"); + const char * sum_key = conf_instance_get_item_value_ref( conf_instance, "KEY" ); + const char * obs_key = conf_instance_get_name_ref(conf_instance); + int size = history_get_last_restart( history ); + int obs_restart_nr = __conf_instance_get_restart_nr(conf_instance , obs_key , history , size); + + if (obs_restart_nr == 0) { + int day,month,year; + time_t start_time = history_get_time_t_from_restart_nr( history , 0 ); + util_set_date_values( start_time , &day , &month , &year); + + fprintf(stderr,"** ERROR: It is unfortunately not possible to use summary observations from the\n"); + fprintf(stderr," start of the simulation. Problem with observation:%s at %02d/%02d/%4d\n",obs_key , day,month,year); + exit(1); + } + { + if (strcmp( error_mode , "REL") == 0) + obs_error *= obs_value; + else if (strcmp( error_mode , "RELMIN") == 0) + obs_error = util_double_max( min_error , obs_error * obs_value ); + + obs_vector_add_summary_obs( obs_vector , obs_restart_nr , sum_key , obs_key , obs_value , obs_error , NULL , 0); + } + } +} + + + + +obs_vector_type * obs_vector_alloc_from_GENERAL_OBSERVATION(const conf_instance_type * conf_instance , const history_type * history, const ensemble_config_type * ensemble_config) { + if(!conf_instance_is_of_class(conf_instance, "GENERAL_OBSERVATION")) + util_abort("%s: internal error. expected \"GENERAL_OBSERVATION\" instance, got \"%s\".\n", + __func__, conf_instance_get_class_name_ref(conf_instance) ); + const char * obs_key = conf_instance_get_name_ref(conf_instance); + const char * state_kw = conf_instance_get_item_value_ref( conf_instance, "DATA" ); + if (ensemble_config_has_key( ensemble_config , state_kw )) { + const char * obs_key = conf_instance_get_name_ref(conf_instance); + int size = history_get_last_restart( history ); + obs_vector_type * obs_vector = obs_vector_alloc( GEN_OBS , obs_key , ensemble_config_get_node(ensemble_config , state_kw ), size); + int obs_restart_nr = __conf_instance_get_restart_nr(conf_instance , obs_key , history , size); + const char * index_file = NULL; + const char * index_list = NULL; + const char * obs_file = NULL; + const char * error_covar_file = NULL; + + if (conf_instance_has_item(conf_instance , "INDEX_FILE")) + index_file = conf_instance_get_item_value_ref( conf_instance, "INDEX_FILE" ); + + if (conf_instance_has_item(conf_instance , "INDEX_LIST")) + index_list = conf_instance_get_item_value_ref( conf_instance, "INDEX_LIST" ); + + if (conf_instance_has_item(conf_instance , "OBS_FILE")) + obs_file = conf_instance_get_item_value_ref( conf_instance, "OBS_FILE" ); + + if (conf_instance_has_item(conf_instance , "ERROR_COVAR")) + error_covar_file = conf_instance_get_item_value_ref( conf_instance, "ERROR_COVAR" ); + + { + const enkf_config_node_type * config_node = ensemble_config_get_node( ensemble_config , state_kw); + if (enkf_config_node_get_impl_type(config_node) == GEN_DATA) { + double scalar_error = -1; + double scalar_value = -1; + gen_obs_type * gen_obs ; + + if (conf_instance_has_item(conf_instance , "VALUE")) { + scalar_value = conf_instance_get_item_value_double(conf_instance , "VALUE"); + scalar_error = conf_instance_get_item_value_double(conf_instance , "ERROR"); + } + + /** The config system has ensured that we have either OBS_FILE or (VALUE and ERROR). */ + gen_obs = gen_obs_alloc( enkf_config_node_get_ref( config_node ) , obs_key , obs_file , scalar_value , scalar_error , index_file , index_list , error_covar_file); + obs_vector_install_node( obs_vector , obs_restart_nr , gen_obs ); + } else { + ert_impl_type impl_type = enkf_config_node_get_impl_type(config_node); + util_abort("%s: %s has implementation type:\'%s\' - expected:\'%s\'.\n",__func__ , state_kw , enkf_types_get_impl_name(impl_type) , enkf_types_get_impl_name(GEN_DATA)); + } + } + return obs_vector; + } else { + fprintf(stderr,"** Warning the ensemble key:%s does not exist - observation:%s not added \n", state_kw , obs_key); + return NULL; + } +} + + + +// Should check the refcase for key - if it is != NULL. + +bool obs_vector_load_from_HISTORY_OBSERVATION(obs_vector_type * obs_vector , + const conf_instance_type * conf_instance , + const history_type * history , + ensemble_config_type * ensemble_config, + double std_cutoff ) { + + if(!conf_instance_is_of_class(conf_instance, "HISTORY_OBSERVATION")) + util_abort("%s: internal error. expected \"HISTORY_OBSERVATION\" instance, got \"%s\".\n",__func__, conf_instance_get_class_name_ref(conf_instance) ); + + { + bool initOK = false; + int size , restart_nr; + double_vector_type * value = double_vector_alloc(0,0); + double_vector_type * std = double_vector_alloc(0,0); + bool_vector_type * valid = bool_vector_alloc(0 , false); + + /* The auto_corrf parameters can not be "segmentized" */ + double auto_corrf_param = -1; + const char * auto_corrf_name = NULL; + + + double error = conf_instance_get_item_value_double(conf_instance, "ERROR" ); + double error_min = conf_instance_get_item_value_double(conf_instance, "ERROR_MIN" ); + const char * error_mode = conf_instance_get_item_value_ref( conf_instance, "ERROR_MODE"); + const char * sum_key = conf_instance_get_name_ref( conf_instance ); + + if(conf_instance_has_item(conf_instance, "AUTO_CORRF")) { + auto_corrf_name = conf_instance_get_item_value_ref( conf_instance , "AUTO_CORRF"); + auto_corrf_param = conf_instance_get_item_value_double(conf_instance, "AUTO_CORRF_PARAM"); + if(conf_instance_has_item(conf_instance, "AUTO_CORRF_PARAM")) + auto_corrf_param = conf_instance_get_item_value_double(conf_instance, "AUTO_CORRF_PARAM"); + else + util_abort("%s: When specifying AUTO_CORRF you must also give a vlaue for AUTO_CORRF_PARAM",__func__); + } + + + // Get time series data from history object and allocate + size = history_get_last_restart(history); + if (history_init_ts( history , sum_key , value , valid )) { + + // Create the standard deviation vector + if(strcmp(error_mode, "ABS") == 0) { + for( restart_nr = 0; restart_nr < size; restart_nr++) + double_vector_iset( std , restart_nr , error ); + } else if(strcmp(error_mode, "REL") == 0) { + for( restart_nr = 0; restart_nr < size; restart_nr++) + double_vector_iset( std , restart_nr , error * abs( double_vector_iget( value , restart_nr ))); + } else if(strcmp(error_mode, "RELMIN") == 0) { + for(restart_nr = 0; restart_nr < size; restart_nr++) { + double tmp_std = util_double_max( error_min , error * abs( double_vector_iget( value , restart_nr ))); + double_vector_iset( std , restart_nr , tmp_std); + } + } else + util_abort("%s: Internal error. Unknown error mode \"%s\"\n", __func__, error_mode); + + + // Handle SEGMENTs which can be used to customize the observation error. */ + { + stringlist_type * segment_keys = conf_instance_alloc_list_of_sub_instances_of_class_by_name(conf_instance, "SEGMENT"); + stringlist_sort( segment_keys , NULL ); + + int num_segments = stringlist_get_size(segment_keys); + + for(int segment_nr = 0; segment_nr < num_segments; segment_nr++) + { + const char * segment_name = stringlist_iget(segment_keys, segment_nr); + const conf_instance_type * segment_conf = conf_instance_get_sub_instance_ref(conf_instance, segment_name); + + int start = conf_instance_get_item_value_int( segment_conf, "START" ); + int stop = conf_instance_get_item_value_int( segment_conf, "STOP" ); + double error_segment = conf_instance_get_item_value_double(segment_conf, "ERROR" ); + double error_min_segment = conf_instance_get_item_value_double(segment_conf, "ERROR_MIN" ); + const char * error_mode_segment = conf_instance_get_item_value_ref( segment_conf, "ERROR_MODE"); + + if(start < 0) + { + printf("%s: WARNING - Segment out of bounds. Truncating start of segment to 0.\n", __func__); + start = 0; + } + + if(stop >= size) + { + printf("%s: WARNING - Segment out of bounds. Truncating end of segment to %d.\n", __func__, size - 1); + stop = size -1; + } + + if(start > stop) + { + printf("%s: WARNING - Segment start after stop. Truncating end of segment to %d.\n", __func__, start ); + stop = start; + } + + // Create the standard deviation vector + if(strcmp(error_mode_segment, "ABS") == 0) { + for( restart_nr = start; restart_nr <= stop; restart_nr++) + double_vector_iset( std , restart_nr , error_segment) ; + } else if(strcmp(error_mode_segment, "REL") == 0) { + for( restart_nr = start; restart_nr <= stop; restart_nr++) + double_vector_iset( std , restart_nr , error_segment * abs(double_vector_iget( value , restart_nr))); + } else if(strcmp(error_mode_segment, "RELMIN") == 0) { + for(restart_nr = start; restart_nr <= stop ; restart_nr++) { + double tmp_std = util_double_max( error_min_segment , error_segment * abs( double_vector_iget( value , restart_nr ))); + double_vector_iset( std , restart_nr , tmp_std); + } + } else + util_abort("%s: Internal error. Unknown error mode \"%s\"\n", __func__, error_mode); + } + stringlist_free(segment_keys); + } + + + /* + This is where the summary observations are finally added. + */ + for (restart_nr = 0; restart_nr < size; restart_nr++) { + if (bool_vector_safe_iget( valid , restart_nr)) { + if (double_vector_iget( std , restart_nr) > std_cutoff) { + obs_vector_add_summary_obs( obs_vector , restart_nr , sum_key , sum_key , + double_vector_iget( value ,restart_nr) , double_vector_iget( std , restart_nr ) , + auto_corrf_name , auto_corrf_param); + } else + fprintf(stderr,"** Warning: to small observation error in observation %s:%d - ignored. \n", sum_key , restart_nr); + } + } + initOK = true; + } + double_vector_free(std); + double_vector_free(value); + bool_vector_free(valid); + return initOK; + } +} + +void obs_vector_scale_std(obs_vector_type * obs_vector, double std_multiplier) { + vector_type * observation_nodes = obs_vector->nodes; + + for (int i=0; iscale_std(observation, std_multiplier); + } + + } +} + + +static const char * __summary_kw( const char * field_name ) { + if (strcmp( field_name , "PRESSURE") == 0) + return "BPR"; + else if (strcmp( field_name , "SWAT") == 0) + return "BSWAT"; + else if (strcmp( field_name , "SGAS") == 0) + return "BSGAS"; + else { + util_abort("%s: sorry - could not \'translate\' field:%s to block summary variable\n",__func__ , field_name); + return NULL; + } +} + + +obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_type * conf_instance , + const ecl_grid_type * grid , + const ecl_sum_type * refcase , + const history_type * history, + ensemble_config_type * ensemble_config) { + + if(!conf_instance_is_of_class(conf_instance, "BLOCK_OBSERVATION")) + util_abort("%s: internal error. expected \"BLOCK_OBSERVATION\" instance, got \"%s\".\n", + __func__, conf_instance_get_class_name_ref(conf_instance) ); + + block_obs_source_type source_type = SOURCE_SUMMARY; + const char * obs_label = conf_instance_get_name_ref(conf_instance); + const char * source_string = conf_instance_get_item_value_ref(conf_instance , "SOURCE"); + const char * field_name = conf_instance_get_item_value_ref(conf_instance , "FIELD"); + const char * sum_kw = NULL; + bool OK = true; + + if (strcmp(source_string , "FIELD") == 0) { + source_type = SOURCE_FIELD; + if (!ensemble_config_has_key( ensemble_config , field_name)) { + OK = false; + fprintf(stderr,"** Warning the ensemble key:%s does not exist - observation:%s not added \n", field_name , obs_label); + } + } else if (strcmp( source_string , "SUMMARY") == 0) { + source_type = SOURCE_SUMMARY; + sum_kw = __summary_kw( field_name ); + } else + util_abort("%s: internal error \n",__func__); + + if (OK) { + obs_vector_type * obs_vector = NULL; + int size = history_get_last_restart( history ); + int obs_restart_nr ; + + stringlist_type * summary_keys = stringlist_alloc_new(); + stringlist_type * obs_pt_keys = conf_instance_alloc_list_of_sub_instances_of_class_by_name(conf_instance, "OBS"); + int num_obs_pts = stringlist_get_size(obs_pt_keys); + + double * obs_value = util_calloc(num_obs_pts , sizeof * obs_value); + double * obs_std = util_calloc(num_obs_pts , sizeof * obs_std ); + int * obs_i = util_calloc(num_obs_pts , sizeof * obs_i ); + int * obs_j = util_calloc(num_obs_pts , sizeof * obs_j ); + int * obs_k = util_calloc(num_obs_pts , sizeof * obs_k ); + + obs_restart_nr = __conf_instance_get_restart_nr(conf_instance , obs_label , history , size); + + /** Build the observation. */ + for(int obs_pt_nr = 0; obs_pt_nr < num_obs_pts; obs_pt_nr++) { + const char * obs_key = stringlist_iget(obs_pt_keys, obs_pt_nr); + const conf_instance_type * obs_instance = conf_instance_get_sub_instance_ref(conf_instance, obs_key); + const char * error_mode = conf_instance_get_item_value_ref(obs_instance, "ERROR_MODE"); + double error = conf_instance_get_item_value_double(obs_instance, "ERROR"); + double value = conf_instance_get_item_value_double(obs_instance, "VALUE"); + double min_error = conf_instance_get_item_value_double(obs_instance, "ERROR_MIN"); + + if (strcmp( error_mode , "REL") == 0) + error *= value; + else if (strcmp( error_mode , "RELMIN") == 0) + error = util_double_max( error * value , min_error ); + + obs_value[obs_pt_nr] = value; + obs_std [obs_pt_nr] = error; + + /** + The input values i,j,k come from the user, and are offset 1. They + are immediately shifted with -1 to become C-based offset zero. + */ + obs_i[obs_pt_nr] = conf_instance_get_item_value_int( obs_instance, "I") - 1; + obs_j[obs_pt_nr] = conf_instance_get_item_value_int( obs_instance, "J") - 1; + obs_k[obs_pt_nr] = conf_instance_get_item_value_int( obs_instance, "K") - 1; + + if (source_type == SOURCE_SUMMARY) { + char * summary_key = smspec_alloc_block_ijk_key( SUMMARY_KEY_JOIN_STRING , sum_kw , + obs_i[obs_pt_nr] + 1 , + obs_j[obs_pt_nr] + 1 , + obs_k[obs_pt_nr] + 1 ); + + stringlist_append_owned_ref( summary_keys , summary_key ); + } + } + + + if (source_type == SOURCE_FIELD) { + const enkf_config_node_type * config_node = ensemble_config_get_node( ensemble_config , field_name); + const field_config_type * field_config = enkf_config_node_get_ref( config_node ); + block_obs_type * block_obs = block_obs_alloc(obs_label, source_type , NULL , field_config , grid , num_obs_pts, obs_i, obs_j, obs_k, obs_value, obs_std); + + if (block_obs != NULL) { + obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , ensemble_config_get_node(ensemble_config , field_name), size ); + obs_vector_install_node( obs_vector , obs_restart_nr , block_obs); + } + } else if (source_type == SOURCE_SUMMARY) { + OK = true; + if (refcase != NULL) { + for (int i=0; i < stringlist_get_size( summary_keys ); i++) { + const char * sum_key = stringlist_iget( summary_keys , i ); + if (!ecl_sum_has_key(refcase , sum_key)) { + /* + If the + */ + fprintf(stderr,"** Warning missing summary %s for cell: (%d,%d,%d) in refcase - make sure that \"BPR %d %d %d\" is included in ECLIPSE summary specification \n" , + sum_key , obs_i[i]+1 , obs_j[i]+1 , obs_k[i]+1 , obs_i[i]+1 , obs_j[i]+1 , obs_k[i]+1 ); + //OK = false; + } + } + } + if (OK) { + // We can create the container node and add the summary nodes. + enkf_config_node_type * container_config = ensemble_config_add_container( ensemble_config , NULL ); + + for (int i=0; i < stringlist_get_size( summary_keys ); i++) { + const char * sum_key = stringlist_iget( summary_keys , i ); + enkf_config_node_type * child_node = ensemble_config_add_summary( ensemble_config , sum_key , LOAD_FAIL_WARN ); + enkf_config_node_update_container( container_config , child_node ); + } + + { + block_obs_type * block_obs = block_obs_alloc(obs_label, source_type , summary_keys , container_config , grid , num_obs_pts, obs_i, obs_j, obs_k, obs_value, obs_std); + if (block_obs != NULL) { + obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , container_config, size ); + obs_vector_install_node( obs_vector , obs_restart_nr , block_obs); + } + } + } + } else + util_abort("%s: invalid source value \n",__func__); + + free(obs_value); + free(obs_std); + free(obs_i); + free(obs_j); + free(obs_k); + stringlist_free(obs_pt_keys); + stringlist_free(summary_keys); + + return obs_vector; + } else { + fprintf(stderr,"** Warning the ensemble key:%s does not exist - observation:%s not added \n", field_name , obs_label); + return NULL; + } +} +/*****************************************************************/ + +void obs_vector_iget_observations(const obs_vector_type * obs_vector , int report_step , obs_data_type * obs_data, const active_list_type * active_list) { + void * obs_node = vector_iget( obs_vector->nodes , report_step ); + if ( obs_node != NULL) + obs_vector->get_obs(obs_node , obs_data , report_step , active_list); +} + + +void obs_vector_measure(const obs_vector_type * obs_vector , enkf_fs_type * fs , state_enum state , int report_step , const enkf_state_type * enkf_state , meas_data_type * meas_data , const active_list_type * active_list) { + + void * obs_node = vector_iget( obs_vector->nodes , report_step ); + if ( obs_node != NULL ) { + enkf_node_type * enkf_node = enkf_state_get_node( enkf_state , obs_vector_get_state_kw( obs_vector )); + node_id_type node_id = { .report_step = report_step , + .state = state , + .iens = enkf_state_get_iens( enkf_state ) }; + + enkf_node_load(enkf_node , fs , node_id); + obs_vector->measure(obs_node , enkf_node_value_ptr(enkf_node) , node_id , meas_data , active_list); + } +} + + + +/*****************************************************************/ +/** Here comes many different functions for misfit calculations. */ + +/** + This is the lowest level function: + + * It is checked that the obs_vector is active for the actual report + step; if it is not active 0.0 is returned without any further + ado. + + * It is assumed the enkf_node_instance contains valid data for this + report_step. This is not checked in this function, and is the + responsability of the calling scope. + + * The underlying chi2 function will do a type-check of node - and + fail hard if it is not correct. + +*/ + + +static double obs_vector_chi2__(const obs_vector_type * obs_vector , int report_step , const enkf_node_type * node, node_id_type node_id) { + void * obs_node = vector_iget( obs_vector->nodes , report_step ); + + if ( obs_node != NULL) + return obs_vector->chi2( obs_node , enkf_node_value_ptr( node ), node_id); + else + return 0.0; /* Observation not active for this report step. */ + +} + + + + + +double obs_vector_chi2(const obs_vector_type * obs_vector , enkf_fs_type * fs , node_id_type node_id) { + enkf_node_type * enkf_node = enkf_node_alloc( obs_vector->config_node ); + double chi2 = 0; + + if (enkf_node_try_load( enkf_node , fs , node_id)) + chi2 = obs_vector_chi2__(obs_vector , node_id.report_step , enkf_node , node_id); + + enkf_node_free( enkf_node ); + return chi2; +} + + + + +/** + This function will evaluate the chi2 for the ensemble members + [iens1,iens2) and report steps [step1,step2). + + Observe that the chi2 pointer is assumed to be allocated for the + complete ensemble, altough this function only operates on part of + it. +*/ + + +//This will not work for container observations ..... + +void obs_vector_ensemble_chi2(const obs_vector_type * obs_vector , + enkf_fs_type * fs, + bool_vector_type * valid , + int step1 , + int step2 , + int iens1 , + int iens2 , + state_enum load_state , + double ** chi2) { + + int step; + enkf_node_type * enkf_node = enkf_node_alloc( obs_vector->config_node ); + node_id_type node_id; + node_id.state = load_state; + for (step = step1; step <= step2; step++) { + int iens; + node_id.report_step = step; + { + void * obs_node = vector_iget( obs_vector->nodes , step); + + if (obs_node == NULL) { + for (iens = iens1; iens < iens2; iens++) + chi2[step][iens] = 0; + } else { + for (iens = iens1; iens < iens2; iens++) { + node_id.iens = iens; + if (enkf_node_try_load( enkf_node , fs , node_id)) + chi2[step][iens] = obs_vector_chi2__(obs_vector , step , enkf_node , node_id); + else { + chi2[step][iens] = 0; + // Missing data - this member will be marked as invalid in the misfit calculations. + bool_vector_iset( valid , iens , false ); + } + } + } + } + } + enkf_node_free( enkf_node ); +} + + + +/** + This function will evaluate the total chi2 for one ensemble member + (i.e. sum over report steps). +*/ + + +double obs_vector_total_chi2(const obs_vector_type * obs_vector , enkf_fs_type * fs , int iens, state_enum load_state) { + int report_step; + double sum_chi2 = 0; + enkf_node_type * enkf_node = enkf_node_alloc( obs_vector->config_node ); + node_id_type node_id = {.report_step = 0, .iens = iens , .state = load_state }; + + for (report_step = 0; report_step < vector_get_size( obs_vector->nodes ); report_step++) { + if (vector_iget(obs_vector->nodes , report_step) != NULL) { + node_id.report_step = report_step; + + if (enkf_node_try_load( enkf_node , fs , node_id)) + sum_chi2 += obs_vector_chi2__(obs_vector , report_step , enkf_node, node_id); + + } + } + enkf_node_free( enkf_node ); + return sum_chi2; +} + + +/** + This function will sum up all timesteps of the obs_vector, for all ensemble members. +*/ + +void obs_vector_ensemble_total_chi2(const obs_vector_type * obs_vector , enkf_fs_type * fs , int ens_size , state_enum load_state , double * sum_chi2) { + const bool verbose = true; + msg_type * msg; + int report_step; + int iens; + char * msg_text = NULL; + + for (iens = 0; iens < ens_size; iens++) + sum_chi2[iens] = 0; + + if (verbose) { + msg = msg_alloc("Observation: " , false); + msg_show(msg); + } + + { + node_id_type node_id = {.report_step = 0, .iens = iens , .state = load_state }; + enkf_node_type * enkf_node = enkf_node_alloc( obs_vector->config_node ); + for (report_step = 0; report_step < vector_get_size( obs_vector->nodes); report_step++) { + if (verbose) { + msg_text = util_realloc_sprintf( msg_text , "%s[%03d]" , obs_vector->obs_key , report_step); + msg_update(msg , msg_text); + } + if (vector_iget(obs_vector->nodes , report_step) != NULL) { + node_id.report_step = report_step; + for (iens = 0; iens < ens_size; iens++) { + node_id.iens = iens; + + if (enkf_node_try_load( enkf_node , fs , node_id)) + sum_chi2[iens] += obs_vector_chi2__(obs_vector , report_step , enkf_node, node_id); + + } + } + } + enkf_node_free( enkf_node ); + } + + if (verbose) { + msg_free(msg , true); + util_safe_free( msg_text ); + } +} + +const char * obs_vector_get_obs_key( const obs_vector_type * obs_vector) { + return obs_vector->obs_key; +} + + +/*****************************************************************/ + + +VOID_FREE(obs_vector) + diff --git a/ThirdParty/Ert/devel/libenkf/src/qc_module.c b/ThirdParty/Ert/devel/libenkf/src/qc_module.c index 760ffa436e..556d4b5871 100644 --- a/ThirdParty/Ert/devel/libenkf/src/qc_module.c +++ b/ThirdParty/Ert/devel/libenkf/src/qc_module.c @@ -54,21 +54,15 @@ qc_module_type * qc_module_alloc( ert_workflow_list_type * workflow_list , const qc_module->runpath_list = runpath_list_alloc(); qc_module->runpath_list_file = NULL; qc_module_set_path( qc_module , qc_path ); - { - char * cwd = util_alloc_cwd(); - char * runpath_list_file = util_alloc_filename( cwd , RUNPATH_LIST_FILE , NULL); + qc_module_set_runpath_list_file( qc_module , NULL, RUNPATH_LIST_FILE ); - qc_module_set_runpath_list_file( qc_module , runpath_list_file ); - - free( runpath_list_file ); - free( cwd ); - } return qc_module; } void qc_module_free( qc_module_type * qc_module ) { util_safe_free( qc_module->qc_path ); + util_safe_free( qc_module->runpath_list_file); runpath_list_free( qc_module->runpath_list ); free( qc_module ); } @@ -83,9 +77,38 @@ void qc_module_export_runpath_list( const qc_module_type * qc_module ) { runpath_list_fprintf( qc_module->runpath_list , stream ); fclose( stream ); } + +static void qc_module_set_runpath_list_file__( qc_module_type * qc_module , const char * runpath_list_file) { + util_safe_free( qc_module->runpath_list_file ); + qc_module->runpath_list_file = util_alloc_string_copy( runpath_list_file ); +} -void qc_module_set_runpath_list_file( qc_module_type * qc_module , const char * filename) { - qc_module->runpath_list_file = util_realloc_string_copy( qc_module->runpath_list_file , filename ); + +void qc_module_set_runpath_list_file( qc_module_type * qc_module , const char * basepath, const char * filename) { + + if (filename && util_is_abs_path( filename )) + qc_module_set_runpath_list_file__( qc_module , filename ); + else { + const char * file = RUNPATH_LIST_FILE; + + if (filename != NULL) + file = filename; + + char * file_with_path_prefix = NULL; + if (basepath != NULL) { + file_with_path_prefix = util_alloc_filename(basepath, file, NULL); + } + else + file_with_path_prefix = util_alloc_string_copy(file); + + { + char * absolute_path = util_alloc_abs_path(file_with_path_prefix); + qc_module_set_runpath_list_file__( qc_module , absolute_path ); + free( absolute_path ); + } + + free(file_with_path_prefix); + } } const char * qc_module_get_runpath_list_file( qc_module_type * qc_module) { @@ -149,6 +172,9 @@ void qc_module_init( qc_module_type * qc_module , const config_type * config) { const char * qc_workflow = config_get_value_as_path(config , QC_WORKFLOW_KEY); qc_module_set_workflow( qc_module , qc_workflow ); } + + if (config_item_set( config, RUNPATH_FILE_KEY)) + qc_module_set_runpath_list_file(qc_module, NULL, config_get_value(config, RUNPATH_FILE_KEY)); } @@ -162,6 +188,9 @@ void qc_module_add_config_items( config_type * config ) { item = config_add_schema_item( config , QC_WORKFLOW_KEY , false ); config_schema_item_set_argc_minmax(item , 1 , 1 ); config_schema_item_iset_type( item , 0 , CONFIG_EXISTING_PATH ); + + item = config_add_schema_item( config , RUNPATH_FILE_KEY , false ); + config_schema_item_set_argc_minmax(item , 1 , 1 ); } diff --git a/ThirdParty/Ert/devel/libenkf/src/rng_config.c b/ThirdParty/Ert/devel/libenkf/src/rng_config.c index bea6a62229..d4be6ed809 100644 --- a/ThirdParty/Ert/devel/libenkf/src/rng_config.c +++ b/ThirdParty/Ert/devel/libenkf/src/rng_config.c @@ -98,10 +98,12 @@ rng_type * rng_config_alloc_rng( rng_config_type * rng_config ) { In the special case that seed_load == seed_store; we accept a seed_load argument pointing to a non-existant file. */ - if (test_string_equal( seed_load , seed_store)) - rng_init( rng , INIT_DEV_URANDOM ); - else - util_abort("%s: tried to load random seed from non-existing file:%s \n",__func__ , seed_load); + if (seed_store) { + if (util_string_equal( seed_store , seed_load)) + rng_init( rng , INIT_DEV_URANDOM ); + else + util_abort("%s: tried to load random seed from non-existing file:%s \n",__func__ , seed_load); + } } } else rng_init( rng , INIT_DEV_URANDOM ); diff --git a/ThirdParty/Ert/devel/libenkf/src/summary_obs.c b/ThirdParty/Ert/devel/libenkf/src/summary_obs.c index 3c002bedb4..7a5f2ba57f 100644 --- a/ThirdParty/Ert/devel/libenkf/src/summary_obs.c +++ b/ThirdParty/Ert/devel/libenkf/src/summary_obs.c @@ -119,6 +119,7 @@ UTIL_IS_INSTANCE_FUNCTION(summary_obs , SUMMARY_OBS_TYPE_ID); void summary_obs_free(summary_obs_type * summary_obs) { free(summary_obs->summary_key); + free(summary_obs->obs_key); free(summary_obs); } @@ -198,6 +199,15 @@ double summary_obs_get_std( const summary_obs_type * summary_obs ) { return summary_obs->std; } +void summary_obs_scale_std(summary_obs_type * summary_obs, double std_multiplier ) { + summary_obs->std = summary_obs->std * std_multiplier; +} + +void summary_obs_scale_std__(void * summary_obs, double std_multiplier ) { + summary_obs_type * observation = summary_obs_safe_cast(summary_obs); + summary_obs_scale_std(observation, std_multiplier); +} + /*****************************************************************/ diff --git a/ThirdParty/Ert/devel/libenkf/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libenkf/tests/CMakeLists.txt index fbfba306bd..a4ebfbc40e 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libenkf/tests/CMakeLists.txt @@ -1,67 +1,80 @@ add_executable( enkf_runpath_list enkf_runpath_list.c ) -target_link_libraries( enkf_runpath_list enkf ) +target_link_libraries( enkf_runpath_list enkf test_util ) add_executable( enkf_site_config enkf_site_config.c ) -target_link_libraries( enkf_site_config enkf ) +target_link_libraries( enkf_site_config enkf test_util ) add_executable( enkf_time_map enkf_time_map.c ) -target_link_libraries( enkf_time_map enkf ) +target_link_libraries( enkf_time_map enkf test_util ) add_executable( enkf_ensemble_GEN_PARAM enkf_ensemble_GEN_PARAM.c ) -target_link_libraries( enkf_ensemble_GEN_PARAM enkf ) +target_link_libraries( enkf_ensemble_GEN_PARAM enkf test_util ) add_executable( enkf_ensemble enkf_ensemble.c ) -target_link_libraries( enkf_ensemble enkf ) +target_link_libraries( enkf_ensemble enkf test_util ) add_executable( enkf_main enkf_main.c ) -target_link_libraries( enkf_main enkf ) +target_link_libraries( enkf_main enkf test_util ) add_test( enkf_main ${EXECUTABLE_OUTPUT_PATH}/enkf_main ) #----------------------------------------------------------------- add_executable( enkf_forward_init_GEN_KW enkf_forward_init_GEN_KW.c ) -target_link_libraries( enkf_forward_init_GEN_KW enkf ) -add_test( enkf_forward_init_GEN_KW_TRUE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_KW ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/config_GEN_KW_true TRUE) -add_test( enkf_forward_init_GEN_KW_FALSE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_KW ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/config_GEN_KW_false FALSE) +target_link_libraries( enkf_forward_init_GEN_KW enkf test_util ) + +add_test( enkf_forward_init_GEN_KW_TRUE + ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_KW + ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_KW_true TRUE) + +add_test( enkf_forward_init_GEN_KW_FALSE + ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_KW + ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_KW_false FALSE) + #----------------------------------------------------------------- add_executable( enkf_forward_init_GEN_PARAM enkf_forward_init_GEN_PARAM.c ) -target_link_libraries( enkf_forward_init_GEN_PARAM enkf ) -add_test( enkf_forward_init_GEN_PARAM_TRUE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_PARAM ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/config_GEN_PARAM_true TRUE) -add_test( enkf_forward_init_GEN_PARAM_FALSE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_PARAM ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/config_GEN_PARAM_false FALSE) +target_link_libraries( enkf_forward_init_GEN_PARAM enkf test_util ) + +add_test( enkf_forward_init_GEN_PARAM_TRUE + ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_PARAM + ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_PARAM_true TRUE) + +add_test( enkf_forward_init_GEN_PARAM_FALSE + ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_PARAM + ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_PARAM_false FALSE) #----------------------------------------------------------------- add_executable( enkf_forward_init_SURFACE enkf_forward_init_SURFACE.c ) -target_link_libraries( enkf_forward_init_SURFACE enkf ) +target_link_libraries( enkf_forward_init_SURFACE enkf test_util ) add_test( enkf_forward_init_SURFACE_TRUE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_SURFACE - ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface/config_surface_true + ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface config_surface_true ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface/Surface.irap TRUE) add_test( enkf_forward_init_SURFACE_FALSE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_SURFACE - ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface/config_surface_false + ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface config_surface_false ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface/Surface.irap FALSE) #----------------------------------------------------------------- add_executable( enkf_forward_init_FIELD enkf_forward_init_FIELD.c ) -target_link_libraries( enkf_forward_init_FIELD enkf ) +target_link_libraries( enkf_forward_init_FIELD enkf test_util ) add_test( enkf_forward_init_FIELD_TRUE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_FIELD - ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field/config_field_true + ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field config_field_true ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field/petro.grdecl TRUE) add_test( enkf_forward_init_FIELD_FALSE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_FIELD - ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field/config_field_false + ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field config_field_false ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field/petro.grdecl FALSE) @@ -69,40 +82,51 @@ add_test( enkf_forward_init_FIELD_FALSE add_executable( enkf_iter_config enkf_iter_config.c ) -target_link_libraries( enkf_iter_config enkf ) +target_link_libraries( enkf_iter_config enkf test_util ) add_test( enkf_iter_config ${EXECUTABLE_OUTPUT_PATH}/enkf_iter_config ) add_executable( enkf_model_config enkf_model_config.c ) -target_link_libraries( enkf_model_config enkf ) +target_link_libraries( enkf_model_config enkf test_util ) add_test( enkf_model_config ${EXECUTABLE_OUTPUT_PATH}/enkf_model_config ) add_executable( enkf_rng enkf_rng.c ) -target_link_libraries( enkf_rng enkf ) -add_test( enkf_rng ${EXECUTABLE_OUTPUT_PATH}/enkf_rng ${CMAKE_CURRENT_SOURCE_DIR}/data/config/rng) +target_link_libraries( enkf_rng enkf test_util ) +add_test( enkf_rng ${EXECUTABLE_OUTPUT_PATH}/enkf_rng ${CMAKE_CURRENT_SOURCE_DIR}/data/config rng) add_executable( enkf_report_list enkf_report_list.c ) -target_link_libraries( enkf_report_list enkf ) +target_link_libraries( enkf_report_list enkf test_util ) add_test( enkf_report_list ${EXECUTABLE_OUTPUT_PATH}/enkf_report_list ${CMAKE_CURRENT_SOURCE_DIR}/data/config/ert_report_list) add_executable( enkf_refcase_list enkf_refcase_list.c ) -target_link_libraries( enkf_refcase_list enkf ) +target_link_libraries( enkf_refcase_list enkf test_util ) add_test( enkf_refcase_list ${EXECUTABLE_OUTPUT_PATH}/enkf_refcase_list ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat*/ECLIPSE) add_test( enkf_refcase_list2 ${EXECUTABLE_OUTPUT_PATH}/enkf_refcase_list ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat*/ECLIPSE.*) set_property( TEST enkf_refcase_list PROPERTY LABELS StatoilData ) set_property( TEST enkf_refcase_list2 PROPERTY LABELS StatoilData ) - add_executable( enkf_ecl_config enkf_ecl_config.c ) -target_link_libraries( enkf_ecl_config enkf ) +target_link_libraries( enkf_ecl_config enkf test_util ) add_test( enkf_ecl_config1 ${EXECUTABLE_OUTPUT_PATH}/enkf_ecl_config ) add_test( enkf_ecl_config2 ${EXECUTABLE_OUTPUT_PATH}/enkf_ecl_config ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE) set_property( TEST enkf_ecl_config2 PROPERTY LABELS StatoilData ) add_executable( enkf_ecl_config_config enkf_ecl_config_config.c ) -target_link_libraries( enkf_ecl_config_config enkf ) +target_link_libraries( enkf_ecl_config_config enkf test_util ) add_test( enkf_ecl_config_config ${EXECUTABLE_OUTPUT_PATH}/enkf_ecl_config_config ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/ecl_config ) set_property( TEST enkf_ecl_config_config PROPERTY LABELS StatoilData ) +add_executable( enkf_qc_module_test enkf_qc_module_test.c ) +target_link_libraries( enkf_qc_module_test enkf test_util ) +add_test( enkf_qc_module_test ${EXECUTABLE_OUTPUT_PATH}/enkf_qc_module_test ) + +add_executable(enkf_obs_tests enkf_obs_tests.c) +target_link_libraries(enkf_obs_tests enkf test_util ) +add_test(enkf_obs_tests ${EXECUTABLE_OUTPUT_PATH}/enkf_obs_tests) + +add_executable(obs_vector_tests obs_vector_tests.c) +target_link_libraries(obs_vector_tests enkf test_util ) +add_test(obs_vector_tests ${EXECUTABLE_OUTPUT_PATH}/obs_vector_tests) + add_test( enkf_runpath_list ${EXECUTABLE_OUTPUT_PATH}/enkf_runpath_list ) add_test( enkf_site_config ${EXECUTABLE_OUTPUT_PATH}/enkf_site_config /project/res/etc/ERT/site-config) add_test( enkf_time_map1 ${EXECUTABLE_OUTPUT_PATH}/enkf_time_map ) diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/FAULT_TEMPLATE b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/FAULT_TEMPLATE similarity index 100% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/FAULT_TEMPLATE rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/FAULT_TEMPLATE diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/MULTFLT.TXT b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/MULTFLT.TXT similarity index 100% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/MULTFLT.TXT rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/MULTFLT.TXT diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_false b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_false similarity index 75% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_false rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_false index 0a66f8edee..d66f17444a 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_false +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_false @@ -1,8 +1,8 @@ JOBNAME Job%d -RUNPATH /tmp/simulations/run%d +RUNPATH simulations/run%d NUM_REALIZATIONS 1 -ENSPATH /tmp/Storage +ENSPATH Storage JOB_SCRIPT script.sh GEN_KW MULTFLT FAULT_TEMPLATE MULTFLT.INC MULTFLT.TXT INIT_FILES:MULTFLT_INIT diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_true b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_true similarity index 77% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_true rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_true index 4f883ec841..f8d48f73c5 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_true +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_true @@ -1,8 +1,8 @@ JOBNAME Job%d -RUNPATH /tmp/simulations/run%d +RUNPATH simulations/run%d NUM_REALIZATIONS 1 -ENSPATH /tmp/Storage +ENSPATH Storage JOB_SCRIPT script.sh GEN_KW MULTFLT FAULT_TEMPLATE MULTFLT.INC MULTFLT.TXT INIT_FILES:MULTFLT_INIT FORWARD_INIT:TRUE diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_false b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_false similarity index 54% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_false rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_false index 4c00c3f259..4454bbab15 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_false +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_false @@ -1,8 +1,8 @@ JOBNAME Job%d -RUNPATH /tmp/simulations/run%d +RUNPATH simulations/run%d NUM_REALIZATIONS 1 -ENSPATH /tmp/Storage +ENSPATH Storage JOB_SCRIPT script.sh diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_true b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_true similarity index 76% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_true rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_true index f354a72795..da1d098edb 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_true +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_true @@ -1,8 +1,8 @@ JOBNAME Job%d -RUNPATH /tmp/simulations/run%d +RUNPATH simulations/run%d NUM_REALIZATIONS 1 -ENSPATH /tmp/Storage +ENSPATH Storage JOB_SCRIPT script.sh diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/script.sh b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/script.sh similarity index 100% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/script.sh rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/script.sh diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/rng b/ThirdParty/Ert/devel/libenkf/tests/data/config/rng index 07caf77275..ad8ee50cb1 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/rng +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/rng @@ -1,6 +1,6 @@ NUM_REALIZATIONS 25 -STORE_SEED /tmp/seed2 -LOAD_SEED /tmp/seed2 +STORE_SEED seed2 +LOAD_SEED seed2 -- The settings below here are artifacts which should not be necessary ... JOB_SCRIPT script.sh diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_FIELD.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_FIELD.c index 779072920c..33fae2b179 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_FIELD.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_FIELD.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -44,17 +45,21 @@ void create_runpath(enkf_main_type * enkf_main ) { int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); + const char * root_path = argv[1]; + const char * config_file = argv[2]; + const char * init_file = argv[3]; + const char * forward_init_string = argv[4]; + test_work_area_type * work_area = test_work_area_alloc(config_file , false); + test_work_area_copy_directory_content( work_area , root_path ); + test_work_area_install_file( work_area , init_file ); { - const char * config_file = argv[1]; - const char * init_file = argv[2]; - const char * forward_init_string = argv[3]; bool forward_init; bool strict = true; enkf_main_type * enkf_main; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); - util_clear_directory( "/tmp/Storage" , true , true ); + util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); @@ -88,7 +93,7 @@ int main(int argc , char ** argv) { .state = ANALYZED }; create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); + test_assert_true( util_is_directory( "simulations/run0" )); { bool loadOK = true; @@ -102,9 +107,9 @@ int main(int argc , char ** argv) { test_assert_false( enkf_node_has_data( field_node , fs, node_id )); - util_unlink_existing( "/tmp/simulations/run0/petro.grdecl" ); + util_unlink_existing( "simulations/run0/petro.grdecl" ); - test_assert_false( enkf_node_forward_init( field_node , "/tmp/simulations/run0" , 0 )); + test_assert_false( enkf_node_forward_init( field_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_false( loadOK ); @@ -115,7 +120,7 @@ int main(int argc , char ** argv) { } - util_copy_file( init_file , "/tmp/simulations/run0/petro.grdecl"); + util_copy_file( init_file , "simulations/run0/petro.grdecl"); { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); @@ -125,7 +130,7 @@ int main(int argc , char ** argv) { enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } - test_assert_true( enkf_node_forward_init( field_node , "/tmp/simulations/run0" , 0)); + test_assert_true( enkf_node_forward_init( field_node , "simulations/run0" , 0)); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); @@ -138,17 +143,17 @@ int main(int argc , char ** argv) { test_assert_double_equal( 0.28485405445 , value); } } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); - test_assert_true( util_is_file( "/tmp/simulations/run0/PORO.grdecl" )); - test_assert_true( enkf_node_fload( field_node , "/tmp/simulations/run0/PORO.grdecl")); + test_assert_true( util_is_directory( "simulations/run0" )); + test_assert_true( util_is_file( "simulations/run0/PORO.grdecl" )); + test_assert_true( enkf_node_fload( field_node , "simulations/run0/PORO.grdecl")); { double value; test_assert_true( enkf_node_user_get( field_node , fs , "4,4,4" , node_id , &value)); test_assert_double_equal( 0.130251303315 , value); } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_KW.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_KW.c index d041901b41..4de0c97afc 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_KW.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_KW.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -44,16 +45,19 @@ void create_runpath(enkf_main_type * enkf_main ) { int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); - { - const char * config_file = argv[1]; - const char * forward_init_string = argv[2]; + const char * root_path = argv[1]; + const char * config_file = argv[2]; + const char * forward_init_string = argv[3]; + test_work_area_type * work_area = test_work_area_alloc(config_file , false); + test_work_area_copy_directory_content( work_area , root_path ); + { bool forward_init; bool strict = true; enkf_main_type * enkf_main; - + test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); - - util_clear_directory( "/tmp/Storage" , true , true ); + + util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); @@ -62,15 +66,15 @@ int main(int argc , char ** argv) { const enkf_config_node_type * gen_kw_config_node = enkf_node_get_config( gen_kw_node ); char * init_file1 = enkf_config_node_alloc_initfile( gen_kw_config_node , NULL , 0); char * init_file2 = enkf_config_node_alloc_initfile( gen_kw_config_node , "/tmp", 0); - + test_assert_bool_equal( enkf_config_node_use_forward_init( gen_kw_config_node ) , forward_init ); test_assert_string_equal( init_file1 , "MULTFLT_INIT"); test_assert_string_equal( init_file2 , "/tmp/MULTFLT_INIT"); - + free( init_file1 ); free( init_file2 ); } - + test_assert_bool_equal( enkf_node_use_forward_init( gen_kw_node ) , forward_init ); if (forward_init) test_assert_bool_not_equal( enkf_node_initialize( gen_kw_node , 0 , enkf_state_get_rng( state )) , forward_init); @@ -85,14 +89,14 @@ int main(int argc , char ** argv) { node_id_type node_id = {.report_step = 0 , .iens = 0, .state = ANALYZED }; - + create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); + test_assert_true( util_is_directory( "simulations/run0" )); { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); - + { run_mode_type run_mode = ENSEMBLE_EXPERIMENT; enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ @@ -100,23 +104,22 @@ int main(int argc , char ** argv) { test_assert_false( enkf_node_has_data( gen_kw_node , fs, node_id )); + util_unlink_existing( "simulations/run0/MULTFLT_INIT" ); - util_unlink_existing( "/tmp/simulations/run0/MULTFLT_INIT" ); - - test_assert_false( enkf_node_forward_init( gen_kw_node , "/tmp/simulations/run0" , 0 )); + test_assert_false( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_false( loadOK ); - + loadOK = true; enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); stringlist_free( msg_list ); test_assert_false( loadOK ); } - - + + { - FILE * stream = util_fopen("/tmp/simulations/run0/MULTFLT_INIT" , "w"); + FILE * stream = util_fopen("simulations/run0/MULTFLT_INIT" , "w"); fprintf(stream , "123456.0\n" ); fclose( stream ); } @@ -130,7 +133,7 @@ int main(int argc , char ** argv) { enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } - test_assert_true( enkf_node_forward_init( gen_kw_node , "/tmp/simulations/run0" , 0 )); + test_assert_true( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); @@ -143,20 +146,20 @@ int main(int argc , char ** argv) { test_assert_double_equal( 123456.0 , value); } } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); - test_assert_true( util_is_file( "/tmp/simulations/run0/MULTFLT.INC" )); + test_assert_true( util_is_directory( "simulations/run0" )); + test_assert_true( util_is_file( "simulations/run0/MULTFLT.INC" )); { - FILE * stream = util_fopen("/tmp/simulations/run0/MULTFLT.INC" , "r"); + FILE * stream = util_fopen("simulations/run0/MULTFLT.INC" , "r"); double value; fscanf(stream , "%lg" , &value); fclose( stream ); test_assert_double_equal( 123456.0 , value); } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } + test_work_area_free( work_area ); } - diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_PARAM.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_PARAM.c index 7b76059dc3..a6a0424759 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_PARAM.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_PARAM.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -44,16 +45,19 @@ void create_runpath(enkf_main_type * enkf_main ) { int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); + const char * root_path = argv[1]; + const char * config_file = argv[2]; + const char * forward_init_string = argv[3]; + test_work_area_type * work_area = test_work_area_alloc(config_file , false); + test_work_area_copy_directory_content( work_area , root_path ); { - const char * config_file = argv[1]; - const char * forward_init_string = argv[2]; bool forward_init; bool strict = true; enkf_main_type * enkf_main; - + test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); - util_clear_directory( "/tmp/Storage" , true , true ); + util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); @@ -87,7 +91,7 @@ int main(int argc , char ** argv) { .state = ANALYZED }; create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); + test_assert_true( util_is_directory( "simulations/run0" )); { run_mode_type run_mode = ENSEMBLE_EXPERIMENT; @@ -95,13 +99,13 @@ int main(int argc , char ** argv) { test_assert_false( enkf_node_has_data( gen_param_node , fs, node_id )); - util_unlink_existing( "/tmp/simulations/run0/PARAM_INIT" ); + util_unlink_existing( "simulations/run0/PARAM_INIT" ); } { - FILE * stream = util_fopen("/tmp/simulations/run0/PARAM_INIT" , "w"); + FILE * stream = util_fopen("simulations/run0/PARAM_INIT" , "w"); fprintf(stream , "0\n1\n2\n3\n" ); fclose( stream ); } @@ -115,7 +119,7 @@ int main(int argc , char ** argv) { enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } - test_assert_true( enkf_node_forward_init( gen_param_node , "/tmp/simulations/run0" , 0 )); + test_assert_true( enkf_node_forward_init( gen_param_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); @@ -134,12 +138,12 @@ int main(int argc , char ** argv) { test_assert_double_equal( 2 , value); } } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); - test_assert_true( util_is_file( "/tmp/simulations/run0/PARAM.INC" )); + test_assert_true( util_is_directory( "simulations/run0" )); + test_assert_true( util_is_file( "simulations/run0/PARAM.INC" )); { - FILE * stream = util_fopen("/tmp/simulations/run0/PARAM.INC" , "r"); + FILE * stream = util_fopen("simulations/run0/PARAM.INC" , "r"); double v0,v1,v2,v3; fscanf(stream , "%lg %lg %lg %lg" , &v0,&v1,&v2,&v3); fclose( stream ); @@ -148,9 +152,10 @@ int main(int argc , char ** argv) { test_assert_double_equal( 2 , v2); test_assert_double_equal( 3 , v3); } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } + test_work_area_free( work_area ); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_SURFACE.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_SURFACE.c index e540d075e5..0122e6f0ad 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_SURFACE.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_SURFACE.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -44,17 +45,23 @@ void create_runpath(enkf_main_type * enkf_main ) { int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); + const char * root_path = argv[1]; + const char * config_file = argv[2]; + const char * init_file = argv[3]; + const char * forward_init_string = argv[4]; + test_work_area_type * work_area = test_work_area_alloc(config_file , false); + + test_work_area_copy_directory_content( work_area , root_path ); + test_work_area_install_file( work_area , init_file ); { - const char * config_file = argv[1]; - const char * init_file = argv[2]; - const char * forward_init_string = argv[3]; + bool forward_init; bool strict = true; enkf_main_type * enkf_main; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); - util_clear_directory( "/tmp/Storage" , true , true ); + util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); @@ -88,7 +95,7 @@ int main(int argc , char ** argv) { .state = ANALYZED }; create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); + test_assert_true( util_is_directory( "simulations/run0" )); { bool loadOK = true; @@ -102,9 +109,9 @@ int main(int argc , char ** argv) { test_assert_false( enkf_node_has_data( surface_node , fs, node_id )); - util_unlink_existing( "/tmp/simulations/run0/Surface.irap" ); + util_unlink_existing( "simulations/run0/Surface.irap" ); - test_assert_false( enkf_node_forward_init( surface_node , "/tmp/simulations/run0" , 0 )); + test_assert_false( enkf_node_forward_init( surface_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_false( loadOK ); @@ -115,7 +122,7 @@ int main(int argc , char ** argv) { } - util_copy_file( init_file , "/tmp/simulations/run0/Surface.irap"); + util_copy_file( init_file , "simulations/run0/Surface.irap"); { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); @@ -125,7 +132,7 @@ int main(int argc , char ** argv) { enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } - test_assert_true( enkf_node_forward_init( surface_node , "/tmp/simulations/run0" , 0 )); + test_assert_true( enkf_node_forward_init( surface_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); @@ -141,11 +148,11 @@ int main(int argc , char ** argv) { test_assert_double_equal( 2737.0122 , value); } } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); - test_assert_true( util_is_file( "/tmp/simulations/run0/SURFACE.INC" )); - test_assert_true( enkf_node_fload( surface_node , "/tmp/simulations/run0/SURFACE.INC")); + test_assert_true( util_is_directory( "simulations/run0" )); + test_assert_true( util_is_file( "simulations/run0/SURFACE.INC" )); + test_assert_true( enkf_node_fload( surface_node , "simulations/run0/SURFACE.INC")); { double value; test_assert_true( enkf_node_user_get( surface_node , fs , "0" , node_id , &value)); @@ -154,7 +161,7 @@ int main(int argc , char ** argv) { test_assert_true( enkf_node_user_get( surface_node , fs , "5" , node_id , &value)); test_assert_double_equal( 2737.0122 , value); } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_obs_tests.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_obs_tests.c new file mode 100644 index 0000000000..45fdf8d5c3 --- /dev/null +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_obs_tests.c @@ -0,0 +1,50 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'enkf_enkf_obs_tests.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 + +int main(int argc, char ** argv) { + enkf_obs_type * enkf_obs = enkf_obs_alloc(); + + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WWCT", NULL, 2); + summary_obs_type * summary_obs1 = summary_obs_alloc( "SummaryKey" , "ObservationKey" , 43.2, 2.0 , AUTO_CORRF_EXP, 42); + obs_vector_install_node( obs_vector , 0 , summary_obs1 ); + + summary_obs_type * summary_obs2 = summary_obs_alloc( "SummaryKey2" , "ObservationKey2" , 4.2, 0.1 , AUTO_CORRF_EXP, 42); + obs_vector_install_node( obs_vector , 1 , summary_obs2 ); + + obs_vector_type * obs_vector2 = obs_vector_alloc(SUMMARY_OBS, "WWCT2", NULL, 2); + summary_obs_type * summary_obs3 = summary_obs_alloc( "SummaryKey" , "ObservationKey" , 43.2, 2.0 , AUTO_CORRF_EXP, 42); + obs_vector_install_node( obs_vector2 , 0 , summary_obs3 ); + + summary_obs_type * summary_obs4 = summary_obs_alloc( "SummaryKey2" , "ObservationKey2" , 4.2, 0.1 , AUTO_CORRF_EXP, 42); + obs_vector_install_node( obs_vector2 , 1 , summary_obs4 ); + + enkf_obs_add_obs_vector(enkf_obs, "PROP0", obs_vector); + enkf_obs_add_obs_vector(enkf_obs, "PROP", obs_vector2); + + enkf_obs_scale_std(enkf_obs, 3.3); + + enkf_obs_free(enkf_obs); + + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_qc_module_test.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_qc_module_test.c new file mode 100644 index 0000000000..aed44b9498 --- /dev/null +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_qc_module_test.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'enkf_ecl_config.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 + +int main(int argc, char ** argv) { + + ert_workflow_list_type * list = NULL; + qc_module_type * qc_module = qc_module_alloc(list, ""); + + char * expected_path = util_alloc_abs_path(".ert_runpath_list"); + test_assert_string_equal(expected_path, qc_module_get_runpath_list_file(qc_module)); + free(expected_path); + + qc_module_set_runpath_list_file(qc_module, "Folder", NULL); + expected_path = util_alloc_abs_path("Folder/.ert_runpath_list"); + test_assert_string_equal(expected_path, qc_module_get_runpath_list_file(qc_module)); + free(expected_path); + + qc_module_set_runpath_list_file(qc_module, "Folder", "thefilename.txt"); + expected_path = util_alloc_abs_path("Folder/thefilename.txt"); + test_assert_string_equal(expected_path, qc_module_get_runpath_list_file(qc_module)); + free(expected_path); + + qc_module_set_runpath_list_file(qc_module, "/tmp/ouagadogo", "thefilename.txt"); + test_assert_string_equal("/tmp/ouagadogo/thefilename.txt", qc_module_get_runpath_list_file(qc_module)); + + qc_module_free(qc_module); + + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_rng.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_rng.c index b74d51a8a1..f5b5f9d02c 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_rng.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_rng.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -30,6 +31,7 @@ int main(int argc , char ** argv) { unsigned int rand1,rand2; { + test_work_area_type * work_area = test_work_area_alloc("enkf-rng-0", false); { enkf_main_type * enkf_main = enkf_main_alloc_empty(); enkf_main_resize_ensemble( enkf_main , 10 ); @@ -50,12 +52,14 @@ int main(int argc , char ** argv) { enkf_main_free( enkf_main ); } test_assert_uint_not_equal( rand1 , rand2 ); + test_work_area_free( work_area ); } /*****************************************************************/ { - const char * seed_file = "/tmp/seed"; + test_work_area_type * work_area = test_work_area_alloc("enkf-rng-1" , false ); + const char * seed_file = "seed"; { enkf_main_type * enkf_main = enkf_main_alloc_empty(); { @@ -88,19 +92,24 @@ int main(int argc , char ** argv) { enkf_main_free( enkf_main ); } test_assert_uint_equal( rand1 , rand2 ); - util_unlink_existing( seed_file ); + test_work_area_free( work_area ); + } /*****************************************************************/ { + const char * config_path = argv[1]; + const char * config_file = argv[2]; + test_work_area_type * work_area = test_work_area_alloc("enkf-rng-2" , false ); + test_work_area_copy_directory_content( work_area , config_path ); { - enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , argv[1] , true , true ); + enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , true , true ); enkf_state_type * state = enkf_main_iget_state( enkf_main , 9 ); rand1 = enkf_state_get_random( state ); enkf_main_free( enkf_main ); } { - enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , argv[1] , true , true ); + enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , true , true ); enkf_state_type * state = enkf_main_iget_state( enkf_main , 9 ); rand2 = enkf_state_get_random( state ); enkf_main_free( enkf_main ); @@ -108,12 +117,13 @@ int main(int argc , char ** argv) { test_assert_uint_equal( rand1 , rand2 ); { - enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , argv[1] , true , true ); + enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , true , true ); enkf_state_type * state = enkf_main_iget_state( enkf_main , 9 ); rand2 = enkf_state_get_random( state ); enkf_main_free( enkf_main ); } test_assert_uint_equal( rand1 , rand2 ); + test_work_area_free( work_area ); } exit(0); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_runpath_list.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_runpath_list.c index 4fe6d9676a..44e66c0145 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_runpath_list.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_runpath_list.c @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -98,7 +99,8 @@ int main(int argc , char ** argv) { } { - const char *filename = "/tmp/runpath_list.txt"; + test_work_area_type * work_area = test_work_area_alloc("enkf_runpath_list" , true); + const char *filename = "runpath_list.txt"; { FILE * stream = util_fopen( filename, "w"); runpath_list_fprintf( list , stream ); @@ -118,6 +120,7 @@ int main(int argc , char ** argv) { } fclose( stream ); } + test_work_area_free( work_area ); } } runpath_list_free( list ); diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_time_map.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_time_map.c index 21c6d50f9b..034a3ccce2 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_time_map.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_time_map.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -55,8 +56,9 @@ void ecl_test( const char * ecl_case ) { void simple_test() { -time_map_type * time_map = time_map_alloc( ); - const char * mapfile = "/tmp/map"; + time_map_type * time_map = time_map_alloc( ); + test_work_area_type * work_area = test_work_area_alloc("enkf_time_map" , true); + const char * mapfile = "map"; test_assert_true( time_map_update( time_map , 0 , 100 ) ); test_assert_true( time_map_update( time_map , 1 , 200 ) ); @@ -83,6 +85,7 @@ time_map_type * time_map = time_map_alloc( ); time_map_fwrite( time_map , mapfile); test_assert_time_t_not_equal( mtime1 , util_file_mtime( mapfile ) ); } + test_work_area_free( work_area ); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/obs_vector_tests.c b/ThirdParty/Ert/devel/libenkf/tests/obs_vector_tests.c new file mode 100644 index 0000000000..5bf7f83fc6 --- /dev/null +++ b/ThirdParty/Ert/devel/libenkf/tests/obs_vector_tests.c @@ -0,0 +1,222 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'enkf_obs_vector_tests.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 "ert/enkf/gen_obs.h" + +bool alloc_strippedparameters_noerrors() { + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WHAT", NULL, 0); + obs_vector_free(obs_vector); + return true; +} + +/*******Summary obs tests*******************/ +bool scale_std_summary_nodata_no_errors() { + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WHAT", NULL, 0); + obs_vector_scale_std(obs_vector, 2.0); + obs_vector_free(obs_vector); + return true; +} + +bool scale_std_summarysingleobservation_no_errors() { + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WHAT", NULL, 1); + + summary_obs_type * summary_obs = summary_obs_alloc("SummaryKey", "ObservationKey", 43.2, 2.0, AUTO_CORRF_EXP, 42); + obs_vector_install_node(obs_vector, 0, summary_obs); + + test_assert_double_equal(2.0, summary_obs_get_std(summary_obs)); + obs_vector_scale_std(obs_vector, 2.0); + test_assert_double_equal(4.0, summary_obs_get_std(summary_obs)); + + obs_vector_free(obs_vector); + return true; +} + +bool scale_std_summarymanyobservations_no_errors() { + int num_observations = 100; + double scaling_factor = 1.456; + + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WHAT", NULL, num_observations); + + test_assert_bool_equal(0, obs_vector_get_num_active(obs_vector)); + + summary_obs_type * observations[num_observations]; + for (int i = 0; i < num_observations; i++) { + summary_obs_type * summary_obs = summary_obs_alloc("SummaryKey", "ObservationKey", 43.2, i, AUTO_CORRF_EXP, 42); + obs_vector_install_node(obs_vector, i, summary_obs); + observations[i] = summary_obs; + } + + for (int i = 0; i < num_observations; i++) { + summary_obs_type * before_scale = observations[i]; + test_assert_double_equal(i, summary_obs_get_std(before_scale)); + } + + test_assert_bool_equal(num_observations, obs_vector_get_num_active(obs_vector)); + + obs_vector_scale_std(obs_vector, scaling_factor); + + for (int i = 0; i < num_observations; i++) { + summary_obs_type * after_scale = observations[i]; + test_assert_double_equal(i * scaling_factor, summary_obs_get_std(after_scale)); + } + + obs_vector_free(obs_vector); + return true; +} + +/************ Block obs tests *****************************************************/ + +bool scale_std_block_nodata_no_errors() { + obs_vector_type * obs_vector = obs_vector_alloc(BLOCK_OBS, "WHAT", NULL, 0); + obs_vector_scale_std(obs_vector, 2.0); + obs_vector_free(obs_vector); + return true; +} + +block_obs_type * create_block_obs(ecl_grid_type * grid, int size, double value, double std_dev) { + int * i = util_calloc(size, sizeof * i); + int * j = util_calloc(size, sizeof * j); + int * k = util_calloc(size, sizeof * k); + double * obs_value = util_calloc(size, sizeof * obs_value); + double * obs_std = util_calloc(size, sizeof * obs_std); + + for (int num = 0; num < size; num++) { + obs_value[num] = value; + obs_std[num] = std_dev; + i[num] = num; + j[num] = num; + k[num] = num; + } + + block_obs_type * block_obs = block_obs_alloc("Label", SOURCE_FIELD, NULL, NULL, grid, size, i, j, k, obs_value, obs_std); + + free(i); + free(j); + free(k); + free(obs_value); + free(obs_std); + + return block_obs; +} + +bool scale_std_block100observations_no_errors() { + int num_observations = 100; + int num_points = 10; + + obs_vector_type * obs_vector = obs_vector_alloc(BLOCK_OBS, "WHAT", NULL, num_observations); + ecl_grid_type * grid = ecl_grid_alloc_rectangular(num_points, num_points, num_points, 1.0, 1.0, 1.0, NULL); + + double scale_factor = 3.3; + double obs_value = 44; + double obs_std = 3.2; + + block_obs_type * observations[num_observations]; + + for (int i = 0; i < num_observations; i++) { + block_obs_type * block_obs = create_block_obs(grid, num_points, obs_value, obs_std); + obs_vector_install_node(obs_vector, i, block_obs); + observations[i] = block_obs; + } + + for (int i = 0; i < num_observations; i++) { + for (int point_nr = 0; point_nr < num_points; point_nr++) { + double value, std; + block_obs_iget(observations[i], point_nr, &value, &std); + test_assert_double_equal(obs_value, value); + test_assert_double_equal(obs_std, std); + } + } + + obs_vector_scale_std(obs_vector, scale_factor); + + for (int i = 0; i < num_observations; i++) { + for (int point_nr = 0; point_nr < num_points; point_nr++) { + double value, std; + block_obs_iget(observations[i], point_nr, &value, &std); + test_assert_double_equal(obs_value, value); + test_assert_double_equal(obs_std * scale_factor, std); + } + } + + ecl_grid_free(grid); + obs_vector_free(obs_vector); + return true; +} + +/*************Gen obs tests************************************************/ + +bool scale_std_gen_nodata_no_errors() { + obs_vector_type * obs_vector = obs_vector_alloc(GEN_OBS, "WHAT", NULL, 0); + obs_vector_scale_std(obs_vector, 2.0); + obs_vector_free(obs_vector); + return true; +} + +bool scale_std_gen_withdata_no_errors() { + int num_observations = 100; + double value = 42; + double std_dev = 2.2; + double multiplier = 3.4; + + obs_vector_type * obs_vector = obs_vector_alloc(GEN_OBS, "WHAT", NULL, num_observations); + + gen_obs_type * observations[num_observations]; + for (int i = 0; i < num_observations; i++) { + gen_obs_type * gen_obs = gen_obs_alloc(NULL, "WWCT-GEN", NULL, value, std_dev, NULL, NULL, NULL); + obs_vector_install_node(obs_vector, i, gen_obs); + observations[i] = gen_obs; + } + + obs_vector_scale_std(obs_vector, multiplier); + + + + for (int i = 0; i < num_observations; i++) { + char * index_key = util_alloc_sprintf("%d", i); + double value_new, std_new; + bool valid; + gen_obs_user_get_with_data_index(observations[i], index_key, &value_new, &std_new, &valid); + test_assert_double_equal(std_dev * multiplier, std_new); + test_assert_double_equal(value, value_new); + free(index_key); + } + + obs_vector_free(obs_vector); + return true; +} + +int main(int argc, char ** argv) { + test_assert_bool_equal(alloc_strippedparameters_noerrors(), true); + test_assert_bool_equal(scale_std_summary_nodata_no_errors(), true); + test_assert_bool_equal(scale_std_summarysingleobservation_no_errors(), true); + test_assert_bool_equal(scale_std_summarymanyobservations_no_errors(), true); + + test_assert_bool_equal(scale_std_block_nodata_no_errors(), true); + test_assert_bool_equal(scale_std_block100observations_no_errors(), true); + + test_assert_bool_equal(scale_std_gen_nodata_no_errors(), true); + test_assert_bool_equal(scale_std_gen_withdata_no_errors(), true); + + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libert_util/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libert_util/applications/CMakeLists.txt index 33ae1ade68..b16c480385 100644 --- a/ThirdParty/Ert/devel/libert_util/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libert_util/applications/CMakeLists.txt @@ -2,3 +2,6 @@ link_directories( ${ERT_BINARY_DIR}/libert_util/src ) add_executable( matrix_test matrix_test.c ) target_link_libraries( matrix_test ert_util ) +if (USE_RUNPATH) + add_runpath( matrix_test ) +endif() diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/rng.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/rng.h index bfe0f2db32..73ea7e6259 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/rng.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/rng.h @@ -22,6 +22,7 @@ #ifdef __cplusplus extern "C" { #endif +#include #include diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/test_util.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/test_util.h index 1083b21b08..92721b931d 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/test_util.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/test_util.h @@ -30,13 +30,13 @@ extern "C" { void test_error_exit( const char * fmt , ...); - bool test_string_equal( const char * s1 , const char * s2 ); #define test_exit( fmt, ...) test_exit__( __FILE__ , __LINE__ , fmt , __VA_ARGS__); void test_exit__(const char * file , int line , const char * fmt , ...); #define test_assert_string_equal( s1 , s2 ) test_assert_string_equal__(s1 , s2 , __FILE__ , __LINE__) - void test_assert_string_equal__( const char * s1 , const char * s2 , const char * file , int line); + void test_assert_string_equal__( const char * s1 , const char * s2 , const char * file , int line); + bool test_check_string_equal( const char *s1 , const char * s2); #define test_assert_int_equal( i1 , i2 ) test_assert_int_equal__( (i1) , (i2) , __FILE__ , __LINE__ ) void test_assert_int_equal__( int i1 , int i2 , const char * file , int line ); @@ -53,6 +53,7 @@ extern "C" { #define test_assert_double_equal( d1 , d2 ) test_assert_double_equal__( (d1) , (d2) , __FILE__ , __LINE__ ) void test_assert_double_equal__( double d1 , double d2 , const char * file , int line ); + bool test_check_double_equal( double d1 , double d2); #define test_assert_double_not_equal( d1 , d2 ) test_assert_double_not_equal__( (d1) , (d2) , __FILE__ , __LINE__ ) void test_assert_double_not_equal__( double d1 , double d2 , const char * file , int line ); diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/test_work_area.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/test_work_area.h new file mode 100644 index 0000000000..1cd04aa900 --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/test_work_area.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'test_work_area.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 __TEST_WORK_AREA_H__ +#define __TEST_WORK_AREA_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + typedef struct test_work_area_struct test_work_area_type; + + test_work_area_type * test_work_area_alloc(const char * test_name , bool store); + void test_work_area_free(test_work_area_type * work_area); + const char * test_work_area_get_cwd( const test_work_area_type * work_area ); + const char * test_work_area_get_original_cwd( const test_work_area_type * work_area ); + void test_work_area_install_file( test_work_area_type * work_area , const char * input_src_file ); + void test_work_area_copy_directory( test_work_area_type * work_area , const char * input_directory); + void test_work_area_copy_directory_content( test_work_area_type * work_area , const char * input_directory); + void test_work_area_copy_file( test_work_area_type * work_area , const char * input_file); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/util.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/util.h index a8dea74729..b664a78ea5 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/util.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/util.h @@ -24,10 +24,10 @@ #include #include #include +#include #ifdef HAVE_GETUID #include -#include #endif #ifdef ERT_WINDOWS @@ -47,6 +47,28 @@ extern"C" { #endif +/* + These ifdefs are an attempt to support large files (> 2GB) + transparently on both Windows and Linux. See source file + libert_util/src/util_lfs.c for more details. + + The symbol WINDOWS_LFS should be defined during compilation + if you want support of large files on windows. +*/ + +#ifdef WINDOWS_LFS +typedef struct _stat64 stat_type; +typedef __int64 offset_type; +#else +typedef struct stat stat_type; +#ifdef HAVE_FSEEKO + typedef off_t offset_type; +#else + typedef long offset_type; +#endif +#endif + + /*****************************************************************/ /* @@ -65,6 +87,7 @@ typedef bool (walk_dir_callback_ftype) (const char * , /* The current director void *); /* Arbitrary argument */ + typedef enum {left_pad = 0, right_pad = 1, center_pad = 2} string_alignement_type; @@ -141,6 +164,11 @@ typedef enum {left_pad = 0, int util_roundf( float x ); int util_round( double x ); + offset_type util_ftell(FILE * stream); + int util_fseek(FILE * stream, offset_type offset, int whence); + void util_rewind(FILE * stream); + int util_stat(const char * filename , stat_type * stat_info); + int util_fstat(int fileno, stat_type * stat_info); #ifdef HAVE_VA_COPY #define UTIL_VA_COPY(target,src) va_copy(target,src) @@ -150,7 +178,8 @@ typedef enum {left_pad = 0, #ifdef HAVE_OPENDIR - void util_copy_directory(const char * , const char * , const char *); + void util_copy_directory_content(const char * src_path , const char * target_path); + void util_copy_directory(const char * , const char *); void util_walk_directory(const char * root_path , walk_file_callback_ftype * file_callback , void * file_callback_arg , walk_dir_callback_ftype * dir_callback , void * dir_callback_arg); #endif @@ -176,6 +205,8 @@ typedef enum {left_pad = 0, FILE * util_fopen__(const char * filename , const char * mode); void util_fclose( FILE * stream ); bool util_fopen_test(const char *, const char *); + char * util_split_alloc_dirname( const char * input_path ); + char * util_split_alloc_filename( const char * input_path ); void util_alloc_file_components(const char * , char ** , char **, char **); //char * util_realloc_full_path(char * , const char *, const char *); char * util_alloc_tmp_file(const char * , const char * , bool ); @@ -329,6 +360,7 @@ typedef enum {left_pad = 0, bool util_files_equal( const char * file1 , const char * file2 ); double util_kahan_sum(const double *data, size_t N); bool util_double_approx_equal( double d1 , double d2); + bool util_double_approx_equal__( double d1 , double d2, double epsilon); int util_fnmatch( const char * pattern , const char * string ); void util_localtime( time_t * t , struct tm * ts ); diff --git a/ThirdParty/Ert/devel/libert_util/src/CMakeLists.txt b/ThirdParty/Ert/devel/libert_util/src/CMakeLists.txt index a753d36d3b..ec8e8d4e20 100644 --- a/ThirdParty/Ert/devel/libert_util/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libert_util/src/CMakeLists.txt @@ -1,6 +1,11 @@ -set(source_files rng.c lookup_table.c statistics.c mzran.c set.c hash_node.c hash_sll.c hash.c node_data.c node_ctype.c util.c thread_pool.c msg.c arg_pack.c path_fmt.c menu.c subst_list.c subst_func.c vector.c parser.c stringlist.c matrix.c buffer.c log.c template.c timer.c test_util.c time_interval.c string_util.c) +set(source_files rng.c lookup_table.c statistics.c mzran.c set.c hash_node.c hash_sll.c hash.c node_data.c node_ctype.c util.c thread_pool.c msg.c arg_pack.c path_fmt.c menu.c subst_list.c subst_func.c vector.c parser.c stringlist.c matrix.c buffer.c log.c template.c timer.c time_interval.c string_util.c) -set(header_files ssize_t.h type_macros.h rng.h lookup_table.h statistics.h mzran.h set.h hash.h hash_node.h hash_sll.h node_data.h node_ctype.h util.h thread_pool.h msg.h arg_pack.h path_fmt.h stringlist.h menu.h subst_list.h subst_func.h vector.h parser.h matrix.h buffer.h log.h template.h timer.h test_util.h time_interval.h string_util.h) +set(header_files ssize_t.h type_macros.h rng.h lookup_table.h statistics.h mzran.h set.h hash.h hash_node.h hash_sll.h node_data.h node_ctype.h util.h thread_pool.h msg.h arg_pack.h path_fmt.h stringlist.h menu.h subst_list.h subst_func.h vector.h parser.h matrix.h buffer.h log.h template.h timer.h time_interval.h string_util.h) + +set( test_source test_util.c test_work_area.c ) + + +#set_property(SOURCE hash.c PROPERTY COMPILE_FLAGS "-Wno-error") if (WITH_LATEX) @@ -43,8 +48,17 @@ if (WITH_PTHREAD) list( APPEND header_files thread_pool_posix.h ) endif() -add_library( ert_util ${LIBRARY_TYPE} ${source_files} ) +add_library( ert_util ${LIBRARY_TYPE} ${source_files} ) +if (BUILD_TESTS) + add_library( test_util ${LIBRARY_TYPE} ${test_source} ) + target_link_libraries( test_util ert_util ) +endif() + set_target_properties( ert_util PROPERTIES VERSION 1.0 SOVERSION 1.0 ) +if (USE_RUNPATH) + add_runpath( ert_util ) +endif() + if (WITH_PTHREAD) target_link_libraries( ert_util ${PTHREAD_LIBRARY} ) diff --git a/ThirdParty/Ert/devel/libert_util/src/log.c b/ThirdParty/Ert/devel/libert_util/src/log.c index bea28caa3c..ccb3cabb32 100644 --- a/ThirdParty/Ert/devel/libert_util/src/log.c +++ b/ThirdParty/Ert/devel/libert_util/src/log.c @@ -196,7 +196,7 @@ void log_sync(log_type * logh) { #ifdef HAVE_FSYNC fsync( logh->fd ); #endif - fseek( logh->stream , 0 , SEEK_END ); + util_fseek( logh->stream , 0 , SEEK_END ); } diff --git a/ThirdParty/Ert/devel/libert_util/src/lookup_table.c b/ThirdParty/Ert/devel/libert_util/src/lookup_table.c index 0a4d4e2da2..5b2e9a5f65 100644 --- a/ThirdParty/Ert/devel/libert_util/src/lookup_table.c +++ b/ThirdParty/Ert/devel/libert_util/src/lookup_table.c @@ -162,7 +162,7 @@ double lookup_table_get_max_value( lookup_table_type * lookup_table ) { double lookup_table_get_min_value( lookup_table_type * lookup_table ) { lookup_table_assert_sorted( lookup_table ); - return lookup_table->ymax; + return lookup_table->ymin; } diff --git a/ThirdParty/Ert/devel/libert_util/src/parser.c b/ThirdParty/Ert/devel/libert_util/src/parser.c index 73c5de9a03..353abcaaed 100644 --- a/ThirdParty/Ert/devel/libert_util/src/parser.c +++ b/ThirdParty/Ert/devel/libert_util/src/parser.c @@ -560,7 +560,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 = ftell(stream); + long int current_pos = util_ftell(stream); int string_index; for ( string_index = 0; string_index < strlen(string); string_index++) { int c = fgetc( stream ); @@ -574,7 +574,7 @@ static bool fgetc_while_equal( FILE * stream , const char * string , bool case_s } if (!equal) /* OK - not equal - go back. */ - fseek( stream , current_pos , SEEK_SET); + util_fseek( stream , current_pos , SEEK_SET); return equal; } @@ -598,7 +598,7 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char if (!case_sensitive) util_strupr( string ); { - long int initial_pos = ftell( stream ); /* Store the inital position. */ + long int initial_pos = util_ftell( stream ); /* Store the inital position. */ bool cont = true; if (strstr( string , parser->comment_start ) != NULL) @@ -610,11 +610,11 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char /* Special treatment of quoters - does not properly handle escaping of the quoters. */ if (is_in_quoters( c , parser )) { - long int quote_start_pos = ftell(stream); + long int quote_start_pos = util_ftell(stream); if (!fseek_quote_end( c , stream )) { - fseek( stream , quote_start_pos , SEEK_SET); + util_fseek( stream , quote_start_pos , SEEK_SET); fprintf(stderr,"Warning: unterminated quotation starting at line: %d \n",util_get_current_linenr( stream )); - fseek(stream , 0 , SEEK_END); + util_fseek(stream , 0 , SEEK_END); } /* Now we are either at the first character following a @@ -628,7 +628,7 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char /* OK - this might be the start of a comment - let us check further. */ bool comment_start = fgetc_while_equal( stream , &parser->comment_start[1] , false); if (comment_start) { - long int comment_start_pos = ftell(stream) - strlen( parser->comment_start ); + long int comment_start_pos = util_ftell(stream) - strlen( parser->comment_start ); /* Start seeking for comment_end */ if (!util_fseek_string(stream , parser->comment_end , true , true)) { /* @@ -636,9 +636,9 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char The file is just positioned at the end - and the routine will exit at the next step - with a Warning. */ - fseek( stream , comment_start_pos , SEEK_SET); + util_fseek( stream , comment_start_pos , SEEK_SET); fprintf(stderr,"Warning: unterminated comment starting at line: %d \n",util_get_current_linenr( stream )); - fseek(stream , 0 , SEEK_END); + util_fseek(stream , 0 , SEEK_END); } continue; /* Now we are at the character following a comment end - or at EOF. */ } @@ -662,9 +662,9 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char if (string_found) { if (!skip_string) - fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */ + util_fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */ } else - fseek(stream , initial_pos , SEEK_SET); /* Could not find the string reposition at initial position. */ + util_fseek(stream , initial_pos , SEEK_SET); /* Could not find the string reposition at initial position. */ } free( string ); return string_found; diff --git a/ThirdParty/Ert/devel/libert_util/src/test_util.c b/ThirdParty/Ert/devel/libert_util/src/test_util.c index 13e60e147b..e89fefdffd 100644 --- a/ThirdParty/Ert/devel/libert_util/src/test_util.c +++ b/ThirdParty/Ert/devel/libert_util/src/test_util.c @@ -53,7 +53,7 @@ void test_exit__(const char * file , int line , const char * fmt , ...) { } -bool test_string_equal( const char * s1 , const char * s2 ) { +bool test_check_string_equal( const char * s1 , const char * s2 ) { bool equal = true; if (s1 == NULL && s2 == NULL) return true; @@ -72,7 +72,7 @@ bool test_string_equal( const char * s1 , const char * s2 ) { void test_assert_string_equal__( const char * s1 , const char * s2 , const char * file, int line) { - bool equal = test_string_equal( s1 , s2 ); + bool equal = test_check_string_equal( s1 , s2 ); if (!equal) test_error_exit( "%s:%d => String are different s1:[%s] s2:[%s]\n" , file , line , s1 , s2 ); } @@ -193,15 +193,20 @@ void test_assert_mem_not_equal__( const void * p1 , const void * p2 , size_t byt } +bool test_check_double_equal( double d1 , double d2) { + const double tolerance = 1e-5; + return util_double_approx_equal__( d1 , d2 , tolerance ); +} + void test_assert_double_equal__( double d1 , double d2, const char * file , int line) { - if (!util_double_approx_equal(d1 , d2)) + if (!test_check_double_equal(d1 , d2)) test_error_exit( "%s:%d => double values:%g %g are not sufficiently similar\n" , file , line , d1 , d2); } void test_assert_double_not_equal__( double d1 , double d2, const char * file , int line) { - if (util_double_approx_equal(d1 , d2)) + if (test_check_double_equal(d1 , d2)) test_error_exit( "%s:%d => double values:%15.12g %15.12g are equal.\n" , file , line , d1 , d2); } diff --git a/ThirdParty/Ert/devel/libert_util/src/test_work_area.c b/ThirdParty/Ert/devel/libert_util/src/test_work_area.c new file mode 100644 index 0000000000..c1b1f60738 --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/src/test_work_area.c @@ -0,0 +1,216 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'test_work_area.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 + +/* + This file implements a small work area implementation to be used for + tests which write to disk. The implementation works by creating a + work area in /tmp and then call chdir() change the current working + directory. + + An important aspect of this implementation is that test output from + different users should not come in conflict with e.g. permission + problems, to achieve this the directories created will be per user. + + When creating the work area you pass in a boolean flag whether you + want the area to be retained when the destructor is called. After + the the work_area is destroyed the cwd is changed back to the value + it had before the area was created. + + The functions test_work_area_install_file(), + test_work_area_copy_directory() and + test_work_area_copy_directory_content() can be used to populate the + work area with files and directories needed for the test + execution. These functions have some intelligence when it comes to + interpreting relative paths; a relative path input argument is + interpreted relative to the original cwd. + + Basic usage example: + -------------------- + + + -- Create directory /tmp/$USER/ert-test/my/funn/test and call + -- chdir() to the newly created directory. + test_work_area_type * work_area = test_work_area_alloc("my/funny/test" , true); + + -- Make files available from the test directory. + test_work_area_install_file(work_area , "/home/user/build/test-data/file1"); + test_work_area_install_file(work_area , "relative/path/file2"); + + -- Recursively copy directory and directory content into test area: + test_work_area_copy_directory(work_area , "/home/user/build/test-data/case1"); + + ... + -- Do normal test operations + ... + + -- Destroy test_work_area structure; since the work_area is created + -- with input flag @retain set to true the are on disk will not be + -- cleared. After the test_work_area_free( ) function has been + -- called the original cwd will be restored. + + test_work_area_free( work_area ); +*/ + + +#define PATH_FMT "/tmp/%s/ert-test/%s/%08d" /* /tmp/username/ert-test/test_name/random-integer */ + +struct test_work_area_struct { + bool retain; + char * cwd; + char * original_cwd; +}; + + +static test_work_area_type * test_work_area_alloc__(const char * path , bool retain) { + util_make_path( path ); + if (true) { + test_work_area_type * work_area = util_malloc( sizeof * work_area ); + work_area->retain = retain; + work_area->cwd = util_alloc_string_copy( path ); + work_area->original_cwd = util_alloc_cwd(); + chdir( work_area->cwd ); + + return work_area; + } +} + + + +test_work_area_type * test_work_area_alloc(const char * test_name, bool retain) { + if (test_name) { + uid_t uid = getuid(); + struct passwd * pw = getpwuid( uid ); + rng_type * rng = rng_alloc(MZRAN , INIT_CLOCK ); + char * path = util_alloc_sprintf( PATH_FMT , pw->pw_name , test_name , rng_get_int( rng , 100000000 )); + test_work_area_type * work_area = test_work_area_alloc__( path , retain ); + free( path ); + rng_free( rng ); + return work_area; + } else + return NULL; +} + + + +void test_work_area_free(test_work_area_type * work_area) { + if (!work_area->retain) + util_clear_directory( work_area->cwd , true , true ); + + chdir( work_area->original_cwd ); + free( work_area->original_cwd ); + free( work_area->cwd ); + free( work_area ); +} + + +const char * test_work_area_get_cwd( const test_work_area_type * work_area ) { + return work_area->cwd; +} + + +const char * test_work_area_get_original_cwd( const test_work_area_type * work_area ) { + return work_area->original_cwd; +} + + +/** + The point of this function is that the test code should be able to + access the file @input_file independent of the fact that it has + changed path. If @input_file is an absolute path the function will + do nothing, if @input_file is a realtive path the function will + copy @input_file from the location relative to the original cwd to + the corresponding location relative to the test cwd. +*/ + +void test_work_area_install_file( test_work_area_type * work_area , const char * input_src_file ) { + if (util_is_abs_path( input_src_file )) + return; + else { + char * src_file = util_alloc_filename( work_area->original_cwd , input_src_file , NULL ); + char * src_path; + + util_alloc_file_components( input_src_file , &src_path , NULL , NULL); + if (!util_entry_exists( src_path )) + util_make_path( src_path ); + + if (util_file_exists( src_file )) { + char * target_file = util_alloc_filename( work_area->cwd , input_src_file , NULL ); + util_copy_file( src_file , target_file ); + free( target_file ); + } + free( src_file ); + } +} + + +void test_work_area_copy_directory( test_work_area_type * work_area , const char * input_directory) { + char * src_directory; + + if (util_is_abs_path( input_directory )) + src_directory = util_alloc_string_copy( input_directory ); + else + src_directory = util_alloc_filename( work_area->original_cwd , input_directory , NULL); + + util_copy_directory(src_directory , work_area->cwd ); + free( src_directory ); +} + + +void test_work_area_copy_directory_content( test_work_area_type * work_area , const char * input_directory) { + char * src_directory; + + if (util_is_abs_path( input_directory )) + src_directory = util_alloc_string_copy( input_directory ); + else + src_directory = util_alloc_filename( work_area->original_cwd , input_directory , NULL); + + util_copy_directory_content(src_directory , work_area->cwd ); + free( src_directory ); +} + + + +void test_work_area_copy_file( test_work_area_type * work_area , const char * input_file) { + if (input_file) { + char * src_file; + + if (util_is_abs_path( input_file )) + src_file = util_alloc_string_copy( input_file ); + else + src_file = util_alloc_filename( work_area->original_cwd , input_file , NULL); + + if (util_file_exists( src_file )) { + char * target_file = util_split_alloc_filename( input_file ); + util_copy_file( src_file , target_file ); + } + free( src_file ); + } +} + + diff --git a/ThirdParty/Ert/devel/libert_util/src/util.c b/ThirdParty/Ert/devel/libert_util/src/util.c index de0cee7d73..d28337a9bd 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util.c +++ b/ThirdParty/Ert/devel/libert_util/src/util.c @@ -349,11 +349,10 @@ double util_kahan_sum(const double *data, size_t N) { } -bool util_double_approx_equal( double d1 , double d2) { +bool util_double_approx_equal__( double d1 , double d2, double epsilon) { if (d1 == d2) return true; else { - double epsilon = 1e-6; double diff = fabs(d1 - d2); double sum = fabs(d1) + fabs(d2); @@ -365,6 +364,12 @@ bool util_double_approx_equal( double d1 , double d2) { } +bool util_double_approx_equal( double d1 , double d2) { + double epsilon = 1e-6; + return util_double_approx_equal__( d1 , d2 , epsilon ); +} + + char * util_alloc_substring_copy(const char *src , int offset , int N) { char *copy; if ((N + offset) < strlen(src)) { @@ -453,14 +458,14 @@ void util_rewind_line(FILE *stream) { int c; do { - if (ftell(stream) == 0) + if (util_ftell(stream) == 0) at_eol = true; else { - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); c = fgetc(stream); at_eol = EOL_CHAR(c); if (!at_eol) - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); } } while (!at_eol); } @@ -489,7 +494,7 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string util_strupr( string ); { int len = strlen( string ); - long int initial_pos = ftell( stream ); /* Store the inital position. */ + long int initial_pos = util_ftell( stream ); /* Store the inital position. */ bool cont = true; do { int c = fgetc( stream ); @@ -497,7 +502,7 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string c = toupper( c ); if (c == string[0]) { /* OK - we got the first character right - lets try in more detail: */ - long int current_pos = ftell(stream); + long int current_pos = util_ftell(stream); bool equal = true; int string_index; for (string_index = 1; string_index < len; string_index++) { @@ -515,7 +520,7 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string string_found = true; cont = false; } else /* Go back to current pos and continue searching. */ - fseek(stream , current_pos , SEEK_SET); + util_fseek(stream , current_pos , SEEK_SET); } if (c == EOF) @@ -525,9 +530,9 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string if (string_found) { if (!skip_string) - fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */ + util_fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */ } else - fseek(stream , initial_pos , SEEK_SET); /* Could not find the string reposition at initial position. */ + util_fseek(stream , initial_pos , SEEK_SET); /* Could not find the string reposition at initial position. */ } free( string ); @@ -551,13 +556,13 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string char * util_fscanf_alloc_upto(FILE * stream , const char * stop_string, bool include_stop_string) { - long int start_pos = ftell(stream); + long int start_pos = util_ftell(stream); if (util_fseek_string(stream , stop_string , include_stop_string , true)) { /* Default case sensitive. */ - long int end_pos = ftell(stream); + long int end_pos = util_ftell(stream); int len = end_pos - start_pos; char * buffer = util_calloc( (len + 1) , sizeof * buffer ); - fseek(stream , start_pos , SEEK_SET); + util_fseek(stream , start_pos , SEEK_SET); util_fread( buffer , 1 , len , stream , __func__); buffer[len] = '\0'; @@ -569,7 +574,7 @@ char * util_fscanf_alloc_upto(FILE * stream , const char * stop_string, bool inc static char * util_fscanf_alloc_line__(FILE *stream , bool *at_eof , char * line) { - int init_pos = ftell(stream); + int init_pos = util_ftell(stream); char * new_line; int len; char end_char; @@ -598,7 +603,7 @@ static char * util_fscanf_alloc_line__(FILE *stream , bool *at_eof , char * line end_char = c; } - if (fseek(stream , init_pos , SEEK_SET) != 0) + if (util_fseek(stream , init_pos , SEEK_SET) != 0) util_abort("%s: fseek failed: %d/%s \n",__func__ , errno , strerror(errno)); new_line = util_realloc(line , len + 1 ); @@ -753,9 +758,9 @@ char * util_alloc_cwd(void) { bool util_is_cwd( const char * path ) { bool is_cwd = false; - struct stat path_stat; + stat_type path_stat; - if (stat(path , &path_stat) == 0) { + if (util_stat(path , &path_stat) == 0) { if (S_ISDIR( path_stat.st_mode )) { char * cwd = util_alloc_cwd(); #ifdef ERT_WINDOWS @@ -766,8 +771,8 @@ bool util_is_cwd( const char * path ) { */ util_abort("%s: Internal error - function not properly implmented on Windows \n",__func__); #else - struct stat cwd_stat; - stat(cwd , &cwd_stat); + stat_type cwd_stat; + util_stat(cwd , &cwd_stat); if (cwd_stat.st_ino == path_stat.st_ino) is_cwd = true; #endif @@ -1110,7 +1115,7 @@ void util_fskip_lines(FILE * stream , int lines) { at_eof = true; else { if (c != '\n') - fseek( stream , -1 , SEEK_CUR ); + util_fseek( stream , -1 , SEEK_CUR ); } } @@ -1154,7 +1159,7 @@ int util_forward_line(FILE * stream , bool * at_eof) { *at_eof = true; else { if (!EOL_CHAR(c)) - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); } } else col++; @@ -1219,7 +1224,7 @@ static void util_fskip_chars__(FILE * stream , const char * skip_set , bool comp } } while (cont); if (!*at_eof) - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); } @@ -1252,7 +1257,7 @@ static void util_fskip_space__(FILE * stream , bool complimentary_set , bool *at } } while (cont); if (!*at_eof) - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); } @@ -1324,16 +1329,16 @@ char * util_fscanf_alloc_token(FILE * stream) { /* Skipping initial whitespace */ do { - int pos = ftell(stream); + int pos = util_ftell(stream); c = fgetc(stream); if (EOL_CHAR(c)) { /* Going back to position at newline */ - fseek(stream , pos , SEEK_SET); + util_fseek(stream , pos , SEEK_SET); cont = false; } else if (c == EOF) cont = false; else if (!util_char_in(c , 2 , space_set)) { - fseek(stream , pos , SEEK_SET); + util_fseek(stream , pos , SEEK_SET); cont = false; } } while (cont); @@ -1346,7 +1351,7 @@ char * util_fscanf_alloc_token(FILE * stream) { cont = true; { int length = 0; - long int token_start = ftell(stream); + long int token_start = util_ftell(stream); do { c = fgetc(stream); @@ -1359,10 +1364,10 @@ char * util_fscanf_alloc_token(FILE * stream) { else length++; } while (cont); - if (EOL_CHAR(c)) fseek(stream , -1 , SEEK_CUR); + if (EOL_CHAR(c)) util_fseek(stream , -1 , SEEK_CUR); token = util_calloc(length + 1 , sizeof * token ); - fseek(stream , token_start , SEEK_SET); + util_fseek(stream , token_start , SEEK_SET); { int i; for (i = 0; i < length; i++) @@ -1907,14 +1912,14 @@ bool util_fscanf_bool(FILE * stream , bool * value) { bool util_fscanf_int(FILE * stream , int * value) { - long int start_pos = ftell(stream); + long int start_pos = util_ftell(stream); char * token = util_fscanf_alloc_token(stream); bool value_OK = false; if (token != NULL) { value_OK = util_sscanf_int(token , value); if (!value_OK) - fseek(stream , start_pos , SEEK_SET); + util_fseek(stream , start_pos , SEEK_SET); free(token); } return value_OK; @@ -2072,14 +2077,14 @@ char * util_scanf_alloc_string(const char * prompt) { int util_count_file_lines(FILE * stream) { - long int init_pos = ftell(stream); + long int init_pos = util_ftell(stream); int lines = 0; bool at_eof = false; do { int col = util_forward_line(stream , &at_eof); if (col > 0) lines++; } while (!at_eof); - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return lines; } @@ -2103,10 +2108,10 @@ int util_count_content_file_lines(FILE * stream) { c = fgetc(stream); if (! feof(stream) ) { if (!EOL_CHAR(c)){ - fseek(stream , -1 , SEEK_CUR); - } + util_fseek(stream , -1 , SEEK_CUR); + } }else if (c == EOF){ - lines++; + lines++; } } else if (c == EOF){ @@ -2301,7 +2306,7 @@ bool util_files_equal( const char * file1 , const char * file2 ) { static void util_fclear_region( FILE * stream , long offset , long region_size) { - fseek( stream , offset , SEEK_SET ); + util_fseek( stream , offset , SEEK_SET ); { int i; for ( i=0; i < region_size; i++) @@ -2311,10 +2316,10 @@ static void util_fclear_region( FILE * stream , long offset , long region_size) static void util_fmove_block(FILE * stream , long offset , long shift , char * buffer , int buffer_size) { - fseek( stream , offset , SEEK_SET ); + util_fseek( stream , offset , SEEK_SET ); { int bytes_read = fread( buffer , sizeof * buffer , buffer_size , stream ); - fseek( stream , offset + shift , SEEK_SET ); + util_fseek( stream , offset + shift , SEEK_SET ); fwrite( buffer , sizeof * buffer , bytes_read , stream ); } } @@ -2342,10 +2347,10 @@ int util_fmove( FILE * stream , long offset , long shift) { long file_size; // Determine size of file. { - long init_pos = ftell( stream ); - fseek( stream , 0 , SEEK_END); - file_size = ftell( stream ); - fseek( stream , init_pos , SEEK_SET ); + long init_pos = util_ftell( stream ); + util_fseek( stream , 0 , SEEK_END); + file_size = util_ftell( stream ); + util_fseek( stream , init_pos , SEEK_SET ); } // Validate offset and shift input values. @@ -2409,8 +2414,8 @@ bool util_file_exists(const char *filename) { */ bool util_entry_exists( const char * entry ) { - struct stat stat_buffer; - int stat_return = stat(entry, &stat_buffer); + stat_type stat_buffer; + int stat_return = util_stat(entry, &stat_buffer); if (stat_return == 0) return true; else { @@ -2445,9 +2450,9 @@ bool util_entry_exists( const char * entry ) { bool util_is_directory(const char * path) { - struct stat stat_buffer; + stat_type stat_buffer; - if (stat(path , &stat_buffer) == 0) + if (util_stat(path , &stat_buffer) == 0) return S_ISDIR(stat_buffer.st_mode); else if (errno == ENOENT) /*Path does not exist at all. */ @@ -2461,9 +2466,9 @@ bool util_is_directory(const char * path) { bool util_is_file(const char * path) { - struct stat stat_buffer; + stat_type stat_buffer; - if (stat(path , &stat_buffer) == 0) + if (util_stat(path , &stat_buffer) == 0) return S_ISREG(stat_buffer.st_mode); else if (errno == ENOENT) /*Path does not exist at all. */ @@ -2483,8 +2488,8 @@ bool util_is_file(const char * path) { #ifdef HAVE_FORK bool util_is_executable(const char * path) { if (util_file_exists(path)) { - struct stat stat_buffer; - stat(path , &stat_buffer); + stat_type stat_buffer; + util_stat(path , &stat_buffer); if (S_ISREG(stat_buffer.st_mode)) return (stat_buffer.st_mode & S_IXUSR); else @@ -2498,8 +2503,8 @@ bool util_is_executable(const char * path) { Will not differtiate between files and directories. */ bool util_entry_readable( const char * entry ) { - struct stat buffer; - if (stat( entry , &buffer ) == 0) + stat_type buffer; + if (util_stat( entry , &buffer ) == 0) return buffer.st_mode & S_IRUSR; else return false; /* If stat failed - typically not existing entry - we return false. */ @@ -2514,8 +2519,8 @@ bool util_file_readable( const char * file ) { } bool util_entry_writable( const char * entry ) { - struct stat buffer; - if (stat( entry , &buffer ) == 0) + stat_type buffer; + if (util_stat( entry , &buffer ) == 0) return buffer.st_mode & S_IWUSR; else return false; /* If stat failed - typically not existing entry - we return false. */ @@ -2538,8 +2543,8 @@ bool util_is_executable(const char * path) { /* If it exists on windows it is readable ... */ bool util_entry_readable( const char * entry ) { - struct stat buffer; - if (stat( entry , &buffer ) == 0) + stat_type buffer; + if (util_stat( entry , &buffer ) == 0) return true; else return false; /* If stat failed - typically not existing entry - we return false. */ @@ -2547,8 +2552,8 @@ bool util_entry_readable( const char * entry ) { /* If it exists on windows it is readable ... */ bool util_entry_writable( const char * entry ) { - struct stat buffer; - if (stat( entry , &buffer ) == 0) + stat_type buffer; + if (util_stat( entry , &buffer ) == 0) return true; else return false; /* If stat failed - typically not existing entry - we return false. */ @@ -2710,14 +2715,14 @@ void util_alloc_file_components(const char * file, char **_path , char **_basena size_t util_file_size(const char *file) { - struct stat buffer; + stat_type buffer; int fildes; fildes = open(file , O_RDONLY); if (fildes == -1) util_abort("%s: failed to open:%s - %s \n",__func__ , file , strerror(errno)); - fstat(fildes, &buffer); + util_fstat(fildes, &buffer); close(fildes); return buffer.st_size; @@ -2757,11 +2762,11 @@ void util_ftruncate(FILE * stream , long size) { */ bool util_same_file(const char * file1 , const char * file2) { - struct stat buffer1 , buffer2; + stat_type buffer1 , buffer2; int stat1,stat2; - stat1 = stat(file1, &buffer1); // In the case of symlinks the stat call will stat the target file and not the link. - stat2 = stat(file2, &buffer2); + stat1 = util_stat(file1, &buffer1); // In the case of symlinks the stat call will stat the target file and not the link. + stat2 = util_stat(file2, &buffer2); if ((stat1 == 0) && (stat1 == stat2)) { if (buffer1.st_ino == buffer2.st_ino) @@ -2788,7 +2793,7 @@ bool util_fmt_bit8_stream(FILE * stream ) { const int min_read = 256; /* Critically small */ const double bit8set_limit = 0.00001; const int buffer_size = 131072; - long int start_pos = ftell(stream); + long int start_pos = util_ftell(stream); bool fmt_file; { double bit8set_fraction; @@ -2812,7 +2817,7 @@ bool util_fmt_bit8_stream(FILE * stream ) { else fmt_file = false; } - fseek(stream , start_pos , SEEK_SET); + util_fseek(stream , start_pos , SEEK_SET); return fmt_file; } @@ -2850,17 +2855,17 @@ bool util_fmt_bit8(const char *filename ) { double util_file_difftime(const char *file1 , const char *file2) { - struct stat b1, b2; + stat_type b1, b2; int f1,f2; time_t t1,t2; f1 = open(file1 , O_RDONLY); - fstat(f1, &b1); + util_fstat(f1, &b1); t1 = b1.st_mtime; close(f1); f2 = open(file2 , O_RDONLY); - fstat(f2, &b2); + util_fstat(f2, &b2); t2 = b2.st_mtime; close(f2); @@ -2872,8 +2877,8 @@ time_t util_file_mtime(const char * file) { time_t mtime = -1; int fd = open( file , O_RDONLY); if (fd != -1) { - struct stat f_stat; - fstat(fd , &f_stat ); + stat_type f_stat; + util_fstat(fd , &f_stat ); mtime = f_stat.st_mtime; close( fd ); } @@ -3021,10 +3026,10 @@ bool util_sscanf_date(const char * date_token , time_t * t) { bool util_fscanf_date(FILE *stream , time_t *t) { - int init_pos = ftell(stream); + int init_pos = util_ftell(stream); char * date_token = util_fscanf_alloc_token(stream); bool return_value = util_sscanf_date(date_token , t); - if (!return_value) fseek(stream , init_pos , SEEK_SET); + if (!return_value) util_fseek(stream , init_pos , SEEK_SET); free(date_token); return return_value; } @@ -4072,9 +4077,9 @@ void util_fskip_string(FILE *stream) { if (len == 0) return; /* The user has written NULL with util_fwrite_string(). */ else if (len == -1) - fseek( stream , 1 , SEEK_CUR); /* Magic length for "" - skip the '\0' */ + util_fseek( stream , 1 , SEEK_CUR); /* Magic length for "" - skip the '\0' */ else - fseek(stream , len + 1 , SEEK_CUR); /* Skip the data in a normal string. */ + util_fseek(stream , len + 1 , SEEK_CUR); /* Skip the data in a normal string. */ } @@ -4128,15 +4133,15 @@ bool util_fread_bool(FILE * stream) { void util_fskip_int(FILE * stream) { - fseek( stream , sizeof (int) , SEEK_CUR); + util_fseek( stream , sizeof (int) , SEEK_CUR); } void util_fskip_long(FILE * stream) { - fseek( stream , sizeof (long) , SEEK_CUR); + util_fseek( stream , sizeof (long) , SEEK_CUR); } void util_fskip_bool(FILE * stream) { - fseek( stream , sizeof (bool) , SEEK_CUR); + util_fseek( stream , sizeof (bool) , SEEK_CUR); } @@ -4773,9 +4778,9 @@ int util_get_type( void * data ) { */ int util_get_current_linenr(FILE * stream) { - long init_pos = ftell(stream); + long init_pos = util_ftell(stream); int line_nr = 0; - fseek( stream , 0L , SEEK_SET); + util_fseek( stream , 0L , SEEK_SET); { int char_nr; int c; @@ -4893,7 +4898,7 @@ int util_fnmatch( const char * pattern , const char * string ) { #ifdef HAVE_FNMATCH return fnmatch( pattern , string , 0 ); #else -#pragma comment(lib , "shlwapi.lib"); +#pragma comment(lib , "shlwapi.lib") bool match = PathMatchSpec( string , pattern ); // shlwapi if (match) return 0; @@ -4975,6 +4980,7 @@ int util_round( double x ) { return (int) (x + 0.5); } #endif #include "util_path.c" +#include "util_lfs.c" int util_type_get_id( const void * data ) { int type_id = ((const int*) data)[0]; diff --git a/ThirdParty/Ert/devel/libert_util/src/util_fork.c b/ThirdParty/Ert/devel/libert_util/src/util_fork.c index 2eda0d2806..3af24be1a9 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_fork.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_fork.c @@ -239,7 +239,7 @@ char * util_alloc_filename_from_stream( FILE * input_stream ) { */ bool util_ping(const char *hostname) { - pid_t ping_pid = util_fork_exec(PING_CMD , 4 , (const char *[4]) {"-c" , "3" , "-q", hostname} , false , NULL , NULL , NULL , NULL , NULL); + pid_t ping_pid = util_fork_exec(PING_CMD , 4 , (const char *[4]) {"-c" , "3" , "-q", hostname} , false , NULL , NULL , NULL , "/dev/null" , "/dev/null"); int wait_status; pid_t wait_pid = waitpid(ping_pid , &wait_status , 0); diff --git a/ThirdParty/Ert/devel/libert_util/src/util_getuid.c b/ThirdParty/Ert/devel/libert_util/src/util_getuid.c index 23c18633c3..2f95fa7f2b 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_getuid.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_getuid.c @@ -1,15 +1,15 @@ uid_t util_get_entry_uid( const char * file ) { - struct stat buffer; - stat( file , &buffer); + stat_type buffer; + util_stat( file , &buffer); return buffer.st_uid; } bool util_chmod_if_owner( const char * filename , mode_t new_mode) { - struct stat buffer; + stat_type buffer; uid_t exec_uid = getuid(); - stat( filename , &buffer ); + util_stat( filename , &buffer ); if (exec_uid == buffer.st_uid) { /* OKAY - the current running uid is also the owner of the file. */ mode_t current_mode = buffer.st_mode & ( S_IRWXU + S_IRWXG + S_IRWXO ); @@ -39,8 +39,8 @@ bool util_chmod_if_owner( const char * filename , mode_t new_mode) { bool util_addmode_if_owner( const char * filename , mode_t add_mode) { - struct stat buffer; - stat( filename , &buffer ); + stat_type buffer; + util_stat( filename , &buffer ); { mode_t current_mode = buffer.st_mode & ( S_IRWXU + S_IRWXG + S_IRWXO ); @@ -56,8 +56,8 @@ bool util_addmode_if_owner( const char * filename , mode_t add_mode) { Implements shell chmod -??? behaviour. */ bool util_delmode_if_owner( const char * filename , mode_t del_mode) { - struct stat buffer; - stat( filename , &buffer ); + stat_type buffer; + util_stat( filename , &buffer ); { mode_t current_mode = buffer.st_mode & ( S_IRWXU + S_IRWXG + S_IRWXO ); diff --git a/ThirdParty/Ert/devel/libert_util/src/util_lfs.c b/ThirdParty/Ert/devel/libert_util/src/util_lfs.c new file mode 100644 index 0000000000..fb9931e75d --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/src/util_lfs.c @@ -0,0 +1,110 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'util_win64.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. +*/ + +/* + This file, together with ifdef and typedef in util.h together try to + define transparent large file (> 2GB) support on windows and + linux. To support large files the datatype used to hold a file + offset must be 64 bit, in practical consequences this means: + + - functions ftell() and fseek() must use 64 bit offset types. + - The size field in struct stat must be 64 bit. + + On linux (at least on 64 bit platform) this is the deafult, + i.e. large files can be accessed out of the box. On windows the + situaton is more complicated: + + - functions ftell() and fseek() expect 32 bit offset types. + - The size field in struct stat is a 32 bit variable. + + Observe that the situation where 32 bit offset variables are used on + windows apply even on a 64 bit platform. To provide large file + support windows has the functions _ftelli64() and _fseeki64() and + the struct _stat64. Here we provide small wrapper functions + util_ftell(), util_fseek() and typedef struct stat_info. + + The final challenge is that the types 'long' and 'off_t == long' + have different size on windows and linux: + + + Windows(64 bit): sizeof(long) = 4 + sizeof(off_t) = 4 + + Linux(64 bit): sizeof(long) = 8 + sizeof(off_t) = 8 + + + To protect against this confusion we have typedefed a type + 'offset_type' in util.h, and all file operations should use that type. +*/ + +offset_type util_ftell(FILE * stream) { +#ifdef WINDOWS_LFS + return _ftelli64(stream); +#else + #ifdef HAVE_FSEEKO + return ftello(stream); + #else + return ftell(stream); + #endif +#endif +} + + +int util_fseek(FILE * stream, offset_type offset, int whence) { +#ifdef WINDOWS_LFS + return _fseeki64(stream , offset , whence); +#else + #ifdef HAVE_FSEEKO + return fseeko( stream , offset , whence ); + #else + return fseek( stream , offset , whence ); + #endif +#endif +} + + + +void util_rewind(FILE * stream) { +#ifdef WINDOWS_LFS_SUPPORT + _fseeki64(stream , 0L , SEEK_SET); +#else + rewind( stream ); +#endif +} + + + + + +int util_stat(const char * filename , stat_type * stat_info) { +#ifdef WINDOWS_LFS_SUPPORT + return _stat64(filename , stat_info); +#else + return stat(filename , stat_info); +#endif +} + + +int util_fstat(int fileno, stat_type * stat_info) { +#ifdef WINDOWS_LFS_SUPPORT + return _fstat64(fileno , stat_info); +#else + return fstat(fileno , stat_info); +#endif +} diff --git a/ThirdParty/Ert/devel/libert_util/src/util_opendir.c b/ThirdParty/Ert/devel/libert_util/src/util_opendir.c index e12da3bc8c..05848bf898 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_opendir.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_opendir.c @@ -1,13 +1,5 @@ -/** - Externals: -*/ -typedef struct msg_struct msg_type; -msg_type * msg_alloc(const char * , bool); -void msg_show(msg_type * ); -void msg_free(msg_type * , bool); -void msg_update(msg_type * , const char * ); -static void util_copy_directory__(const char * src_path , const char * target_path , int buffer_size , void * buffer , msg_type * msg) { +static void util_copy_directory__(const char * src_path , const char * target_path , int buffer_size , void * buffer ) { if (!util_is_directory(src_path)) util_abort("%s: %s is not a directory \n",__func__ , src_path); @@ -26,11 +18,11 @@ static void util_copy_directory__(const char * src_path , const char * target_pa char * full_src_path = util_alloc_filename(src_path , dp->d_name , NULL); char * full_target_path = util_alloc_filename(target_path , dp->d_name , NULL); if (util_is_file( full_src_path )) { - if (msg != NULL) - msg_update( msg , full_src_path); util_copy_file__( full_src_path , full_target_path , buffer_size , buffer , true); - } else - util_copy_directory__( full_src_path , full_target_path , buffer_size , buffer , msg); + } else { + if (util_is_directory( full_src_path ) && !util_is_link( full_src_path)) + util_copy_directory__( full_src_path , full_target_path , buffer_size , buffer); + } free( full_src_path ); free( full_target_path ); @@ -43,6 +35,14 @@ static void util_copy_directory__(const char * src_path , const char * target_pa } +void util_copy_directory_content(const char * src_path , const char * target_path) { + int buffer_size = 16 * 1024 * 1024; /* 16 MB */ + void * buffer = util_malloc( buffer_size ); + + util_copy_directory__( src_path , target_path , buffer_size , buffer); + free( buffer ); +} + /** Equivalent to shell command cp -r src_path target_path */ @@ -50,35 +50,18 @@ static void util_copy_directory__(const char * src_path , const char * target_pa /* Does not handle symlinks (I think ...). */ -void util_copy_directory(const char * src_path , const char * __target_path , const char * prompt) { +void util_copy_directory(const char * src_path , const char * __target_path) { int num_components; char ** path_parts; char * path_tail; char * target_path; - void * buffer = NULL; - int buffer_size = 512 * 1024 * 1024; /* 512 MB */ - do { - buffer = malloc(buffer_size); - if (buffer == NULL) buffer_size /= 2; - } while ((buffer == NULL) && (buffer_size > 0)); - - if (buffer_size == 0) - util_abort("%s: failed to allocate any memory ?? \n",__func__); util_path_split(src_path , &num_components , &path_parts); path_tail = path_parts[num_components - 1]; target_path = util_alloc_filename(__target_path , path_tail , NULL); - { - msg_type * msg = NULL; - if (prompt != NULL) { - msg = msg_alloc(prompt , false); - msg_show( msg ); - util_copy_directory__(src_path , target_path , buffer_size , buffer ,msg); - } - msg_free(msg , true); - } - free( buffer ); + util_copy_directory_content(src_path , target_path ); + free(target_path); util_free_stringlist( path_parts , num_components ); } diff --git a/ThirdParty/Ert/devel/libert_util/src/util_path.c b/ThirdParty/Ert/devel/libert_util/src/util_path.c index 40e512aaff..2bf953f232 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_path.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_path.c @@ -105,11 +105,11 @@ void util_make_path(const char *_path) { char * util_alloc_tmp_file(const char * path, const char * prefix , bool include_pid ) { // Should be reimplemented to use mkstemp() const int pid_digits = 6; - const int pid_max = 1000000; const int random_digits = 6; const int random_max = 1000000; #ifdef HAVE_PID_T + const int pid_max = 1000000; pid_t pid = getpid() % pid_max; #else int pid = 0; @@ -201,8 +201,31 @@ int util_proc_mem_free(void) { +char * util_split_alloc_dirname( const char * input_path ) { + char * path; + util_alloc_file_components( input_path , &path , NULL , NULL); + return path; +} +char * util_split_alloc_filename( const char * input_path ) { + char * filename = NULL; + { + char * basename; + char * extension; + + util_alloc_file_components( input_path , NULL , &basename , &extension); + + if (basename) + filename = util_alloc_filename( NULL , basename , extension ); + + util_safe_free( basename ); + util_safe_free( extension ); + } + + return filename; +} + void util_path_split(const char *line , int *_tokens, char ***_token_list) { diff --git a/ThirdParty/Ert/devel/libert_util/src/util_symlink.c b/ThirdParty/Ert/devel/libert_util/src/util_symlink.c index 6f051825d5..10e414640a 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_symlink.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_symlink.c @@ -24,7 +24,7 @@ void util_make_slink(const char *target , const char * link) { */ bool util_is_link(const char * path) { - struct stat stat_buffer; + stat_type stat_buffer; if (lstat(path , &stat_buffer) == 0) return S_ISLNK(stat_buffer.st_mode); else if (errno == ENOENT) diff --git a/ThirdParty/Ert/devel/libert_util/src/util_zlib.c b/ThirdParty/Ert/devel/libert_util/src/util_zlib.c index acdad08263..d8f098de04 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_zlib.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_zlib.c @@ -201,7 +201,7 @@ void util_fread_compressed(void *__data , FILE * stream) { */ void * util_fread_alloc_compressed(FILE * stream) { - long current_pos = ftell(stream); + long current_pos = util_ftell(stream); char * data; int size; @@ -209,7 +209,7 @@ void * util_fread_alloc_compressed(FILE * stream) { if (size == 0) return NULL; else { - fseek(stream , current_pos , SEEK_SET); + util_fseek(stream , current_pos , SEEK_SET); data = util_calloc(size , sizeof * data ); util_fread_compressed(data , stream); return data; @@ -226,7 +226,7 @@ int util_fread_sizeof_compressed(FILE * stream) { int size; fread(&size , sizeof size , 1 , stream); - fseek( stream , pos , SEEK_SET ); + util_fseek( stream , pos , SEEK_SET ); return size; } @@ -244,7 +244,7 @@ void util_fskip_compressed(FILE * stream) { do { unsigned long compressed_size; fread(&compressed_size , sizeof compressed_size , 1 , stream); - fseek(stream , compressed_size , SEEK_CUR); + util_fseek(stream , compressed_size , SEEK_CUR); fread(&offset , sizeof offset , 1 , stream); } while (offset < size); } diff --git a/ThirdParty/Ert/devel/libert_util/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libert_util/tests/CMakeLists.txt index 5c88534d83..5457bf2469 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libert_util/tests/CMakeLists.txt @@ -5,104 +5,116 @@ # 1. First server - this should be an existing server which should return true. # 2. This should be an invalid hostname - should return false. # 3. This should be an valid host which does not answer ping - i.e currently off? -set(PING_SERVERS "localhost" CACHE STRING "List of LSF servers for testing") +set(PING_SERVERS "" CACHE STRING "List of servers for testing ping") link_directories( ${ERT_BINARY_DIR}/libert_util/src ) add_executable( ert_util_type_vector_test ert_util_type_vector_test.c ) -target_link_libraries( ert_util_type_vector_test ert_util ) +target_link_libraries( ert_util_type_vector_test ert_util test_util ) add_test( ert_util_type_vector_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_type_vector_test ) +add_executable( ert_util_filename ert_util_filename.c ) +target_link_libraries( ert_util_filename ert_util test_util ) +add_test( ert_util_filename ${EXECUTABLE_OUTPUT_PATH}/ert_util_filename ) + add_executable( ert_util_string_util ert_util_string_util.c ) -target_link_libraries( ert_util_string_util ert_util ) +target_link_libraries( ert_util_string_util ert_util test_util ) add_test( ert_util_string_util ${EXECUTABLE_OUTPUT_PATH}/ert_util_string_util ) add_executable( ert_util_vector_test ert_util_vector_test.c ) -target_link_libraries( ert_util_vector_test ert_util ) +target_link_libraries( ert_util_vector_test ert_util test_util ) add_test( ert_util_vector_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_vector_test ) add_executable( ert_util_cwd_test ert_util_cwd_test.c ) -target_link_libraries( ert_util_cwd_test ert_util ) +target_link_libraries( ert_util_cwd_test ert_util test_util ) add_test( ert_util_cwd_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_cwd_test ${CMAKE_CURRENT_BINARY_DIR}) add_executable( ert_util_relpath_test ert_util_relpath_test.c ) -target_link_libraries( ert_util_relpath_test ert_util ) +target_link_libraries( ert_util_relpath_test ert_util test_util ) add_test( ert_util_relpath_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_relpath_test ) add_executable( ert_util_path_stack_test ert_util_path_stack_test.c ) -target_link_libraries( ert_util_path_stack_test ert_util ) +target_link_libraries( ert_util_path_stack_test ert_util test_util ) add_test( ert_util_path_stack_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_path_stack_test ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) add_executable( ert_util_PATH_test ert_util_PATH_test.c ) -target_link_libraries( ert_util_PATH_test ert_util ) +target_link_libraries( ert_util_PATH_test ert_util test_util ) add_test( ert_util_PATH_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_PATH_test ) add_executable( ert_util_strcat_test ert_util_strcat_test.c ) -target_link_libraries( ert_util_strcat_test ert_util ) +target_link_libraries( ert_util_strcat_test ert_util test_util ) add_test( ert_util_strcat_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_strcat_test ) add_executable( ert_util_sprintf_escape ert_util_sprintf_escape.c ) -target_link_libraries( ert_util_sprintf_escape ert_util ) +target_link_libraries( ert_util_sprintf_escape ert_util test_util ) add_test( ert_util_sprintf_escape ${EXECUTABLE_OUTPUT_PATH}/ert_util_sprintf_escape ) add_executable( ert_util_stringlist_test ert_util_stringlist_test.c ) -target_link_libraries( ert_util_stringlist_test ert_util ) +target_link_libraries( ert_util_stringlist_test ert_util test_util ) add_test( ert_util_stringlist_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_stringlist_test ) add_executable( ert_util_realpath ert_util_realpath.c ) -target_link_libraries( ert_util_realpath ert_util ) +target_link_libraries( ert_util_realpath ert_util test_util ) add_test( ert_util_realpath ${EXECUTABLE_OUTPUT_PATH}/ert_util_realpath ) add_executable( ert_util_hash_test ert_util_hash_test.c ) -target_link_libraries( ert_util_hash_test ert_util ) +target_link_libraries( ert_util_hash_test ert_util test_util ) add_test( ert_util_hash_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_hash_test ) add_executable( ert_util_binary_split ert_util_binary_split.c ) -target_link_libraries( ert_util_binary_split ert_util ) +target_link_libraries( ert_util_binary_split ert_util test_util ) add_test( ert_util_binary_split ${EXECUTABLE_OUTPUT_PATH}/ert_util_binary_split ) add_executable( ert_util_logh ert_util_logh.c ) -target_link_libraries( ert_util_logh ert_util ) +target_link_libraries( ert_util_logh ert_util test_util ) add_test( ert_util_logh ${EXECUTABLE_OUTPUT_PATH}/ert_util_logh ) add_executable( ert_util_rng ert_util_rng.c ) -target_link_libraries( ert_util_rng ert_util ) +target_link_libraries( ert_util_rng ert_util test_util ) add_test( ert_util_rng ${EXECUTABLE_OUTPUT_PATH}/ert_util_rng ) add_executable( ert_util_time_interval ert_util_time_interval.c ) -target_link_libraries( ert_util_time_interval ert_util ) +target_link_libraries( ert_util_time_interval ert_util test_util ) add_test( ert_util_time_interval ${EXECUTABLE_OUTPUT_PATH}/ert_util_time_interval ) add_executable( ert_util_before_after ert_util_before_after.c ) -target_link_libraries( ert_util_before_after ert_util ) +target_link_libraries( ert_util_before_after ert_util test_util ) add_test( ert_util_before_after ${EXECUTABLE_OUTPUT_PATH}/ert_util_before_after ) add_executable( ert_util_approx_equal ert_util_approx_equal.c ) -target_link_libraries( ert_util_approx_equal ert_util ) +target_link_libraries( ert_util_approx_equal ert_util test_util ) add_test( ert_util_approx_equal ${EXECUTABLE_OUTPUT_PATH}/ert_util_approx_equal ) add_executable( ert_util_ping ert_util_ping.c ) -target_link_libraries( ert_util_ping ert_util ) +target_link_libraries( ert_util_ping ert_util test_util ) add_test( ert_util_ping ${EXECUTABLE_OUTPUT_PATH}/ert_util_ping ${PING_SERVERS}) add_executable( ert_util_file_readable ert_util_file_readable.c ) -target_link_libraries( ert_util_file_readable ert_util ) +target_link_libraries( ert_util_file_readable ert_util test_util ) add_test( ert_util_file_readable ${EXECUTABLE_OUTPUT_PATH}/ert_util_file_readable ${FILE_READABLE_SERVERS}) add_executable( ert_util_addr2line ert_util_addr2line.c ) -target_link_libraries( ert_util_addr2line ert_util ) +target_link_libraries( ert_util_addr2line ert_util test_util ) add_test( ert_util_addr2line ${EXECUTABLE_OUTPUT_PATH}/ert_util_addr2line) +add_executable( ert_util_work_area ert_util_work_area.c ) +target_link_libraries( ert_util_work_area ert_util test_util ) +add_test( NAME ert_util_work_area + COMMAND ${EXECUTABLE_OUTPUT_PATH}/ert_util_work_area data/file1.txt ${CMAKE_CURRENT_SOURCE_DIR}/data/file2.txt data + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + + + if (WITH_LATEX) add_executable( ert_util_latex_test ert_util_latex_test.c ) - target_link_libraries(ert_util_latex_test ert_util ) + target_link_libraries(ert_util_latex_test ert_util test_util ) add_test( ert_util_latex_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_latex_test ${CMAKE_CURRENT_SOURCE_DIR}/data/latex_OK.tex ) endif() add_executable( ert_util_arg_pack ert_util_arg_pack.c) set_target_properties( ert_util_arg_pack PROPERTIES COMPILE_FLAGS "-Werror") -target_link_libraries( ert_util_arg_pack ert_util ) +target_link_libraries( ert_util_arg_pack ert_util test_util ) add_test( ert_util_arg_pack ${EXECUTABLE_OUTPUT_PATH}/ert_util_arg_pack) diff --git a/ThirdParty/Ert/devel/libert_util/tests/data/file1.txt b/ThirdParty/Ert/devel/libert_util/tests/data/file1.txt new file mode 100644 index 0000000000..0ee389557a --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/tests/data/file1.txt @@ -0,0 +1 @@ +Some content diff --git a/ThirdParty/Ert/devel/libert_util/tests/data/file2.txt b/ThirdParty/Ert/devel/libert_util/tests/data/file2.txt new file mode 100644 index 0000000000..de9afa7f69 --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/tests/data/file2.txt @@ -0,0 +1 @@ +More content diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_filename.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_filename.c new file mode 100644 index 0000000000..4bd358ecd9 --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_filename.c @@ -0,0 +1,73 @@ +/* + 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 + + +void test_dirname() { + const char * src_file1 = "/some/very/long/path/file.txt"; + const char * src_file2 = "relative/path/file.txt"; + const char * src_file3 = "file.txt"; + + char * path1 = util_split_alloc_dirname( src_file1 ); + char * path2 = util_split_alloc_dirname( src_file2 ); + char * path3 = util_split_alloc_dirname( src_file3 ); + + test_assert_string_equal( "/some/very/long/path" , path1); + test_assert_string_equal( "relative/path" , path2); + test_assert_NULL( path3 ); + + free( path1 ); + free( path2 ); +} + + + +void test_filename() { + const char * src_file1 = "/some/very/long/path/file1.txt"; + const char * src_file2 = "relative/path/file2"; + const char * src_file3 = "/tmp"; + + char * file1 = util_split_alloc_filename( src_file1 ); + char * file2 = util_split_alloc_filename( src_file2 ); + char * file3 = util_split_alloc_filename( src_file3 ); + + test_assert_string_equal( "file1.txt" , file1); + test_assert_string_equal( "file2" , file2); + test_assert_NULL( file3 ); + free( file1 ); + free( file2 ); + +} + + + + +int main(int argc , char ** argv) { + + test_dirname(); + test_filename(); + exit(0); + +} diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_logh.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_logh.c index 2f928c1fd1..0528fe2601 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_logh.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_logh.c @@ -19,12 +19,14 @@ #include #include +#include #include #include -#define LOG_FILE "/tmp/log.txt" +#define LOG_FILE "log.txt" int main(int argc , char ** argv) { + test_work_area_type * work_area = test_work_area_alloc("util/logh" , false); { log_type * logh = log_open( NULL , 0 ); @@ -40,5 +42,6 @@ int main(int argc , char ** argv) { test_assert_true( log_is_open( logh )); log_close( logh ); } + test_work_area_free( work_area ); exit(0); } diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_ping.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_ping.c index 5b0a31876b..5b41aa69e7 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_ping.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_ping.c @@ -25,17 +25,17 @@ int main( int argc , char ** argv) { - stringlist_type * server_list = stringlist_alloc_from_split( argv[1] , " "); - argc = stringlist_get_size( server_list ); - - if (argc >= 1) - test_assert_true( util_ping( stringlist_iget( server_list , 0 ))); + test_assert_true( util_ping("localhost" )); + test_assert_true( util_ping("127.0.0.1" )); + test_assert_false( util_ping("does.not.exist")); - if (argc >= 2) - test_assert_false( util_ping( stringlist_iget( server_list , 1 ))); - - if (argc >= 3) - test_assert_false( util_ping( stringlist_iget( server_list , 2 ))); + if (argc > 1) { + stringlist_type * server_list = stringlist_alloc_from_split( argv[1] , " "); + int is ; + for (is = 0; is < stringlist_get_size( server_list ); is++) { + test_assert_true( util_ping( stringlist_iget( server_list , is ))); + } + } exit(0); } diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_realpath.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_realpath.c index c42adf6108..cd742c31bd 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_realpath.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_realpath.c @@ -24,7 +24,7 @@ void test_path(const char * input , const char * expected) { char * rpath = util_alloc_realpath__( input ); - if (!test_string_equal( rpath , expected )) + if (!test_check_string_equal( rpath , expected )) test_error_exit("util_alloc_realpath__(%s) => %s expected:%s \n",input , rpath , expected); else printf("OK: %s -> %s \n",input , rpath); diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_relpath_test.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_relpath_test.c index 0eac93bf9a..f571fcfbb5 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_relpath_test.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_relpath_test.c @@ -28,7 +28,7 @@ void test_path(int nr , const char * root , const char * path , const char * true_path) { char * rel_path = util_alloc_rel_path( root , path); - if (!test_string_equal( rel_path , true_path)) + if (!test_check_string_equal( rel_path , true_path)) test_error_exit("Case:%d rel_path(%s,%s) -> %s failed - expected: %s\n" , nr , root , path , rel_path , true_path); else printf("Case:%d OK \n",nr); diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_strcat_test.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_strcat_test.c index e022fc51d1..a3831dde94 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_strcat_test.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_strcat_test.c @@ -26,7 +26,7 @@ void test_strcat(char * s1 , const char *s2 , const char * expected) { char * cat = util_strcat_realloc(s1 , s2 ); - if (test_string_equal( cat , expected )) + if (test_check_string_equal( cat , expected )) util_safe_free( cat ); else test_error_exit("util_strcat_realloc(%s,%s) Got:%s expected:%s \n",s1,s2,cat , expected); diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_work_area.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_work_area.c new file mode 100644 index 0000000000..5f257a70cd --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_work_area.c @@ -0,0 +1,124 @@ +/* + 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 + + +void test_get_cwd() { + test_work_area_type * work_area = test_work_area_alloc( "CWD-TEST", false); + char * cwd = util_alloc_cwd(); + test_assert_string_equal( cwd , test_work_area_get_cwd( work_area )); + free( cwd ); + test_work_area_free( work_area ); +} + + +void test_get_original_cwd() { + char * cwd = util_alloc_cwd(); + test_work_area_type * work_area = test_work_area_alloc( "CWD-ORG-TEST", false); + test_assert_string_equal( cwd , test_work_area_get_original_cwd( work_area )); + free( cwd ); + test_work_area_free( work_area ); +} + + + + +void create_test_area(const char * test_name , bool store) { + char * pre_cwd = util_alloc_cwd(); + test_work_area_type * work_area = test_work_area_alloc( test_name , store); + char * work_path = util_alloc_string_copy( test_work_area_get_cwd( work_area )); + + test_assert_true( util_is_directory( work_path )); + test_work_area_free( work_area ); + test_assert_bool_equal( store , util_entry_exists( work_path )); + + { + char * post_cwd = util_alloc_cwd(); + test_assert_string_equal( pre_cwd , post_cwd ); + free( post_cwd ); + } + free( pre_cwd ); + free( work_path ); +} + + +void test_install_file_exists(const char * filename ) { + char * abs_input_path = util_alloc_abs_path( filename ); + test_work_area_type * work_area = test_work_area_alloc( "FILE-TEST" , false); + + test_work_area_install_file( work_area , filename ); + test_assert_true( util_files_equal( abs_input_path , filename )); + test_work_area_free( work_area ); + free( abs_input_path ); +} + + +void test_copy_directory(const char * rel_path) { + test_work_area_type * work_area = test_work_area_alloc( "FILE-TEST" , false); + test_work_area_copy_directory( work_area , rel_path ); + test_assert_true( util_is_directory( rel_path )); + test_work_area_free( work_area ); +} + + +void test_input() { + test_work_area_type * work_area = test_work_area_alloc( NULL , false ); + test_assert_NULL( work_area ); +} + + + +void test_copy_file( const char * src_file ) { + char * filename = util_split_alloc_filename( src_file ); + test_work_area_type * work_area = test_work_area_alloc( "copy-file" , true ); + test_work_area_copy_file( work_area , src_file ); + + test_assert_true( util_file_exists( filename )); + + test_work_area_free( work_area ); + free( filename ); +} + + + +int main(int argc , char ** argv) { + const char * rel_path_file = argv[1]; + const char * abs_path_file = argv[2]; + const char * rel_directory = argv[3]; + + create_test_area("STORE-TEST" , true ); + create_test_area("DEL-TEST" , false); + test_install_file_exists( rel_path_file ); + test_install_file_exists( abs_path_file ); + test_copy_directory( rel_directory ); + test_input(); + test_get_cwd(); + test_get_original_cwd(); + + test_copy_file( rel_path_file ); + test_copy_file( abs_path_file ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libgeometry/src/CMakeLists.txt b/ThirdParty/Ert/devel/libgeometry/src/CMakeLists.txt index cc1391ab09..8dc42c6d20 100644 --- a/ThirdParty/Ert/devel/libgeometry/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libgeometry/src/CMakeLists.txt @@ -4,6 +4,9 @@ set( header_files geo_surface.h geo_util.h geo_pointset.h geo_region.h geo_polyg add_library( ert_geometry ${LIBRARY_TYPE} ${source_files} ) set_target_properties( ert_geometry PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( ert_geometry ert_util ) +if (USE_RUNPATH) + add_runpath( ert_geometry ) +endif() #----------------------------------------------------------------- diff --git a/ThirdParty/Ert/devel/libgeometry/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libgeometry/tests/CMakeLists.txt index fcedece5f1..fccc73ffaf 100644 --- a/ThirdParty/Ert/devel/libgeometry/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libgeometry/tests/CMakeLists.txt @@ -1,5 +1,5 @@ add_executable( geo_surface geo_surface.c ) -target_link_libraries( geo_surface ert_geometry ) +target_link_libraries( geo_surface ert_geometry test_util ) add_test( geo_surface ${EXECUTABLE_OUTPUT_PATH}/geo_surface ${PROJECT_SOURCE_DIR}/test-data/Statoil/Geometry/Surface.irap diff --git a/ThirdParty/Ert/devel/libjob_queue/CMakeLists.txt b/ThirdParty/Ert/devel/libjob_queue/CMakeLists.txt index 159c0c64e8..31482517e7 100644 --- a/ThirdParty/Ert/devel/libjob_queue/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libjob_queue/CMakeLists.txt @@ -23,7 +23,7 @@ endif() add_subdirectory( src ) -if (BUILD_APPLICATONS) +if (BUILD_APPLICATIONS) add_subdirectory( applications ) endif() diff --git a/ThirdParty/Ert/devel/libjob_queue/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libjob_queue/applications/CMakeLists.txt index c80e58df09..1358818a99 100644 --- a/ThirdParty/Ert/devel/libjob_queue/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libjob_queue/applications/CMakeLists.txt @@ -1,2 +1,8 @@ add_executable( block_node block_node.c ) target_link_libraries( block_node job_queue ert_util) +if (USE_RUNPATH) + add_runpath( block_node ) +endif() + +set (destination ${CMAKE_INSTALL_PREFIX}/bin) +install(TARGETS block_node DESTINATION ${destination}) diff --git a/ThirdParty/Ert/devel/libjob_queue/applications/block_node.c b/ThirdParty/Ert/devel/libjob_queue/applications/block_node.c index 6056bea60a..32b26ab595 100644 --- a/ThirdParty/Ert/devel/libjob_queue/applications/block_node.c +++ b/ThirdParty/Ert/devel/libjob_queue/applications/block_node.c @@ -15,144 +15,191 @@ See the GNU General Public License at for more details. */ -#ifdef INCLUDE_LSF -#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include -#define BLOCK_COMMAND "/d/proj/bg/enkf/bin/block_node.py" +#include + +#define BLOCK_COMMAND "/project/res/bin/block-job" #define STATOIL_LSF_REQUEST "select[cs && x86_64Linux]" + +static lsf_driver_type * lsf_driver; +static vector_type * job_pool; +static hash_type * nodes; + + typedef struct { - struct submit lsf_request; - struct submitReply lsf_reply; - long int lsf_jobnr; - char * host_name; - const char * command; - bool running; - bool block_job; -} lsf_job_type; + lsf_job_type * lsf_job; + stringlist_type * hostlist; + bool running; + bool block_job; +} block_job_type; +typedef struct { + int target; + int current; +} count_pair_type; -lsf_job_type * lsf_job_alloc(char * queue_name) { - lsf_job_type * lsf_job = util_malloc( sizeof * lsf_job ); - - memset(&lsf_job->lsf_request , 0 , sizeof (lsf_job->lsf_request)); - lsf_job->lsf_request.queue = queue_name; - lsf_job->lsf_request.beginTime = 0; - lsf_job->lsf_request.termTime = 0; - lsf_job->lsf_request.numProcessors = 1; - lsf_job->lsf_request.maxNumProcessors = 1; - lsf_job->lsf_request.command = BLOCK_COMMAND; - lsf_job->lsf_request.outFile = "/tmp/lsf"; - lsf_job->lsf_request.jobName = "lsf"; - lsf_job->lsf_request.resReq = STATOIL_LSF_REQUEST; - { - int i; - for (i=0; i < LSF_RLIM_NLIMITS; i++) - lsf_job->lsf_request.rLimits[i] = DEFAULT_RLIMIT; - } - lsf_job->lsf_request.options2 = 0; - lsf_job->lsf_request.options = SUB_QUEUE + SUB_JOB_NAME + SUB_OUT_FILE + SUB_RES_REQ; - lsf_job->host_name = NULL; - lsf_job->running = false; - lsf_job->block_job = false; - return lsf_job; +count_pair_type * count_pair_alloc() { + count_pair_type * pair = util_malloc( sizeof * pair ); + pair->target = 0; + pair->current = 0; + return pair; } -void update_job_status( lsf_job_type * job , hash_type * nodes) { - if (!job->running) { - struct jobInfoEnt *job_info; - if (lsb_openjobinfo(job->lsf_jobnr , NULL , NULL , NULL , NULL , ALL_JOB) == 1) { - job_info = lsb_readjobinfo( NULL ); - lsb_closejobinfo(); - - if (job_info->status == JOB_STAT_RUN) { - job->running = true; - job->host_name = util_realloc_string_copy( job->host_name , job_info->exHosts[0]); /* Hardcoded only one node. */ - if (hash_has_key( nodes, job->host_name)) {/* This is one of the instances which should be left running. */ - job->block_job = true; - printf("Got a block on:%s \n",job->host_name); +block_job_type * block_job_alloc() { + block_job_type * job = util_malloc( sizeof * job ); + + job->lsf_job = NULL; + job->running = false; + job->block_job = false; + job->hostlist = stringlist_alloc_new(); + + return job; +} + + +void block_job_free( block_job_type * block_job ) { + stringlist_free( block_job->hostlist ); + if (block_job->lsf_job) + lsf_job_free( block_job->lsf_job ); + + free( block_job ); +} + + +const char * block_job_get_hostname( const block_job_type * block_job ) { + return stringlist_iget( block_job->hostlist , 0 ); +} + + + +void update_job_status( block_job_type * job ) { + if (!job->running) { + int lsf_status = lsf_driver_get_job_status_lsf( lsf_driver , job->lsf_job ); + if (lsf_status == JOB_STAT_RUN) { + lsf_job_export_hostnames( job->lsf_job , job->hostlist ); + { + int ihost; + for (ihost = 0; ihost < stringlist_get_size( job->hostlist ); ihost++) { + const char * host = stringlist_iget( job->hostlist , ihost ); + if (hash_has_key( nodes, host)) { /* This is one of the instances which should be left running. */ + count_pair_type * pair = hash_get( nodes , host); + if (pair->current < pair->target) { + pair->current += 1; + job->block_job = true; + } + } } } + job->running = true; } } } -void lsf_job_submit( lsf_job_type * job ) { - job->lsf_jobnr = lsb_submit( &job->lsf_request , &job->lsf_reply ); -} - - - - -void lsf_job_kill( lsf_job_type * job ) { - lsb_forcekilljob(job->lsf_jobnr); -} - - - -void lsf_job_free( lsf_job_type * job ) { - if (job->block_job) - printf("Node: %-16s blocked by job:%ld \n",job->host_name , job->lsf_jobnr); - else - lsf_job_kill( job ); - - util_safe_free( job->host_name ); - free( job ); -} - - -void lsf_job_free__( void * arg) { - lsf_job_free( (lsf_job_type * ) arg); -} - /*****************************************************************/ -void add_jobs(vector_type * job_pool , int chunk_size) { +void add_jobs( int chunk_size) { int i; + char * cwd = util_alloc_cwd(); for (i=0; i < chunk_size; i++) { - lsf_job_type * job = lsf_job_alloc("normal"); - vector_append_owned_ref( job_pool , job , lsf_job_free__); - lsf_job_submit( job ); + block_job_type * job = block_job_alloc(); + job->lsf_job = lsf_driver_submit_job(lsf_driver , BLOCK_COMMAND , 1 , cwd , "BLOCK" , 0 , NULL ); + vector_append_ref( job_pool , job ); } + free( cwd ); } -void update_pool_status(vector_type * job_pool , hash_type * block_nodes , int * blocked , int * pending) { +void update_pool_status( bool *all_blocked , int * pending) { int i; - int block_count = 0; - int pend_count = 0; + int pend_count = 0; + *all_blocked = true; + for (i=0; i < vector_get_size( job_pool ); i++) { - lsf_job_type * job = vector_iget( job_pool , i ); - update_job_status( job , block_nodes ); + block_job_type * job = vector_iget( job_pool , i ); + update_job_status( job ); + if (!job->running) pend_count++; - else { - if (job->block_job) - block_count++; + } + + { + hash_iter_type * iter = hash_iter_alloc( nodes ); + while (!hash_iter_is_complete( iter )) { + const char * hostname = hash_iter_get_next_key( iter ); + const count_pair_type * count = hash_get( nodes , hostname ); + if (count->current < count->target) + *all_blocked = false; } } - *blocked = block_count; *pending = pend_count; } +void print_status() { + int total_running = 0; + int total_pending = 0; + for (int i=0; i < vector_get_size( job_pool ); i++) { + block_job_type * job = vector_iget( job_pool , i ); + if (job->running) + total_running += 1; + else + total_pending += 1; + } + printf("Running:%3d Pending: %3d Blocks active: ",total_running , total_pending); + { + hash_iter_type * iter = hash_iter_alloc( nodes ); + while (!hash_iter_is_complete( iter )) { + const char * hostname = hash_iter_get_next_key( iter ); + const count_pair_type * count = hash_get( nodes , hostname ); + printf("%s %d/%d ",hostname , count->current , count->target); + } + printf("\n"); + hash_iter_free( iter ); + } +} + + +void block_node_exit( int signal ) { + int job_nr; + + print_status(); + for (job_nr = 0; job_nr < vector_get_size( job_pool ); job_nr++) { + block_job_type * job = vector_iget( job_pool , job_nr ); + + if (job->block_job) { + printf("Job:%ld is running on host: ", lsf_job_get_jobnr( job->lsf_job )); + stringlist_fprintf( job->hostlist , " " , stdout ); + printf("\n"); + } else + lsf_driver_kill_job( lsf_driver , job->lsf_job ); + + block_job_free( job ); + } + printf("Remember to kill these jobs when the BLOCK is no longer needed\n"); + if (signal != 0) + exit(0); +} int main( int argc, char ** argv) { @@ -160,78 +207,78 @@ int main( int argc, char ** argv) { util_exit("block_node node1 node2 node3:2 \n"); /* Initialize lsf environment */ - util_setenv__( "LSF_BINDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/bin" ); - util_setenv__( "LSF_LINDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib" ); - util_setenv__( "XLSF_UIDDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib/uid" ); - util_setenv__( "LSF_SERVERDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/etc"); - util_setenv__( "LSF_ENVDIR" , "/prog/LSF/conf"); + util_setenv( "LSF_BINDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/bin" ); + util_setenv( "LSF_LINDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib" ); + util_setenv( "XLSF_UIDDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib/uid" ); + util_setenv( "LSF_SERVERDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/etc"); + util_setenv( "LSF_ENVDIR" , "/prog/LSF/conf"); util_update_path_var( "PATH" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/bin" , false); util_update_path_var( "LD_LIBRARY_PATH" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib" , false); - if (lsb_init(NULL) != 0) - util_abort("%s failed to initialize LSF environment : %s/%d \n",__func__ , lsb_sysmsg() , lsberrno); - util_setenv__("BSUB_QUIET" , "yes" ); - { - hash_type * nodes = hash_alloc(); - int node_count = 0; - int iarg; - printf("Attempting to block nodes \n"); - for (iarg = 1; iarg < argc; iarg++) { - char node_name[64]; - int num_slots; - if (sscanf(argv[iarg] , "%s:%d" , node_name , &num_slots) != 2) - num_slots = 1; + + lsf_driver = lsf_driver_alloc(); + if (lsf_driver_get_submit_method( lsf_driver ) != LSF_SUBMIT_INTERNAL) + util_exit("Sorry - the block_node program must be invoked on a proper LSF node \n"); - hash_insert_int( nodes , node_name , num_slots ); - node_count += num_slots; - - printf(" %s",node_name); - if (num_slots != 1) - printf(" * %d",num_slots ); - printf("\n"); - } - printf("-----------------------------------------------------------------\n"); + { + int iarg; + int total_blocked_target = 0; + nodes = hash_alloc(); + for (iarg = 1; iarg < argc; iarg++) { + char *node_name; + int num_slots; + + { + char * num_slots_string; + util_binary_split_string( argv[iarg] , ":" , true , &node_name , &num_slots_string); + if (num_slots_string) + util_sscanf_int( num_slots_string , &num_slots); + else + num_slots = 1; + } + + if (!hash_has_key( nodes , node_name)) + hash_insert_hash_owned_ref( nodes , node_name , count_pair_alloc() , free); + + { + count_pair_type * pair = hash_get( nodes , node_name); + pair->target += num_slots; + } + total_blocked_target += num_slots; + } + + signal(SIGINT , block_node_exit ); { const int sleep_time = 5; - const int max_attempt = 25; - const int chunk_size = 10; /* We submit this many at a time. */ - const int max_pool_size = 100; /* The absolute total maximum of jobs we will submit. */ + const int chunk_size = 10; /* We submit this many at a time. */ + const int max_pool_size = 1000; /* The absolute total maximum of jobs we will submit. */ - vector_type * job_pool = vector_alloc_new(); bool cont = true; int pending = 0; - int blocked; - int attempt = 0; + bool all_blocked; + job_pool = vector_alloc_new(); + while (cont) { - printf("Attempt: %2d/%2d ",attempt , max_attempt); fflush( stdout ); + printf("[Ctrl-C to give up] "); fflush( stdout ); + if (cont) sleep( sleep_time ); if (pending == 0) { if (vector_get_size( job_pool ) < max_pool_size) - add_jobs( job_pool , chunk_size ); + add_jobs( chunk_size ); } - update_pool_status( job_pool , nodes , &blocked , &pending); - if (blocked == node_count) - cont = false; /* Ok - we have got them all blocked - leave the building. */ + update_pool_status( &all_blocked , &pending); + print_status(); - attempt++; - if (attempt > max_attempt) + if (all_blocked) cont = false; - - if (cont) sleep( sleep_time ); - printf("\n"); } - if (blocked < node_count) + if (!all_blocked) printf("Sorry - failed to block all the nodes \n"); - vector_free( job_pool ); + block_node_exit( 0 ); hash_free( nodes ); } } } -#else -int main( int argc, char ** argv) { - return 0; -} -#endif diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/local_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/local_driver.h index e172626aae..dbfcdc245e 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/local_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/local_driver.h @@ -42,6 +42,7 @@ extern "C" { void local_driver_free__(void * __driver ); job_status_type local_driver_get_job_status(void * __driver , void * __job); void local_driver_free_job(void * __job); + void local_driver_init_option_list(stringlist_type * option_list); diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/lsf_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/lsf_driver.h index 5adf0c2b06..69f9fd7ac5 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/lsf_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/lsf_driver.h @@ -53,6 +53,9 @@ extern "C" { typedef struct lsf_driver_struct lsf_driver_type; typedef struct lsf_job_struct lsf_job_type; + void lsf_job_export_hostnames( const lsf_job_type * job , stringlist_type * hostlist); + void lsf_job_free(lsf_job_type * job); + long lsf_job_get_jobnr( const lsf_job_type * job ); void * lsf_driver_alloc( ); stringlist_type * lsf_driver_alloc_cmd(lsf_driver_type * driver , @@ -85,6 +88,9 @@ typedef struct lsf_job_struct lsf_job_type; bool lsf_driver_has_option( const void * __driver , const char * option_key); const void * lsf_driver_get_option( const void * __driver , const char * option_key); bool lsf_driver_set_option( void * __driver , const char * option_key , const void * value); + void lsf_driver_init_option_list(stringlist_type * option_list); + + UTIL_SAFE_CAST_HEADER( lsf_driver ); diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/queue_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/queue_driver.h index 06940673da..f99ab17254 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/queue_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/queue_driver.h @@ -121,7 +121,8 @@ extern "C" { typedef bool (set_option_ftype) (void *, const char*, const void *); typedef const void * (get_option_ftype) (const void *, const char *); typedef bool (has_option_ftype) (const void *, const char *); - + typedef void (init_option_list_ftype) (stringlist_type *); + queue_driver_type * queue_driver_alloc_RSH(const char * rsh_cmd, const hash_type * rsh_hostlist); queue_driver_type * queue_driver_alloc_LSF(const char * queue_name, const char * resource_request, const char * remote_lsf_server); @@ -133,11 +134,12 @@ extern "C" { void queue_driver_free_job(queue_driver_type * driver, void * job_data); void queue_driver_kill_job(queue_driver_type * driver, void * job_data); job_status_type queue_driver_get_status(queue_driver_type * driver, void * job_data); - + const char * queue_driver_get_name(const queue_driver_type * driver); bool queue_driver_set_option(queue_driver_type * driver, const char * option_key, const void * value); const void * queue_driver_get_option(queue_driver_type * driver, const char * option_key); + void queue_driver_init_option_list(queue_driver_type * driver, stringlist_type * option_list); void queue_driver_free(queue_driver_type * driver); void queue_driver_free__(void * driver); diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/rsh_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/rsh_driver.h index ad7909ae13..7e41c4e768 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/rsh_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/rsh_driver.h @@ -49,6 +49,7 @@ extern "C" { bool rsh_driver_set_option( void * __driver, const char * option_key , const void * value ); const void * rsh_driver_get_option( const void * __driver , const char * option_key); + void rsh_driver_init_option_list(stringlist_type * option_list); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h index 5f3db45f65..5df778021f 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h @@ -65,9 +65,10 @@ extern "C" { const void * torque_driver_get_option(const void * __driver, const char * option_key); bool torque_driver_set_option(void * __driver, const char * option_key, const void * value); + void torque_driver_init_option_list(stringlist_type * option_list); void torque_job_create_submit_script(const char * run_path, const char * submit_cmd, int argc, const char ** job_argv); - + UTIL_SAFE_CAST_HEADER(torque_driver); #ifdef __cplusplus diff --git a/ThirdParty/Ert/devel/libjob_queue/src/CMakeLists.txt b/ThirdParty/Ert/devel/libjob_queue/src/CMakeLists.txt index 95984eef9e..85dafa3738 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libjob_queue/src/CMakeLists.txt @@ -2,6 +2,7 @@ set(source_files forward_model.c queue_driver.c job_queue.c local_driver.c rsh_driver.c torque_driver.c ext_job.c ext_joblist.c workflow_job.c workflow.c workflow_joblist.c) set(header_files job_queue.h queue_driver.h local_driver.h rsh_driver.h torque_driver.h ext_job.h ext_joblist.h forward_model.h workflow_job.h workflow.h workflow_joblist.h) +set_property(SOURCE rsh_driver.c PROPERTY COMPILE_FLAGS "-Wno-error") if (USE_LSF) list( APPEND source_files lsf_driver.c) @@ -16,6 +17,9 @@ endif() add_library( job_queue SHARED ${source_files} ) set_target_properties( job_queue PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( job_queue config ert_util ) +if (USE_RUNPATH) + add_runpath( job_queue ) +endif() if (NEED_LIBDL) target_link_libraries( job_queue dl ) diff --git a/ThirdParty/Ert/devel/libjob_queue/src/job_queue.c b/ThirdParty/Ert/devel/libjob_queue/src/job_queue.c index a2bce78ed5..97fbe5acc9 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/job_queue.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/job_queue.c @@ -1344,6 +1344,11 @@ void job_queue_run_jobs(job_queue_type * queue , int num_total_run, bool verbose thread_pool_join( queue->work_pool ); thread_pool_free( queue->work_pool ); } + /* + Observe that after the job_queue_finalize() function has been + called the queue object should not be queried on any longer; that + will silently give horribly wrong results. + */ job_queue_finalize( queue ); pthread_mutex_unlock( &queue->run_mutex ); } diff --git a/ThirdParty/Ert/devel/libjob_queue/src/local_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/local_driver.c index d12872dda9..2d57a2c914 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/local_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/local_driver.c @@ -199,6 +199,10 @@ bool local_driver_set_option( void * __driver , const char * option_key , const return false; } +void local_driver_init_option_list(stringlist_type * option_list) { + //No options specific for local driver; do nothing +} + #undef LOCAL_DRIVER_ID #undef LOCAL_JOB_ID diff --git a/ThirdParty/Ert/devel/libjob_queue/src/lsb.c b/ThirdParty/Ert/devel/libjob_queue/src/lsb.c index 13dadd89bc..6702eeaa3e 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/lsb.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/lsb.c @@ -153,7 +153,6 @@ int lsb_initialize( const lsb_type * lsb) { directory containing LSF configuration information, the whole thing will crash and burn if this is not properly set. */ - printf("Calling initialize ... \n"); if ( lsb->lsb_init(NULL) != 0 ) { fprintf(stderr,"LSF_ENVDIR: "); if (getenv("LSF_ENVDIR") != NULL) diff --git a/ThirdParty/Ert/devel/libjob_queue/src/lsf_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/lsf_driver.c index 642ececf25..36265836e6 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/lsf_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/lsf_driver.c @@ -181,6 +181,20 @@ void lsf_job_free(lsf_job_type * job) { } +void lsf_job_export_hostnames( const lsf_job_type * job , stringlist_type * hostlist) { + int host_nr; + + stringlist_clear( hostlist ); + for (host_nr = 0; host_nr < job->num_exec_host; host_nr++) + stringlist_append_copy( hostlist , job->exec_host[ host_nr ]); +} + + +long lsf_job_get_jobnr( const lsf_job_type * job ) { + return job->lsf_jobnr; +} + + static int lsf_job_parse_bsub_stdout(const lsf_driver_type * driver , const char * stdout_file) { int jobid = -1; FILE * stream = util_fopen(stdout_file , "r"); @@ -859,6 +873,16 @@ bool lsf_driver_has_option( const void * __driver , const char * option_key) { return false; } +void lsf_driver_init_option_list(stringlist_type * option_list) { + stringlist_append_ref(option_list, LSF_QUEUE); + stringlist_append_ref(option_list, LSF_RESOURCE); + stringlist_append_ref(option_list, LSF_SERVER); + stringlist_append_ref(option_list, LSF_RSH_CMD); + stringlist_append_ref(option_list, LSF_LOGIN_SHELL); + stringlist_append_ref(option_list, LSF_BSUB_CMD); + stringlist_append_ref(option_list, LSF_BJOBS_CMD); + stringlist_append_ref(option_list, LSF_BKILL_CMD); +} diff --git a/ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c index 48f6781ce4..be68d3f475 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c @@ -69,6 +69,7 @@ struct queue_driver_struct { set_option_ftype * set_option; get_option_ftype * get_option; has_option_ftype * has_option; + init_option_list_ftype * init_options; void * data; /* Driver specific data - passed as first argument to the driver functions above. */ @@ -110,6 +111,7 @@ static queue_driver_type * queue_driver_alloc_empty() { driver->name = NULL; driver->data = NULL; driver->max_running_string = NULL; + driver->init_options = NULL; return driver; } @@ -139,6 +141,7 @@ queue_driver_type * queue_driver_alloc(job_driver_type type) { driver->get_option = lsf_driver_get_option; driver->has_option = lsf_driver_has_option; driver->name = util_alloc_string_copy("LSF"); + driver->init_options = lsf_driver_init_option_list; driver->data = lsf_driver_alloc(); break; case LOCAL_DRIVER: @@ -148,6 +151,7 @@ queue_driver_type * queue_driver_alloc(job_driver_type type) { driver->free_job = local_driver_free_job; driver->free_driver = local_driver_free__; driver->name = util_alloc_string_copy("local"); + driver->init_options = local_driver_init_option_list; driver->data = local_driver_alloc(); break; case RSH_DRIVER: @@ -159,6 +163,7 @@ queue_driver_type * queue_driver_alloc(job_driver_type type) { driver->set_option = rsh_driver_set_option; driver->get_option = rsh_driver_get_option; driver->name = util_alloc_string_copy("RSH"); + driver->init_options = rsh_driver_init_option_list; driver->data = rsh_driver_alloc(); break; case TORQUE_DRIVER: @@ -170,10 +175,11 @@ queue_driver_type * queue_driver_alloc(job_driver_type type) { driver->set_option = torque_driver_set_option; driver->get_option = torque_driver_get_option; driver->name = util_alloc_string_copy("TORQUE"); + driver->init_options = torque_driver_init_option_list; driver->data = torque_driver_alloc(); break; default: - util_abort("%s: unrecognized driver type:%d \n", type); + util_abort("%s: unrecognized driver type:%d \n", __func__, type); } return driver; } @@ -276,6 +282,17 @@ const void * queue_driver_get_option(queue_driver_type * driver, const char * op /*****************************************************************/ +void queue_driver_init_option_list(queue_driver_type * driver, stringlist_type * option_list) { + //Add options common for all driver types + stringlist_append_ref(option_list, MAX_RUNNING); + + //Add options for the specific driver type + if (driver->init_options) + driver->init_options(option_list); + else + util_abort("%s: driver:%s does not support run time reading of options\n", __func__, driver->name); + } + queue_driver_type * queue_driver_alloc_LSF(const char * queue_name, const char * resource_request, const char * remote_lsf_server) { queue_driver_type * driver = queue_driver_alloc(LSF_DRIVER); diff --git a/ThirdParty/Ert/devel/libjob_queue/src/rsh_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/rsh_driver.c index 871466d6d8..ee916b8380 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/rsh_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/rsh_driver.c @@ -465,6 +465,12 @@ const void * rsh_driver_get_option( const void * __driver , const char * option_ } +void rsh_driver_init_option_list(stringlist_type * option_list) { + stringlist_append_ref(option_list, RSH_HOST); + stringlist_append_ref(option_list, RSH_HOSTLIST); + stringlist_append_ref(option_list, RSH_CMD); + stringlist_append_ref(option_list, RSH_CLEAR_HOSTLIST); +} #undef RSH_JOB_ID diff --git a/ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c index 19f01caec7..00bfafbf27 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c @@ -169,6 +169,16 @@ const void * torque_driver_get_option(const void * __driver, const char * option } } +void torque_driver_init_option_list(stringlist_type * option_list) { + stringlist_append_ref(option_list, TORQUE_QSUB_CMD); + stringlist_append_ref(option_list, TORQUE_QSTAT_CMD); + stringlist_append_ref(option_list, TORQUE_QDEL_CMD); + stringlist_append_ref(option_list, TORQUE_QUEUE); + stringlist_append_ref(option_list, TORQUE_NUM_CPUS_PER_NODE); + stringlist_append_ref(option_list, TORQUE_NUM_NODES); + stringlist_append_ref(option_list, TORQUE_KEEP_QSUB_OUTPUT); +} + torque_job_type * torque_job_alloc() { torque_job_type * job; job = util_malloc(sizeof * job); diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libjob_queue/tests/CMakeLists.txt index 53c960f96b..7612e1aec7 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libjob_queue/tests/CMakeLists.txt @@ -4,10 +4,10 @@ add_executable( "create file" create_file.c ) add_executable( job_workflow_test job_workflow_test.c ) -target_link_libraries( job_workflow_test job_queue ) -target_link_libraries( "create file" job_queue ) -target_link_libraries( job_loadOK job_queue ) -target_link_libraries( job_loadFail job_queue ) +target_link_libraries( job_workflow_test job_queue test_util ) +target_link_libraries( "create file" job_queue test_util ) +target_link_libraries( job_loadOK job_queue test_util ) +target_link_libraries( job_loadFail job_queue test_util ) add_test( job_workflow_test ${EXECUTABLE_OUTPUT_PATH}/job_workflow_test ${EXECUTABLE_OUTPUT_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/data/internal_job) @@ -22,7 +22,7 @@ add_test( job_loadFail3 ${EXECUTABLE_OUTPUT_PATH}/job_loadFail ${CMAKE_CURRENT_S add_executable( job_queue_test job_queue_test.c ) -target_link_libraries( job_queue_test job_queue ) +target_link_libraries( job_queue_test job_queue test_util ) add_test( job_queue_test ${EXECUTABLE_OUTPUT_PATH}/job_queue_test ) @@ -37,16 +37,16 @@ set(LSF_SERVERS "LOCAL" CACHE STRING "List of LSF servers for testing") add_executable( job_lsf_test job_lsf_test.c ) -target_link_libraries( job_lsf_test job_queue util ) +target_link_libraries( job_lsf_test job_queue util test_util ) add_executable( job_lsf_submit_test job_lsf_submit_test.c ) -target_link_libraries( job_lsf_submit_test job_queue util ) +target_link_libraries( job_lsf_submit_test job_queue util test_util ) add_executable( job_program job_program.c ) if (HAVE_LSF_LIBRARY) add_executable( job_lsb job_lsb.c ) - target_link_libraries( job_lsb job_queue util ) + target_link_libraries( job_lsb job_queue util test_util ) add_test( job_lsb ${EXECUTABLE_OUTPUT_PATH}/job_lsb ) endif() @@ -58,11 +58,11 @@ if (LSF_SERVERS) endif() add_executable( job_torque_test job_torque_test.c ) -target_link_libraries( job_torque_test job_queue util ) +target_link_libraries( job_torque_test job_queue util test_util ) add_test( job_torque_test ${EXECUTABLE_OUTPUT_PATH}/job_torque_test ) add_executable( job_torque_submit_test job_torque_submit_test.c ) -target_link_libraries( job_torque_submit_test job_queue util ) +target_link_libraries( job_torque_submit_test job_queue util test_util ) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/qsub_emulators/ DESTINATION ${EXECUTABLE_OUTPUT_PATH}) add_test(NAME job_torque_submit_test WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/job_torque_submit_test dummyparam) set_property(TEST job_torque_submit_test PROPERTY ENVIRONMENT “setenv PATH ${EXECUTABLE_OUTPUT_PATH}:$PATH”) diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_lsf_submit_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_lsf_submit_test.c index 42ce02fcbe..f93160388a 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_lsf_submit_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_lsf_submit_test.c @@ -64,7 +64,6 @@ void test_submit(lsf_driver_type * driver , const char * server , const char * b free( run_path ); } - printf("Submit:%s OK \n",server); } diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_queue_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_queue_test.c index 41a2990987..d3de35cda7 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_queue_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_queue_test.c @@ -28,6 +28,7 @@ #include #include "ert/job_queue/torque_driver.h" +#include void job_queue_set_driver_(job_driver_type driver_type) { job_queue_type * queue = job_queue_alloc(10, "OK", "ERROR"); @@ -82,6 +83,75 @@ void set_option_valid_on_specific_driver_returns_true() { queue_driver_free(driver_torque); } +void get_driver_option_lists() { + //Torque driver option list + { + queue_driver_type * driver_torque = queue_driver_alloc(TORQUE_DRIVER); + stringlist_type * option_list = stringlist_alloc_new(); + queue_driver_init_option_list(driver_torque, option_list); + + test_assert_true(stringlist_contains(option_list, MAX_RUNNING)); + test_assert_true(stringlist_contains(option_list, TORQUE_QSUB_CMD)); + test_assert_true(stringlist_contains(option_list, TORQUE_QSTAT_CMD)); + test_assert_true(stringlist_contains(option_list, TORQUE_QDEL_CMD)); + test_assert_true(stringlist_contains(option_list, TORQUE_QUEUE)); + test_assert_true(stringlist_contains(option_list, TORQUE_NUM_CPUS_PER_NODE)); + test_assert_true(stringlist_contains(option_list, TORQUE_NUM_NODES)); + test_assert_true(stringlist_contains(option_list, TORQUE_KEEP_QSUB_OUTPUT)); + + stringlist_free(option_list); + queue_driver_free(driver_torque); + } + + //Local driver option list (only general queue_driver options) + { + queue_driver_type * driver_local = queue_driver_alloc(LOCAL_DRIVER); + stringlist_type * option_list = stringlist_alloc_new(); + queue_driver_init_option_list(driver_local, option_list); + + test_assert_true(stringlist_contains(option_list, MAX_RUNNING)); + + stringlist_free(option_list); + queue_driver_free(driver_local); + } + + //Lsf driver option list + { + queue_driver_type * driver_lsf = queue_driver_alloc(LSF_DRIVER); + stringlist_type * option_list = stringlist_alloc_new(); + queue_driver_init_option_list(driver_lsf, option_list); + + test_assert_true(stringlist_contains(option_list, MAX_RUNNING)); + test_assert_true(stringlist_contains(option_list, LSF_QUEUE)); + test_assert_true(stringlist_contains(option_list, LSF_RESOURCE)); + test_assert_true(stringlist_contains(option_list, LSF_SERVER)); + test_assert_true(stringlist_contains(option_list, LSF_RSH_CMD)); + test_assert_true(stringlist_contains(option_list, LSF_LOGIN_SHELL)); + test_assert_true(stringlist_contains(option_list, LSF_BSUB_CMD)); + test_assert_true(stringlist_contains(option_list, LSF_BJOBS_CMD)); + test_assert_true(stringlist_contains(option_list, LSF_BKILL_CMD)); + + stringlist_free(option_list); + queue_driver_free(driver_lsf); + } + + //Rsh driver option list + { + queue_driver_type * driver_rsh = queue_driver_alloc(RSH_DRIVER); + stringlist_type * option_list = stringlist_alloc_new(); + queue_driver_init_option_list(driver_rsh, option_list); + + test_assert_true(stringlist_contains(option_list, MAX_RUNNING)); + test_assert_true(stringlist_contains(option_list, RSH_HOST)); + test_assert_true(stringlist_contains(option_list, RSH_HOSTLIST)); + test_assert_true(stringlist_contains(option_list, RSH_CMD)); + test_assert_true(stringlist_contains(option_list, RSH_CLEAR_HOSTLIST)); + + stringlist_free(option_list); + queue_driver_free(driver_rsh); + } +} + int main(int argc, char ** argv) { job_queue_set_driver_(LSF_DRIVER); job_queue_set_driver_(TORQUE_DRIVER); @@ -92,6 +162,7 @@ int main(int argc, char ** argv) { set_option_invalid_value_returns_false(); set_option_valid_on_specific_driver_returns_true(); - + get_driver_option_lists(); + exit(0); } diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c index 6bffdd3ca0..3f4ffe6aea 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -71,29 +72,36 @@ void getoption_nooptionsset_defaultoptionsreturned() { } void create_submit_script_script_according_to_input() { - char ** args = util_calloc(2, sizeof * args); - args[0] = "/tmp/jaja/"; - args[1] = "number2arg"; - char * script_filename = util_alloc_filename("/tmp/", "qsub_script", "sh"); - torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); - printf("Create submit script OK\n"); + test_work_area_type * work_area = test_work_area_alloc("job_torque_test" , true); + const char * script_filename = "qsub_script.sh"; - FILE* file_stream = util_fopen(script_filename, "r"); - bool at_eof = false; + { + char ** args = util_calloc(2, sizeof * args); + args[0] = "/tmp/jaja/"; + args[1] = "number2arg"; + torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); + free( args ); + } + + { + FILE* file_stream = util_fopen(script_filename, "r"); + bool at_eof = false; + + char * line = util_fscanf_alloc_line(file_stream, &at_eof); + test_assert_string_equal("#!/bin/sh", line); + free(line); - char * line = util_fscanf_alloc_line(file_stream, &at_eof); - test_assert_string_equal("#!/bin/sh", line); - free(line); + line = util_fscanf_alloc_line(file_stream, &at_eof); + test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line); + free(line); - line = util_fscanf_alloc_line(file_stream, &at_eof); - test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line); - free(line); + line = util_fscanf_alloc_line(file_stream, &at_eof); + free(line); + test_assert_true(at_eof); - line = util_fscanf_alloc_line(file_stream, &at_eof); - free(line); - test_assert_true(at_eof); - - fclose(file_stream); + fclose(file_stream); + } + test_work_area_free( work_area ); } diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_workflow_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_workflow_test.c index 7ee25a005a..00e9bb5678 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_workflow_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_workflow_test.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -78,12 +79,11 @@ static void create_exjob( const char * workflow , const char * bin_path) int main( int argc , char ** argv) { -#ifdef ERT_LINUX - const char * exjob_file = "/tmp/xflow"; -#endif - + const char * exjob_file = "job"; const char * bin_path = argv[1]; const char * internal_workflow = argv[2]; + test_work_area_type * work_area = test_work_area_alloc( "job_workflow_test" , true); + signal(SIGSEGV , util_abort_signal); create_exjob( exjob_file , bin_path ); { @@ -113,8 +113,8 @@ int main( int argc , char ** argv) { { - const char * workflow_file = "/tmp/workflow"; - const char * tmp_file = "/tmp/fileX"; + const char * workflow_file = "workflow"; + const char * tmp_file = "fileX"; workflow_type * workflow; create_workflow( workflow_file , tmp_file , int_value ); @@ -161,8 +161,8 @@ int main( int argc , char ** argv) { } { workflow_joblist_type * joblist = workflow_joblist_alloc(); - const char * workflow_file = "/tmp/workflow"; - const char * tmp_file = "/tmp/fileX"; + const char * workflow_file = "workflow"; + const char * tmp_file = "fileX"; int read_value; int int_value = 100; workflow_type * workflow; @@ -174,5 +174,6 @@ int main( int argc , char ** argv) { test_assert_false( workflow_run( workflow , &read_value , false , NULL) ); test_assert_int_equal( workflow_get_stack_size( workflow ) , 0 ); } + test_work_area_free( work_area ); exit(0); } diff --git a/ThirdParty/Ert/devel/libplot/src/CMakeLists.txt b/ThirdParty/Ert/devel/libplot/src/CMakeLists.txt index cfa0e164a5..993fe20327 100644 --- a/ThirdParty/Ert/devel/libplot/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libplot/src/CMakeLists.txt @@ -6,6 +6,9 @@ add_library( plot ${LIBRARY_TYPE} ${source_files} ) target_link_libraries( plot ert_util ${PLPLOT_LIBRARY} ) set_target_properties( plot PROPERTIES VERSION 1.0 SOVERSION 1.0 ) +if (USE_RUNPATH) + add_runpath( plot ) +endif() #----------------------------------------------------------------- if (INSTALL_ERT) install(TARGETS plot DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ThirdParty/Ert/devel/librms/applications/CMakeLists.txt b/ThirdParty/Ert/devel/librms/applications/CMakeLists.txt index 8ed1bafa79..4f360d8506 100644 --- a/ThirdParty/Ert/devel/librms/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/librms/applications/CMakeLists.txt @@ -8,6 +8,10 @@ add_executable( tag_list tag_list.c ) set(program_list rms_extract rms_setname rms_stat rms_test tag_list) foreach(prog ${program_list}) target_link_libraries( ${prog} rms ecl util ) + if (USE_RUNPATH) + add_runpath( ${prog} ) + endif() + #----------------------------------------------------------------- if (RMS_INSTALL_PREFIX) set (destination ${RMS_INSTALL_PREFIX}/bin) diff --git a/ThirdParty/Ert/devel/librms/src/CMakeLists.txt b/ThirdParty/Ert/devel/librms/src/CMakeLists.txt index bba790f2d5..fd90066a09 100644 --- a/ThirdParty/Ert/devel/librms/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/librms/src/CMakeLists.txt @@ -3,6 +3,9 @@ set( header_files rms_file.h rms_util.h rms_tag.h rms_type.h rms_tagkey.h rms_st add_library( rms ${LIBRARY_TYPE} ${source_files} ) set_target_properties( rms PROPERTIES VERSION 1.0 SOVERSION 1.0 ) +if (USE_RUNPATH) + add_runpath( rms ) +endif() #----------------------------------------------------------------- if (INSTALL_ERT) diff --git a/ThirdParty/Ert/devel/librms/src/rms_file.c b/ThirdParty/Ert/devel/librms/src/rms_file.c index b973b36761..ef0461a24f 100644 --- a/ThirdParty/Ert/devel/librms/src/rms_file.c +++ b/ThirdParty/Ert/devel/librms/src/rms_file.c @@ -268,8 +268,8 @@ rms_tag_type * rms_file_fread_alloc_tag(rms_file_type * rms_file , const char *t bool cont = true; bool tag_found = false; - long int start_pos = ftell(rms_file->stream); - fseek(rms_file->stream , 0 , SEEK_SET); + long int start_pos = util_ftell(rms_file->stream); + util_fseek(rms_file->stream , 0 , SEEK_SET); rms_file_init_fread(rms_file); while (cont) { bool eof_tag; @@ -283,7 +283,7 @@ rms_tag_type * rms_file_fread_alloc_tag(rms_file_type * rms_file , const char *t cont = false; } if (tag == NULL) { - fseek(rms_file->stream , start_pos , SEEK_SET); + util_fseek(rms_file->stream , start_pos , SEEK_SET); fprintf(stderr,"%s: could not find tag: \"%s\" (with %s=%s) in file:%s - aborting.\n",__func__ , tagname , keyname , keyvalue , rms_file->filename); abort(); } @@ -457,15 +457,15 @@ void rms_file_2eclipse(const char * rms_file , const char * ecl_path, bool ecl_f bool rms_file_is_roff(FILE * stream) { const int len = strlen(rms_comment1); char *header = malloc(strlen(rms_comment1) + 1); - const long int current_pos = ftell(stream); + const long int current_pos = util_ftell(stream); bool roff_file = false; - fseek(stream , 1 + 1 + 8 , SEEK_CUR); /* Skipping #roff-bin#0# WILL Fail with formatted files */ + util_fseek(stream , 1 + 1 + 8 , SEEK_CUR); /* Skipping #roff-bin#0# WILL Fail with formatted files */ rms_util_fread_string(header , len+1 , stream); if (strncmp(rms_comment1 , header , len) == 0) roff_file = true; - fseek(stream , current_pos , SEEK_SET); + util_fseek(stream , current_pos , SEEK_SET); free(header); return roff_file; } @@ -481,7 +481,7 @@ void old_rms_roff_load(const char *filename , const char *param_name , float *pa int size; FILE *stream = fopen(filename , "r"); - fseek(stream , offset , SEEK_SET); + util_fseek(stream , offset , SEEK_SET); fread(&size , 1 , sizeof size , stream); n_read = fread(param , sizeof *param , size , stream); diff --git a/ThirdParty/Ert/devel/librms/src/rms_tag.c b/ThirdParty/Ert/devel/librms/src/rms_tag.c index 4384f4055a..f21235f726 100644 --- a/ThirdParty/Ert/devel/librms/src/rms_tag.c +++ b/ThirdParty/Ert/devel/librms/src/rms_tag.c @@ -187,7 +187,7 @@ static void rms_tag_add_tagkey(const rms_tag_type *tag , const rms_tagkey_type * static bool rms_tag_at_endtag(FILE *stream) { - const int init_pos = ftell(stream); + const int init_pos = util_ftell(stream); bool at_endtag; char tag[7]; if (rms_util_fread_string(tag , 7 , stream)) { @@ -199,7 +199,7 @@ static bool rms_tag_at_endtag(FILE *stream) { at_endtag = false; if (!at_endtag) - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return at_endtag; } diff --git a/ThirdParty/Ert/devel/librms/src/rms_tagkey.c b/ThirdParty/Ert/devel/librms/src/rms_tagkey.c index c9014cb1ed..3e0fb2ccd1 100644 --- a/ThirdParty/Ert/devel/librms/src/rms_tagkey.c +++ b/ThirdParty/Ert/devel/librms/src/rms_tagkey.c @@ -420,12 +420,12 @@ static void rms_tagkey_set_data_size(rms_tagkey_type *tagkey , FILE *stream , in if (tagkey->rms_type == rms_char_type) { if (stream != NULL) { - const long int init_pos = ftell(stream); + const long int init_pos = util_ftell(stream); int i; for (i=0; i < tagkey->size; i++) rms_util_fskip_string(stream); - tagkey->data_size = ftell(stream) - init_pos; - fseek(stream , init_pos , SEEK_SET); + tagkey->data_size = util_ftell(stream) - init_pos; + util_fseek(stream , init_pos , SEEK_SET); } else tagkey->data_size = strlen + 1; } else diff --git a/ThirdParty/Ert/devel/librms/src/rms_util.c b/ThirdParty/Ert/devel/librms/src/rms_util.c index 59b92bbeaf..16dd6533bd 100644 --- a/ThirdParty/Ert/devel/librms/src/rms_util.c +++ b/ThirdParty/Ert/devel/librms/src/rms_util.c @@ -101,11 +101,11 @@ void rms_util_fskip_string(FILE *stream) { int rms_util_fread_strlen(FILE *stream) { - long int init_pos = ftell(stream); + long int init_pos = util_ftell(stream); int len; rms_util_fskip_string(stream); - len = ftell(stream) - init_pos; - fseek(stream , init_pos , SEEK_SET); + len = util_ftell(stream) - init_pos; + util_fseek(stream , init_pos , SEEK_SET); return len; } @@ -116,7 +116,7 @@ int rms_util_fread_strlen(FILE *stream) { bool rms_util_fread_string(char *string , int max_length , FILE *stream) { bool read_ok = true; bool cont = true; - long int init_pos = ftell(stream); + long int init_pos = util_ftell(stream); int pos = 0; while (cont) { fread(&string[pos] , sizeof *string , 1 , stream); @@ -128,7 +128,7 @@ bool rms_util_fread_string(char *string , int max_length , FILE *stream) { if (max_length > 0) { if (pos == max_length) { read_ok = false; - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); cont = false; } } diff --git a/ThirdParty/Ert/devel/libsched/CMakeLists.txt b/ThirdParty/Ert/devel/libsched/CMakeLists.txt index c5e65c48a3..3edab07684 100644 --- a/ThirdParty/Ert/devel/libsched/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libsched/CMakeLists.txt @@ -3,6 +3,6 @@ if (BUILD_APPLICATONS) add_subdirectory( applications ) endif() -#if (BUILD_TESTS) -# add_subdirectory( tests ) -#endif() +if (BUILD_TESTS) + add_subdirectory( tests ) +endif() diff --git a/ThirdParty/Ert/devel/libsched/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libsched/applications/CMakeLists.txt index 3416f7625b..83f41113b9 100644 --- a/ThirdParty/Ert/devel/libsched/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libsched/applications/CMakeLists.txt @@ -10,6 +10,9 @@ add_executable( sched_summary.x sched_summary.c ) set(program_list sched_summary.x) foreach(prog ${program_list}) target_link_libraries( ${prog} sched ecl ert_util ) + if (USE_RUNPATH) + add_runpath( ${prog} ) + endif() #----------------------------------------------------------------- if (SCHED_INSTALL_PREFIX) set (destination ${SCHED_INSTALL_PREFIX}/bin) diff --git a/ThirdParty/Ert/devel/libsched/include/ert/sched/history.h b/ThirdParty/Ert/devel/libsched/include/ert/sched/history.h index f56376055d..efa10fec51 100644 --- a/ThirdParty/Ert/devel/libsched/include/ert/sched/history.h +++ b/ThirdParty/Ert/devel/libsched/include/ert/sched/history.h @@ -28,6 +28,7 @@ extern "C" { #include #include +#include #include @@ -66,6 +67,8 @@ typedef struct history_struct history_type; int history_get_restart_nr_from_days(const history_type *, double days); time_t history_get_time_t_from_restart_nr( const history_type * history , int restart_nr); int history_get_restart_nr_from_time_t( const history_type * history , time_t time); + + UTIL_IS_INSTANCE_HEADER( history ); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libsched/src/CMakeLists.txt b/ThirdParty/Ert/devel/libsched/src/CMakeLists.txt index ab88ff6800..60eb417cb4 100644 --- a/ThirdParty/Ert/devel/libsched/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libsched/src/CMakeLists.txt @@ -10,7 +10,9 @@ add_library( sched ${LIBRARY_TYPE} ${source_files} ) set_target_properties( sched PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( sched ert_util ecl) - +if (USE_RUNPATH) + add_runpath( sched ) +endif() #----------------------------------------------------------------- if (INSTALL_ERT) install(TARGETS sched DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ThirdParty/Ert/devel/libsched/src/history.c b/ThirdParty/Ert/devel/libsched/src/history.c index 5c3f155b18..49c7e1759e 100644 --- a/ThirdParty/Ert/devel/libsched/src/history.c +++ b/ThirdParty/Ert/devel/libsched/src/history.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -25,13 +26,17 @@ #include #include +#include #include #include #include +#define HISTORY_TYPE_ID 66143109 + struct history_struct{ + UTIL_TYPE_ID_DECLARATION; const ecl_sum_type * refcase; /* ecl_sum instance used when the data are taken from a summary instance. Observe that this is NOT owned by history instance.*/ const sched_file_type * sched_file; /* Not owned. */ sched_history_type * sched_history; @@ -73,13 +78,13 @@ const char * history_get_source_string( history_source_type history_source ) { } - - +UTIL_IS_INSTANCE_FUNCTION( history , HISTORY_TYPE_ID ) static history_type * history_alloc_empty( ) { history_type * history = util_malloc(sizeof * history); + UTIL_TYPE_ID_INIT( history , HISTORY_TYPE_ID ); history->refcase = NULL; history->sched_history = NULL; history->sched_file = NULL; @@ -155,9 +160,9 @@ bool history_init_ts( const history_type * history , const char * summary_key , double_vector_reset( value ); bool_vector_reset( valid ); bool_vector_set_default( valid , false); - + if (history->source == SCHEDULE) { - + for (int tstep = 0; tstep <= sched_history_get_last_history(history->sched_history); tstep++) { if (sched_history_open( history->sched_history , summary_key , tstep)) { bool_vector_iset( valid , tstep , true ); @@ -174,25 +179,36 @@ bool history_init_ts( const history_type * history , const char * summary_key , /* Must create a new key with 'H' for historical values. */ const ecl_smspec_type * smspec = ecl_sum_get_smspec( history->refcase ); const char * join_string = ecl_smspec_get_join_string( smspec ); - - local_key = util_alloc_sprintf( "%sH%s%s" , ecl_sum_get_keyword( history->refcase , summary_key ) , join_string , ecl_sum_get_wgname( history->refcase , summary_key )); + ecl_smspec_var_type var_type = ecl_smspec_identify_var_type( summary_key ); + + if ((var_type == ECL_SMSPEC_WELL_VAR) || (var_type == ECL_SMSPEC_GROUP_VAR)) + local_key = util_alloc_sprintf( "%sH%s%s" , + ecl_sum_get_keyword( history->refcase , summary_key ) , + join_string , + ecl_sum_get_wgname( history->refcase , summary_key )); + else if (var_type == ECL_SMSPEC_FIELD_VAR) + local_key = util_alloc_sprintf( "%sH" , ecl_sum_get_keyword( history->refcase , summary_key )); + else + local_key = NULL; // If we try to get historical values of e.g. Region quantities it will fail. } else local_key = (char *) summary_key; - if (ecl_sum_has_general_var( history->refcase , local_key )) { - for (int tstep = 0; tstep <= history_get_last_restart(history); tstep++) { - int time_index = ecl_sum_iget_report_end( history->refcase , tstep ); - if (time_index >= 0) { - double_vector_iset( value , tstep , ecl_sum_get_general_var( history->refcase , time_index , local_key )); - bool_vector_iset( valid , tstep , true ); - } else - bool_vector_iset( valid , tstep , false ); /* Did not have this report step */ + if (local_key) { + if (ecl_sum_has_general_var( history->refcase , local_key )) { + for (int tstep = 0; tstep <= history_get_last_restart(history); tstep++) { + int time_index = ecl_sum_iget_report_end( history->refcase , tstep ); + if (time_index >= 0) { + double_vector_iset( value , tstep , ecl_sum_get_general_var( history->refcase , time_index , local_key )); + bool_vector_iset( valid , tstep , true ); + } else + bool_vector_iset( valid , tstep , false ); /* Did not have this report step */ + } + initOK = true; } - initOK = true; + + if (history->source == REFCASE_HISTORY) + free( local_key ); } - - if (history->source == REFCASE_HISTORY) - free( local_key ); } return initOK; } diff --git a/ThirdParty/Ert/devel/libsched/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libsched/tests/CMakeLists.txt new file mode 100644 index 0000000000..66bac6124d --- /dev/null +++ b/ThirdParty/Ert/devel/libsched/tests/CMakeLists.txt @@ -0,0 +1,16 @@ +#add_executable( sched_load sched_load.c ) +#target_link_libraries( sched_load sched test_util ) +#add_test( sched_load ${EXECUTABLE_OUTPUT_PATH}/sched_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Heidrun/Schedule.sch ) + +#add_executable( sched_tokenize sched_tokenize.c ) +#target_link_libraries( sched_tokenize sched test_util ) +#add_test( sched_tokenize ${EXECUTABLE_OUTPUT_PATH}/sched_tokenize ${CMAKE_CURRENT_SOURCE_DIR}/test-data/token_test1 ) + +add_executable( sched_history_summary sched_history_summary.c ) +target_link_libraries( sched_history_summary sched test_util ) +add_test( sched_history_summary1 ${EXECUTABLE_OUTPUT_PATH}/sched_history_summary ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) +add_test( sched_history_summary2 ${EXECUTABLE_OUTPUT_PATH}/sched_history_summary ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE ) + +#set_property( TEST sched_load PROPERTY LABELS StatoilData) +set_property( TEST sched_history_summary1 PROPERTY LABELS StatoilData) +set_property( TEST sched_history_summary2 PROPERTY LABELS StatoilData) diff --git a/ThirdParty/Ert/devel/libsched/tests/sched_history_summary.c b/ThirdParty/Ert/devel/libsched/tests/sched_history_summary.c new file mode 100644 index 0000000000..6f94d38d36 --- /dev/null +++ b/ThirdParty/Ert/devel/libsched/tests/sched_history_summary.c @@ -0,0 +1,72 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'sched_history_summary.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 + + + +int main(int argc, char **argv) { + char * sum_case = argv[1]; + ecl_sum_type * refcase = ecl_sum_fread_alloc_case( sum_case , ":" ); + history_type * hist_h = history_alloc_from_refcase( refcase , true ); + history_type * hist_sim = history_alloc_from_refcase( refcase , false ); + + test_assert_true( history_is_instance( hist_h ) ); + test_assert_true( history_is_instance( hist_sim ) ); + test_assert_int_equal( history_get_last_restart( hist_sim ) , ecl_sum_get_last_report_step( refcase ) ); + test_assert_int_equal( history_get_last_restart( hist_h ) , ecl_sum_get_last_report_step( refcase ) ); + + { + double_vector_type * value_sim = double_vector_alloc(0 , 0); + double_vector_type * value_h = double_vector_alloc(0 , 0); + bool_vector_type * valid_sim = bool_vector_alloc( 0 , false ); + bool_vector_type * valid_h = bool_vector_alloc( 0 , false ); + + test_assert_true( history_init_ts( hist_sim , "FOPT" , value_sim , valid_sim )); + test_assert_true( history_init_ts( hist_h , "FOPT" , value_h , valid_h )); + { + int step; + for (step = 1; step < ecl_sum_get_last_report_step( refcase ); step++) { + test_assert_true( bool_vector_iget( valid_sim , step )); + test_assert_true( bool_vector_iget( valid_h , step )); + { + int time_index = ecl_sum_iget_report_end( refcase , step ); + test_assert_double_equal( ecl_sum_get_general_var( refcase , time_index , "FOPT" ) , double_vector_iget( value_sim , step )); + test_assert_double_equal( ecl_sum_get_general_var( refcase , time_index , "FOPTH" ) , double_vector_iget( value_h , step )); + } + } + } + bool_vector_free( valid_sim ); + bool_vector_free( valid_h ); + + double_vector_free( value_sim ); + double_vector_free( value_h ); + } + + + history_free( hist_h ); + history_free( hist_sim ); + ecl_sum_free( refcase ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/python/CMakeLists.txt b/ThirdParty/Ert/devel/python/CMakeLists.txt index eff179dba0..db21efb45b 100644 --- a/ThirdParty/Ert/devel/python/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/CMakeLists.txt @@ -1,3 +1,5 @@ set(PYTHON_INSTALL_PREFIX "python") -add_subdirectory( test ) +if (BUILD_TESTS) + add_subdirectory( test ) +endif() add_subdirectory( python ) diff --git a/ThirdParty/Ert/devel/python/ert/config/config_enums.py b/ThirdParty/Ert/devel/python/ert/config/config_enums.py deleted file mode 100644 index 199c16dfd0..0000000000 --- a/ThirdParty/Ert/devel/python/ert/config/config_enums.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'config.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 libconfig -from ert.cwrap.cenum import create_enum - - -# config_item_types from config_schema_item.h -create_enum( libconfig.lib , "config_schema_item_type_enum_iget" , "config_types_enum" , globals()) - -# config_item_types from config_schema_item.h -create_enum( libconfig.lib , "config_schema_item_unrecognized_enum_iget" , "config_unrecognized_enum" , name_space = globals()) diff --git a/ThirdParty/Ert/devel/python/ert/config/config_parser.py b/ThirdParty/Ert/devel/python/ert/config/config_parser.py deleted file mode 100644 index d3a7477b93..0000000000 --- a/ThirdParty/Ert/devel/python/ert/config/config_parser.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'config_parser.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 ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from config_enums import * - -class ConfigParser(CClass): - - def __init__(self): - c_ptr = cfunc.alloc() - self.init_cobj( c_ptr , cfunc.free ) - - - def parse(self , filename , comment_string = "--" , include_kw = "INCLUDE" , define_kw = None , unrecognized = CONFIG_UNRECOGNIZED_WARN , validate = True): - return cfunc.parse(self , filename , comment_string , include_kw , define_kw , unrecognized , validate) - - - def add(self , kw , required = False): - cfunc.add_schema_item( self , kw , required ) - - -################################################################# - -cwrapper = CWrapper( libconfig.lib ) -cwrapper.registerType( "config" , ConfigParser ) -cfunc = CWrapperNameSpace("config") -cfunc.alloc = cwrapper.prototype("c_void_p config_alloc()") -cfunc.free = cwrapper.prototype("void config_free( config )") -cfunc.parse = cwrapper.prototype("bool config_parse( config , char* , char* , char* , char*, int , bool)") -cfunc.add_schema_item = cwrapper.prototype("bool config_add_schema_item( config , char* , bool)") diff --git a/ThirdParty/Ert/devel/python/python/ert/config/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/config/CMakeLists.txt index 63bc5fa791..337282c11a 100644 --- a/ThirdParty/Ert/devel/python/python/ert/config/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/config/CMakeLists.txt @@ -1 +1,7 @@ -add_python_package("Python ert.config" ${PYTHON_INSTALL_PREFIX}/ert/config "config.py;__init__.py;libconfig.py;config_enums.py;config_parser.py" True) +set(PYTHON_SOURCES + __init__.py + config_enums.py + config_parser.py +) + +add_python_package("Python ert.config" ${PYTHON_INSTALL_PREFIX}/ert/config "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/config/__init__.py b/ThirdParty/Ert/devel/python/python/ert/config/__init__.py index e69de29bb2..302cb8031f 100644 --- a/ThirdParty/Ert/devel/python/python/ert/config/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/config/__init__.py @@ -0,0 +1,23 @@ +# Copyright (C) 2013 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. +from ert.cwrap import clib +import ert.util + +CONFIG_LIB = clib.ert_load("libconfig.so") + + +from .config_enums import ContentTypeEnum, UnrecognizedEnum +from .config_parser import ConfigParser , SchemaItem , ContentItem , ContentNode \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/config/config.py b/ThirdParty/Ert/devel/python/python/ert/config/config.py deleted file mode 100644 index cc5a0a1458..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/config/config.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'config.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 libconfig - -from config_enums import * -from config_parser import ConfigParser , SchemaItem , ContentItem , ContentNode - diff --git a/ThirdParty/Ert/devel/python/python/ert/config/config_enums.py b/ThirdParty/Ert/devel/python/python/ert/config/config_enums.py index da30d1cf9b..22279e6fa2 100644 --- a/ThirdParty/Ert/devel/python/python/ert/config/config_enums.py +++ b/ThirdParty/Ert/devel/python/python/ert/config/config_enums.py @@ -12,10 +12,11 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. -from ert.cwrap.cenum import create_enum -import libconfig +# for more details. -create_enum( libconfig.lib , "config_schema_item_type_enum_iget" , "content_type" , name_space = globals()) +from ert.cwrap import create_enum +from ert.config import CONFIG_LIB -create_enum( libconfig.lib , "config_schema_item_unrecognized_enum_iget" , "unrecognized" , name_space = globals()) +ContentTypeEnum = create_enum(CONFIG_LIB, "config_schema_item_type_enum_iget", "ContentTypeEnum") + +UnrecognizedEnum = create_enum(CONFIG_LIB, "config_schema_item_unrecognized_enum_iget", "UnrecognizedEnum") diff --git a/ThirdParty/Ert/devel/python/python/ert/config/config_parser.py b/ThirdParty/Ert/devel/python/python/ert/config/config_parser.py index 3b03978494..e60d45ab44 100644 --- a/ThirdParty/Ert/devel/python/python/ert/config/config_parser.py +++ b/ThirdParty/Ert/devel/python/python/ert/config/config_parser.py @@ -15,62 +15,58 @@ # for more details. import os.path -import libconfig -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -import config_enums + +from ert.config import UnrecognizedEnum, CONFIG_LIB +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace class SchemaItem(CClass): - - def __init__(self , keyword , required = False): - c_ptr = cfunc.schema_alloc( keyword , required ) - self.init_cref( c_ptr , cfunc.schema_free) + def __init__(self, keyword, required=False): + c_ptr = cfunc.schema_alloc(keyword, required) + self.init_cref(c_ptr, cfunc.schema_free) + - @classmethod - def wrap(cls , c_ptr , parent): - obj = object.__new__( cls ) - obj.init_cref( c_ptr , parent ) + def wrap(cls, c_ptr, parent): + obj = object.__new__(cls) + obj.init_cref(c_ptr, parent) return obj - def iget_type( self , index ): - return cfunc.schema_iget_type( self , index ) + def iget_type( self, index ): + return cfunc.schema_iget_type(self, index) - def iset_type( self , index , type ): - cfunc.schema_iset_type( self , index , type ) - - def set_argc_minmax(self , min , max): - cfunc.schema_set_argc_minmax( self , min , max ) + def iset_type( self, index, schema_type ): + cfunc.schema_iset_type(self, index, schema_type) + + def set_argc_minmax(self, minimum, maximum): + cfunc.schema_set_argc_minmax(self, minimum, maximum) #----------------------------------------------------------------- class ContentItem(CClass): # Not possible to create new python instances of this class - + @classmethod - def wrap(cls , c_ptr , parent): - obj = object.__new__( cls ) - obj.init_cref( c_ptr , parent ) + def wrap(cls, c_ptr, parent): + obj = object.__new__(cls) + obj.init_cref(c_ptr, parent) return obj def __len__(self): - return cfunc.content_size( self ) - + return cfunc.content_size(self) - def __getitem__(self , index): - if isinstance(index , int): - if index >= 0 and index < self.__len__(): - c_ptr = cfunc.iget_content_node( self , index ) - return ContentNode.wrap( c_ptr , self ) + + def __getitem__(self, index): + if isinstance(index, int): + if (index >= 0) and (index < self.__len__()): + c_ptr = cfunc.iget_content_node(self, index) + return ContentNode.wrap(c_ptr, self) else: raise IndexError else: raise ValueError("[] operator must have integer index") - - #----------------------------------------------------------------- @@ -79,87 +75,86 @@ class ContentItem(CClass): class ContentNode(CClass): # Not possible to create new python instances of this class - - @classmethod - def wrap(cls , c_ptr , parent): - obj = object.__new__( cls ) - obj.init_cref( c_ptr , parent ) - return obj - - def __len__(self): - return cfunc.content_node_size( self ) - def __getitem__(self , index): - if isinstance(index , int): - if index >= 0 and index < self.__len__(): - return cfunc.content_node_iget( self , index ) + @classmethod + def wrap(cls, c_ptr, parent): + obj = object.__new__(cls) + obj.init_cref(c_ptr, parent) + return obj + + def __len__(self): + return cfunc.content_node_size(self) + + def __getitem__(self, index): + if isinstance(index, int): + if (index >= 0) and (index < self.__len__()): + return cfunc.content_node_iget(self, index) else: raise IndexError else: raise ValueError("[] operator must have integer index") - def content(self , sep = " "): - return cfunc.content_full_string(self , sep) - + def content(self, sep=" "): + return cfunc.content_full_string(self, sep) #----------------------------------------------------------------- class ConfigParser(CClass): - def __init__(self): c_ptr = cfunc.config_alloc() - self.init_cobj(c_ptr , cfunc.config_free ) + self.init_cobj(c_ptr, cfunc.config_free) - - def add(self , keyword , required = False): - c_ptr = cfunc.add( self , keyword , required ) - schema_item = SchemaItem.wrap(c_ptr , self) + + def add(self, keyword, required=False): + c_ptr = cfunc.add(self, keyword, required) + schema_item = SchemaItem.wrap(c_ptr, self) return schema_item - - - def parse( self , config_file , comment_string = "--" , include_kw = "INCLUDE" , define_kw = "DEFINE" , unrecognized = config_enums.unrecognized.CONFIG_UNRECOGNIZED_WARN , validate = True): - if os.path.exists( config_file ): - return cfunc.parse( self , config_file , comment_string , include_kw , define_kw , unrecognized , validate ) + + + def parse( self, config_file, comment_string="--", include_kw="INCLUDE", define_kw="DEFINE", + unrecognized=UnrecognizedEnum.CONFIG_UNRECOGNIZED_WARN, validate=True): + if os.path.exists(config_file): + return cfunc.parse(self, config_file, comment_string, include_kw, define_kw, unrecognized, validate) else: raise IOError("File: %s does not exists") - def __getitem__(self , keyword): - if cfunc.has_content(self , keyword): - c_ptr = cfunc.get_content(self , keyword ) - return ContentItem.wrap( c_ptr , self ) + def __getitem__(self, keyword): + if cfunc.has_content(self, keyword): + c_ptr = cfunc.get_content(self, keyword) + return ContentItem.wrap(c_ptr, self) else: return None #----------------------------------------------------------------- - -cwrapper = CWrapper( libconfig.lib ) -cwrapper.registerType( "config_parser" , ConfigParser ) -cwrapper.registerType( "schema_item" , SchemaItem ) -cwrapper.registerType( "content_item" , ContentItem ) -cwrapper.registerType( "content_node" , ContentNode ) +cwrapper = CWrapper(CONFIG_LIB) +cwrapper.registerType("config_parser", ConfigParser) +cwrapper.registerType("schema_item", SchemaItem) +cwrapper.registerType("content_item", ContentItem) +cwrapper.registerType("content_node", ContentNode) cfunc = CWrapperNameSpace("config") -cfunc.add = cwrapper.prototype("c_void_p config_add_schema_item( config_parser , char* , bool)") +cfunc.add = cwrapper.prototype("c_void_p config_add_schema_item( config_parser , char* , bool)") cfunc.config_alloc = cwrapper.prototype("c_void_p config_alloc( )") -cfunc.config_free = cwrapper.prototype("void config_free( config_parser )") -cfunc.parse = cwrapper.prototype("bool config_parse( config_parser , char* , char* , char* , char* , int , bool )") -cfunc.has_content = cwrapper.prototype("bool config_has_content_item( config_parser , char*) ") -cfunc.get_content = cwrapper.prototype("c_void_p config_get_content_item( config_parser , char*) ") +cfunc.config_free = cwrapper.prototype("void config_free( config_parser )") +cfunc.parse = cwrapper.prototype("bool config_parse( config_parser , char* , char* , char* , char* , int , bool )") +cfunc.has_content = cwrapper.prototype("bool config_has_content_item( config_parser , char*) ") +cfunc.get_content = cwrapper.prototype("c_void_p config_get_content_item( config_parser , char*) ") -cfunc.schema_alloc = cwrapper.prototype("c_void_p config_schema_item_alloc( char* , bool )") -cfunc.schema_free = cwrapper.prototype("void config_schema_item_free( schema_item )") -cfunc.schema_iget_type = cwrapper.prototype("int config_schema_item_iget_type( schema_item ,int)") -cfunc.schema_iset_type = cwrapper.prototype("void config_schema_item_iset_type( schema_item , int , int)") -cfunc.schema_set_argc_minmax = cwrapper.prototype("void config_schema_item_set_argc_minmax( schema_item , int , int)") +cfunc.schema_alloc = cwrapper.prototype("c_void_p config_schema_item_alloc( char* , bool )") +cfunc.schema_free = cwrapper.prototype("void config_schema_item_free( schema_item )") +cfunc.schema_iget_type = cwrapper.prototype("int config_schema_item_iget_type( schema_item ,int)") +cfunc.schema_iset_type = cwrapper.prototype("void config_schema_item_iset_type( schema_item , int , int)") +cfunc.schema_set_argc_minmax = cwrapper.prototype("void config_schema_item_set_argc_minmax( schema_item , int , int)") -cfunc.content_size = cwrapper.prototype("int config_content_item_get_size( content_item )") -cfunc.iget_content_node = cwrapper.prototype("int config_content_item_iget_node( content_item , int)") -cfunc.content_node_iget = cwrapper.prototype("char* config_content_node_iget( content_node , int)") -cfunc.content_node_size = cwrapper.prototype("int config_content_node_get_size( content_node )") +cfunc.content_size = cwrapper.prototype("int config_content_item_get_size( content_item )") +cfunc.iget_content_node = cwrapper.prototype("int config_content_item_iget_node( content_item , int)") +cfunc.content_node_iget = cwrapper.prototype("char* config_content_node_iget( content_node , int)") +cfunc.content_node_size = cwrapper.prototype("int config_content_node_get_size( content_node )") cfunc.content_full_string = cwrapper.prototype("char* config_content_node_get_full_string( content_node , char* )") + diff --git a/ThirdParty/Ert/devel/python/python/ert/config/libconfig.py b/ThirdParty/Ert/devel/python/python/ert/config/libconfig.py deleted file mode 100644 index ed57ae0943..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/config/libconfig.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libconfig.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 ert.cwrap.clib as clib -lib = clib.ert_load("libconfig.so") - diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/cwrap/CMakeLists.txt index 38297e14f2..e05fd016d3 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/CMakeLists.txt @@ -1 +1,10 @@ -add_python_package("Python ert.cwrap" ${PYTHON_INSTALL_PREFIX}/ert/cwrap "cclass.py;cenum.py;cfile.py;clib.py;cwrap.py;__init__.py" True) +set(PYTHON_SOURCES + __init__.py + cclass.py + cenum.py + cfile.py + clib.py + cwrap.py +) + +add_python_package("Python ert.cwrap" ${PYTHON_INSTALL_PREFIX}/ert/cwrap "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/__init__.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/__init__.py index be661504b2..062953444e 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/__init__.py @@ -39,3 +39,8 @@ the process of interacting with a C library: FILE pointer. """ +from .cclass import CClass +from .cenum import create_enum +from .cfile import CFILE +from .clib import load, ert_lib_path, ert_load +from .cwrap import CWrapper, CWrapperNameSpace \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/cclass.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/cclass.py index b6543c67b2..419b11ddf8 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/cclass.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/cclass.py @@ -97,6 +97,19 @@ class CClass(object): else: return ctypes.c_void_p( obj.c_ptr ) + @classmethod + def asPythonObject( cls , c_ptr, cfree): + assert cfree is not None + obj = cls( ) + obj.init_cobj( c_ptr , cfree) + return obj + + @classmethod + def asPythonReference( cls , c_ptr , parent ): + obj = cls( ) + obj.init_cref( c_ptr , parent ) + return obj + def init_cref(self , c_ptr , parent): self.c_ptr = c_ptr diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/cenum.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/cenum.py index e1ce2d9bec..926d12dbdd 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/cenum.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/cenum.py @@ -21,19 +21,20 @@ import ctypes import sys - -def make_enum(name , attrs): +def make_enum(name, attributes): class cls(object): pass cls.__name__ = name - for key in attrs.keys(): - setattr(cls , key , attrs[key]) + cls.enum_names = [] + for key in attributes.keys(): + setattr(cls, key, attributes[key]) + cls.enum_names.append(key) + return cls - -def create_enum( lib, func_name , enum_name , name_space = None): +def create_enum( lib, func_name, enum_name, name_space=None): """ Create and insert enum values as integer constants. @@ -98,27 +99,27 @@ def create_enum( lib, func_name , enum_name , name_space = None): """ try: - func = getattr( lib , func_name ) + func = getattr(lib, func_name) except AttributeError: - sys.exit("Could not find enum description function:%s - can not load enum:%s." % (func_name , enum_name)) + sys.exit("Could not find enum description function:%s - can not load enum:%s." % (func_name, enum_name)) func.restype = ctypes.c_char_p - func.argtypes = [ ctypes.c_int , ctypes.POINTER(ctypes.c_int) ] + func.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)] enum = {} index = 0 while True: value = ctypes.c_int() - name = func( index , ctypes.byref( value )) + name = func(index, ctypes.byref(value)) if name: if name_space: - name_space[ name ] = value.value - enum[ name ] = value.value + name_space[name] = value.value + enum[name] = value.value index += 1 else: break - enum = make_enum( enum_name , enum ) + enum = make_enum(enum_name, enum) if name_space: - name_space[ enum_name ] = enum + name_space[enum_name] = enum return enum diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/clib.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/clib.py index f772ab6b11..d15bd4ea83 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/clib.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/clib.py @@ -19,12 +19,11 @@ Convenience module for loading shared library. import ctypes import os -import os.path ert_lib_path = None -def __load__( lib_list , ert_prefix): +def __load__( lib_list, ert_prefix): """ Thin wrapper around the ctypes.CDLL function for loading shared library. @@ -44,17 +43,17 @@ def __load__( lib_list , ert_prefix): for lib in lib_list: try: if ert_prefix: - ert_lib = os.path.join( ert_lib_path , lib ) - dll = ctypes.CDLL( ert_lib , ctypes.RTLD_GLOBAL ) + ert_lib = os.path.join(ert_lib_path, lib) + dll = ctypes.CDLL(ert_lib, ctypes.RTLD_GLOBAL) else: - dll = ctypes.CDLL( lib , ctypes.RTLD_GLOBAL ) + dll = ctypes.CDLL(lib, ctypes.RTLD_GLOBAL) return dll - except Exception,exc: + except Exception, exc: error_list[lib] = exc error_msg = "\nFailed to load shared library:%s\n\ndlopen() error:\n" % lib_list[0] for lib in error_list.keys(): - error_msg += " %16s : %s\n" % (lib , error_list[lib]) + error_msg += " %16s : %s\n" % (lib, error_list[lib]) error_msg += "\n" LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH") @@ -70,7 +69,7 @@ variable. Your current LD_LIBRARY_PATH setting is: You might need to update this variable? """ % LD_LIBRARY_PATH - raise ImportError( error_msg ) + raise ImportError(error_msg) ################################################################# @@ -79,7 +78,7 @@ def load( *lib_list ): """ Will try to load shared library with normal load semantics. """ - return __load__(lib_list , False ) + return __load__(lib_list, False) def ert_load( *lib_list ): @@ -90,10 +89,10 @@ def ert_load( *lib_list ): """ if ert_lib_path: try: - return __load__(lib_list , True ) + return __load__(lib_list, True) except ImportError: # Try again - ignoring the ert_lib_path setting. - return load( *lib_list ) + return load(*lib_list) else: # The ert_lib_path variable has not been set; just try a normal load. - return load( *lib_list ) + return load(*lib_list) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/ecl/CMakeLists.txt index ebf1fd1faf..6a1cb0f0ac 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/CMakeLists.txt @@ -1,13 +1,35 @@ -add_python_package("Python ert.ecl" ${PYTHON_INSTALL_PREFIX}/ert/ecl "ecl_case.py;ecl_rft_cell.py;ecl_default.py;ecl_file.py;ecl_grav_calc.py;ecl_grav.py;ecl_grid.py;ecl_kw.py;ecl.py;ecl_queue.py;ecl_region.py;ecl_rft.py;ecl_subsidence.py;ecl_sum.py;ecl_util.py;fortio.py;__init__.py;libecl.py" True) +SET(PYTHON_SOURCES + __init__.py + ecl.py + ecl_case.py + ecl_default.py + ecl_file.py + ecl_grav.py + ecl_grav_calc.py + ecl_grid.py + ecl_kw.py + ecl_queue.py + ecl_region.py + ecl_rft.py + ecl_rft_cell.py + ecl_subsidence.py + ecl_sum.py + ecl_util.py + fortio.py + + ) + +add_python_package("Python ert.ecl" ${PYTHON_INSTALL_PREFIX}/ert/ecl "${PYTHON_SOURCES}" True) set( ECL_LOCAL_TARGET "" CACHE FILE "Name of optional external ecl_local module") if (EXISTS ${ECL_LOCAL_TARGET}) - if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") - EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E create_symlink "${ECL_LOCAL_TARGET}" "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") - message("-- Adding symlink ${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py -> ${ECL_LOCAL_TARGET}") - endif() + 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") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/__init__.py b/ThirdParty/Ert/devel/python/python/ert/ecl/__init__.py index 182104376a..a759125d37 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/__init__.py @@ -68,7 +68,36 @@ per module organization: all symbols in the package are available under the common namespace 'ecl'. - libecl: This module contains some low-level ctypes trickery to - actually load the shared library libecl.so. """ +from ert.cwrap import clib + +import ert.util +import ert.geo + + + +try: + clib.load("libgomp" , "libgomp.so.1") + openmp = True +except ImportError: + openmp = False + +ECL_LIB = clib.ert_load("libecl.so") + + +from .ecl_sum import EclSum #, EclSumVector, EclSumNode, EclSMSPECNode +from .ecl_util import EclFileEnum, EclFileFlagEnum, EclPhaseEnum, EclTypeEnum, EclUtil +from .ecl_default import EclDefault +from .ecl_rft_cell import EclPLTCell, EclRFTCell +from .ecl_rft import EclRFT, EclRFTFile +from .fortio import FortIO +from .ecl_kw import EclKW +from .ecl_file import EclFile +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_queue import EclQueue + +#from .ecl_queue import diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl.py index 7489956b6b..ec599ab6a8 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl.py @@ -31,26 +31,67 @@ following construction: It is not necessary to use the this module. See the doc/import.txt document in the ert-python source distribution for more details of module import and namespace resolution. -""" -import libecl -from ecl_kw import EclKW -from ecl_case import EclCase -from ecl_file import EclFile -from ecl_sum import EclSum -from ecl_rft import EclRFTFile , EclRFT -from ecl_rft_cell import EclRFTCell, EclPLTCell -from ecl_grid import EclGrid -from ecl_grav import EclGrav -from ecl_subsidence import EclSubsidence -from ecl_region import EclRegion -from fortio import FortIO -from ecl_queue import EclQueue -import ecl_util -from ecl_util import * - -import ecl_default +# """ +# import libecl +# from ecl_kw import EclKW +# from ecl_case import EclCase +# from ecl_file import EclFile +# from ecl_sum import EclSum +# from ecl_rft import EclRFTFile , EclRFT +# from ecl_rft_cell import EclRFTCell, EclPLTCell +# from ecl_grid import EclGrid +# from ecl_grav import EclGrav +# from ecl_subsidence import EclSubsidence +# from ecl_region import EclRegion +# from fortio import FortIO +# from ecl_queue import EclQueue +# import ecl_util +# from ecl_util import * +# +# import ecl_default +#from warnings import warn +#warn("The ecl namespace is deprecated! Please import ecl classes like this: import ert.ecl as ecl!") + +from .ecl_sum import EclSum #, EclSumVector, EclSumNode, EclSMSPECNode +from .ecl_rft_cell import EclPLTCell, EclRFTCell +from .ecl_rft import EclRFT, EclRFTFile +from .ecl_kw import EclKW +from .ecl_file import EclFile +from .fortio import FortIO +from .ecl_grid import EclGrid +from .ecl_region import EclRegion +from .ecl_case import EclCase +from .ecl_subsidence import EclSubsidence +from .ecl_grav_calc import deltag, phase_deltag +from .ecl_grav import EclGrav +from .ecl_queue import EclQueue + +from .ecl_default import default + + +#Legacy import support +class default_wrapper(object): + default = default + +ecl_default = default_wrapper() + + +from .ecl_util import EclFileEnum, EclFileFlagEnum, EclPhaseEnum, EclTypeEnum, EclUtil + +#make enum values globally available in ert.ecl.ecl +for enum in EclFileEnum.enum_names: + globals()[enum] = getattr(EclFileEnum, enum) + +for enum in EclFileFlagEnum.enum_names: + globals()[enum] = getattr(EclFileFlagEnum, enum) + +for enum in EclPhaseEnum.enum_names: + globals()[enum] = getattr(EclPhaseEnum, enum) + +for enum in EclTypeEnum.enum_names: + globals()[enum] = getattr(EclTypeEnum, enum) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_case.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_case.py index 5c29c919ad..e72d958d04 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_case.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_case.py @@ -19,14 +19,11 @@ Implements EclCase class which is a container for one ECLIPSE case. This module is a pure Python module which does not directly invoke any C based functions. """ - -import os.path -import ecl_sum -import ecl_grid -import ecl_rft -import ecl_default -import ecl_util +import os import warnings +from ert.ecl import EclRFTFile, EclGrid, EclSum, EclUtil + + class EclCase: """ @@ -95,7 +92,7 @@ class EclCase: at these times will lead to an instant 'crash and burn'. """ if not self.__sum: - self.__sum = ecl_sum.EclSum( self.case ) + self.__sum = EclSum( self.case ) return self.__sum @@ -105,7 +102,7 @@ class EclCase: An EclGrid instance for the current case; or None. """ if not self.__grid: - self.__grid = ecl_grid.EclGrid( self.case ) + self.__grid = EclGrid( self.case ) return self.__grid @@ -115,7 +112,7 @@ class EclCase: An EclRFTFile instance for the current case; or None. """ if not self.__rft: - self.__rft = ecl_rft.EclRFTFile( self.case ) + self.__rft = EclRFTFile( self.case ) return self.__rft @@ -191,21 +188,21 @@ class EclCase: """ import ert.job_queue.driver as queue_driver - num_cpu = ecl_util.get_num_cpu( self.datafile ) + num_cpu = EclUtil.get_num_cpu( self.datafile ) argv = [ecl_version , self.datafile , num_cpu] if ecl_cmd is None: ecl_cmd = ecl_default.default.ecl_cmd if driver_type is None: - driver_type = ecl_default.default.driver_type + driver_type = ECL_DEFAULT.driver_type if ecl_version is None: - ecl_version = ecl_default.default.ecl_version + ecl_version = ECL_DEFAULT.ecl_version if driver is None: if driver_options is None: - driver_options = ecl_default.default.driver_options[ driver_type ] + driver_options = ECL_DEFAULT.driver_options[ driver_type ] driver = queue_driver.Driver( driver_type , max_running = 0 , options = driver_options ) job = driver.submit( self.base , ecl_cmd , self.path , argv , blocking = blocking) return job diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_default.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_default.py index 7524be7dde..c30de32685 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_default.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_default.py @@ -1,6 +1,6 @@ # Copyright (C) 2011 Statoil ASA, Norway. # -# The file 'ecl_default.py' is part of ERT - Ensemble based Reservoir Tool. +# The file 'ecl_default.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 @@ -56,77 +56,119 @@ The ecl_local module can define the following variables: Depending on the computing environment some variables might be irrelevant; it is not necessary to set variables which will not be used. -""" +""" -class EclDefault: - __ecl_cmd = None - __ecl_version = None - __lsf_resource_request = None - __driver_type = None - __driver_options = None - def __init__(self): - pass +class EclDefault(object): + _initialized = False - def safe_get( self , attr ): - """ - Internal function to get class attributes. - - Will raise NotImplemtedError if the attribute has not been - loaded from the site spesific ecl_default module. - """ - if hasattr( self , "__%s" % attr): - value = getattr( self , "__%s" % attr) - return value - else: - raise NotImplementedError("The default attribute:%s has not been set - you must update/provide a ecl_local module." % attr) - - @property - def ecl_cmd( self ): + _ecl_cmd = None + _ecl_version = None + _lsf_resource_request = None + _driver_type = None + _driver_options = None + + @staticmethod + def _initializeEclDefaults(): + if not EclDefault._initialized: + try: + import ert.ecl.ecl_local as ecl_local + + if hasattr(ecl_local, "ecl_cmd"): + EclDefault._ecl_cmd = ecl_local.ecl_cmd + + if hasattr(ecl_local, "ecl_version"): + EclDefault._ecl_version = ecl_local.ecl_version + + if hasattr(ecl_local, "lsf_resource_request"): + EclDefault._lsf_resource_request = ecl_local.lsf_resource_request + + if hasattr(ecl_local, "driver_type"): + EclDefault._driver_type = ecl_local.driver_type + + if hasattr(ecl_local, "driver_options"): + EclDefault._driver_options = ecl_local.driver_options + + + except ImportError as e: + pass + + EclDefault._initialized = True + + + @staticmethod + def ecl_cmd(): """ The path to the executable used to invoke ECLIPSE. """ - return self.safe_get( "ecl_cmd" ) + EclDefault._initializeEclDefaults() + + if EclDefault._ecl_cmd is None: + EclDefault._attributeIsNotSet("ecl_cmd") + return EclDefault._ecl_cmd + + @staticmethod + def driver_type(): + EclDefault._initializeEclDefaults() + + if EclDefault._driver_type is None: + EclDefault._attributeIsNotSet("driver_type") + return EclDefault._driver_type + + @staticmethod + def driver_options(): + EclDefault._initializeEclDefaults() + + if EclDefault._driver_options is None: + EclDefault._attributeIsNotSet("driver_options") + return EclDefault._driver_options + + @staticmethod + def ecl_version(): + EclDefault._initializeEclDefaults() + + if EclDefault._ecl_version is None: + EclDefault._attributeIsNotSet("ecl_version") + return EclDefault._ecl_version + + @staticmethod + def lsf_resource_request(): + EclDefault._initializeEclDefaults() + + if EclDefault._lsf_resource_request is None: + EclDefault._attributeIsNotSet("lsf_resource_request") + return EclDefault._lsf_resource_request + + @staticmethod + def _attributeIsNotSet(attribute_name): + raise NotImplementedError("The default attribute:%s has not been set - you must update/provide a ecl_local module." % attribute_name) + + +#Legacy import support + +class default_wrapper(object): + #from warnings import warn + #warn("The ecl_default namespace is deprecated! Please retrieve ecl_default values from the class: ert.ecl.EclDefault!") @property - def driver_type( self ): - return self.safe_get( "driver_type" ) + def ecl_cmd(self): + return EclDefault.ecl_cmd() @property - def driver_options( self ): - return self.safe_get( "driver_options" ) + def driver_type(self): + return EclDefault.driver_type() @property - def ecl_version( self ): - return self.safe_get( "ecl_version" ) + def driver_options(self): + return EclDefault.driver_options() @property - def lsf_resource_request( self ): - return self.safe_get( "lsf_resource_request" ) + def ecl_version(self): + return EclDefault.ecl_version() + + @property + def lsf_resource_request(self): + return EclDefault.lsf_resource_request() -try: - import ecl_local - - if hasattr( ecl_local , "ecl_cmd"): - EclDefault.__ecl_cmd = ecl_local.ecl_cmd - - if hasattr( ecl_local , "ecl_version"): - EclDefault.__ecl_version = ecl_local.ecl_version - - if hasattr( ecl_local , "lsf_resource_request"): - EclDefault.__lsf_resource_request = ecl_local.lsf_resource_request - - if hasattr( ecl_local , "driver_type"): - EclDefault.__driver_type = ecl_local.driver_type - - if hasattr( ecl_local , "driver_options"): - EclDefault.__driver_options = ecl_local.driver_options - - -except ImportError: - pass - - -default = EclDefault() - +default = default_wrapper() \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_file.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_file.py index 37ab3eed4b..fd299f580e 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_file.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_file.py @@ -35,19 +35,13 @@ 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 os.path -import datetime -import ctypes -import types -import libecl import re +import types +import datetime +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import EclKW, ECL_LIB +from ert.util import ctime -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ecl_kw import EclKW -from ert.util.ctime import ctime -from ert.util.stringlist import StringList class EclFile(CClass): @@ -73,7 +67,7 @@ class EclFile(CClass): if dtime: OK = cfunc.restart_block_time( obj , ctime( dtime )) - elif not report_step == None: + elif not report_step is None: OK = cfunc.restart_block_step( obj , report_step ) else: raise TypeError("restart_block() requires either dtime or report_step argument - none given.") @@ -703,7 +697,7 @@ class EclFile(CClass): # 2. Creating a wrapper object around the libecl library, -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_file" , EclFile ) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav.py index 5d3ad12596..e16dad67e7 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav.py @@ -21,14 +21,9 @@ 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 ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import EclPhaseEnum, ECL_LIB -import libecl -import ecl_file -import ecl_region -import ecl_grid -from ecl_util import ECL_WATER_PHASE , ECL_OIL_PHASE , ECL_GAS_PHASE, ecl_phase_enum -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass class EclGrav(CClass): """ @@ -47,7 +42,7 @@ class EclGrav(CClass): 3. Evalute the gravitational response with the eval() method. """ - def __init__( self , grid , init_file ): + def __init__( self, grid, init_file ): """ Creates a new EclGrav instance. @@ -55,12 +50,10 @@ class EclGrav(CClass): of EclGrid and EclFile respectively. """ self.init_file = init_file # Inhibit premature garbage collection of init_file - self.init_cobj( cfunc.grav_alloc(grid , init_file) , cfunc.free) - + self.init_cobj(cfunc.grav_alloc(grid, init_file), cfunc.free) - - def add_survey_RPORV( self , survey_name , restart_file ): + def add_survey_RPORV( self, survey_name, restart_file ): """ Add new survey based on RPORV keyword. @@ -84,9 +77,9 @@ class EclGrav(CClass): add_survey_PORMOD() and add_survey_FIP() are alternatives which are based on other keywords. """ - cfunc.add_survey_RPORV( self , survey_name , restart_file ) + cfunc.add_survey_RPORV(self, survey_name, restart_file) - def add_survey_PORMOD( self , survey_name , restart_file ): + def add_survey_PORMOD( self, survey_name, restart_file ): """ Add new survey based on PORMOD keyword. @@ -94,9 +87,9 @@ class EclGrav(CClass): the PORV_MOD keyword from the restart file; see add_survey_RPORV() for further details. """ - cfunc.add_survey_PORMOD( self , survey_name , restart_file ) + cfunc.add_survey_PORMOD(self, survey_name, restart_file) - def add_survey_FIP( self , survey_name , restart_file ): + def add_survey_FIP( self, survey_name, restart_file ): """ Add new survey based on FIP keywords. @@ -109,9 +102,9 @@ class EclGrav(CClass): the new_std_density() (and possibly also add_std_density()) method before calling the add_survey_FIP() method. """ - cfunc.add_survey_FIP( self , survey_name , restart_file ) + cfunc.add_survey_FIP(self, survey_name, restart_file) - def add_survey_RFIP( self , survey_name , restart_file ): + def add_survey_RFIP( self, survey_name, restart_file ): """ Add new survey based on RFIP keywords. @@ -120,10 +113,11 @@ class EclGrav(CClass): calculated based on the RFIPxxx keyword along with the per-cell mass density of the respective phases. """ - cfunc.add_survey_RFIP( self , survey_name , restart_file ) + cfunc.add_survey_RFIP(self, survey_name, restart_file) - - def eval(self , base_survey , monitor_survey , pos , region = None , phase_mask = ECL_OIL_PHASE + ECL_GAS_PHASE + ECL_WATER_PHASE): + + 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. @@ -150,10 +144,10 @@ class EclGrav(CClass): sum of the relevant integer constants 'ECL_OIL_PHASE', 'ECL_GAS_PHASE' and 'ECL_WATER_PHASE'. """ - return cfunc.eval( self , base_survey , monitor_survey , region , pos[0] , pos[1] , pos[2] , phase_mask) - + return cfunc.eval(self, base_survey, monitor_survey, region, pos[0], pos[1], pos[2], phase_mask) - def new_std_density( self , phase_enum , default_density): + + def new_std_density( self, phase_enum, default_density): """ Adds a new phase with a corresponding density. @@ -171,9 +165,9 @@ class EclGrav(CClass): used before you use the add_survey_FIP() method to add a survey based on the FIP keyword. """ - cfunc.new_std_density( self , phase_enum , default_density ) - - def add_std_density( self , phase_enum , pvtnum , density): + cfunc.new_std_density(self, phase_enum, default_density) + + def add_std_density( self, phase_enum, pvtnum, density): """ Add standard conditions density for PVT region @pvtnum. @@ -191,12 +185,12 @@ class EclGrav(CClass): used before you use the add_survey_FIP() method to add a survey based on the FIP keyword. """ - cfunc.add_std_density( self , phase_enum , pvtnum , density ) + cfunc.add_std_density(self, phase_enum, pvtnum, density) # 2. Creating a wrapper object around the libecl library, -cwrapper = CWrapper( libecl.lib ) -cwrapper.registerType( "ecl_grav" , EclGrav ) +cwrapper = CWrapper(ECL_LIB) +cwrapper.registerType("ecl_grav", EclGrav) # 3. Installing the c-functions used to manipulate ecl_grav instances. @@ -204,16 +198,16 @@ cwrapper.registerType( "ecl_grav" , EclGrav ) # used outside this scope. cfunc = CWrapperNameSpace("ecl_grav") -cfunc.grav_alloc = cwrapper.prototype("c_void_p ecl_grav_alloc( ecl_grid , ecl_file )") -cfunc.free = cwrapper.prototype("void ecl_grav_free( ecl_grav )") +cfunc.grav_alloc = cwrapper.prototype("c_void_p ecl_grav_alloc( ecl_grid , ecl_file )") +cfunc.free = cwrapper.prototype("void ecl_grav_free( ecl_grav )") # Return value ignored in the add_survey_xxx() functions: -cfunc.add_survey_RPORV = cwrapper.prototype("c_void_p ecl_grav_add_survey_RPORV( ecl_grav , char* , ecl_file )") -cfunc.add_survey_PORMOD = cwrapper.prototype("c_void_p ecl_grav_add_survey_PORMOD( ecl_grav , char* , ecl_file )") -cfunc.add_survey_FIP = cwrapper.prototype("c_void_p ecl_grav_add_survey_FIP( ecl_grav , char* , ecl_file )") -cfunc.add_survey_RFIP = cwrapper.prototype("c_void_p ecl_grav_add_survey_RFIP( ecl_grav , char* , ecl_file )") +cfunc.add_survey_RPORV = cwrapper.prototype("c_void_p ecl_grav_add_survey_RPORV( ecl_grav , char* , ecl_file )") +cfunc.add_survey_PORMOD = cwrapper.prototype("c_void_p ecl_grav_add_survey_PORMOD( ecl_grav , char* , ecl_file )") +cfunc.add_survey_FIP = cwrapper.prototype("c_void_p ecl_grav_add_survey_FIP( ecl_grav , char* , ecl_file )") +cfunc.add_survey_RFIP = cwrapper.prototype("c_void_p ecl_grav_add_survey_RFIP( ecl_grav , char* , ecl_file )") -cfunc.new_std_density = cwrapper.prototype("void ecl_grav_new_std_density( ecl_grav , int , double)") -cfunc.add_std_density = cwrapper.prototype("void ecl_grav_add_std_density( ecl_grav , int , int , double)") -cfunc.eval = cwrapper.prototype("double ecl_grav_eval( ecl_grav , char* , char* , ecl_region , double , double , double, int)") +cfunc.new_std_density = cwrapper.prototype("void ecl_grav_new_std_density( ecl_grav , int , double)") +cfunc.add_std_density = cwrapper.prototype("void ecl_grav_add_std_density( ecl_grav , int , int , double)") +cfunc.eval = cwrapper.prototype("double ecl_grav_eval( ecl_grav , char* , char* , ecl_region , double , double , double, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav_calc.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav_calc.py index fce876cd92..68d911c8b5 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav_calc.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav_calc.py @@ -12,19 +12,12 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CWrapper, CWrapperNameSpace +from ert.ecl import ECL_LIB -from ert.cwrap.cwrap import * -import libecl -import ctypes -from ecl_kw import EclKW , ECL_INT_TYPE -from ecl_grid import EclGrid - - - -def phase_deltag( xyz , grid , init , sat1 , rho1 , porv1 , sat2 , rho2 , porv2): - +def phase_deltag( xyz, grid, init, sat1, rho1, porv1, sat2, rho2, porv2): # Observe that the function cfunc.phase_deltag() is called # directly with c_ptr pointer values, and that the function is # prototyped with c_void_p arguments instead of ecl_grid and @@ -34,13 +27,11 @@ def phase_deltag( xyz , grid , init , sat1 , rho1 , porv1 , sat2 , rho2 , porv2) # Python/ctypes bug in the current 2.4 implementation; the call # sequencence should modified to use the from_param() method like # the rest of the bindings. - - return cfunc.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 ) - + return cfunc.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) # 1. All restart files should have water, i.e. the SWAT keyword. @@ -48,58 +39,56 @@ def phase_deltag( xyz , grid , init , sat1 , rho1 , porv1 , sat2 , rho2 , porv2) # in addition the model must contain one additional phase - which should have a density. # 3. The restart files can never contain oil saturation. -def deltag( xyz , grid , init_file , restart_file1 , restart_file2): - swat1 = restart_file1.iget_named_kw( "SWAT" , 0) - swat2 = restart_file2.iget_named_kw( "SWAT" , 0) +def deltag( xyz, grid, init_file, restart_file1, restart_file2): + swat1 = restart_file1.iget_named_kw("SWAT", 0) + swat2 = restart_file2.iget_named_kw("SWAT", 0) - phase_list = [ ( swat1 , swat2) ] + phase_list = [( swat1, swat2)] - if restart_file1.has_kw( "SGAS" ): + 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 ) + 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) ] + 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_file.has_kw( "OIL_DEN" ): + 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) ] + phase_list += [(soil1, soil2)] else: # Gas / Water system sgas1 = 1 - swat1 sgas2 = 1 - swat2 sgas1.name = "SGAS" sgas2.name = "SGAS" - phase_list += [ (sgas1 , sgas2) ] + phase_list += [(sgas1, sgas2)] + + porv1 = restart_file1.iget_named_kw("RPORV", 0) + porv2 = restart_file2.iget_named_kw("RPORV", 0) - 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) + 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 - - -cwrapper = CWrapper( libecl.lib ) -cfunc = CWrapperNameSpace("ecl_grav") +cwrapper = CWrapper(ECL_LIB) +cfunc = CWrapperNameSpace("ecl_grav") cfunc.phase_deltag = cwrapper.prototype("double ecl_grav_phase_deltag( double, double ,double , c_void_p , c_void_p , c_void_p , c_void_p , c_void_p , c_void_p , c_void_p , c_void_p)") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grid.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grid.py index b7644f26ed..c2822f8832 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grid.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grid.py @@ -23,16 +23,13 @@ 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 -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import DoubleVector # Requires merging of typemaps .... -import libecl -import ecl_kw -from ert.cwrap.cfile import CFILE + import numpy +import sys +from ert.cwrap import CClass, CFILE, CWrapper, CWrapperNameSpace +from ert.ecl import EclTypeEnum, EclKW, ECL_LIB + class EclGrid(CClass): """ @@ -567,11 +564,11 @@ class EclGrid(CClass): if dims[0] == self.nx and dims[1] == self.ny and dims[2] == self.nz: dtype = array.dtype if dtype == numpy.int32: - type = ecl_kw.ECL_INT_TYPE + type = EclTypeEnum.ECL_INT_TYPE elif dtype == numpy.float32: - type = ecl_kw.ECL_FLOAT_TYPE + type = EclTypeEnum.ECL_FLOAT_TYPE elif dtype == numpy.float64: - type = ecl_kw.ECL_DOUBLE_TYPE + type = EclTypeEnum.ECL_DOUBLE_TYPE else: sys.exit("Do not know how to create ecl_kw from type:%s" % dtype) @@ -584,7 +581,7 @@ class EclGrid(CClass): # Silently truncate to length 8 - ECLIPSE has it's challenges. kw_name = kw_name[0:8] - kw = ecl_kw.EclKW.new( kw_name , size , type ) + kw = EclKW.new( kw_name , size , type ) active_index = 0 global_index = 0 for k in range( self.nz ): @@ -713,7 +710,7 @@ class EclGrid(CClass): # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_grid" , EclGrid ) # 3. Installing the c-functions used to manipulate ecl_kw instances. diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_kw.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_kw.py index 3dd54874b9..613cd9e383 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_kw.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_kw.py @@ -37,17 +37,12 @@ files. This module also has (some) support for working with GRDECL The ecl_kw.py implementation wraps the ecl_kw.c implementation from the libecl library. """ -import types -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.cwrap.cfile import CFILE -from ecl_util import ECL_CHAR_TYPE, ECL_DOUBLE_TYPE, ECL_INT_TYPE, ECL_BOOL_TYPE, ECL_MESS_TYPE, ECL_FLOAT_TYPE -import ecl_util -import fortio -import libecl -import warnings +import ctypes +import types + import numpy +from ert.cwrap import CClass, CFILE, CWrapper, CWrapperNameSpace +from ert.ecl import ECL_LIB, EclTypeEnum, EclUtil class classprop(object): @@ -95,28 +90,28 @@ class EclKW(CClass): @classmethod - def create( cls , name, size , type): + def create( cls , 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 (silently truncated - to eight characters), @size elements and datatype @type. Using + to eight characters), @size elements and datatype @data_type. Using this method you could create a SOIL keyword with: soil_kw = EclKW.new( "SOIL" , 10000 , ECL_FLOAT_TYPE ) """ obj = cls() - c_ptr = cfunc.alloc_new( name , size , type ) + c_ptr = cfunc.alloc_new( name , size , data_type ) obj.init_cobj( c_ptr , cfunc.free ) obj.__init( ) return obj @classmethod - def new( cls , name, size , type): - return cls.create( name , size , type ) + def new( cls , name, size , data_type): + return cls.create( name , size , data_type ) # Could this method be avoided totally by using an ecl_kw return @@ -135,8 +130,8 @@ class EclKW(CClass): @classmethod - def slice_copy( cls , src , slice ): - (start , stop , step) = slice.indices( src.size ) + def slice_copy( cls , src , slice_range ): + (start , stop , step) = slice_range.indices( src.size ) if stop > start: c_ptr = cfunc.slice_copyc( src , start , stop , step) obj = cls( ) @@ -162,7 +157,7 @@ class EclKW(CClass): @classmethod - def read_grdecl( cls , file , kw , strict = True , ecl_type = None): + def read_grdecl( cls , filename , kw , strict = True , ecl_type = None): """ Function to load an EclKW instance from a grdecl file. @@ -231,18 +226,18 @@ class EclKW(CClass): it finds in the file. """ - cfile = CFILE( file ) + cfile = CFILE( filename ) 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 = ECL_INT_TYPE + ecl_type = EclTypeEnum.ECL_INT_TYPE else: - ecl_type = ECL_FLOAT_TYPE + ecl_type = EclTypeEnum.ECL_FLOAT_TYPE - if not ecl_type in [ECL_FLOAT_TYPE , ECL_INT_TYPE]: + if not ecl_type in [EclTypeEnum.ECL_FLOAT_TYPE , EclTypeEnum.ECL_INT_TYPE]: raise TypeError("The type:%d is invalid when loading keyword:%s" % (ecl_type , kw)) c_ptr = cfunc.load_grdecl( cfile , kw , strict , ecl_type ) @@ -255,7 +250,7 @@ class EclKW(CClass): return None @classmethod - def fseek_grdecl( cls , file , kw , rewind = False): + def fseek_grdecl( cls , filename , kw , rewind = False): """ Will search through the open file and look for string @kw. @@ -279,13 +274,13 @@ class EclKW(CClass): true the function rewind to the beginning of the file and search from there after the initial search. """ - cfile = CFILE( file ) + cfile = CFILE( filename ) return cfunc.fseek_grdecl( kw , rewind , cfile) @classmethod - def grdecl_load( cls , file , kw , ecl_type = ECL_FLOAT_TYPE): + def grdecl_load( cls , file , kw , ecl_type = EclTypeEnum.ECL_FLOAT_TYPE): """Use read_grdecl() instead.""" #warnings.warn("The grdecl_load method has been renamed to read_grdecl()" , DeprecationWarning) return cls.read_grdecl(file , kw , ecl_type ) @@ -343,15 +338,15 @@ class EclKW(CClass): def __init(self): self.data_ptr = None self.ecl_type = cfunc.get_type( self ) - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: self.data_ptr = cfunc.int_ptr( self ) self.dtype = numpy.int32 self.str_fmt = "%8d" - elif self.ecl_type == ECL_FLOAT_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: self.data_ptr = cfunc.float_ptr( self ) self.dtype = numpy.float32 self.str_fmt = "%13.4f" - elif self.ecl_type == ECL_DOUBLE_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: self.data_ptr = cfunc.double_ptr( self ) self.dtype = numpy.float64 self.str_fmt = "%13.4f" @@ -359,9 +354,9 @@ class EclKW(CClass): # Iteration not supported for CHAR / BOOL self.data_ptr = None self.dtype = None - if self.ecl_type == ECL_CHAR_TYPE: + if self.ecl_type == EclTypeEnum.ECL_CHAR_TYPE: self.str_fmt = "%8s" - elif self.ecl_type == ECL_BOOL_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_BOOL_TYPE: self.str_fmt = "%d" else: self.str_fmt = "%s" #"Message type" @@ -398,9 +393,9 @@ class EclKW(CClass): if self.data_ptr: return self.data_ptr[ index ] else: - if self.ecl_type == ECL_BOOL_TYPE: + if self.ecl_type == EclTypeEnum.ECL_BOOL_TYPE: return cfunc.iget_bool( self, index) - elif self.ecl_type == ECL_CHAR_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_CHAR_TYPE: return cfunc.iget_char_ptr( self , index ) else: raise TypeError("Internal implementation error ...") @@ -426,9 +421,9 @@ class EclKW(CClass): if self.data_ptr: self.data_ptr[ index ] = value else: - if self.ecl_type == ECL_BOOL_TYPE: + if self.ecl_type == EclTypeEnum.ECL_BOOL_TYPE: cfunc.iset_bool( self , index , value) - elif self.ecl_type == ECL_CHAR_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_CHAR_TYPE: return cfunc.iset_char_ptr( self , index , value) else: raise SystemError("Internal implementation error ...") @@ -453,7 +448,7 @@ class EclKW(CClass): if not mul: factor = 1.0 / factor - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: if isinstance( factor , int ): cfunc.scale_int( self , factor ) else: @@ -485,7 +480,7 @@ class EclKW(CClass): else: sign = -1 - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: if isinstance( delta , int ): cfunc.shift_int( self , delta * sign) else: @@ -607,7 +602,7 @@ class EclKW(CClass): if mask: mask.set_kw( self , value , force_active ) else: - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: if isinstance( value , int ): cfunc.set_int( self , value ) else: @@ -754,17 +749,17 @@ class EclKW(CClass): @property def type( self ): # enum ecl_type_enum from ecl_util.h - if self.ecl_type == ECL_CHAR_TYPE: + if self.ecl_type == EclTypeEnum.ECL_CHAR_TYPE: return "CHAR" - if self.ecl_type == ECL_FLOAT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: return "REAL" - if self.ecl_type == ECL_DOUBLE_TYPE: + if self.ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: return "DOUB" - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: return "INTE" - if self.ecl_type == ECL_BOOL_TYPE: + if self.ecl_type == EclTypeEnum.ECL_BOOL_TYPE: return "BOOL" - if self.ecl_type == ECL_MESS_TYPE: + if self.ecl_type == EclTypeEnum.ECL_MESS_TYPE: return "MESS" @@ -776,15 +771,15 @@ class EclKW(CClass): Will raise TypeError exception if the keyword is not of numerical type. """ - if self.ecl_type == ECL_FLOAT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: min = ctypes.c_float() max = ctypes.c_float() cfunc.max_min_float( self , ctypes.byref( max ) , ctypes.byref( min )) - elif self.ecl_type == ECL_DOUBLE_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: min = ctypes.c_double() max = ctypes.c_double() cfunc.max_min_double( self , ctypes.byref( max ) , ctypes.byref( min )) - elif self.ecl_type == ECL_INT_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_INT_TYPE: min = ctypes.c_int() max = ctypes.c_int() cfunc.max_min_int( self , ctypes.byref( max ) , ctypes.byref( min )) @@ -805,11 +800,11 @@ class EclKW(CClass): @property def numeric(self): - if self.ecl_type == ECL_FLOAT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: return True - if self.ecl_type == ECL_DOUBLE_TYPE: + if self.ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: return True - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: return True return False @@ -820,7 +815,7 @@ class EclKW(CClass): @property def type_name( self ): - return ecl_util.type_name( self.ecl_type ) + return EclUtil.type_name( self.ecl_type ) @property def header( self ): @@ -828,7 +823,8 @@ class EclKW(CClass): def iget( self , index ): - raise DeprecationWarning("The iget() method is deprecated use array notation: kw[index] instead.") + from warnings import warn + warn("The iget() method is deprecated use array notation: kw[index] instead.", DeprecationWarning) return self.__getitem__( index ) @@ -962,7 +958,7 @@ class EclKW(CClass): # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_kw" , EclKW ) # 3. Installing the c-functions used to manipulate ecl_kw instances. diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_queue.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_queue.py index 3487dcd9a1..840d35e3b2 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_queue.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_queue.py @@ -34,23 +34,19 @@ the EclQueue class it is important to consult the documentation of the JobQueue class in ert.job_queue.queue as well. """ import os.path - -from ert.job_queue.queue import JobQueue -import ert.job_queue.driver as queue_driver -import libecl -from ecl_default import default -import ecl_util +from ert.ecl import EclUtil, EclDefault +from ert.job_queue import JobQueue, Driver -class EclQueue( JobQueue ): - def __init__(self , - driver = None , - driver_type = None, - driver_options = None, - ecl_version = None, - ecl_cmd = None, - max_running = 0, - size = 0): +class EclQueue(JobQueue): + def __init__(self, + driver=None, + driver_type=None, + driver_options=None, + ecl_version=None, + ecl_cmd=None, + max_running=0, + size=0): """ Create a new queue instance to manage ECLIPSE simulations. @@ -146,24 +142,25 @@ class EclQueue( JobQueue ): after the main thread has exited - not yet :-( """ if ecl_cmd is None: - ecl_cmd = ecl_default.default.ecl_cmd - + ecl_cmd = EclDefault.ecl_cmd() + if driver_type is None: - driver_type = ecl_default.default.driver_type + driver_type = EclDefault.driver_type() if ecl_version is None: - ecl_version = ecl_default.default.ecl_version + ecl_version = EclDefault.ecl_version() self.ecl_version = ecl_version - self.ecl_cmd = ecl_cmd + self.ecl_cmd = ecl_cmd if driver is None: if driver_options is None: - driver_options = default.driver_options[ driver_type ] - driver = queue_driver.Driver( driver_type , max_running = max_running , options = driver_options ) - JobQueue.__init__( self , driver , size = size) + driver_options = EclDefault.driver_options()[driver_type] + driver = Driver(driver_type, max_running=max_running, options=driver_options) - - def submit( self , data_file): + JobQueue.__init__(self, driver, size=size) + + + def submit( self, data_file): """ Will submit a new simulation of case given by @data_file. @@ -171,9 +168,10 @@ class EclQueue( JobQueue ): ert.job_queue.queue.job module which can be used to query the status of the job while it is running. """ - (path_base , ext) = os.path.splitext( data_file ) - (run_path , base) = os.path.split( path_base ) - - argv = [ self.ecl_version , path_base , "%s" % ecl_util.get_num_cpu( data_file )] - return JobQueue.submit( self , self.ecl_cmd , run_path , base , argv) + (path_base, ext) = os.path.splitext(data_file) + (run_path, base) = os.path.split(path_base) + + num_cpu = EclUtil.get_num_cpu(data_file) + argv = [self.ecl_version, path_base, "%s" % num_cpu] + return JobQueue.submit(self, self.ecl_cmd, run_path, base, argv, num_cpu=num_cpu) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_region.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_region.py index 2c95f114d3..300a065bad 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_region.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_region.py @@ -25,16 +25,52 @@ 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 import warnings -import libecl -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import IntVector -from ert.geo.geo_polygon import GeoPolygon -from ecl_kw import ECL_INT_TYPE , ECL_FLOAT_TYPE , ECL_DOUBLE_TYPE, EclKW -import ecl_grid +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import EclKW, EclTypeEnum, ECL_LIB +from ert.geo import GeoPolygon +from ert.util import IntVector +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(CClass): @@ -203,45 +239,6 @@ class EclRegion(CClass): ################################################################## - - 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 - @select_method def select_more( self , ecl_kw , limit , intersect = False): @@ -735,9 +732,9 @@ class EclRegion(CClass): """ See usage documentation on iadd_kw(). """ - self.scalar_apply_kw( ecl_kw , shift , {ECL_INT_TYPE : cfunc.shift_kw_int, - ECL_FLOAT_TYPE : cfunc.shift_kw_float , - ECL_DOUBLE_TYPE : cfunc.shift_kw_double} , force_active) + self.scalar_apply_kw( ecl_kw , shift , {EclTypeEnum.ECL_INT_TYPE : cfunc.shift_kw_int, + EclTypeEnum.ECL_FLOAT_TYPE : cfunc.shift_kw_float , + EclTypeEnum.ECL_DOUBLE_TYPE : cfunc.shift_kw_double} , force_active) def isub_kw( self , target_kw , delta_kw , force_active = False): if isinstance(delta_kw , EclKW): @@ -753,9 +750,9 @@ class EclRegion(CClass): """ See usage documentation on iadd_kw(). """ - self.scalar_apply_kw( ecl_kw , scale , {ECL_INT_TYPE : cfunc.scale_kw_int, - ECL_FLOAT_TYPE : cfunc.scale_kw_float , - ECL_DOUBLE_TYPE : cfunc.scale_kw_double} , force_active) + self.scalar_apply_kw( ecl_kw , scale , {EclTypeEnum.ECL_INT_TYPE : cfunc.scale_kw_int, + EclTypeEnum.ECL_FLOAT_TYPE : cfunc.scale_kw_float , + EclTypeEnum.ECL_DOUBLE_TYPE : cfunc.scale_kw_double} , force_active) def imul_kw( self , target_kw , other , force_active = False): if isinstance(other , EclKW): @@ -790,9 +787,9 @@ class EclRegion(CClass): """ See usage documentation on iadd_kw(). """ - self.scalar_apply_kw( ecl_kw , value , {ECL_INT_TYPE : cfunc.set_kw_int, - ECL_FLOAT_TYPE : cfunc.set_kw_float , - ECL_DOUBLE_TYPE : cfunc.set_kw_double} , force_active) + self.scalar_apply_kw( ecl_kw , value , {EclTypeEnum.ECL_INT_TYPE : cfunc.set_kw_int, + EclTypeEnum.ECL_FLOAT_TYPE : cfunc.set_kw_float , + EclTypeEnum.ECL_DOUBLE_TYPE : cfunc.set_kw_double} , force_active) @@ -813,7 +810,7 @@ class EclRegion(CClass): IntVector instance with active indices in the region. """ c_ptr = cfunc.get_active_list( self ) - active_list = IntVector.ref( c_ptr , self ) + active_list = IntVector.asPythonReference( c_ptr , self ) return active_list @property @@ -822,7 +819,7 @@ class EclRegion(CClass): IntVector instance with global indices in the region. """ c_ptr = cfunc.get_global_list( self ) - global_list = IntVector.ref( c_ptr , self ) + global_list = IntVector.asPythonReference( c_ptr , self ) return global_list @property @@ -864,7 +861,7 @@ class EclRegion(CClass): def kw_index_list(self , ecl_kw , force_active): c_ptr = cfunc.get_kw_index_list( self , ecl_kw , force_active) - index_list = IntVector.ref( c_ptr , self ) + index_list = IntVector.asPythonReference( c_ptr , self ) return index_list @@ -878,7 +875,7 @@ class EclRegion(CClass): # 2. Creating a wrapper object around the libecl library. -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_region" , EclRegion ) # 3. Installing the c-functions used to manipulate. diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft.py index 8689e5ecda..1544a1b96d 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft.py @@ -17,17 +17,12 @@ Module for loading ECLIPSE RFT files. """ -import ctypes import types import warnings +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import EclRFTCell, EclPLTCell, ECL_LIB +from ert.util import ctime -import libecl -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.ctime import ctime -from ecl_rft_cell import EclRFTCell, EclPLTCell - - class EclRFTFile(CClass): """ @@ -224,9 +219,9 @@ class EclRFT(CClass): def __cell_ref( self , cell_ptr ): if self.is_RFT(): - return EclRFTCell.ref( cell_ptr , self ) + return EclRFTCell.asPythonReference( cell_ptr , self ) elif self.is_PLT(): - return EclPLTCell.ref( cell_ptr , self ) + return EclPLTCell.asPythonReference( cell_ptr , self ) else: raise NotImplementedError("Only RFT and PLT cells are implemented") @@ -321,7 +316,7 @@ class EclRFT(CClass): # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_rft_file" , EclRFTFile ) cwrapper.registerType( "ecl_rft" , EclRFT ) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft_cell.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft_cell.py index 4cd4727ddd..b853386c85 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft_cell.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft_cell.py @@ -15,12 +15,9 @@ # for more details. import warnings -import ctypes -import types +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import ECL_LIB -import libecl -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass class RFTCell(CClass): """The RFTCell is a base class for the cells which are part of an RFT/PLT. @@ -102,7 +99,7 @@ class EclRFTCell(RFTCell): return cell @classmethod - def ref(cls, c_ptr , parent): + def asPythonReference(cls, c_ptr , parent): cell = EclRFTCell() cell.init_cref( c_ptr , parent ) return cell @@ -126,14 +123,14 @@ class EclRFTCell(RFTCell): class EclPLTCell(RFTCell): @classmethod - def new(self , i , j , k , depth , pressure , orat , grat , wrat , conn_start , flowrate , oil_flowrate , gas_flowrate , water_flowrate ): + def new(self , i , j , k , depth , pressure , orat , grat , wrat , conn_start ,conn_end, flowrate , oil_flowrate , gas_flowrate , water_flowrate ): cell = EclPLTCell() - c_ptr = cfunc.alloc_PLT( i,j,k,depth,pressure,orat , grat , wrat , conn_start , flowrate , oil_flowrate , gas_flowrate , water_flowrate) + c_ptr = cfunc.alloc_PLT( i,j,k,depth,pressure,orat , grat , wrat , conn_start , conn_end, flowrate , oil_flowrate , gas_flowrate , water_flowrate) cell.init_cobj( c_ptr , cfunc.free ) return cell @classmethod - def ref(cls, c_ptr , parent): + def asPythonReference(cls, c_ptr , parent): cell = EclPLTCell() cell.init_cref( c_ptr , parent ) return cell @@ -162,6 +159,18 @@ class EclPLTCell(RFTCell): """ return cfunc.get_conn_start( self ) + @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 cfunc.get_conn_end( self ) + @property def flowrate(self): return cfunc.get_flowrate( self ) @@ -182,7 +191,7 @@ class EclPLTCell(RFTCell): ################################################################# -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "rft_cell" , RFTCell) cwrapper.registerType( "ecl_rft_cell" , EclRFTCell ) cwrapper.registerType( "ecl_plt_cell" , EclPLTCell ) @@ -190,7 +199,7 @@ cwrapper.registerType( "ecl_plt_cell" , EclPLTCell ) cfunc = CWrapperNameSpace("ecl_rft_cell") cfunc.alloc_RFT = cwrapper.prototype("c_void_p ecl_rft_cell_alloc_RFT( int, int , int , double , double , double , double)") -cfunc.alloc_PLT = cwrapper.prototype("c_void_p ecl_rft_cell_alloc_PLT( int, int , int , double , double , double , double, double , double , double , double , double , double )") +cfunc.alloc_PLT = cwrapper.prototype("c_void_p ecl_rft_cell_alloc_PLT( int, int , int , double , double , double, double , double, double , double , double , double , double , double )") cfunc.free = cwrapper.prototype("void ecl_rft_cell_free( rft_cell )") cfunc.get_pressure = cwrapper.prototype("double ecl_rft_cell_get_pressure( rft_cell )") @@ -208,6 +217,7 @@ cfunc.get_grat = cwrapper.prototype("double ecl_rft_cell_get_grat( ecl_plt_cell cfunc.get_wrat = cwrapper.prototype("double ecl_rft_cell_get_wrat( ecl_plt_cell )") cfunc.get_conn_start = cwrapper.prototype("double ecl_rft_cell_get_connection_start( ecl_plt_cell )") +cfunc.get_conn_end = cwrapper.prototype("double ecl_rft_cell_get_connection_end( ecl_plt_cell )") cfunc.get_flowrate = cwrapper.prototype("double ecl_rft_cell_get_flowrate( ecl_plt_cell )") cfunc.get_oil_flowrate = cwrapper.prototype("double ecl_rft_cell_get_oil_flowrate( ecl_plt_cell )") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_subsidence.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_subsidence.py index 4aa41274ef..c47f37e69b 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_subsidence.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_subsidence.py @@ -22,13 +22,8 @@ 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. """ - -import libecl -import ecl_file -import ecl_region -import ecl_grid -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import ECL_LIB class EclSubsidence(CClass): @@ -48,7 +43,7 @@ class EclSubsidence(CClass): 3. Evalute the subsidence response with the eval() method. """ - def __init__( self , grid , init_file ): + def __init__( self, grid, init_file ): """ Creates a new EclSubsidence instance. @@ -56,10 +51,10 @@ class EclSubsidence(CClass): of EclGrid and EclFile respectively. """ self.init_file = init_file # Inhibit premature garbage collection of init_file - self.init_cobj( cfunc.subsidence_alloc( grid , init_file ) , cfunc.free ) - + self.init_cobj(cfunc.subsidence_alloc(grid, init_file), cfunc.free) - def add_survey_PRESSURE( self , survey_name , restart_file ): + + def add_survey_PRESSURE( self, survey_name, restart_file ): """ Add new survey based on PRESSURE keyword. @@ -81,10 +76,10 @@ class EclSubsidence(CClass): The pore volume is calculated from the initial pore volume and the PRESSURE keyword from the restart file. """ - cfunc.add_survey_PRESSURE( self , survey_name , restart_file ) + cfunc.add_survey_PRESSURE(self, survey_name, restart_file) - - def eval(self , base_survey , monitor_survey , pos , compressibility , poisson_ratio , region = None): + + def eval(self, base_survey, monitor_survey, pos, compressibility, poisson_ratio, region=None): """ Calculates the subsidence change between two surveys. @@ -108,20 +103,21 @@ class EclSubsidence(CClass): The argument @compressibility is the total reservoir compressibility. """ - return cfunc.eval( self , base_survey , monitor_survey , region , pos[0] , pos[1] , pos[2] , compressibility, poisson_ratio) + return cfunc.eval(self, base_survey, monitor_survey, region, pos[0], pos[1], pos[2], compressibility, + poisson_ratio) # 2. Creating a wrapper object around the libecl library, -cwrapper = CWrapper( libecl.lib ) -cwrapper.registerType( "ecl_subsidence" , EclSubsidence ) +cwrapper = CWrapper(ECL_LIB) +cwrapper.registerType("ecl_subsidence", EclSubsidence) # 3. Installing the c-functions used to manipulate ecl_subsidence instances. # These functions are used when implementing the EclSubsidence class, not # used outside this scope. cfunc = CWrapperNameSpace("ecl_subsidence") -cfunc.subsidence_alloc = cwrapper.prototype("c_void_p ecl_subsidence_alloc( ecl_grid , ecl_file )") -cfunc.free = cwrapper.prototype("void ecl_subsidence_free( ecl_subsidence )") +cfunc.subsidence_alloc = cwrapper.prototype("c_void_p ecl_subsidence_alloc( ecl_grid , ecl_file )") +cfunc.free = cwrapper.prototype("void ecl_subsidence_free( ecl_subsidence )") # Return value ignored in the add_survey_xxx() functions: -cfunc.add_survey_PRESSURE = cwrapper.prototype("c_void_p ecl_subsidence_add_survey_PRESSURE( ecl_subsidence , char* , ecl_file )") -cfunc.eval = cwrapper.prototype("double ecl_subsidence_eval( ecl_subsidence , char* , char* , ecl_region , double , double , double, double, double)") +cfunc.add_survey_PRESSURE = cwrapper.prototype("c_void_p ecl_subsidence_add_survey_PRESSURE( ecl_subsidence , char* , ecl_file )") +cfunc.eval = cwrapper.prototype("double ecl_subsidence_eval( ecl_subsidence , char* , char* , ecl_region , double , double , double, double, double)") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_sum.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_sum.py index 308ef6ebc2..e335cce4c0 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_sum.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_sum.py @@ -25,17 +25,11 @@ libecl/src directory. # 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 ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util import StringList, ctime, DoubleVector, TimeVector +from ert.ecl import ECL_LIB - - -import libecl -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.stringlist import StringList -from ert.util.ctime import ctime -from ert.ert.erttypes import time_vector, double_vector - -import numpy +import numpy #import ert.ecl_plot.sum_plot as sum_plot @@ -46,11 +40,13 @@ import numpy # implementation could be replaced with: # # from matplotlib.dates import date2num +from ert.util.tvector import TimeVector + 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 +MINUTES_PER_DAY = 60 * HOURS_PER_DAY +SECONDS_PER_DAY = 60 * MINUTES_PER_DAY +MUSECONDS_PER_DAY = 1e6 * SECONDS_PER_DAY def date2num( dt ): """ @@ -1231,20 +1227,26 @@ class EclSum( CClass ): def alloc_time_vector(self, report_only): - return time_vector(cfunc.alloc_time_vector(self, report_only)) + c_ptr = cfunc.alloc_time_vector(self, report_only) + v = TimeVector.asPythonObject(c_ptr, TimeVector.free) + return v def alloc_data_vector(self, data_index, report_only): - return double_vector(cfunc.alloc_data_vector(self, data_index, report_only)) + c_ptr = cfunc.alloc_data_vector(self, data_index, report_only) + v = DoubleVector.asPythonObject(c_ptr, DoubleVector.free) + return v def get_general_var_index(self, key): - return cfunc.get_general_var_index( self , key ) + c_ptr = cfunc.get_general_var_index( self , key ) + v = TimeVector.asPythonObject(c_ptr, TimeVector.free) + return v ################################################################# # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_sum" , EclSum ) cwrapper.registerType( "smspec_node" , EclSMSPECNode ) @@ -1296,7 +1298,7 @@ cfunc.get_report_time = cwrapper.prototype("time_t ecl_sum_get_r cfunc.fwrite_sum = cwrapper.prototype("void ecl_sum_fwrite(ecl_sum)") cfunc.set_case = cwrapper.prototype("void ecl_sum_set_case(ecl_sum, char*)") cfunc.alloc_time_vector = cwrapper.prototype("c_void_p ecl_sum_alloc_time_vector(ecl_sum, bool)") -cfunc.alloc_data_vector = cwrapper.prototype("c_void_p ecl_sum_alloc_data_vector(ecl_sum, int, bool)") +cfunc.alloc_data_vector = cwrapper.prototype("c_void_p ecl_sum_alloc_data_vector(ecl_sum, int, bool)") #----------------------------------------------------------------- # smspec node related stuff diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_util.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_util.py index f4217d4334..65ca98009c 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_util.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_util.py @@ -24,58 +24,64 @@ ert.cwrap.cenum.create_enum() function in a semi-automagic manner. In addition to the enum definitions there are a few stateless functions from ecl_util.c which are not bound to any class type. """ +from ert.cwrap import create_enum, CWrapper, CWrapperNameSpace -from ert.cwrap.cwrap import * -from ert.cwrap.cenum import create_enum -from ert.util.ctime import ctime -import libecl +from ert.ecl import ECL_LIB # ecl_file_enum from ecl_util.h -create_enum( libecl.lib , "ecl_util_file_enum_iget" , "ecl_file_enum" , globals()) +EclFileEnum = create_enum(ECL_LIB, "ecl_util_file_enum_iget", "ecl_file_enum") # ecl_phase_enum from ecl_util.h -create_enum( libecl.lib , "ecl_util_phase_enum_iget" , "ecl_phase_enum" , name_space = globals()) +EclPhaseEnum = create_enum(ECL_LIB, "ecl_util_phase_enum_iget", "ecl_phase_enum") # ecl_type_enum defintion from ecl_util.h -create_enum( libecl.lib , "ecl_util_type_enum_iget" , "ecl_type_enum" , name_space = globals()) +EclTypeEnum = create_enum(ECL_LIB, "ecl_util_type_enum_iget", "ecl_type_enum") # ecl_file_flag_type defintion from ecl_file.h -create_enum( libecl.lib , "ecl_util_file_flags_enum_iget" , "ecl_file_flag_enum" , name_space = globals()) +EclFileFlagEnum = create_enum(ECL_LIB, "ecl_util_file_flags_enum_iget", "ecl_file_flag_enum") -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 cfunc.get_num_cpu( datafile ) +cwrapper = CWrapper(ECL_LIB) +cfunc = CWrapperNameSpace("ecl_util") - -def get_file_type( filename ): - """ - Will inspect an ECLIPSE filename and return an integer type flag. - """ - return cfunc.get_file_type( filename , None , None ) - - -def type_name( ecl_type ): - return cfunc.get_type_name( ecl_type ) - - -def get_start_date( datafile ): - return cfunc.get_start_date( datafile ).datetime() - - - -cwrapper = CWrapper( libecl.lib ) -cfunc = CWrapperNameSpace("ecl_util") - -cfunc.get_num_cpu = cwrapper.prototype("int ecl_util_get_num_cpu( char* )") -cfunc.get_file_type = cwrapper.prototype("int ecl_util_get_file_type( char* , bool* , int*)") -cfunc.get_type_name = cwrapper.prototype("char* ecl_util_get_type_name( int )") +cfunc.get_num_cpu = cwrapper.prototype("int ecl_util_get_num_cpu( char* )") +cfunc.get_file_type = cwrapper.prototype("int ecl_util_get_file_type( char* , bool* , int*)") +cfunc.get_type_name = cwrapper.prototype("char* ecl_util_get_type_name( int )") cfunc.get_start_date = cwrapper.prototype("time_t ecl_util_get_start_date( char* )") + +class EclUtil(object): + @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 cfunc.get_num_cpu(datafile) + + @staticmethod + def get_file_type( filename ): + """ + Will inspect an ECLIPSE filename and return an integer type flag. + """ + return cfunc.get_file_type(filename, None, None) + + @staticmethod + def type_name(ecl_type): + return cfunc.get_type_name(ecl_type) + + @staticmethod + def get_start_date(datafile): + return cfunc.get_start_date(datafile).datetime() + + + +get_num_cpu = EclUtil.get_num_cpu +get_file_type = EclUtil.get_file_type +type_name = EclUtil.type_name +get_start_date = EclUtil.get_start_date diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/fortio.py b/ThirdParty/Ert/devel/python/python/ert/ecl/fortio.py index b5411c3a6a..03f5dafdac 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/fortio.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/fortio.py @@ -36,12 +36,9 @@ 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. """ +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace, CFILE +from ert.ecl import ECL_LIB -import libecl -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cfile import CFILE -from ert.cwrap.cclass import CClass class FortIO(CClass): """ @@ -59,7 +56,7 @@ class FortIO(CClass): # """ # Create a FortIO handle connected to file @filename. @mode as in fopen() # - # Will create a FortIO handle conntected to the file + # Will create a FortIO handle connected to the file # @filename. The @mode flag is passed directly to the final # fopen() call and should be "r" to open the file for reading # and "w" for writing. @@ -147,7 +144,7 @@ class FortIO(CClass): # 2. Creating a wrapper object around the libecl library, # registering the type map : fortio <-> FortIO -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType("fortio" , FortIO ) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/libecl.py b/ThirdParty/Ert/devel/python/python/ert/ecl/libecl.py deleted file mode 100644 index 929daaa7b2..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/libecl.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libecl.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. -""" -This module will load the libecl.so shared library. -""" - -# This statement is necessary for side-effects (i.e. the final -# dlopen("libutil.so") call). -import ert.util.libutil -import ert.geo.libgeo - -import ert.cwrap.clib as clib - -try: - clib.load("libgomp" , "libgomp.so.1") - openmp = True -except ImportError: - openmp = False - -lib = clib.ert_load("libecl.so") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/enkf/CMakeLists.txt index 0ea246117a..5969d2c5ee 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/CMakeLists.txt @@ -1 +1,30 @@ -add_python_package("Python ert.enkf" ${PYTHON_INSTALL_PREFIX}/ert/enkf "analysis_config.py;enkf_main.py;ert_templates.py;gen_kw_config.py;model_config.py;ecl_config.py;enkf_node.py;field_config.py;__init__.py;obs_vector.py;enkf_config_node.py;enkf_obs.py;block_obs.py;libenkf.py;plot_config.py;enkf_enum.py;enkf.py;field.py;local_config.py;site_config.py;enkf_fs.py;ens_config.py;gen_data_config.py;time_map.py;ert_template.py;enkf_state.py" True) +set(PYTHON_SOURCES + __init__.py + analysis_config.py + enkf_main.py + ert_templates.py + gen_kw_config.py + model_config.py + ecl_config.py + enkf_node.py + field_config.py + obs_vector.py + enkf_config_node.py + enkf_obs.py + block_obs.py + libenkf.py + plot_conf.py + enkf_enum.py + enkf.py + field.py + local_config.py + site_config.py + enkf_fs.py + ens_config.py + gen_data_config.py + time_map.py + ert_template.py + enkf_state.py +) + +add_python_package("Python ert.enkf" ${PYTHON_INSTALL_PREFIX}/ert/enkf "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/ecl_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/ecl_config.py index c3e67a3cc9..afe2c50419 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/ecl_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/ecl_config.py @@ -14,22 +14,20 @@ # See the GNU General Public License at # for more details. -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from enkf_enum import * -import libenkf -import ert.util.libutil +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +import libenkf from ert.ecl.ecl_sum import EclSum -from ert.util.stringlist import StringList +from ert.util.stringlist import StringList + + class EclConfig(CClass): - - def __init__(self , c_ptr , parent = None): + def __init__(self, c_ptr, parent=None): if parent: - self.init_cref( c_ptr , parent) + self.init_cref(c_ptr, parent) else: - self.init_cobj( c_ptr , cfunc.free ) + self.init_cobj(c_ptr, cfunc.free) @property def get_eclbase(self): @@ -40,7 +38,7 @@ class EclConfig(CClass): def get_data_file(self): datafile = cfunc.get_data_file(self) return datafile - + @property def get_gridfile(self): gridfile = cfunc.get_gridfile(self) @@ -72,21 +70,22 @@ class EclConfig(CClass): def load_refcase(self, refcase): cfunc.load_refcase(self, refcase) - - @property - def get_static_kw_list(self): - return StringList(c_ptr = cfunc.get_static_kw_list( self ) , parent = self) - @property + @property + def get_static_kw_list(self): + return StringList(c_ptr=cfunc.get_static_kw_list(self), parent=self) + + @property def get_refcase(self): - refcase = EclSum(self.get_refcase_name, join_string = ":" , include_restart = True, c_ptr = cfunc.get_refcase( self ), parent = self) + refcase = EclSum(self.get_refcase_name, join_string=":", include_restart=True, c_ptr=cfunc.get_refcase(self), + parent=self) return refcase - + def clear_static_kw(self): cfunc.clear_static_kw(self) - def add_static_kw(self,kw): - cfunc.add_static_kw(self,kw) + def add_static_kw(self, kw): + cfunc.add_static_kw(self, kw) @property def get_grid(self): @@ -95,28 +94,28 @@ class EclConfig(CClass): @property def get_sched_file(self): return cfunc.get_sched_file(self) -################################################################## -cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "ecl_config" , EclConfig ) + ################################################################## + +cwrapper = CWrapper(libenkf.lib) +cwrapper.registerType("ecl_config", EclConfig) cfunc = CWrapperNameSpace("ecl_config") - -cfunc.free = cwrapper.prototype("void ecl_config_free( ecl_config )") -cfunc.get_eclbase = cwrapper.prototype("char* ecl_config_get_eclbase( ecl_config )") -cfunc.get_data_file = cwrapper.prototype("char* ecl_config_get_data_file(ecl_config)") -cfunc.get_gridfile = cwrapper.prototype("char* ecl_config_get_gridfile(ecl_config)") -cfunc.set_gridfile = cwrapper.prototype("void ecl_config_set_grid(ecl_config, char*)") -cfunc.get_schedule_file = cwrapper.prototype("char* ecl_config_get_schedule_file(ecl_config)") -cfunc.set_schedule_file = cwrapper.prototype("void ecl_config_set_schedule_file(ecl_config, char*)") -cfunc.get_init_section = cwrapper.prototype("char* ecl_config_get_init_section(ecl_config)") -cfunc.set_init_section = cwrapper.prototype("void ecl_config_set_init_section(ecl_config, char*)") -cfunc.get_refcase_name = cwrapper.prototype("char* ecl_config_get_refcase_name(ecl_config)") -cfunc.load_refcase = cwrapper.prototype("void ecl_config_load_refcase(ecl_config, char*)") +cfunc.free = cwrapper.prototype("void ecl_config_free( ecl_config )") +cfunc.get_eclbase = cwrapper.prototype("char* ecl_config_get_eclbase( ecl_config )") +cfunc.get_data_file = cwrapper.prototype("char* ecl_config_get_data_file(ecl_config)") +cfunc.get_gridfile = cwrapper.prototype("char* ecl_config_get_gridfile(ecl_config)") +cfunc.set_gridfile = cwrapper.prototype("void ecl_config_set_grid(ecl_config, char*)") +cfunc.get_schedule_file = cwrapper.prototype("char* ecl_config_get_schedule_file(ecl_config)") +cfunc.set_schedule_file = cwrapper.prototype("void ecl_config_set_schedule_file(ecl_config, char*)") +cfunc.get_init_section = cwrapper.prototype("char* ecl_config_get_init_section(ecl_config)") +cfunc.set_init_section = cwrapper.prototype("void ecl_config_set_init_section(ecl_config, char*)") +cfunc.get_refcase_name = cwrapper.prototype("char* ecl_config_get_refcase_name(ecl_config)") +cfunc.load_refcase = cwrapper.prototype("void ecl_config_load_refcase(ecl_config, char*)") cfunc.get_static_kw_list = cwrapper.prototype("c_void_p ecl_config_get_static_kw_list(ecl_config)") -cfunc.clear_static_kw = cwrapper.prototype("void ecl_config_clear_static_kw(ecl_config)") -cfunc.add_static_kw = cwrapper.prototype("void ecl_config_add_static_kw(ecl_config, char*)") -cfunc.get_grid = cwrapper.prototype("c_void_p ecl_config_get_grid(ecl_config)") -cfunc.get_refcase = cwrapper.prototype("c_void_p ecl_config_get_refcase(ecl_config)") -cfunc.get_sched_file = cwrapper.prototype("c_void_p ecl_config_get_sched_file(ecl_config)") +cfunc.clear_static_kw = cwrapper.prototype("void ecl_config_clear_static_kw(ecl_config)") +cfunc.add_static_kw = cwrapper.prototype("void ecl_config_add_static_kw(ecl_config, char*)") +cfunc.get_grid = cwrapper.prototype("c_void_p ecl_config_get_grid(ecl_config)") +cfunc.get_refcase = cwrapper.prototype("c_void_p ecl_config_get_refcase(ecl_config)") +cfunc.get_sched_file = cwrapper.prototype("c_void_p ecl_config_get_sched_file(ecl_config)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_fs.py b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_fs.py index 96e7cc3d8e..49bae0d6d1 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_fs.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_fs.py @@ -52,6 +52,10 @@ class EnkfFs(CClass): @property def get_time_map(self): return TimeMap(cfunc.get_time_map(self), parent = self) + + @staticmethod + def exists(path): + return cfunc.exists(path) ################################################################## @@ -66,3 +70,4 @@ cfunc.has_vector = cwrapper.prototype("bool enkf_fs_has_vector(enkf_fs, cfunc.fread_node = cwrapper.prototype("void enkf_fs_fread_node(enkf_fs, buffer, char*, c_uint, int, int, c_uint)") cfunc.fread_vector = cwrapper.prototype("void enkf_fs_fread_vector(enkf_fs, buffer, char*, c_uint, int, c_uint)") cfunc.get_time_map = cwrapper.prototype("c_void_p enkf_fs_get_time_map(enkf_fs)") +cfunc.exists = cwrapper.prototype("bool enkf_fs_exists(char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_main.py b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_main.py index 5ded9202e4..229228e369 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_main.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_main.py @@ -15,10 +15,6 @@ # for more details. import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from ert.job_queue.job_queue import JobQueue from ert.enkf.enkf_enum import * from ert.ert.enums import * from ert.enkf.ens_config import * @@ -31,13 +27,14 @@ from ert.enkf.gen_kw_config import * from ert.enkf.gen_data_config import * from ert.enkf.field_config import * from ert.enkf.enkf_obs import * -from ert.enkf.plot_config import * +from ert.enkf.plot_conf import * from ert.enkf.site_config import * from ert.enkf.libenkf import * from ert.enkf.enkf_fs import * from ert.enkf.ert_templates import * from ert.enkf.enkf_state import * -from ert.util.log import * +from ert.util import Log + class EnKFMain(CClass): @@ -102,7 +99,7 @@ class EnKFMain(CClass): @property def plot_config(self): - plot_conf = PlotConfig( c_ptr = cfunc.get_plot_config( self ), parent = self) + plot_conf = PlotConf( c_ptr = cfunc.get_plot_config( self ), parent = self) return plot_conf def set_eclbase(self, eclbase): @@ -240,6 +237,12 @@ class EnKFMain(CClass): def fprintf_config(self): cfunc.fprintf_config(self) + + def select_fs(self,path): + cfunc.select_fs(self,path) + + def fs_exists(self,case): + return cfunc.fs_exists(self,case) ################################################################## @@ -299,3 +302,5 @@ cfunc.get_current_fs = cwrapper.prototype("char* enkf_main_get_cur cfunc.alloc_caselist = cwrapper.prototype("c_void_p enkf_main_alloc_caselist(enkf_main)") cfunc.fprintf_config = cwrapper.prototype("void enkf_main_fprintf_config(enkf_main)") cfunc.create_new_config = cwrapper.prototype("void enkf_main_create_new_config(char* , char*, char* , char* , int)") +cfunc.select_fs = cwrapper.prototype("void enkf_main_select_fs(enkf_main, char*)") +cfunc.fs_exists = cwrapper.prototype("bool enkf_main_fs_exists(enkf_main, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/libenkf.py b/ThirdParty/Ert/devel/python/python/ert/enkf/libenkf.py index 89452d3add..5adf6f9361 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/libenkf.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/libenkf.py @@ -13,9 +13,10 @@ # # See the GNU General Public License at # for more details. -import ert.util.libutil -import ert.ecl.libecl -import ert.job_queue.libjob_queue + +import ert.util +import ert.ecl +import ert.job_queue import ert.rms.librms import ert.cwrap.clib as clib diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/model_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/model_config.py index 1f5aea0808..4c9ce0a684 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/model_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/model_config.py @@ -14,51 +14,46 @@ # See the GNU General Public License at # for more details. -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from enkf_enum import * -from ert.job_queue.forward_model import ForwardModel -from libenkf import * -from ert.sched.libsched import * -from ert.sched.history import HistoryType -from ert.sched.sched_file import * -from ert.ecl.ecl_sum import * -from ert.sched.history import * +import ctypes +from ert.job_queue import ForwardModel +from ert.sched import HistoryType +from libenkf import * +from enkf_enum import * +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace + + class ModelConfig(CClass): - - def __init__(self , c_ptr , parent = None): + def __init__(self, c_ptr, parent=None): if parent: - self.init_cref( c_ptr , parent) + self.init_cref(c_ptr, parent) else: - self.init_cobj( c_ptr , cfunc.free ) + self.init_cobj(c_ptr, cfunc.free) @property def get_enkf_sched_file(self): - return cfunc.get_enkf_sched_file( self ) + return cfunc.get_enkf_sched_file(self) def set_enkf_sched_file(self, file): - cfunc.get_enkf_sched_file( self , file) + cfunc.get_enkf_sched_file(self, file) @property def get_history_source(self): - return HistoryType(c_ptr = cfunc.get_history_source( self ) , parent = self) + return HistoryType(c_ptr=cfunc.get_history_source(self), parent=self) def set_history_source(self, history_source, sched_file, refcase): return cfunc.select_history(self, history_source, sched_file, refcase) - + @property def get_max_internal_submit(self): - return cfunc.get_max_internal_submit( self ) + return cfunc.get_max_internal_submit(self) def set_max_internal_submit(self, max): - cfunc.get_max_internal_submit( self , max) + cfunc.get_max_internal_submit(self, max) - @property + @property def get_forward_model(self): - ford_model = ForwardModel( c_ptr = cfunc.get_forward_model( self ), parent = self) + ford_model = ForwardModel(c_ptr=cfunc.get_forward_model(self), parent=self) return ford_model @property @@ -71,25 +66,27 @@ class ModelConfig(CClass): def select_runpath(self, path_key): return cfunc.select_runpath(self, path_key) -################################################################## -cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "model_config" , ModelConfig ) + ################################################################## + +cwrapper = CWrapper(libenkf.lib) +cwrapper.registerType("model_config", ModelConfig) cfunc = CWrapperNameSpace("model_config") ################################################################## ################################################################## -cfunc.free = cwrapper.prototype("void model_config_free( model_config )") -cfunc.get_enkf_sched_file = cwrapper.prototype("char* model_config_get_enkf_sched_file( model_config )") -cfunc.set_enkf_sched_file = cwrapper.prototype("void model_config_set_enkf_sched_file( model_config, char*)") -cfunc.get_history_source = cwrapper.prototype("c_void_p model_config_get_history_source(model_config)") -cfunc.select_history = cwrapper.prototype("bool model_config_select_history(model_config, history_type, c_void_p, ecl_sum)") -cfunc.get_forward_model = cwrapper.prototype("c_void_p model_config_get_forward_model(model_config)") +cfunc.free = cwrapper.prototype("void model_config_free( model_config )") +cfunc.get_enkf_sched_file = cwrapper.prototype("char* model_config_get_enkf_sched_file( model_config )") +cfunc.set_enkf_sched_file = cwrapper.prototype("void model_config_set_enkf_sched_file( model_config, char*)") +cfunc.get_history_source = cwrapper.prototype("c_void_p model_config_get_history_source(model_config)") +cfunc.select_history = cwrapper.prototype( + "bool model_config_select_history(model_config, history_type, c_void_p, ecl_sum)") +cfunc.get_forward_model = cwrapper.prototype("c_void_p model_config_get_forward_model(model_config)") cfunc.get_max_internal_submit = cwrapper.prototype("int model_config_get_max_internal_submit(model_config)") cfunc.set_max_internal_submit = cwrapper.prototype("void model_config_set_max_internal_submit(model_config, int)") -cfunc.get_case_table_file = cwrapper.prototype("char* model_config_get_case_table_file(model_config)") -cfunc.get_runpath_as_char = cwrapper.prototype("char* model_config_get_runpath_as_char(model_config)") -cfunc.select_runpath = cwrapper.prototype("void model_config_select_runpath(model_config, char*)") +cfunc.get_case_table_file = cwrapper.prototype("char* model_config_get_case_table_file(model_config)") +cfunc.get_runpath_as_char = cwrapper.prototype("char* model_config_get_runpath_as_char(model_config)") +cfunc.select_runpath = cwrapper.prototype("void model_config_select_runpath(model_config, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/plot_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/plot_conf.py similarity index 83% rename from ThirdParty/Ert/devel/python/python/ert/enkf/plot_config.py rename to ThirdParty/Ert/devel/python/python/ert/enkf/plot_conf.py index db97918529..a3f652ad49 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/plot_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/plot_conf.py @@ -1,6 +1,6 @@ # Copyright (C) 2012 Statoil ASA, Norway. # -# The file 'plot_config.py' is part of ERT - Ensemble based Reservoir Tool. +# The file 'plot_conf.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 @@ -21,7 +21,7 @@ from ert.util.tvector import * from enkf_enum import * import ert.enkf.libenkf -class PlotConfig(CClass): +class PlotConf(CClass): def __init__(self , c_ptr , parent = None): if parent: @@ -80,24 +80,24 @@ class PlotConfig(CClass): ################################################################## cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "plot_config" , PlotConfig ) +cwrapper.registerType( "plot_conf" , PlotConf ) -cfunc = CWrapperNameSpace("plot_config") +cfunc = CWrapperNameSpace("plot_conf") ################################################################## ################################################################## -cfunc.free = cwrapper.prototype("void plot_config_free( plot_config )") -cfunc.get_path = cwrapper.prototype("char* plot_config_get_path(plot_config)") -cfunc.set_path = cwrapper.prototype("void plot_config_set_path(plot_config, char*)") -cfunc.get_driver = cwrapper.prototype("char* plot_config_get_driver(plot_config)") -cfunc.set_driver = cwrapper.prototype("void plot_config_set_driver(plot_config, char*)") -cfunc.get_errorbar_max = cwrapper.prototype("int plot_config_get_errorbar_max(plot_config)") -cfunc.set_errorbar_max = cwrapper.prototype("void plot_config_set_errorbar_max(plot_config, int)") -cfunc.get_width = cwrapper.prototype("int plot_config_get_width(plot_config)") -cfunc.set_width = cwrapper.prototype("void plot_config_set_width(plot_config, int)") -cfunc.get_height = cwrapper.prototype("int plot_config_get_height(plot_config)") -cfunc.set_height = cwrapper.prototype("void plot_config_set_height(plot_config, int)") -cfunc.get_viewer = cwrapper.prototype("char* plot_config_get_viewer(plot_config)") -cfunc.set_viewer = cwrapper.prototype("void plot_config_set_viewer(plot_config, char*)") -cfunc.get_image_type = cwrapper.prototype("char* plot_config_get_image_type(plot_config)") -cfunc.set_image_type = cwrapper.prototype("void plot_config_set_image_type(plot_config, char*)") +cfunc.free = cwrapper.prototype("void plot_config_free( plot_conf )") +cfunc.get_path = cwrapper.prototype("char* plot_config_get_path(plot_conf)") +cfunc.set_path = cwrapper.prototype("void plot_config_set_path(plot_conf, char*)") +cfunc.get_driver = cwrapper.prototype("char* plot_config_get_driver(plot_conf)") +cfunc.set_driver = cwrapper.prototype("void plot_config_set_driver(plot_conf, char*)") +cfunc.get_errorbar_max = cwrapper.prototype("int plot_config_get_errorbar_max(plot_conf)") +cfunc.set_errorbar_max = cwrapper.prototype("void plot_config_set_errorbar_max(plot_conf, int)") +cfunc.get_width = cwrapper.prototype("int plot_config_get_width(plot_conf)") +cfunc.set_width = cwrapper.prototype("void plot_config_set_width(plot_conf, int)") +cfunc.get_height = cwrapper.prototype("int plot_config_get_height(plot_conf)") +cfunc.set_height = cwrapper.prototype("void plot_config_set_height(plot_conf, int)") +cfunc.get_viewer = cwrapper.prototype("char* plot_config_get_viewer(plot_conf)") +cfunc.set_viewer = cwrapper.prototype("void plot_config_set_viewer(plot_conf, char*)") +cfunc.get_image_type = cwrapper.prototype("char* plot_config_get_image_type(plot_conf)") +cfunc.set_image_type = cwrapper.prototype("void plot_config_set_image_type(plot_conf, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/site_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/site_config.py index 6fd69b037c..6c121b85b1 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/site_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/site_config.py @@ -15,15 +15,12 @@ # for more details. import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * from enkf_enum import * +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.job_queue import ExtJoblist, JobQueue +from ert.util import StringList import libenkf from ert.enkf.libenkf import * -from ert.job_queue.ext_joblist import ExtJoblist -from ert.job_queue.job_queue import JobQueue -from ert.util.stringlist import StringList @@ -143,7 +140,6 @@ class SiteConfig(CClass): def queue_is_running(self): return cfunc.queue_is_running( self ) - @property def get_job_queue(self): return JobQueue( c_ptr = cfunc.get_job_queue(self), parent = self) diff --git a/ThirdParty/Ert/devel/python/python/ert/ert/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/ert/CMakeLists.txt index 290956e8d9..615ca11b3c 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ert/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/ert/CMakeLists.txt @@ -1 +1,9 @@ -add_python_package( "Python ert.ert" ${PYTHON_INSTALL_PREFIX}/ert/ert "__init__.py;enums.py;erttypes.py;ertwrapper.py;c_enums.py" True) +set(PYTHON_SOURCES + __init__.py + enums.py + erttypes.py + ertwrapper.py + c_enums.py +) + +add_python_package( "Python ert.ert" ${PYTHON_INSTALL_PREFIX}/ert/ert "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/ert/enums.py b/ThirdParty/Ert/devel/python/python/ert/ert/enums.py index 0825ada781..fb957139d8 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ert/enums.py +++ b/ThirdParty/Ert/devel/python/python/ert/ert/enums.py @@ -194,6 +194,9 @@ class ert_job_status_type(enum): ALL_FAIL = None USER_KILLED = None USER_EXIT = None + SUCCESS = None + RUNNING_CALLBACK = None + FAILED = None ert_job_status_type.NOT_ACTIVE = ert_job_status_type("JOB_QUEUE_NOT_ACTIVE", 1) ert_job_status_type.LOADING = ert_job_status_type("JOB_QUEUE_LOADING", 2) @@ -209,6 +212,11 @@ ert_job_status_type.ALL_OK = ert_job_status_type("JOB_QUEUE_ALL_OK", 1024) ert_job_status_type.ALL_FAIL = ert_job_status_type("JOB_QUEUE_ALL_FAIL", 2048) ert_job_status_type.USER_KILLED = ert_job_status_type("JOB_QUEUE_USER_KILLED", 4096) ert_job_status_type.USER_EXIT = ert_job_status_type("JOB_QUEUE_USER_EXIT", 8192) +ert_job_status_type.SUCCESS = ert_job_status_type("JOB_QUEUE_SUCCESS", 16384) +ert_job_status_type.RUNNING_CALLBACK = ert_job_status_type("JOB_QUEUE_RUNNING_CALLBACK", 32768) +ert_job_status_type.JOB_QUEUE_FAILED = ert_job_status_type("JOB_QUEUE_FAILED", 65536) + + class gen_data_file_format(enum): diff --git a/ThirdParty/Ert/devel/python/python/ert/ert/ertwrapper.py b/ThirdParty/Ert/devel/python/python/ert/ert/ertwrapper.py index 2d4a823efb..39f4929748 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ert/ertwrapper.py +++ b/ThirdParty/Ert/devel/python/python/ert/ert/ertwrapper.py @@ -12,19 +12,20 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from _ctypes import RTLD_GLOBAL - - -from ctypes import * -import ctypes.util import atexit +from ctypes import CDLL +import ctypes import re import sys import os +from ert.ecl import ECL_LIB +from ert.enkf import libenkf +from ert.job_queue import JOB_QUEUE_LIB +from ert.util import UTIL_LIB import erttypes -import ert -#import ert.enkf.enkf as enkf import ert.enkf.enkf_main as enkf def RH_version(): @@ -64,11 +65,8 @@ class ErtWrapper: def __loadLibraries(self ): """Load libraries that are required by ERT and ERT itself""" - CDLL("libblas.so" , RTLD_GLOBAL) - CDLL("liblapack.so" , RTLD_GLOBAL) - CDLL("libz.so" , RTLD_GLOBAL) CDLL("libnsl.so" , RTLD_GLOBAL) - + LSF_HOME = os.getenv("LSF_HOME") if LSF_HOME: CDLL("%s/lib/liblsf.so" % LSF_HOME , RTLD_GLOBAL) @@ -76,16 +74,10 @@ class ErtWrapper: else: sys.exit("Need a value for environment variable LSF_HOME") - self.util = self.__loadLibrary( "libert_util" ) - self.__loadLibrary( "libert_geometry" ) - self.ecl = self.__loadLibrary( "libecl" ) - self.__loadLibrary( "libsched" ) - self.__loadLibrary( "librms" ) - self.__loadLibrary( "libconfig" ) - self.__loadLibrary( "libanalysis" ) - self.job_queue = self.__loadLibrary( "libjob_queue" ) - self.enkf = self.__loadLibrary( "libenkf" ) - + self.util = UTIL_LIB + self.ecl = ECL_LIB + self.job_queue = JOB_QUEUE_LIB + self.enkf = libenkf.lib self.enkf.enkf_main_install_SIGNALS() @@ -232,7 +224,7 @@ class ErtWrapper: def __getErtPointer(self, function): """Returns a pointer from ERT as a c_long (64-bit support)""" func = getattr( self.enkf, function ) - func.restype = c_long # Should be c_size_t - if that exists. + func.restype = ctypes.c_long # Should be c_size_t - if that exists. return func( self.main ) diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/geo/CMakeLists.txt index f2337e0759..99166aa0b4 100644 --- a/ThirdParty/Ert/devel/python/python/ert/geo/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/geo/CMakeLists.txt @@ -1 +1,6 @@ -add_python_package("Python ert.geo" ${PYTHON_INSTALL_PREFIX}/ert/geo "geo_polygon.py;geo.py;__init__.py;libgeo.py" True) +set(PYTHON_SOURCES + __init__.py + geo_polygon.py +) + +add_python_package("Python ert.geo" ${PYTHON_INSTALL_PREFIX}/ert/geo "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/__init__.py b/ThirdParty/Ert/devel/python/python/ert/geo/__init__.py index ced6e30bc0..133eca3906 100644 --- a/ThirdParty/Ert/devel/python/python/ert/geo/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/geo/__init__.py @@ -15,4 +15,13 @@ # for more details. """ Simple package for working with 2D geometry. + """ +from ert.cwrap import clib + +import ert.util + +ERT_GEOMETRY_LIB = clib.ert_load("libert_geometry.so") + +from .geo_polygon import GeoPolygon + diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/geo.py b/ThirdParty/Ert/devel/python/python/ert/geo/geo.py deleted file mode 100644 index d447d535a0..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/geo/geo.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'geo.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 importing all symbols in the geo package. -""" -import libgeo -from geo_polygon import GeoPolygon - diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/geo_polygon.py b/ThirdParty/Ert/devel/python/python/ert/geo/geo_polygon.py index 47a8756c64..52fcf180cb 100644 --- a/ThirdParty/Ert/devel/python/python/ert/geo/geo_polygon.py +++ b/ThirdParty/Ert/devel/python/python/ert/geo/geo_polygon.py @@ -16,32 +16,28 @@ """ Create a polygon """ +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.geo import ERT_GEOMETRY_LIB -import ctypes -import libgeo -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass - class GeoPolygon(CClass): - - def __init__(self , points): + def __init__(self, points): c_ptr = cfunc.alloc_new() - self.init_cobj( c_ptr , cfunc.free ) - for (xc,yz) in points: - self.add_point( self , xc , yc ) + self.init_cobj(c_ptr, cfunc.free) + for (xc, yc) in points: + self.add_point(xc, yc) - def add_point( self , xc , yc ): - cfunc.add_point( self , xc , yc ) + def add_point( self, xc, yc ): + cfunc.add_point(self, xc, yc) ################################################################# -cwrapper = CWrapper( libgeo.lib ) -cwrapper.registerType( "geo_polygon" , GeoPolygon ) +cwrapper = CWrapper(ERT_GEOMETRY_LIB) +cwrapper.registerType("geo_polygon", GeoPolygon) -cfunc = CWrapperNameSpace("geo_polygon") -cfunc.alloc_new = cwrapper.prototype("c_void_p geo_polygon_alloc( )") -cfunc.add_point = cwrapper.prototype("void geo_polygon_add_point( geo_polygon , double , double )") -cfunc.free = cwrapper.prototype("void geo_polygon_free( geo_polygon )") +cfunc = CWrapperNameSpace("geo_polygon") +cfunc.alloc_new = cwrapper.prototype("c_void_p geo_polygon_alloc( )") +cfunc.add_point = cwrapper.prototype("void geo_polygon_add_point( geo_polygon , double , double )") +cfunc.free = cwrapper.prototype("void geo_polygon_free( geo_polygon )") diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/libgeo.py b/ThirdParty/Ert/devel/python/python/ert/geo/libgeo.py deleted file mode 100644 index 51a82db28b..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/geo/libgeo.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libecl.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. -""" -This module will load the libgeometry.so shared library. -""" - -# This statement is necessary for side-effects (i.e. the final -# dlopen("libutil.so") call). -import ctypes -import ert.util.libutil -import ert.cwrap.clib as clib - -lib = clib.ert_load("libert_geometry.so") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/job_queue/CMakeLists.txt index a7d4e1102e..77386d8609 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/CMakeLists.txt @@ -1 +1,11 @@ -add_python_package("Python ert.job_queue" ${PYTHON_INSTALL_PREFIX}/ert/job_queue "driver.py;__init__.py;job.py;job_queue.py;libjob_queue.py;queue.py;ext_job.py;ext_joblist.py;forward_model.py" True) +set(PYTHON_SOURCES + __init__.py + driver.py + job.py + queue.py + ext_job.py + ext_joblist.py + forward_model.py +) + +add_python_package("Python ert.job_queue" ${PYTHON_INSTALL_PREFIX}/ert/job_queue "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/__init__.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/__init__.py index 59776ca4de..97e06ca9e9 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/__init__.py @@ -18,3 +18,64 @@ The job_queue package contains modules and classes for running external commands. """ +# Getting LSF to work properly is quite painful. The situation +# is a mix of build complexity and LSF specific requirements: +# +# 1. The LSF libraries are accessed from the libjob_queue.so +# library, but observe that the dependancy on the liblsf and +# libbat libraries is through dlopen(), i.e. runtime. This module +# will therefor load happily without access to the lsf libraries. +# +# If you at a later stage create a lsf driver the runtime +# environment must be able to locate the liblsf.so, libbat.so and +# libnsl.so shared libraries, either through LD_LIBRARY_PATH or +# other means. +# +# 2. To actually use LSF you need a whole list of environment +# variables to be set: LSF_BINDIR , LSF_LIBDIR , XLDF_UIDDIR , +# LSF_SERVERDIR, LSF_ENVDIR - this is an LSF requirement and not +# related to ERT or the Python bindings. The normal way to +# achieve this is by sourcing a shell script. +# +# If the environment variable LSF_HOME is set we set the +# remaining LSF variables according to: +# +# LSF_BINDIR = $LSF_HOME/bin +# LSF_LIBDIR = $LSF_HOME/lib +# XLSF_UIDDIR = $LSF_HOME/lib/uid +# LSF_SERVERDIR = $LSF_HOME/etc +# LSF_ENVDIR = $LSF_HOME/conf +# PATH = $PATH:$LSF_BINDIR +# +# Observe that none of these variables are modified if they +# already have a value, furthermore it should be observed that +# the use of an LSF_HOME variable is something invented with ERT, +# and not standard LSF approach. + + +import os +import ert.util +import ert.cwrap.clib as clib + + +def setenv( var, value): + if not os.getenv(var): + os.environ[var] = value + +# Set up the full LSF environment - based onf LSF_HOME +LSF_HOME = os.getenv("LSF_HOME") +if LSF_HOME: + setenv("LSF_BINDIR", "%s/bin" % LSF_HOME) + setenv("LSF_LIBDIR", "%s/lib" % LSF_HOME) + setenv("XLSF_UIDDIR", "%s/lib/uid" % LSF_HOME) + setenv("LSF_SERVERDIR", "%s/etc" % LSF_HOME) + setenv("LSF_ENVDIR", "%s/conf" % LSF_HOME) # This is wrong: Statoil: /prog/LSF/conf + +JOB_QUEUE_LIB = clib.ert_load("libjob_queue.so") + +from .job import Job +from .queue import JobList, JobQueue, statusList, exList, runtimeList +from .driver import QueueDriverEnum, Driver, LSFDriver, RSHDriver, LocalDriver +from .ext_job import ExtJob +from .ext_joblist import ExtJoblist +from .forward_model import ForwardModel \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/driver.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/driver.py index 27b84d9fcb..075c7243bb 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/driver.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/driver.py @@ -16,136 +16,134 @@ import ctypes -import os.path +from ert.cwrap import create_enum, CClass, CWrapper, CWrapperNameSpace -import libjob_queue -from job import Job -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.cwrap.cenum import create_enum +from ert.job_queue import JOB_QUEUE_LIB, Job -# job_driver_type defintion from queue_driver.h -create_enum( libjob_queue.lib , "queue_driver_type_enum_iget" , "queue_driver_enum" , globals()) +QueueDriverEnum = create_enum(JOB_QUEUE_LIB, "queue_driver_type_enum_iget", "QueueDriverEnum") + class Driver(CClass): - def __init__( self , type , max_running = 1 , options = None): + def __init__( self, driver_type, max_running=1, options=None): """ Creates a new driver instance """ - c_ptr = cfunc.alloc_driver( type ) - self.init_cobj( c_ptr , cfunc.free_driver ) + c_ptr = cfunc.alloc_driver(driver_type) + self.init_cobj(c_ptr, cfunc.free_driver) if options: - for (key,value) in options: - self.set_option( key , value ) - self.set_max_running( max_running ) + for (key, value) in options: + self.set_option(key, value) + self.set_max_running(max_running) - def set_option(self , option , value): + def set_option(self, option, value): """ Set the driver option @option to @value. - If the option is sucessfully set the method will return True, + If the option is succlessfully set the method will return True, otherwise the method will return False. If the @option is not recognized the method will return False. The supplied value should be a string. """ - return cfunc.set_str_option( self , option , str(value) ) - + return cfunc.set_str_option(self, option, str(value)) + def is_driver_instance( self ): return True - def submit( self , name , cmd , run_path , argList , num_cpu = 1 , blocking = False): - argc = len( argList ) + def submit( self, name, cmd, run_path, argList, num_cpu=1, blocking=False): + argc = len(argList) argv = (ctypes.c_char_p * argc)() - argv[:] = map( str , argList ) - job_c_ptr = cfunc.submit( self , cmd , num_cpu , run_path , name , argc , argv ) - job = Job( self , job_c_ptr , blocking ) + argv[:] = map(str, argList) + job_c_ptr = cfunc.submit(self, cmd, num_cpu, run_path, name, argc, argv) + job = Job(self, job_c_ptr, blocking) if blocking: job.block() job = None return job - def free_job( self , job ): - cfunc.free_job( self , job ) - - def get_status( self , job ): - status = cfunc.cget_status( self , job ) + def free_job( self, job ): + cfunc.free_job(self, job) + + def get_status( self, job ): + status = cfunc.cget_status(self, job) return status - - def kill_job( self , job ): - cfunc.ckill_job( self , job ) + + def kill_job( self, job ): + cfunc.ckill_job(self, job) def get_max_running( self ): - return cfunc.get_max_running( self ) - - def set_max_running( self , max_running ): - cfunc.set_max_running( self , max_running ) - - max_running = property( get_max_running , set_max_running ) + return cfunc.get_max_running(self) + + def set_max_running( self, max_running ): + cfunc.set_max_running(self, max_running) + + max_running = property(get_max_running, set_max_running) + + @property + def name(self): + return cfunc.get_name(self) class LSFDriver(Driver): - - def __init__(self , - max_running , - lsf_server = None , - queue = "normal" , - resource_request = None): - + def __init__(self, + max_running, + lsf_server=None, + queue="normal", + resource_request=None): # The strings should match the available keys given in the # lsf_driver.h header file. - options = [("LSF_QUEUE" , queue), - ("LSF_SERVER" , lsf_server), - ("LSF_RESOURCE" , resource_request )] - Driver.__init__( self , LSF_DRIVER , max_running = max_running , options = options) - + options = [("LSF_QUEUE", queue), + ("LSF_SERVER", lsf_server), + ("LSF_RESOURCE", resource_request )] + Driver.__init__(self, QueueDriverEnum.LSF_DRIVER, max_running=max_running, options=options) + class LocalDriver(Driver): - - def __init__( self , max_running ): - Driver.__init__( self , LOCAL_DRIVER , max_running , options = [] ) - - + def __init__( self, max_running ): + Driver.__init__(self, QueueDriverEnum.LOCAL_DRIVER, max_running, options=[]) class RSHDriver(Driver): - # Changing shell to bash can come in conflict with running ssh # commands. - - def __init__( self , max_running , rsh_host_list , rsh_cmd = "/usr/bin/ssh" ): + + def __init__( self, max_running, rsh_host_list, rsh_cmd="/usr/bin/ssh" ): """ @rsh_host_list should be a list of tuples like: (hostname , max_running) """ - - options = [("RSH_CMD" , rsh_cmd)] - for (host,host_max) in rsh_host_list: - options.append( ("RSH_HOST" , "%s:%d" % (host , host_max)) ) - Driver.__init__( self , RSH_DRIVER , max_running , options = options ) - + + options = [("RSH_CMD", rsh_cmd)] + for (host, host_max) in rsh_host_list: + options.append(("RSH_HOST", "%s:%d" % (host, host_max))) + Driver.__init__(self, QueueDriverEnum.RSH_DRIVER, max_running, options=options) +#Legacy enum support for ecl_local.py +LSF_DRIVER = QueueDriverEnum.LSF_DRIVER +RSH_DRIVER = QueueDriverEnum.RSH_DRIVER +LOCAL_DRIVER = QueueDriverEnum.LOCAL_DRIVER ################################################################# -cwrapper = CWrapper( libjob_queue.lib ) -cwrapper.registerType( "driver" , Driver ) -cwrapper.registerType( "job" , Job ) -cfunc = CWrapperNameSpace( "driver" ) +cwrapper = CWrapper(JOB_QUEUE_LIB) +cwrapper.registerType("driver", Driver) +cwrapper.registerType("job", Job) +cfunc = CWrapperNameSpace("driver") -cfunc.alloc_driver_lsf = cwrapper.prototype("c_void_p queue_driver_alloc_LSF( char* , char* , char* )") -cfunc.alloc_driver_local = cwrapper.prototype("c_void_p queue_driver_alloc_local( )") -cfunc.alloc_driver_rsh = cwrapper.prototype("c_void_p queue_driver_alloc_RSH( char* , c_void_p )") -cfunc.alloc_driver = cwrapper.prototype("c_void_p queue_driver_alloc( int )") -cfunc.set_driver_option = cwrapper.prototype("void queue_driver_set_option(driver , char* , char*)") +cfunc.alloc_driver_lsf = cwrapper.prototype("c_void_p queue_driver_alloc_LSF( char* , char* , char* )") +cfunc.alloc_driver_local = cwrapper.prototype("c_void_p queue_driver_alloc_local( )") +cfunc.alloc_driver_rsh = cwrapper.prototype("c_void_p queue_driver_alloc_RSH( char* , c_void_p )") +cfunc.alloc_driver = cwrapper.prototype("c_void_p queue_driver_alloc( int )") +cfunc.set_driver_option = cwrapper.prototype("void queue_driver_set_option(driver , char* , char*)") -cfunc.free_driver = cwrapper.prototype("void queue_driver_free( driver )") -cfunc.submit = cwrapper.prototype("c_void_p queue_driver_submit_job( driver , char* , int , char* , char* , int , char**)") -cfunc.free_job = cwrapper.prototype("void queue_driver_free_job( driver , job )") -cfunc.cget_status = cwrapper.prototype("int job_queue_get_status( driver , job)") -cfunc.kill_job = cwrapper.prototype("void queue_driver_kill_job( driver , job )") +cfunc.free_driver = cwrapper.prototype("void queue_driver_free( driver )") +cfunc.submit = cwrapper.prototype("c_void_p queue_driver_submit_job( driver , char* , int , char* , char* , int , char**)") +cfunc.free_job = cwrapper.prototype("void queue_driver_free_job( driver , job )") +cfunc.cget_status = cwrapper.prototype("int job_queue_get_status( driver , job)") +cfunc.kill_job = cwrapper.prototype("void queue_driver_kill_job( driver , job )") cfunc.set_max_running = cwrapper.prototype("void queue_driver_set_max_running( driver , int )") cfunc.get_max_running = cwrapper.prototype("int queue_driver_get_max_running( driver )") - +cfunc.set_str_option = cwrapper.prototype("bool queue_driver_set_option( driver , char* , char*) ") +cfunc.get_name = cwrapper.prototype("char* queue_driver_get_name(driver)") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_job.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_job.py index 3031e62c35..7f8f4bd396 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_job.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_job.py @@ -12,94 +12,90 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.job_queue import JOB_QUEUE_LIB -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -import libjob_queue class ExtJob(CClass): - - def __init__(self , c_ptr , parent = None): + def __init__(self, c_ptr, parent=None): if parent: - self.init_cref( c_ptr , parent) + self.init_cref(c_ptr, parent) else: - self.init_cobj( c_ptr , cfunc.free ) - + self.init_cobj(c_ptr, cfunc.free) + @property def get_private_args_as_string(self): return cfunc.get_private_args_as_string(self) def set_private_args_as_string(self, args): - cfunc.set_private_args_as_string(self, args) + cfunc.set_private_args_as_string(self, args) @property def get_help_text(self): return cfunc.get_help_text(self) - + @property def is_private(self): return cfunc.is_private(self) - + @property def get_config_file(self): return cfunc.get_config_file(self) - + def set_config_file(self, config_file): - cfunc.set_config_file - + cfunc.set_config_file(self, config_file) + @property def get_stdin_file(self): return cfunc.get_stdin_file(self) - - def set_stdin_file(self, file): - cfunc.set_stdin_file(self, file) - - @property + + def set_stdin_file(self, filename): + cfunc.set_stdin_file(self, filename) + + @property def get_stdout_file(self): return cfunc.get_stdout_file(self) - def set_stdout_file(self, file): - cfunc.set_stdout_file(self, file) - - @property + def set_stdout_file(self, filename): + cfunc.set_stdout_file(self, filename) + + @property def get_stderr_file(self): return cfunc.get_stderr_file(self) - def set_stderr_file(self, file): - cfunc.set_stderr_file(self, file) + def set_stderr_file(self, filename): + cfunc.set_stderr_file(self, filename) @property def get_target_file(self): return cfunc.get_target_file(self) - def set_target_file(self, file): - cfunc.set_target_file(self, file) - - @property + def set_target_file(self, filename): + cfunc.set_target_file(self, filename) + + @property def get_executable(self): return cfunc.get_executable(self) def set_executable(self, executable): cfunc.set_executable(self, executable) - - @property + + @property def get_max_running(self): return cfunc.get_max_running(self) def set_max_running(self, max_running): cfunc.set_max_running(self, max_running) - - @property + + @property def get_max_running_minutes(self): return cfunc.get_max_running_minutes(self) - def set_max_running_minutes(self, min): - cfunc.set_max_running_minutes(self, min) - - @property + def set_max_running_minutes(self, min_value): + cfunc.set_max_running_minutes(self, min_value) + + @property def get_environment(self): return cfunc.get_environment(self) @@ -107,29 +103,28 @@ class ExtJob(CClass): cfunc.set_environment(self, key, value) def clear_environment(self): - cfunc. clear_environment(self) - + cfunc.clear_environment(self) + def save(self): cfunc.save(self) @staticmethod def alloc(name, root_path, private): - job = ExtJob(c_ptr = cfunc.alloc(name, root_path, private)) + job = ExtJob(c_ptr=cfunc.alloc(name, root_path, private)) return job @staticmethod def fscanf_alloc(name, root_path, private, config_file): - job = ExtJob(c_ptr = cfunc.fscanf_alloc(name, root_path, private, config_file)) + job = ExtJob(c_ptr=cfunc.fscanf_alloc(name, root_path, private, config_file)) return job ################################################################## -cwrapper = CWrapper( libjob_queue.lib ) -cwrapper.registerType( "ext_job" , ExtJob ) +cwrapper = CWrapper(JOB_QUEUE_LIB) +cwrapper.registerType("ext_job", ExtJob) cfunc = CWrapperNameSpace("ext_job") -################################################################## -################################################################## + cfunc.free = cwrapper.prototype("void ext_job_free( ext_job )") cfunc.get_help_text = cwrapper.prototype("char* ext_job_get_help_text(ext_job)") cfunc.get_private_args_as_string = cwrapper.prototype("char* ext_job_get_private_args_as_string(ext_job)") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_joblist.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_joblist.py index 855312173b..6472304c2f 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_joblist.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_joblist.py @@ -12,17 +12,12 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.job_queue import JOB_QUEUE_LIB, ExtJob +from ert.util import StringList + -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from ert.enkf.enkf_enum import * -import ert.enkf.libenkf -from ert.util.stringlist import StringList -from ert.job_queue.ext_job import ExtJob -import libjob_queue class ExtJoblist(CClass): def __init__(self , c_ptr , parent = None): @@ -52,8 +47,9 @@ class ExtJoblist(CClass): cfunc.add_job(self, job_name, new_job) ################################################################## -cwrapper = CWrapper( libjob_queue.lib ) +cwrapper = CWrapper(JOB_QUEUE_LIB) cwrapper.registerType( "ext_joblist" , ExtJoblist ) + cfunc = CWrapperNameSpace("ext_joblist") ################################################################## ################################################################## diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/forward_model.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/forward_model.py index 2dd6db1d17..9966aad3b3 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/forward_model.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/forward_model.py @@ -12,17 +12,12 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.job_queue import ExtJob, JOB_QUEUE_LIB +from ert.util import StringList + -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from ert.enkf.enkf_enum import * -from ert.enkf.libenkf import * -import libjob_queue -from ert.util.stringlist import StringList -from ert.job_queue.ext_job import ExtJob class ForwardModel(CClass): def __init__(self , c_ptr , parent = None): @@ -48,7 +43,7 @@ class ForwardModel(CClass): cfunc.clear(self) ################################################################## -cwrapper = CWrapper( libjob_queue.lib ) +cwrapper = CWrapper(JOB_QUEUE_LIB) cwrapper.registerType( "forward_model" , ForwardModel ) cfunc = CWrapperNameSpace("forward_model") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/job.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/job.py index 0f66d68be6..25367bb3f4 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/job.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/job.py @@ -17,36 +17,34 @@ import time import datetime -import ctypes -from ert.cwrap.cclass import CClass +from ert.cwrap.cclass import CClass # Enum values nicked from libjob_queue/src/basic_queue_driver.h -STATUS_PENDING = 16 -STATUS_RUNNING = 32 -STATUS_DONE = 64 -STATUS_EXIT = 128 +STATUS_PENDING = 16 +STATUS_RUNNING = 32 +STATUS_DONE = 64 +STATUS_EXIT = 128 class Job(CClass): - def __init__(self , driver , c_ptr , queue_index , blocking = False): - self.driver = driver - self.init_cobj( c_ptr , self.driver.free_job) + def __init__(self, driver, c_ptr, queue_index, blocking=False): + self.driver = driver + self.init_cobj(c_ptr, self.driver.free_job) self.submit_time = datetime.datetime.now() self.queue_index = queue_index - def block( self ): while True: status = self.status() if status == STATUS_DONE or status == STATUS_EXIT: break else: - time.sleep( 1 ) - + time.sleep(1) + def kill( self ): - self.driver.kill_job( self ) - + self.driver.kill_job(self) + @property def run_time( self ): @@ -55,12 +53,12 @@ class Job(CClass): @property def status( self ): - st = self.driver.get_status( self ) + st = self.driver.get_status(self) return st @property def running( self ): - status = self.driver.get_status( self ) + status = self.driver.get_status(self) if status == STATUS_RUNNING: return True else: @@ -69,7 +67,7 @@ class Job(CClass): @property def pending( self ): - status = self.driver.get_status( self ) + status = self.driver.get_status(self) if status == STATUS_PENDING: return True else: @@ -77,7 +75,7 @@ class Job(CClass): @property def complete( self ): - status = self.driver.get_status( self ) + status = self.driver.get_status(self) if status == STATUS_DONE or status == STATUS_EXIT: return True else: diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/job_queue.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/job_queue.py deleted file mode 100644 index 1fcda04d1b..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/job_queue.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'job_queue.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 doc -""" -import libjob_queue -from queue import JobQueue -from driver import Driver -from job import Job - -import ext_job -import ext_joblist -import forward_model diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/libjob_queue.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/libjob_queue.py deleted file mode 100644 index 2615a4c36b..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/libjob_queue.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libjob_queue.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 sys -import ctypes -import ert.util.libutil -import ert.config.libconfig -import ert.cwrap.clib as clib - - -# Getting LSF to work properly is quite painful. The situation -# is a mix of build complexity and LSF specific requirements: -# -# 1. The LSF libraries are accessed from the libjob_queue.so -# library, but observe that the dependancy on the liblsf and -# libbat libraries is through dlopen(), i.e. runtime. This module -# will therefor load happily without access to the lsf libraries. -# -# If you at a later stage create a lsf driver the runtime -# environment must be able to locate the liblsf.so, libbat.so and -# libnsl.so shared libraries, either through LD_LIBRARY_PATH or -# other means. -# -# 2. To actually use LSF you need a whole list of environment -# variables to be set: LSF_BINDIR , LSF_LIBDIR , XLDF_UIDDIR , -# LSF_SERVERDIR, LSF_ENVDIR - this is an LSF requirement and not -# related to ERT or the Python bindings. The normal way to -# achieve this is by sourcing a shell script. -# -# If the environment variable LSF_HOME is set we set the -# remaining LSF variables according to: -# -# LSF_BINDIR = $LSF_HOME/bin -# LSF_LIBDIR = $LSF_HOME/lib -# XLSF_UIDDIR = $LSF_HOME/lib/uid -# LSF_SERVERDIR = $LSF_HOME/etc -# LSF_ENVDIR = $LSF_HOME/conf -# PATH = $PATH:$LSF_BINDIR -# -# Observe that none of these variables are modified if they -# already have a value, furthermore it should be observed that -# the use of an LSF_HOME variable is something invented with ERT, -# and not standard LSF approach. - - -def setenv( var , value): - if not os.getenv( var ): - os.environ[ var ] = value - -# Set up the full LSF environment - based onf LSF_HOME -LSF_HOME = os.getenv( "LSF_HOME") -if LSF_HOME: - setenv( "LSF_BINDIR" , "%s/bin" % LSF_HOME ) - setenv( "LSF_LIBDIR" , "%s/lib" % LSF_HOME ) - setenv( "XLSF_UIDDIR" , "%s/lib/uid" % LSF_HOME ) - setenv( "LSF_SERVERDIR" , "%s/etc" % LSF_HOME) - setenv( "LSF_ENVDIR" , "%s/conf" % LSF_HOME) # This is wrong: Statoil: /prog/LSF/conf - -lib = clib.ert_load("libjob_queue.so") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/queue.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/queue.py index 517e47e38a..b9ab94a26b 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/queue.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/queue.py @@ -16,77 +16,69 @@ """ Module implementing a queue for managing external jobs. - """ +import time +import ctypes -import time -import threading -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass +from types import StringType, IntType # Need to import this to ensure that the ctime type is registered -import ert.util.ctime +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace from ert.util.ctime import ctime -import libjob_queue +from ert.job_queue import JOB_QUEUE_LIB, Job -from job import Job - - class JobList: def __init__(self): self.job_list = [] self.job_dict = {} - - def __getitem__(self , index): + + def __getitem__(self, index): job = None - if isinstance(index , types.StringType): - job = self.job_dict.get( index ) - elif isinstance(index , types.IntType): + if isinstance(index, StringType): + job = self.job_dict.get(index) + elif isinstance(index, IntType): try: job = self.job_list[index] - except: + except LookupError: job = None return job - def add_job( self , job , job_name ): - job_index = len( self.job_list ) + def add_job( self, job, job_name ): + job_index = len(self.job_list) job.job_nr = job_index - self.job_dict[ job_name ] = job - self.job_list.append( job ) - + self.job_dict[job_name] = job + self.job_list.append(job) + @property def size(self): - return len( self.job_list ) - + return len(self.job_list) class exList: - def __init__(self , joblist): - self.joblist = joblist + def __init__(self, job_list): + self.job_list = job_list - def __getitem__(self , index): - job = self.joblist.__getitem__(index) + def __getitem__(self, index): + job = self.job_list.__getitem__(index) if job: return True else: return False - class statusList: - def __init__(self , joblist ): - self.joblist = joblist + def __init__(self, job_list ): + self.job_list = job_list - def __getitem__(self , index): - job = self.joblist.__getitem__(index) + def __getitem__(self, index): + job = self.job_list.__getitem__(index) if job: return job.status() else: @@ -94,16 +86,16 @@ class statusList: class runtimeList: - def __init__(self , joblist , queue): - self.joblist = joblist - self.queue = queue + def __init__(self, job_list, queue): + self.job_list = job_list + self.queue = queue - def __getitem__(self , index): - job = self.joblist.__getitem__(index) + def __getitem__(self, index): + job = self.job_list.__getitem__(index) if job: - sim_start = cfunc.iget_sim_start( self.queue , job.job_nr ) + sim_start = cfunc.iget_sim_start(self.queue, job.job_nr) if not sim_start.ctime() == -1: - return time.time( ) - sim_start.ctime() + return time.time() - sim_start.ctime() else: return None else: @@ -111,7 +103,6 @@ class runtimeList: class JobQueue(CClass): - # If the queue is created with size == 0 that means that it will # just grow as needed; for the queue layer to know when to exit # you must call the function submit_complete() when you have no @@ -122,69 +113,59 @@ class JobQueue(CClass): # necessary to explitly inform the queue layer when all jobs have # been submitted. - #def __init__(self , driver = None, max_submit = 1 , size = 0, c_ptr = None): - # """ - # SHort doc... - # - # - # - # The @size argument is used to say how many jobs the queue will - # run, in total. -# -# size = 0: That means that you do not tell the queue in -# advance how many jobs you have. The queue will just run -# all the jobs you add, but you have to inform the queue in -# some way that all jobs have been submitted. To achieve -# this you should call the submit_complete() method when all -# jobs have been submitted.# -# -# size > 0: The queue will now exactly how many jobs to run, -# and will continue until this number of jobs have completed -# - it is not necessary to call the submit_complete() method -# in this case. -# """ -# -# OK_file = None -# exit_file = None -# if c_ptr: -# self.init_cobj( c_ptr , cfunc.free_queue ) -# else: -# c_ptr = cfunc.stringlist_alloc( ) -# self.init_cobj( c_ptr , cfunc.free_queue ) -# -# self.jobs = JobList() -# self.size = size -# -# self.exists = exList( self.jobs ) -# self.status = statusList( self.jobs ) -# self.run_time = runtimeList( self.jobs , self ) -# -# self.start( blocking = False ) -# if driver: -# self.driver = driver -# cfunc.set_driver( self , driver.c_ptr ) - def __init__(self , c_ptr , parent = None): - if parent: - self.init_cref( c_ptr , parent) - else: - self.init_cobj( c_ptr , cfunc.free ) + def __init__(self, driver=None, max_submit=1, size=0): + """ + Short doc... + + The @size argument is used to say how many jobs the queue will + run, in total. + + size = 0: That means that you do not tell the queue in + advance how many jobs you have. The queue will just run + all the jobs you add, but you have to inform the queue in + some way that all jobs have been submitted. To achieve + this you should call the submit_complete() method when all + jobs have been submitted.# + + size > 0: The queue will know exactly how many jobs to run, + and will continue until this number of jobs have completed + - it is not necessary to call the submit_complete() method + in this case. + """ + + OK_file = None + exit_file = None + + c_ptr = cfunc.alloc(max_submit, OK_file, exit_file) + self.init_cobj(c_ptr, cfunc.free) + + self.jobs = JobList() + self.size = size + + self.exists = exList(self.jobs) + self.status = statusList(self.jobs) + self.run_time = runtimeList(self.jobs, self) + + self.start(blocking=False) + if driver: + self.driver = driver + cfunc.set_driver(self, driver.c_ptr) - - def kill_job(self , index): + def kill_job(self, index): """ Will kill job nr @index. """ - job = self.jobs.__getitem__( index ) + job = self.jobs.__getitem__(index) if job: job.kill() - def start( self , blocking = False): + def start( self, blocking=False): verbose = False - cfunc.run_jobs( self , self.size , verbose ) + cfunc.run_jobs(self, self.size, verbose) - def submit( self , cmd , run_path , job_name , argv , num_cpu = 1): + def submit( self, cmd, run_path, job_name, argv, num_cpu=1): c_argv = (ctypes.c_char_p * len(argv))() c_argv[:] = argv job_index = self.jobs.size @@ -192,11 +173,20 @@ class JobQueue(CClass): done_callback = None callback_arg = None retry_callback = None - - queue_index = cfunc.cadd_job_mt( self , cmd , done_callback , retry_callback , callback_arg , num_cpu , run_path , job_name , len(argv) , c_argv) - job = Job( self.driver , cfunc.get_job_ptr( self , queue_index ) , queue_index , False ) - - self.jobs.add_job( job , job_name ) + + queue_index = cfunc.cadd_job_mt(self, + cmd, + done_callback, + retry_callback, + callback_arg, + num_cpu, + run_path, + job_name, + len(argv), + c_argv) + job = Job(self.driver, cfunc.get_job_ptr(self, queue_index), queue_index, False) + + self.jobs.add_job(job, job_name) return job @@ -208,14 +198,14 @@ class JobQueue(CClass): Will block as long as there are waiting jobs. """ while self.num_waiting > 0: - time.sleep( 1 ) - + time.sleep(1) + def block(self): """ Will block as long as there are running jobs. """ while self.running: - time.sleep( 1 ) + time.sleep(1) def submit_complete( self ): @@ -232,30 +222,30 @@ class JobQueue(CClass): queue, in that case it is not necessary to call the submit_complete() method. """ - cfunc.submit_complete( self ) + cfunc.submit_complete(self) @property def running(self): - return cfunc.is_running( self ) + return cfunc.is_running(self) @property def num_running( self ): - return cfunc.num_running( self ) + return cfunc.num_running(self) @property def num_pending( self ): - return cfunc.num_pending( self ) + return cfunc.num_pending(self) @property def num_waiting( self ): - return cfunc.num_waiting( self ) + return cfunc.num_waiting(self) @property def num_complete( self ): - return cfunc.num_complete( self ) + return cfunc.num_complete(self) - def exists(self , index): + def exists(self, index): job = self.__getitem__(index) if job: return True @@ -264,27 +254,28 @@ class JobQueue(CClass): def get_max_running( self ): return self.driver.get_max_running() - - def set_max_running( self , max_running ): - self.driver.set_max_running( max_running ) - + + def set_max_running( self, max_running ): + self.driver.set_max_running(max_running) + def user_exit(self): cfunc.user_exit(self) def set_pause_on(self): - cfunc.set_pause_on + cfunc.set_pause_on() def set_pause_off(self): - cfunc.set_pause_off + cfunc.set_pause_off() ################################################################# -cwrapper = CWrapper( libjob_queue.lib ) -cwrapper.registerType( "job_queue" , JobQueue ) -cfunc = CWrapperNameSpace( "JobQueue" ) +cwrapper = CWrapper(JOB_QUEUE_LIB) +cwrapper.registerType("job_queue", JobQueue) +cfunc = CWrapperNameSpace("JobQueue") -cfunc.user_exit = cwrapper.prototype("void job_queue_user_exit( job_queue )") -cfunc.free_queue = cwrapper.prototype("void job_queue_free( job_queue )") +cfunc.alloc = cwrapper.prototype("c_void_p job_queue_alloc( int , char* , char* )") +cfunc.user_exit = cwrapper.prototype("void job_queue_user_exit( job_queue )") +cfunc.free = cwrapper.prototype("void job_queue_free( job_queue )") cfunc.set_max_running = cwrapper.prototype("void job_queue_set_max_running( job_queue , int)") cfunc.get_max_running = cwrapper.prototype("int job_queue_get_max_running( job_queue )") cfunc.set_driver = cwrapper.prototype("void job_queue_set_driver( job_queue , c_void_p )") @@ -292,10 +283,12 @@ cfunc.cadd_job_mt = cwrapper.prototype("int job_queue_add_job_mt( job_queue cfunc.cadd_job_st = cwrapper.prototype("int job_queue_add_job_st( job_queue , char* , c_void_p , c_void_p , c_void_p , int , char* , char* , int , char**)") cfunc.start_queue = cwrapper.prototype("void job_queue_run_jobs( job_queue , int , bool)") cfunc.run_jobs = cwrapper.prototype("void job_queue_run_jobs_threaded(job_queue , int , bool)") + cfunc.num_running = cwrapper.prototype("int job_queue_get_num_running( job_queue )") cfunc.num_complete = cwrapper.prototype("int job_queue_get_num_complete( job_queue )") cfunc.num_waiting = cwrapper.prototype("int job_queue_get_num_waiting( job_queue )") cfunc.num_pending = cwrapper.prototype("int job_queue_get_num_pending( job_queue )") + cfunc.is_running = cwrapper.prototype("int job_queue_is_running( job_queue )") cfunc.submit_complete = cwrapper.prototype("void job_queue_submit_complete( job_queue )") cfunc.get_job_ptr = cwrapper.prototype("c_void_p job_queue_iget_job( job_queue , int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/rms/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/rms/CMakeLists.txt index 3c92090d20..d967186453 100644 --- a/ThirdParty/Ert/devel/python/python/ert/rms/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/rms/CMakeLists.txt @@ -1 +1,8 @@ -add_python_package("Python ert.rms" ${PYTHON_INSTALL_PREFIX}/ert/rms "__init__.py;librms.py;rms.py" True) +set(PYTHON_SOURCES + __init__.py + librms.py + rms.py + +) + +add_python_package("Python ert.rms" ${PYTHON_INSTALL_PREFIX}/ert/rms "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/sched/CMakeLists.txt index ac122f161d..714bb73a2b 100644 --- a/ThirdParty/Ert/devel/python/python/ert/sched/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/sched/CMakeLists.txt @@ -1 +1,7 @@ -add_python_package("Python ert.sched" ${PYTHON_INSTALL_PREFIX}/ert/sched "__init__.py;libsched.py;sched_file.py;sched.py;history.py" True) +set(PYTHON_SOURCES + __init__.py + sched_file.py + history.py +) + +add_python_package("Python ert.sched" ${PYTHON_INSTALL_PREFIX}/ert/sched "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/__init__.py b/ThirdParty/Ert/devel/python/python/ert/sched/__init__.py index e69de29bb2..5257711e70 100644 --- a/ThirdParty/Ert/devel/python/python/ert/sched/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/sched/__init__.py @@ -0,0 +1,26 @@ +# Copyright (C) 2013 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. +from ert.cwrap import clib + +import ert.ecl +import ert.util +import ert.geo + +SCHED_LIB = clib.ert_load("libsched.so") + + +from .sched_file import SchedFile +from .history import HistoryType \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/history.py b/ThirdParty/Ert/devel/python/python/ert/sched/history.py index b694f6f04d..144ffb4a9e 100644 --- a/ThirdParty/Ert/devel/python/python/ert/sched/history.py +++ b/ThirdParty/Ert/devel/python/python/ert/sched/history.py @@ -12,25 +12,21 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.sched import SCHED_LIB + -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from ert.ecl.ecl_sum import * -import libsched class HistoryType(CClass): - - def __init__(self , c_ptr , parent = None): + def __init__(self, c_ptr, parent=None): if parent: - self.init_cref( c_ptr , parent) + self.init_cref(c_ptr, parent) else: - self.init_cobj( c_ptr , cfunc.free ) + self.init_cobj(c_ptr, cfunc.free) def get_source_string(self): return cfunc.get_source_string(self) - + @staticmethod def alloc_from_refcase(refcase, use_history): return HistoryType(cfunc.alloc_from_refcase(refcase, use_history)) @@ -38,17 +34,18 @@ class HistoryType(CClass): @staticmethod def alloc_from_sched_file(sched_file): return HistoryType(cfunc.alloc_from_sched_file(":", sched_file)) -################################################################## -cwrapper = CWrapper( libsched.lib ) -cwrapper.registerType( "history_type" , HistoryType ) + ################################################################## + +cwrapper = CWrapper(SCHED_LIB) +cwrapper.registerType("history_type", HistoryType) cfunc = CWrapperNameSpace("history_type") ################################################################## ################################################################## -cfunc.free = cwrapper.prototype("void history_free( history_type )") -cfunc.get_source_string = cwrapper.prototype("char* history_get_source_string(history_type)") -cfunc.alloc_from_refcase = cwrapper.prototype("c_void_p history_alloc_from_refcase(ecl_sum, bool)") -cfunc.alloc_from_sched_file = cwrapper.prototype("c_void_p history_alloc_from_sched_file(char*, c_void_p)") +cfunc.free = cwrapper.prototype("void history_free( history_type )") +cfunc.get_source_string = cwrapper.prototype("char* history_get_source_string(history_type)") +cfunc.alloc_from_refcase = cwrapper.prototype("c_void_p history_alloc_from_refcase(ecl_sum, bool)") +cfunc.alloc_from_sched_file = cwrapper.prototype("c_void_p history_alloc_from_sched_file(char*, c_void_p)") diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/libsched.py b/ThirdParty/Ert/devel/python/python/ert/sched/libsched.py deleted file mode 100644 index 04daaffba5..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/sched/libsched.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libsched.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 ert.cwrap.clib as clib -import ert.util.libutil -import ert.geo.libgeo -import ert.ecl.libecl - -lib = clib.ert_load("libsched.so") - diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/sched.py b/ThirdParty/Ert/devel/python/python/ert/sched/sched.py deleted file mode 100644 index cd96d74f77..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/sched/sched.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'sched.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 libsched -from sched_file import SchedFile - diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/sched_file.py b/ThirdParty/Ert/devel/python/python/ert/sched/sched_file.py index 48287b687b..b6095fd20d 100644 --- a/ThirdParty/Ert/devel/python/python/ert/sched/sched_file.py +++ b/ThirdParty/Ert/devel/python/python/ert/sched/sched_file.py @@ -12,17 +12,12 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.sched import SCHED_LIB +from ert.util import ctime -import types -import ctypes -import libsched -from ert.cwrap.cwrap import * -from ert.cwrap.cfile import CFILE -from ert.cwrap.cclass import CClass -from ert.util.ctime import ctime - class SchedFile(CClass): def __init__(self , filename , start_time): @@ -39,7 +34,7 @@ class SchedFile(CClass): -cwrapper = CWrapper( libsched.lib ) +cwrapper = CWrapper(SCHED_LIB) cwrapper.registerType( "sched_file" , SchedFile ) # 3. Installing the c-functions used to manipulate ecl_kw instances. diff --git a/ThirdParty/Ert/devel/python/python/ert/util/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/util/CMakeLists.txt index 51ef2295a3..fd40f8ebd0 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/util/CMakeLists.txt @@ -1,2 +1,20 @@ -add_python_package("Python ert.util" ${PYTHON_INSTALL_PREFIX}/ert/util - "ctime.py;hash.py;__init__.py;latex.py;libutil.py;buffer.py;lookup_table.py;matrix.py;stat.py;stringlist.py;tvector.py;util_func.py;log.py" T) +set(PYTHON_SOURCES + __init__.py + buffer.py + ctime.py + hash.py + latex.py + log.py + lookup_table.py + matrix.py + stat.py + stringlist.py + tvector.py + util_func.py + +) + + +add_python_package("Python ert.util" ${PYTHON_INSTALL_PREFIX}/ert/util "${PYTHON_SOURCES}" T) + +add_python_package("Python ert.util test" ${PYTHON_INSTALL_PREFIX}/ert/util "test_area.py" F) diff --git a/ThirdParty/Ert/devel/python/python/ert/util/__init__.py b/ThirdParty/Ert/devel/python/python/ert/util/__init__.py index c2ab14ebb8..95010d5a28 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/__init__.py @@ -36,3 +36,33 @@ The modules included in the util package are: """ +import ert.cwrap.clib as clib + +clib.load("libz" , "libz.so.1") + +# Depending on the Fortran compiler which has been used to compile +# blas / lapack the there might be an additional dependency on libg2c: + +try: + # First try to load without libg2c + clib.load("libblas.so" , "libblas.so.3") + clib.load("liblapack.so") +except ImportError: + # Then try to load with libg2c + clib.load("libg2c.so.0") + clib.load("libblas.so" , "libblas.so.3") + clib.load("liblapack.so") + +UTIL_LIB = clib.ert_load("libert_util.so") + +from .tvector import DoubleVector, IntVector, BoolVector, TimeVector, TVector +from .stringlist import StringList +from .stat import quantile, quantile_sorted +from .matrix import Matrix +from .log import Log +from .lookup_table import LookupTable +from .buffer import Buffer +from .ctime import ctime +from .hash import Hash +from .test_area import TestArea, TestAreaContext +from .latex import LaTeX \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/util/buffer.py b/ThirdParty/Ert/devel/python/python/ert/util/buffer.py index b2111e1223..1067af70aa 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/buffer.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/buffer.py @@ -14,33 +14,25 @@ # See the GNU General Public License at # for more details. -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.ctime import ctime -from ert.util.tvector import * -import libutil -from ert.enkf.libenkf import * -#from ert.job_queue.ext_joblist import ExtJoblist +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util import UTIL_LIB + class Buffer(CClass): - - def __init__(self , size , parent = None): + def __init__(self, size, parent=None): c_ptr = cfunc.alloc(size) if parent: - self.init_cref( c_ptr , parent) + self.init_cref(c_ptr, parent) else: - self.init_cobj( c_ptr , cfunc.free ) - + self.init_cobj(c_ptr, cfunc.free) + ################################################################## -cwrapper = CWrapper( libutil.lib ) -cwrapper.registerType( "buffer" , Buffer ) + +cwrapper = CWrapper(UTIL_LIB) +cwrapper.registerType("buffer", Buffer) cfunc = CWrapperNameSpace("buffer") -################################################################## -################################################################## - -cfunc.free = cwrapper.prototype("void buffer_free( buffer )") +cfunc.free = cwrapper.prototype("void buffer_free( buffer )") cfunc.alloc = cwrapper.prototype("c_void_p buffer_alloc(int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/ctime.py b/ThirdParty/Ert/devel/python/python/ert/util/ctime.py index 576c65016e..e8ae49de15 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/ctime.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/ctime.py @@ -20,35 +20,36 @@ import ctypes import types import datetime import time -from ert.cwrap.cwrap import * +from ert.cwrap import CWrapper class ctime(ctypes.c_long): - def __init__(self , value): - if isinstance(value , types.IntType): + def __init__(self, value): + if isinstance(value, types.IntType): self.value = value else: try: # Input value is assumed to be datetime.datetime instance - self.value = int(math.floor(time.mktime( (value.year , value.month , value.day , value.hour , value.minute , value.second , 0 , 0 , -1 ) ))) - except: + self.value = int(math.floor(time.mktime( + (value.year, value.month, value.day, value.hour, value.minute, value.second, 0, 0, -1 )))) + except (OverflowError, ValueError, AttributeError): # Input value is assumed to be datetime.date instance - self.value = int(math.floor(time.mktime( (value.year , value.month , value.day , 0 , 0 , 0 , 0 , 0 , -1 ) ))) - - + self.value = int(math.floor(time.mktime((value.year, value.month, value.day, 0, 0, 0, 0, 0, -1 )))) + + def ctime(self): return self.value def time(self): """Return this time_t as a time.localtime() object""" - return time.localtime( self.value ) + return time.localtime(self.value) def date(self): """Return this time_t as a datetime.date([year, month, day])""" - return datetime.date( *self.time()[0:3]) + return datetime.date(*self.time()[0:3]) def datetime(self): - return datetime.datetime( *self.time()[0:6] ) + return datetime.datetime(*self.time()[0:6]) def __str__(self): return "%s" % (str(self.datetime())) @@ -59,12 +60,15 @@ class ctime(ctypes.c_long): def __lt__(self, other): return not self >= other + def __eq__(self, other): + return self.value == other.value + @property def stripped(self): return time.strptime(self, "%Y-%m-%d %H:%M:S%") -cwrapper = CWrapper( None ) -cwrapper.registerType( "time_t" , ctime ) -cwrapper.registerType( "time_t*" , ctypes.POINTER(ctime)) +cwrapper = CWrapper(None) +cwrapper.registerType("time_t", ctime) +cwrapper.registerType("time_t*", ctypes.POINTER(ctime)) diff --git a/ThirdParty/Ert/devel/python/python/ert/util/hash.py b/ThirdParty/Ert/devel/python/python/ert/util/hash.py index ac7d504474..3f9ced5742 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/hash.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/hash.py @@ -15,28 +15,26 @@ # for more details. -import sys -import ctypes -import libutil -from ert.cwrap.cwrap import * +from ert.cwrap import CWrapper, CWrapperNameSpace, CClass +from ert.util import UTIL_LIB -class Hash: - +class Hash(CClass): def __init__( self ): self.c_ptr = cfunc.hash_alloc() - + def __del__( self ): - cfunc.hash_del( self ) - - def __getitem__(self , key): + cfunc.hash_del(self) + + def __getitem__(self, key): #todo: missing implementation? pass -CWrapper.registerType( "hash" , Hash ) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("hash") +CWrapper.registerType("hash", Hash) +cwrapper = CWrapper(UTIL_LIB) + +cfunc = CWrapperNameSpace("hash") cfunc.hash_alloc = cwrapper.prototype("long hash_alloc( )") -cfunc.hash_free = cwrapper.prototype("void hash_free( hash )") -cfunc.hash_get = cwrapper.prototype("long hash_get(hash , char*)") +cfunc.hash_free = cwrapper.prototype("void hash_free( hash )") +cfunc.hash_get = cwrapper.prototype("long hash_get(hash , char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/latex.py b/ThirdParty/Ert/devel/python/python/ert/util/latex.py index 6df9052cd8..ce6911ef75 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/latex.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/latex.py @@ -16,70 +16,68 @@ """ Module implmenting LaTeX class for wrapping the latex compilation of a file. """ -import libutil -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass - +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util import UTIL_LIB class LaTeX(CClass): - def __init__(self , src_file , in_place = False): - c_ptr = cfunc.alloc( src_file , in_place ) - self.init_cobj( c_ptr , cfunc.free ) + def __init__(self, src_file, in_place=False): + c_ptr = cfunc.alloc(src_file, in_place) + self.init_cobj(c_ptr, cfunc.free) @property def runpath(self): - return cfunc.get_runpath( self ) + return cfunc.get_runpath(self) + + def compile(self, ignore_errors=False, with_xref=False, cleanup=True): + return cfunc.compile(self, ignore_errors, with_xref, cleanup) - def compile(self , ignore_errors = False , with_xref = False , cleanup = True): - return cfunc.compile( self , ignore_errors , with_xref , cleanup) - @property def in_place(self): - return cfunc.compile_in_place( self ) - + return cfunc.compile_in_place(self) + #----------------------------------------------------------------- - def set_target( self , target_file): - cfunc.set_target( self , target_file ) + def set_target( self, target_file): + cfunc.set_target(self, target_file) def get_target( self ): - return cfunc.get_target( self ) + return cfunc.get_target(self) - target = property( get_target , set_target) + target = property(get_target, set_target) #----------------------------------------------------------------- #----------------------------------------------------------------- def get_timeout( self ): - return cfunc.get_timeout( self ) - - def set_timeout( self , timeout): - cfunc.set_timeout( self , timeout) + return cfunc.get_timeout(self) - timeout = property( get_timeout , set_timeout) + def set_timeout( self, timeout): + cfunc.set_timeout(self, timeout) + + timeout = property(get_timeout, set_timeout) #----------------------------------------------------------------- - def link_content( self , directory ): - cfunc.link_directory_content( self , directory ) + def link_content( self, directory ): + cfunc.link_directory_content(self, directory) - def link_path( self , path): - cfunc.link_path( self , path) + def link_path( self, path): + cfunc.link_path(self, path) -cwrapper = CWrapper( libutil.lib ) -cwrapper.registerType( "latex" , LaTeX ) +cwrapper = CWrapper(UTIL_LIB) +cwrapper.registerType("latex", LaTeX) # 3. Installing the c-functions used to manipulate. cfunc = CWrapperNameSpace("latex") -cfunc.alloc = cwrapper.prototype("c_void_p latex_alloc( char* , bool )") -cfunc.free = cwrapper.prototype("void latex_free( latex )") -cfunc.compile = cwrapper.prototype("bool latex_compile(latex , bool , bool , bool)") -cfunc.get_runpath = cwrapper.prototype("char* latex_get_runpath( latex )") -cfunc.get_target = cwrapper.prototype("char* latex_get_target_file( latex )") -cfunc.set_target = cwrapper.prototype("void latex_set_target_file( latex , char* )") -cfunc.set_timeout = cwrapper.prototype("void latex_set_timeout( latex , int )") -cfunc.get_timeout = cwrapper.prototype("int latex_get_timeout( latex )") -cfunc.compile_in_place = cwrapper.prototype("bool latex_compile_in_place( latex )"); -cfunc.link_directory_content = cwrapper.prototype("void latex_link_directory_content( latex , char*)"); -cfunc.link_path = cwrapper.prototype("void latex_link_path( latex , char*)"); +cfunc.alloc = cwrapper.prototype("c_void_p latex_alloc( char* , bool )") +cfunc.free = cwrapper.prototype("void latex_free( latex )") +cfunc.compile = cwrapper.prototype("bool latex_compile(latex , bool , bool , bool)") +cfunc.get_runpath = cwrapper.prototype("char* latex_get_runpath( latex )") +cfunc.get_target = cwrapper.prototype("char* latex_get_target_file( latex )") +cfunc.set_target = cwrapper.prototype("void latex_set_target_file( latex , char* )") +cfunc.set_timeout = cwrapper.prototype("void latex_set_timeout( latex , int )") +cfunc.get_timeout = cwrapper.prototype("int latex_get_timeout( latex )") +cfunc.compile_in_place = cwrapper.prototype("bool latex_compile_in_place( latex )"); +cfunc.link_directory_content = cwrapper.prototype("void latex_link_directory_content( latex , char*)"); +cfunc.link_path = cwrapper.prototype("void latex_link_path( latex , char*)"); diff --git a/ThirdParty/Ert/devel/python/python/ert/util/libutil.py b/ThirdParty/Ert/devel/python/python/ert/util/libutil.py deleted file mode 100644 index 6b909df0d6..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/util/libutil.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libutil.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 ert.cwrap.clib as clib - -clib.load("libz" , "libz.so.1") - -# Depending on the Fortran compiler which has been used to compile -# blas / lapack the there might be an additional dependency on libg2c: - -try: - # First try to load without libg2c - clib.load("libblas.so" , "libblas.so.3") - clib.load("liblapack.so") -except: - # Then try to load with libg2c - clib.load("libg2c.so.0") - clib.load("libblas.so" , "libblas.so.3") - clib.load("liblapack.so") - -lib = clib.ert_load("libert_util.so") - diff --git a/ThirdParty/Ert/devel/python/python/ert/util/log.py b/ThirdParty/Ert/devel/python/python/ert/util/log.py index 9a1fab28ba..ec74372aee 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/log.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/log.py @@ -14,45 +14,43 @@ # See the GNU General Public License at # for more details. -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -import libutil +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util import UTIL_LIB + + class Log(CClass): - - def __init__(self , c_ptr , parent = None): + def __init__(self, c_ptr, parent=None): if parent: - self.init_cref( c_ptr , parent) + self.init_cref(c_ptr, parent) else: - self.init_cobj( c_ptr , cfunc.free ) - + self.init_cobj(c_ptr, cfunc.free) + @property def get_filename(self): #return cfunc.get_filename( self ) return "ert_config.log" - + def reopen(self, filename): print "Logfile cannot be reopened" #cfunc.reopen( self , filename) - + @property def get_level(self): #return cfunc.get_level( self ) return 0 def set_level(self, level): - cfunc.set_level( self , level) + cfunc.set_level(self, level) + ################################################################## -cwrapper = CWrapper( libutil.lib ) -cwrapper.registerType( "log" , Log ) +cwrapper = CWrapper(UTIL_LIB) +cwrapper.registerType("log", Log) cfunc = CWrapperNameSpace("log") -################################################################## -################################################################## -cfunc.free = cwrapper.prototype("void log( log )") -cfunc.get_filename = cwrapper.prototype("char* log_get_filename(log)") -cfunc.reopen = cwrapper.prototype("void log_reopen(log, char*)") -cfunc.get_level = cwrapper.prototype("int log_get_level(log)") -cfunc.set_level = cwrapper.prototype("void log_set_level(log, int)") + +cfunc.free = cwrapper.prototype("void log( log )") +cfunc.get_filename = cwrapper.prototype("char* log_get_filename(log)") +cfunc.reopen = cwrapper.prototype("void log_reopen(log, char*)") +cfunc.get_level = cwrapper.prototype("int log_get_level(log)") +cfunc.set_level = cwrapper.prototype("void log_set_level(log, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/lookup_table.py b/ThirdParty/Ert/devel/python/python/ert/util/lookup_table.py index f0b3a60551..1eca28b904 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/lookup_table.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/lookup_table.py @@ -15,61 +15,60 @@ # for more details. -import sys -import ctypes -import libutil -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass - +from ert.util import UTIL_LIB +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace class LookupTable(CClass): - def __init__(self): self.c_ptr = cfunc.alloc() - - - @property + + + @property def max(self): - return cfunc.max( self ) + return cfunc.max(self) - @property + @property def min(self): - return cfunc.min( self ) + return cfunc.min(self) - @property + @property def arg_max(self): - return cfunc.arg_max( self ) + return cfunc.arg_max(self) - @property + @property def arg_min(self): - return cfunc.arg_min( self ) - - def interp( self , x ): - return cfunc.interp(self , x ) + return cfunc.arg_min(self) + + def interp(self, x): + return cfunc.interp(self, x) + + def append(self, x, y): + cfunc.append(self, x, y) - def append( self , x , y ): - cfunc.append( self , x , y ) - @property def size(self): - return cfunc.size( self ) + return cfunc.size(self) def __del__(self): - cfunc.free( self ) + cfunc.free(self) - -CWrapper.registerType( "lookup_table" , LookupTable ) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("lookup_table") + def __len__(self): + return self.size -cfunc.alloc = cwrapper.prototype("c_void_p lookup_table_alloc_empty()") -cfunc.max = cwrapper.prototype("double lookup_table_get_max_value( lookup_table )") -cfunc.min = cwrapper.prototype("double lookup_table_get_min_value( lookup_table )") -cfunc.arg_max = cwrapper.prototype("double lookup_table_get_max_arg( lookup_table )") -cfunc.arg_min = cwrapper.prototype("double lookup_table_get_min_arg( lookup_table )") -cfunc.append = cwrapper.prototype("void lookup_table_append( lookup_table , double , double )") -cfunc.size = cwrapper.prototype("int lookup_table_get_size( lookup_table )") -cfunc.interp = cwrapper.prototype("double lookup_table_interp( lookup_table , double)") -cfunc.free = cwrapper.prototype("void lookup_table_free( lookup_table )") + +CWrapper.registerType("lookup_table", LookupTable) +cwrapper = CWrapper(UTIL_LIB) + +cfunc = CWrapperNameSpace("lookup_table") + +cfunc.alloc = cwrapper.prototype("c_void_p lookup_table_alloc_empty()") +cfunc.max = cwrapper.prototype("double lookup_table_get_max_value( lookup_table )") +cfunc.min = cwrapper.prototype("double lookup_table_get_min_value( lookup_table )") +cfunc.arg_max = cwrapper.prototype("double lookup_table_get_max_arg( lookup_table )") +cfunc.arg_min = cwrapper.prototype("double lookup_table_get_min_arg( lookup_table )") +cfunc.append = cwrapper.prototype("void lookup_table_append( lookup_table , double , double )") +cfunc.size = cwrapper.prototype("int lookup_table_get_size( lookup_table )") +cfunc.interp = cwrapper.prototype("double lookup_table_interp( lookup_table , double)") +cfunc.free = cwrapper.prototype("void lookup_table_free( lookup_table )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/matrix.py b/ThirdParty/Ert/devel/python/python/ert/util/matrix.py index 49bbe9b0ca..06858af2c9 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/matrix.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/matrix.py @@ -27,37 +27,34 @@ # choice. -import sys -import ctypes -import libutil -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass +from ert.util import UTIL_LIB +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace + class Matrix(CClass): + def __init__(self, rows, columns): + c_ptr = cfunc.matrix_alloc(rows, columns) + self.init_cobj(c_ptr, cfunc.free) - def __init__(self , rows , columns): - c_ptr = cfunc.matrix_alloc( rows , columns ) - self.init_cobj( c_ptr , cfunc.free ) - def __getitem__(self, index_tuple ): - print index_tuple - (i,j) = index_tuple - return cfunc.iget( self , i,j) + # print index_tuple + (i, j) = index_tuple + return cfunc.iget(self, i, j) - def __setitem__(self, index_tuple , value): - (i,j) = index_tuple - return cfunc.iset( self , i,j , value) + def __setitem__(self, index_tuple, value): + (i, j) = index_tuple + return cfunc.iset(self, i, j, value) ################################################################# -CWrapper.registerType( "matrix" , Matrix ) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("matrix") +CWrapper.registerType("matrix", Matrix) +cwrapper = CWrapper(UTIL_LIB) +cfunc = CWrapperNameSpace("matrix") cfunc.matrix_alloc = cwrapper.prototype("c_void_p matrix_alloc( int , int )") -cfunc.free = cwrapper.prototype("void matrix_free( matrix )") -cfunc.iget = cwrapper.prototype("double matrix_iget( matrix , int , int )") -cfunc.iset = cwrapper.prototype("void matrix_iset( matrix , int , int , double)") +cfunc.free = cwrapper.prototype("void matrix_free( matrix )") +cfunc.iget = cwrapper.prototype("double matrix_iget( matrix , int , int )") +cfunc.iset = cwrapper.prototype("void matrix_iset( matrix , int , int , double)") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/stat.py b/ThirdParty/Ert/devel/python/python/ert/util/stat.py index e8654361e6..8342491faf 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/stat.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/stat.py @@ -15,22 +15,20 @@ # for more details. -import ctypes -import libutil -import tvector -from ert.cwrap.cwrap import * - -def quantile( data , q ): - return cfunc.quantile( data , q ) +from ert.util import UTIL_LIB +from ert.cwrap import CWrapper, CWrapperNameSpace -def quantile_sorted( data , q ): - return cfunc.quantile_sorted( data , q ) +def quantile( data, q ): + return cfunc.quantile(data, q) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("stat") +def quantile_sorted( data, q ): + return cfunc.quantile_sorted(data, q) -cfunc.quantile = cwrapper.prototype("double statistics_empirical_quantile( double_vector , double )") +cwrapper = CWrapper(UTIL_LIB) +cfunc = CWrapperNameSpace("stat") + +cfunc.quantile = cwrapper.prototype("double statistics_empirical_quantile( double_vector , double )") cfunc.quantile_sorted = cwrapper.prototype("double statistics_empirical_quantile( double_vector , double )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/stringlist.py b/ThirdParty/Ert/devel/python/python/ert/util/stringlist.py index d90ee9d975..783b9b95a8 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/stringlist.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/stringlist.py @@ -30,17 +30,14 @@ 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. """ +import sys -import libutil -import types -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass - +from ert.util import UTIL_LIB +from types import StringType, IntType +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace class StringList(CClass): - #@classmethod #def NULL( cls ): # obj = object.__new__( cls ) @@ -54,7 +51,7 @@ class StringList(CClass): # return obj - def __init__( self , initial = None , c_ptr = None, parent = None): + def __init__( self, initial=None, c_ptr=None, parent=None): """ Creates a new stringlist instance. @@ -74,23 +71,23 @@ class StringList(CClass): """ if c_ptr: if parent: - self.init_cref( c_ptr , parent) + self.init_cref(c_ptr, parent) else: - self.init_cobj( c_ptr , cfunc.free ) + self.init_cobj(c_ptr, cfunc.free) else: - c_ptr = cfunc.stringlist_alloc( ) - self.init_cobj( c_ptr , cfunc.free ) + c_ptr = cfunc.stringlist_alloc() + self.init_cobj(c_ptr, cfunc.free) if initial: for s in initial: - if isinstance( s , types.StringType): - self.append( s ) + if isinstance(s, StringType): + self.append(s) else: raise TypeError("Item:%s not a string" % s) - def __setitem__(self, index , value): - if isinstance( index , types.IntType): + def __setitem__(self, index, value): + if isinstance(index, IntType): length = self.__len__() if index < 0: # Will only wrap backwards once @@ -98,53 +95,53 @@ class StringList(CClass): if index < 0 or index >= length: raise IndexError - if isinstance(value , types.StringType): - cfunc.stringlist_iset( self , index , value) + if isinstance(value, StringType): + cfunc.stringlist_iset(self, index, value) else: raise TypeError("Item:%s not string type" % value) - def __getitem__(self , index): + 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 , types.IntType): + if isinstance(index, IntType): length = self.__len__() if index < 0: index += length if index < 0 or index >= length: raise IndexError else: - return cfunc.stringlist_iget( self , index ) + return cfunc.stringlist_iget(self, index) else: raise TypeError("Index should be integer type") - def __contains__(self , s): + def __contains__(self, s): """ Implements the 'in' operator. The 'in' check is based on string equality. """ - return cfunc.contains( self , s ) + return cfunc.contains(self, s) - def contains(self , s): + def contains(self, s): """ Checks if the list contains @s. Functionality also available through the 'in' builtin in Python. """ - return self.__contains__( s ) + return self.__contains__(s) def __len__(self): """ The length of the list - used to support builtin len(). """ - return cfunc.stringlist_get_size( self ) + return cfunc.stringlist_get_size(self) def __str__(self): @@ -154,7 +151,7 @@ class StringList(CClass): buffer = "[" length = len(self) for i in range(length): - if i == length -1: + if i == length - 1: buffer += "\'%s\'" % self[i] else: buffer += "\'%s\'," % self[i] @@ -169,17 +166,17 @@ class StringList(CClass): Will raise IndexError if list is empty. """ if len(self): - return cfunc.pop( self ) + return cfunc.pop(self) else: raise IndexError("pop() failed - the list is empty") - + def append(self, s): """ Appends a new string @s to list. """ - if isinstance( s, types.StringType): - cfunc.stringlist_append( self , s) + if isinstance(s, StringType): + cfunc.stringlist_append(self, s) else: sys.exit("Type mismatch") @@ -194,21 +191,21 @@ class StringList(CClass): """ slist = [] for s in self: - slist.append( s ) + slist.append(s) return slist - + @property def last(self): """ Will return the last element in list. Raise IndexError if empty. """ if len(self): - return cfunc.last( self ) + return cfunc.last(self) else: raise IndexError("The list is empty") - def sort(self , cmp_flag = 0): + def sort(self, cmp_flag=0): """ Will sort the list inplace. @@ -220,22 +217,21 @@ class StringList(CClass): 2 : util_strcmp_float() string comparison """ - cfunc.sort( self , cmp_flag ) + cfunc.sort(self, cmp_flag) +CWrapper.registerType("stringlist", StringList) -CWrapper.registerType( "stringlist" , StringList ) - -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("StringList") -cfunc.stringlist_alloc = cwrapper.prototype("c_void_p stringlist_alloc_new( )") -cfunc.free = cwrapper.prototype("void stringlist_free( stringlist )") -cfunc.stringlist_append = cwrapper.prototype("void stringlist_append_copy( stringlist , char* )") -cfunc.stringlist_iget = cwrapper.prototype("char* stringlist_iget( stringlist , int )") -cfunc.stringlist_iget_copy = cwrapper.prototype("char* stringlist_iget_copy(stringlist, int)") -cfunc.stringlist_iset = cwrapper.prototype("void stringlist_iset_copy( stringlist , int , char* )") -cfunc.stringlist_get_size = cwrapper.prototype("int stringlist_get_size( stringlist )") -cfunc.contains = cwrapper.prototype("bool stringlist_contains(stringlist , char*)") -cfunc.sort = cwrapper.prototype("void stringlist_python_sort( stringlist , int)") -cfunc.pop = cwrapper.safe_prototype("char* stringlist_pop( stringlist )") -cfunc.last = cwrapper.safe_prototype("char* stringlist_get_last( stringlist )") +cwrapper = CWrapper(UTIL_LIB) +cfunc = CWrapperNameSpace("StringList") +cfunc.stringlist_alloc = cwrapper.prototype("c_void_p stringlist_alloc_new( )") +cfunc.free = cwrapper.prototype("void stringlist_free( stringlist )") +cfunc.stringlist_append = cwrapper.prototype("void stringlist_append_copy( stringlist , char* )") +cfunc.stringlist_iget = cwrapper.prototype("char* stringlist_iget( stringlist , int )") +cfunc.stringlist_iget_copy = cwrapper.prototype("char* stringlist_iget_copy(stringlist, int)") +cfunc.stringlist_iset = cwrapper.prototype("void stringlist_iset_copy( stringlist , int , char* )") +cfunc.stringlist_get_size = cwrapper.prototype("int stringlist_get_size( stringlist )") +cfunc.contains = cwrapper.prototype("bool stringlist_contains(stringlist , char*)") +cfunc.sort = cwrapper.prototype("void stringlist_python_sort( stringlist , int)") +cfunc.pop = cwrapper.safe_prototype("char* stringlist_pop( stringlist )") +cfunc.last = cwrapper.safe_prototype("char* stringlist_get_last( stringlist )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/test_area.py b/ThirdParty/Ert/devel/python/python/ert/util/test_area.py new file mode 100644 index 0000000000..b3fb3767c7 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/util/test_area.py @@ -0,0 +1,77 @@ +# 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. + +from ert.cwrap import clib, CClass, CWrapper, CWrapperNameSpace + + +lib = clib.ert_load("libtest_util.so") + + +class TestArea(CClass): + def __init__(self, test_name, store_area=False): + c_ptr = cfunc.test_area_alloc(test_name, store_area) + if not c_ptr: + raise Exception("Failed to create TestArea instance") + + self.init_cobj(c_ptr, cfunc.free) + + + def install_file( self, filename): + cfunc.install_file(self, filename) + + + def copy_directory( self, directory): + cfunc.copy_directory(self, directory) + + + def copy_directory_content( self, directory): + cfunc.copy_directory_content(self, directory) + + def copy_file( self, filename): + cfunc.copy_file(self, filename) + + +class TestAreaContext(object): + def __init__(self, test_name, store_area=False): + self.test_name = test_name + self.store_area = store_area + + def __enter__(self): + """ + @rtype: TestArea + """ + self.test_area = TestArea(self.test_name, self.store_area) + return self.test_area + + + def __exit__(self, exc_type, exc_val, exc_tb): + del self.test_area + return False + + + +CWrapper.registerType("test_area", TestArea) + +cwrapper = CWrapper(lib) + +cfunc = CWrapperNameSpace("TestArea") + +cfunc.test_area_alloc = cwrapper.prototype("c_void_p test_work_area_alloc( char* , bool)") +cfunc.free = cwrapper.prototype("void test_work_area_free( test_area )") +cfunc.install_file = cwrapper.prototype("void test_work_area_install_file( test_area , char* )") +cfunc.copy_directory = cwrapper.prototype("void test_work_area_copy_directory( test_area , char* )") +cfunc.copy_file = cwrapper.prototype("void test_work_area_copy_file( test_area , char* )") +cfunc.copy_directory_content = cwrapper.prototype("void test_work_area_copy_directory_content( test_area , char* )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/tvector.py b/ThirdParty/Ert/devel/python/python/ert/util/tvector.py index d8d7c874db..1e0c6e4951 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/tvector.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/tvector.py @@ -41,23 +41,21 @@ float and size_t not currently implemented in the Python version. """ import sys -import types +from types import IntType, SliceType import ctypes -import libutil -from ert.cwrap.cwrap import * -from ert.cwrap.cfile import CFILE -from ert.cwrap.cclass import CClass import numpy +from ert.cwrap import CWrapper, CClass, CFILE, CWrapperNameSpace +from ert.util import UTIL_LIB, ctime class TVector(CClass): - + @classmethod - def strided_copy( cls , obj , slice ): + def strided_copy( cls , obj , slice_range ): """ Will create a new copy according to @slice. @@ -73,7 +71,7 @@ class TVector(CClass): Now 'c' will be a Intvector() instance containing every tenth element from 'v'. """ - (start , stop , step) = slice.indices( obj.size ) + (start , stop , step) = slice_range.indices( obj.size ) if stop > start: new_obj = TVector.__new__( cls ) c_ptr = cls.cstrided_copy( obj , start , stop , step ) @@ -89,20 +87,13 @@ class TVector(CClass): c_ptr = cls.alloc_copy( obj ) new_obj.init_cobj( c_ptr , new_obj.free ) return new_obj - - + + def __new__( cls , **kwargs): obj = object.__new__( cls ) return obj - @classmethod - def ref( cls , c_ptr , parent ): - obj = cls( ) - obj.init_cref( c_ptr , parent ) - return obj - - def copy( self ): """ Create a new copy of the current vector. @@ -122,8 +113,8 @@ class TVector(CClass): init_size = 0 c_ptr = self.alloc( init_size , default_value ) self.init_cobj( c_ptr , self.free ) - self.element_size = self.get_element_size( self ) - + self.element_size = self.get_element_size( self ) + def str_data( self , width , index1 , index2 , fmt): """ @@ -188,7 +179,7 @@ class TVector(CClass): """ Implements read [] operator - @index can be slice instance. """ - if isinstance( index , types.IntType): + if isinstance( index , IntType): length = self.__len__() if index < 0: index += length @@ -197,16 +188,16 @@ class TVector(CClass): raise IndexError else: return self.iget( self , index ) - elif isinstance( index , types.SliceType ): + elif isinstance( index , SliceType ): return self.strided_copy( self , index ) else: raise TypeError("Index should be integer or slice type.") - + def __setitem__( self , index , value ): """ Implements write [] operator - @index must be integer. """ - if isinstance( index , types.IntType): + if isinstance( index , IntType): self.iset( self, index , value ) else: raise TypeError("Index should be integer type") @@ -317,11 +308,11 @@ class TVector(CClass): return copy def __rsub__( self , delta): - return self.__sub__( delta ) * -1 + return self.__sub__( delta ) * -1 def __imul__(self , factor ): return self.__IMUL__( factor ) - + def __mul__( self , factor ): copy = self.__copy__( self ) copy *= factor @@ -329,7 +320,7 @@ class TVector(CClass): def __rmul__(self , factor): return self.__mul__( factor ) - + def __div__(self , divisor): if isinstance( divisor , int ) or isinstance( divisor , float): @@ -338,7 +329,7 @@ class TVector(CClass): return copy else: raise TypeError("Divisor has wrong type:%s" % type( divisor )) - + # No __rdiv__() @@ -378,7 +369,7 @@ class TVector(CClass): The number of elements in the vector. """ return self.get_size( self ) - + def printf( self , fmt = None , name = None , stream = sys.stdout ): """ @@ -410,7 +401,7 @@ class TVector(CClass): return self.get_min( self ) else: raise IndexError - + def min_index( self , reverse = False ): if self.get_size( self ) > 0: @@ -458,7 +449,7 @@ class TVector(CClass): def get_read_only( self ): return self.get_read_only( self ) - + read_only = property( get_read_only , set_read_only ) def set_default( self , value ): @@ -511,19 +502,21 @@ class TVector(CClass): class DoubleVector(TVector): initialized = False + + def __new__( cls , **kwargs ): if not cls.initialized: cls.csort = cfunc.double_vector_sort cls.crsort = cfunc.double_vector_rsort cls.alloc = cfunc.double_vector_alloc cls.alloc_copy = cfunc.double_vector_alloc_copy - cls.free = cfunc.double_vector_free + # cls.free = cfunc.double_vector_free cls.get_size = cfunc.double_vector_size cls.iget = cfunc.double_vector_iget cls.iset = cfunc.double_vector_iset cls.fprintf = cfunc.double_vector_fprintf cls.cappend = cfunc.double_vector_append - cls.idel_block = cfunc.double_vector_idel_block + cls.idel_block = cfunc.double_vector_idel_block cls.cclear = cfunc.double_vector_reset cls.cstrided_copy = cfunc.double_vector_strided_copy cls.csafe_iget = cfunc.double_vector_safe_iget @@ -549,9 +542,9 @@ class DoubleVector(TVector): cls.def_fmt = "%8.4f" cls.initialized = True - obj = TVector.__new__( cls , kwargs ) + obj = TVector.__new__( cls , **kwargs ) return obj - + class BoolVector(TVector): @@ -563,13 +556,13 @@ class BoolVector(TVector): cls.crsort = cfunc.bool_vector_rsort cls.alloc = cfunc.bool_vector_alloc cls.alloc_copy = cfunc.bool_vector_alloc_copy - cls.free = cfunc.bool_vector_free + # cls.free = cfunc.bool_vector_free cls.get_size = cfunc.bool_vector_size cls.iget = cfunc.bool_vector_iget cls.iset = cfunc.bool_vector_iset cls.fprintf = cfunc.bool_vector_fprintf cls.cappend = cfunc.bool_vector_append - cls.idel_block = cfunc.bool_vector_idel_block + cls.idel_block = cfunc.bool_vector_idel_block cls.cclear = cfunc.bool_vector_reset cls.cstrided_copy = cfunc.bool_vector_strided_copy cls.csafe_iget = cfunc.bool_vector_safe_iget @@ -620,11 +613,11 @@ class BoolVector(TVector): return new_obj @classmethod - def create_from_list(cls, size, list): + def create_from_list(cls, size, source_list): """Allocates a bool vector from a Python list""" new_obj = BoolVector.__new__(cls) - c_ptr = cfunc.bool_vector_alloc(size , False) - for index in list: + c_ptr = cfunc.bool_vector_alloc(size , False) + for index in source_list: cfunc.bool_vector_iset(c_ptr, index, True) #c_ptr = cfunc.bool_vector_data_ptr(mask) @@ -633,25 +626,25 @@ class BoolVector(TVector): - + class IntVector(TVector): initialized = False - + def __new__( cls , **kwargs ): if not cls.initialized: cls.csort = cfunc.int_vector_sort cls.crsort = cfunc.int_vector_rsort cls.alloc = cfunc.int_vector_alloc cls.alloc_copy = cfunc.int_vector_alloc_copy - cls.free = cfunc.int_vector_free + # cls.free = cfunc.int_vector_free cls.get_size = cfunc.int_vector_size cls.iget = cfunc.int_vector_iget cls.iset = cfunc.int_vector_iset cls.fprintf = cfunc.int_vector_fprintf cls.cappend = cfunc.int_vector_append - cls.idel_block = cfunc.int_vector_idel_block + cls.idel_block = cfunc.int_vector_idel_block cls.cclear = cfunc.int_vector_reset cls.cstrided_copy = cfunc.int_vector_strided_copy cls.csafe_iget = cfunc.int_vector_safe_iget @@ -679,7 +672,7 @@ class IntVector(TVector): obj = TVector.__new__( cls , **kwargs) return obj - + @classmethod def active_list(cls , range_string): """ @@ -701,6 +694,51 @@ class IntVector(TVector): return new_obj +class TimeVector(TVector): + initialized = False + + def __new__( cls , **kwargs ): + if not cls.initialized: + cls.csort = cfunc.time_t_vector_sort + cls.crsort = cfunc.time_t_vector_rsort + cls.alloc = cfunc.time_t_vector_alloc + cls.alloc_copy = cfunc.time_t_vector_alloc_copy + # cls.free = cfunc.time_t_vector_free + cls.get_size = cfunc.time_t_vector_size + cls.iget = cfunc.time_t_vector_iget + cls.iset = cfunc.time_t_vector_iset + cls.fprintf = cfunc.time_t_vector_fprintf + cls.cappend = cfunc.time_t_vector_append + cls.idel_block = cfunc.time_t_vector_idel_block + cls.cclear = cfunc.time_t_vector_reset + cls.cstrided_copy = cfunc.time_t_vector_strided_copy + cls.csafe_iget = cfunc.time_t_vector_safe_iget + cls.set_read_only = cfunc.time_t_vector_set_read_only + cls.get_read_only = cfunc.time_t_vector_get_read_only + cls.get_max = cfunc.time_t_vector_get_max + cls.get_min = cfunc.time_t_vector_get_min + cls.get_max_index = cfunc.time_t_vector_get_max_index + cls.get_min_index = cfunc.time_t_vector_get_min_index + cls.shift = cfunc.time_t_vector_shift + cls.scale = cfunc.time_t_vector_scale + cls.div = cfunc.time_t_vector_div + cls.inplace_add = cfunc.time_t_vector_inplace_add + cls.inplace_mul = cfunc.time_t_vector_inplace_mul + cls.cassign = cfunc.time_t_vector_assign + cls.memcpy = cfunc.time_t_vector_memcpy + cls.cset_default = cfunc.time_t_vector_set_default + cls.cget_default = cfunc.time_t_vector_get_default + cls.alloc_data_copy = cfunc.time_t_vector_alloc_data_copy + cls.get_element_size = cfunc.time_t_vector_element_size + cls.data_ptr = cfunc.time_t_vector_data_ptr + cls.numpy_dtype = numpy.float64 + cls.def_fmt = "%8.4f" + cls.initialized = True + + obj = TVector.__new__( cls , **kwargs ) + return obj + + ################################################################# buffer_from_ptr = ctypes.pythonapi.PyBuffer_FromMemory @@ -709,39 +747,46 @@ buffer_from_ptr.argtypes = [ ctypes.c_void_p , ctypes.c_long ] CWrapper.registerType( "double_vector" , DoubleVector ) CWrapper.registerType( "int_vector" , IntVector ) -CWrapper.registerType( "bool_vector" , BoolVector ) +CWrapper.registerType( "bool_vector" , BoolVector ) +CWrapper.registerType( "time_t_vector" , TimeVector ) -cwrapper = CWrapper( libutil.lib ) +cwrapper = CWrapper(UTIL_LIB) cfunc = CWrapperNameSpace("tvector") + +BoolVector.free = cwrapper.prototype("void bool_vector_free( bool_vector )") +DoubleVector.free = cwrapper.prototype("void double_vector_free( double_vector )") +IntVector.free = cwrapper.prototype("void int_vector_free( int_vector )") +TimeVector.free = cwrapper.prototype("void time_t_vector_free( time_t_vector )") + cfunc.double_vector_alloc = cwrapper.prototype("c_void_p double_vector_alloc( int , double )") cfunc.double_vector_alloc_copy = cwrapper.prototype("c_void_p double_vector_alloc_copy( double_vector )") cfunc.double_vector_strided_copy = cwrapper.prototype("c_void_p double_vector_alloc_strided_copy( double_vector , int , int , int)") -cfunc.double_vector_free = cwrapper.prototype("void double_vector_free( double_vector )") +# cfunc.double_vector_free = cwrapper.prototype("void double_vector_free( double_vector )") cfunc.double_vector_iget = cwrapper.prototype("double double_vector_iget( double_vector , int )") cfunc.double_vector_safe_iget = cwrapper.prototype("double double_vector_safe_iget( int_vector , int )") cfunc.double_vector_iset = cwrapper.prototype("double double_vector_iset( double_vector , int , double)") cfunc.double_vector_size = cwrapper.prototype("int double_vector_size( double_vector )") -cfunc.double_vector_append = cwrapper.prototype("void double_vector_append( double_vector , double )") -cfunc.double_vector_idel_block = cwrapper.prototype("void double_vector_idel_block( double_vector , int , int )") +cfunc.double_vector_append = cwrapper.prototype("void double_vector_append( double_vector , double )") +cfunc.double_vector_idel_block = cwrapper.prototype("void double_vector_idel_block( double_vector , int , int )") cfunc.double_vector_fprintf = cwrapper.prototype("void double_vector_fprintf( double_vector , FILE , char* , char*)") -cfunc.double_vector_sort = cwrapper.prototype("void double_vector_sort( double_vector )") -cfunc.double_vector_rsort = cwrapper.prototype("void double_vector_rsort( double_vector )") -cfunc.double_vector_reset = cwrapper.prototype("void double_vector_reset( double_vector )") -cfunc.double_vector_get_read_only = cwrapper.prototype("bool double_vector_set_read_only( double_vector )") -cfunc.double_vector_set_read_only = cwrapper.prototype("void double_vector_set_read_only( double_vector , bool )") +cfunc.double_vector_sort = cwrapper.prototype("void double_vector_sort( double_vector )") +cfunc.double_vector_rsort = cwrapper.prototype("void double_vector_rsort( double_vector )") +cfunc.double_vector_reset = cwrapper.prototype("void double_vector_reset( double_vector )") +cfunc.double_vector_get_read_only = cwrapper.prototype("bool double_vector_get_read_only( double_vector )") +cfunc.double_vector_set_read_only = cwrapper.prototype("void double_vector_set_read_only( double_vector , bool )") cfunc.double_vector_get_max = cwrapper.prototype("double double_vector_get_max( double_vector )") cfunc.double_vector_get_min = cwrapper.prototype("double double_vector_get_min( double_vector )") cfunc.double_vector_get_max_index = cwrapper.prototype("int double_vector_get_max_index( double_vector , bool)") cfunc.double_vector_get_min_index = cwrapper.prototype("int double_vector_get_min_index( double_vector , bool)") cfunc.double_vector_shift = cwrapper.prototype("void double_vector_shift( double_vector , double )") -cfunc.double_vector_scale = cwrapper.prototype("void double_vector_scale( double_vector , double )") -cfunc.double_vector_div = cwrapper.prototype("void double_vector_div( double_vector , double )") +cfunc.double_vector_scale = cwrapper.prototype("void double_vector_scale( double_vector , double )") +cfunc.double_vector_div = cwrapper.prototype("void double_vector_div( double_vector , double )") cfunc.double_vector_inplace_add = cwrapper.prototype("void double_vector_inplace_add( double_vector , double_vector )") cfunc.double_vector_inplace_mul = cwrapper.prototype("void double_vector_inplace_mul( double_vector , double_vector )") -cfunc.double_vector_assign = cwrapper.prototype("void double_vector_set_all( double_vector , double)") +cfunc.double_vector_assign = cwrapper.prototype("void double_vector_set_all( double_vector , double)") cfunc.double_vector_memcpy = cwrapper.prototype("void double_vector_memcpy(double_vector , double_vector )") cfunc.double_vector_set_default = cwrapper.prototype("void double_vector_set_default( double_vector , double)") cfunc.double_vector_get_default = cwrapper.prototype("double double_vector_get_default( double_vector )") @@ -753,29 +798,29 @@ cfunc.double_vector_element_size = cwrapper.prototype("int double_ve cfunc.int_vector_alloc_copy = cwrapper.prototype("c_void_p int_vector_alloc_copy( int_vector )") cfunc.int_vector_alloc = cwrapper.prototype("c_void_p int_vector_alloc( int , int )") cfunc.int_vector_strided_copy = cwrapper.prototype("c_void_p int_vector_alloc_strided_copy( int_vector , int , int , int)") -cfunc.int_vector_free = cwrapper.prototype("void int_vector_free( int_vector )") +# cfunc.int_vector_free = cwrapper.prototype("void int_vector_free( int_vector )") cfunc.int_vector_iget = cwrapper.prototype("int int_vector_iget( int_vector , int )") cfunc.int_vector_safe_iget = cwrapper.prototype("int int_vector_safe_iget( int_vector , int )") cfunc.int_vector_iset = cwrapper.prototype("int int_vector_iset( int_vector , int , int)") cfunc.int_vector_size = cwrapper.prototype("int int_vector_size( int_vector )") -cfunc.int_vector_append = cwrapper.prototype("void int_vector_append( int_vector , int )") -cfunc.int_vector_idel_block = cwrapper.prototype("void int_vector_idel_block( int_vector , int , int )") +cfunc.int_vector_append = cwrapper.prototype("void int_vector_append( int_vector , int )") +cfunc.int_vector_idel_block = cwrapper.prototype("void int_vector_idel_block( int_vector , int , int )") cfunc.int_vector_fprintf = cwrapper.prototype("void int_vector_fprintf( int_vector , FILE , char* , char*)") -cfunc.int_vector_sort = cwrapper.prototype("void int_vector_sort( int_vector )") -cfunc.int_vector_rsort = cwrapper.prototype("void int_vector_rsort( int_vector )") -cfunc.int_vector_reset = cwrapper.prototype("void int_vector_reset( int_vector )") -cfunc.int_vector_set_read_only = cwrapper.prototype("void int_vector_set_read_only( int_vector , bool )") -cfunc.int_vector_get_read_only = cwrapper.prototype("bool int_vector_get_read_only( int_vector )") +cfunc.int_vector_sort = cwrapper.prototype("void int_vector_sort( int_vector )") +cfunc.int_vector_rsort = cwrapper.prototype("void int_vector_rsort( int_vector )") +cfunc.int_vector_reset = cwrapper.prototype("void int_vector_reset( int_vector )") +cfunc.int_vector_set_read_only = cwrapper.prototype("void int_vector_set_read_only( int_vector , bool )") +cfunc.int_vector_get_read_only = cwrapper.prototype("bool int_vector_get_read_only( int_vector )") cfunc.int_vector_get_max = cwrapper.prototype("int int_vector_get_max( int_vector )") cfunc.int_vector_get_min = cwrapper.prototype("int int_vector_get_min( int_vector )") cfunc.int_vector_get_max_index = cwrapper.prototype("int int_vector_get_max_index( int_vector , bool)") cfunc.int_vector_get_min_index = cwrapper.prototype("int int_vector_get_min_index( int_vector , bool)") cfunc.int_vector_shift = cwrapper.prototype("void int_vector_shift( int_vector , int )") -cfunc.int_vector_scale = cwrapper.prototype("void int_vector_scale( int_vector , int )") -cfunc.int_vector_div = cwrapper.prototype("void int_vector_div( int_vector , int )") +cfunc.int_vector_scale = cwrapper.prototype("void int_vector_scale( int_vector , int )") +cfunc.int_vector_div = cwrapper.prototype("void int_vector_div( int_vector , int )") cfunc.int_vector_inplace_add = cwrapper.prototype("void int_vector_inplace_add( int_vector , int_vector )") cfunc.int_vector_inplace_mul = cwrapper.prototype("void int_vector_inplace_mul( int_vector , int_vector )") -cfunc.int_vector_assign = cwrapper.prototype("void int_vector_set_all( int_vector , int)") +cfunc.int_vector_assign = cwrapper.prototype("void int_vector_set_all( int_vector , int)") cfunc.int_vector_memcpy = cwrapper.prototype("void int_vector_memcpy(int_vector , int_vector )") cfunc.int_vector_set_default = cwrapper.prototype("void int_vector_set_default( int_vector , int)") cfunc.int_vector_get_default = cwrapper.prototype("int int_vector_get_default( int_vector )") @@ -787,29 +832,29 @@ cfunc.int_vector_element_size = cwrapper.prototype("int int_vector_ele cfunc.bool_vector_alloc_copy = cwrapper.prototype("c_void_p bool_vector_alloc_copy( bool_vector )") cfunc.bool_vector_alloc = cwrapper.prototype("c_void_p bool_vector_alloc( int , bool )") cfunc.bool_vector_strided_copy = cwrapper.prototype("c_void_p bool_vector_alloc_strided_copy( bool_vector , bool , bool , bool)") -cfunc.bool_vector_free = cwrapper.prototype("void bool_vector_free( bool_vector )") +# cfunc.bool_vector_free = cwrapper.prototype("void bool_vector_free( bool_vector )") cfunc.bool_vector_iget = cwrapper.prototype("bool bool_vector_iget( bool_vector , bool )") cfunc.bool_vector_safe_iget = cwrapper.prototype("bool bool_vector_safe_iget( bool_vector , bool )") cfunc.bool_vector_iset = cwrapper.prototype("bool bool_vector_iset( bool_vector , bool , bool)") cfunc.bool_vector_size = cwrapper.prototype("bool bool_vector_size( bool_vector )") -cfunc.bool_vector_append = cwrapper.prototype("void bool_vector_append( bool_vector , bool )") -cfunc.bool_vector_idel_block = cwrapper.prototype("void bool_vector_idel_block( bool_vector , bool , bool )") +cfunc.bool_vector_append = cwrapper.prototype("void bool_vector_append( bool_vector , bool )") +cfunc.bool_vector_idel_block = cwrapper.prototype("void bool_vector_idel_block( bool_vector , bool , bool )") cfunc.bool_vector_fprintf = cwrapper.prototype("void bool_vector_fprintf( bool_vector , FILE , char* , char*)") -cfunc.bool_vector_sort = cwrapper.prototype("void bool_vector_sort( bool_vector )") -cfunc.bool_vector_rsort = cwrapper.prototype("void bool_vector_rsort( bool_vector )") -cfunc.bool_vector_reset = cwrapper.prototype("void bool_vector_reset( bool_vector )") -cfunc.bool_vector_set_read_only = cwrapper.prototype("void bool_vector_set_read_only( bool_vector , bool )") -cfunc.bool_vector_get_read_only = cwrapper.prototype("bool bool_vector_get_read_only( bool_vector )") +cfunc.bool_vector_sort = cwrapper.prototype("void bool_vector_sort( bool_vector )") +cfunc.bool_vector_rsort = cwrapper.prototype("void bool_vector_rsort( bool_vector )") +cfunc.bool_vector_reset = cwrapper.prototype("void bool_vector_reset( bool_vector )") +cfunc.bool_vector_set_read_only = cwrapper.prototype("void bool_vector_set_read_only( bool_vector , bool )") +cfunc.bool_vector_get_read_only = cwrapper.prototype("bool bool_vector_get_read_only( bool_vector )") cfunc.bool_vector_get_max = cwrapper.prototype("bool bool_vector_get_max( bool_vector )") cfunc.bool_vector_get_min = cwrapper.prototype("bool bool_vector_get_min( bool_vector )") cfunc.bool_vector_get_max_index = cwrapper.prototype("bool bool_vector_get_max_index( bool_vector , bool)") cfunc.bool_vector_get_min_index = cwrapper.prototype("bool bool_vector_get_min_index( bool_vector , bool)") cfunc.bool_vector_shift = cwrapper.prototype("void bool_vector_shift( bool_vector , bool )") -cfunc.bool_vector_scale = cwrapper.prototype("void bool_vector_scale( bool_vector , bool )") -cfunc.bool_vector_div = cwrapper.prototype("void bool_vector_div( bool_vector , bool )") +cfunc.bool_vector_scale = cwrapper.prototype("void bool_vector_scale( bool_vector , bool )") +cfunc.bool_vector_div = cwrapper.prototype("void bool_vector_div( bool_vector , bool )") cfunc.bool_vector_inplace_add = cwrapper.prototype("void bool_vector_inplace_add( bool_vector , bool_vector )") cfunc.bool_vector_inplace_mul = cwrapper.prototype("void bool_vector_inplace_mul( bool_vector , bool_vector )") -cfunc.bool_vector_assign = cwrapper.prototype("void bool_vector_set_all( bool_vector , bool)") +cfunc.bool_vector_assign = cwrapper.prototype("void bool_vector_set_all( bool_vector , bool)") cfunc.bool_vector_memcpy = cwrapper.prototype("void bool_vector_memcpy(bool_vector , bool_vector )") cfunc.bool_vector_set_default = cwrapper.prototype("void bool_vector_set_default( bool_vector , bool)") cfunc.bool_vector_get_default = cwrapper.prototype("bool bool_vector_get_default( bool_vector )") @@ -817,6 +862,40 @@ cfunc.bool_vector_alloc_data_copy = cwrapper.prototype("bool* bool_vector_a cfunc.bool_vector_data_ptr = cwrapper.prototype("bool* bool_vector_get_ptr( bool_vector )") cfunc.bool_vector_element_size = cwrapper.prototype("int bool_vector_element_size( bool_vector )") + +cfunc.time_t_vector_alloc = cwrapper.prototype("c_void_p time_t_vector_alloc(int, time_t )") +cfunc.time_t_vector_alloc_copy = cwrapper.prototype("c_void_p time_t_vector_alloc_copy(time_t_vector )") +cfunc.time_t_vector_strided_copy = cwrapper.prototype("c_void_p time_t_vector_alloc_strided_copy(time_t_vector , time_t , time_t , time_t)") +# cfunc.time_t_vector_free = cwrapper.prototype("void time_t_vector_free( time_t_vector )") +cfunc.time_t_vector_iget = cwrapper.prototype("time_t time_t_vector_iget( time_t_vector , int )") +cfunc.time_t_vector_safe_iget = cwrapper.prototype("time_t time_t_vector_safe_iget( time_t_vector , int )") +cfunc.time_t_vector_iset = cwrapper.prototype("time_t time_t_vector_iset( time_t_vector , int , time_t)") +cfunc.time_t_vector_size = cwrapper.prototype("int time_t_vector_size( time_t_vector )") +cfunc.time_t_vector_append = cwrapper.prototype("void time_t_vector_append( time_t_vector , time_t )") +cfunc.time_t_vector_idel_block = cwrapper.prototype("void time_t_vector_idel_block( time_t_vector , int , int )") +cfunc.time_t_vector_fprintf = cwrapper.prototype("void time_t_vector_fprintf( time_t_vector , FILE , char* , char*)") +cfunc.time_t_vector_sort = cwrapper.prototype("void time_t_vector_sort( time_t_vector )") +cfunc.time_t_vector_rsort = cwrapper.prototype("void time_t_vector_rsort( time_t_vector )") +cfunc.time_t_vector_reset = cwrapper.prototype("void time_t_vector_reset( time_t_vector )") +cfunc.time_t_vector_set_read_only = cwrapper.prototype("void time_t_vector_set_read_only( time_t_vector , bool )") +cfunc.time_t_vector_get_read_only = cwrapper.prototype("bool time_t_vector_get_read_only( time_t_vector )") +cfunc.time_t_vector_get_max = cwrapper.prototype("time_t time_t_vector_get_max( time_t_vector )") +cfunc.time_t_vector_get_min = cwrapper.prototype("time_t time_t_vector_get_min( time_t_vector )") +cfunc.time_t_vector_get_max_index = cwrapper.prototype("int time_t_vector_get_max_index( time_t_vector , bool)") +cfunc.time_t_vector_get_min_index = cwrapper.prototype("int time_t_vector_get_min_index( time_t_vector , bool)") +cfunc.time_t_vector_shift = cwrapper.prototype("void time_t_vector_shift( time_t_vector , time_t )") +cfunc.time_t_vector_scale = cwrapper.prototype("void time_t_vector_scale( time_t_vector , time_t )") +cfunc.time_t_vector_div = cwrapper.prototype("void time_t_vector_div( time_t_vector , time_t )") +cfunc.time_t_vector_inplace_add = cwrapper.prototype("void time_t_vector_inplace_add( time_t_vector , time_t_vector )") +cfunc.time_t_vector_inplace_mul = cwrapper.prototype("void time_t_vector_inplace_mul( time_t_vector , time_t_vector )") +cfunc.time_t_vector_assign = cwrapper.prototype("void time_t_vector_set_all( time_t_vector , time_t)") +cfunc.time_t_vector_memcpy = cwrapper.prototype("void time_t_vector_memcpy(time_t_vector , time_t_vector )") +cfunc.time_t_vector_set_default = cwrapper.prototype("void time_t_vector_set_default( time_t_vector , time_t)") +cfunc.time_t_vector_get_default = cwrapper.prototype("time_t time_t_vector_get_default( time_t_vector )") +cfunc.time_t_vector_alloc_data_copy = cwrapper.prototype("time_t* time_t_vector_alloc_data_copy( time_t_vector )") +cfunc.time_t_vector_data_ptr = cwrapper.prototype("time_t* time_t_vector_get_ptr( time_t_vector )") +cfunc.time_t_vector_element_size = cwrapper.prototype("int time_t_vector_element_size( time_t_vector )") + #----------------------------------------------------------------- cfunc.create_active_list = cwrapper.prototype("c_void_p string_util_alloc_active_list( char* )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/util_func.py b/ThirdParty/Ert/devel/python/python/ert/util/util_func.py index d6a5ca4dae..4a4f3622ba 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/util_func.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/util_func.py @@ -17,12 +17,11 @@ Module with utility functions from util.c """ -import ctypes -import libutil -from ert.cwrap.cwrap import * +from ert.util import UTIL_LIB +from ert.cwrap import CWrapper, CWrapperNameSpace -def strcmp_int( s1 , s2): +def strcmp_int( s1, s2): """ Function to compare strings with embedded integers. @@ -45,20 +44,20 @@ def strcmp_int( s1 , s2): character, wheras the strcmp_float() function will interpret '.' as a descimal point. """ - return cfunc.strcmp_int( s1 , s2 ) + return cfunc.strcmp_int(s1, s2) -def strcmp_float( s1 , s2): +def strcmp_float( s1, s2): """ Function to compare strings with embedded numbers. See documentation of strcmp_int() for further details. """ - return cfunc.strcmp_float( s1 , s2 ) + return cfunc.strcmp_float(s1, s2) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("util_func") +cwrapper = CWrapper(UTIL_LIB) +cfunc = CWrapperNameSpace("util_func") -cfunc.strcmp_int = cwrapper.prototype("int util_strcmp_int( char* , char* )") +cfunc.strcmp_int = cwrapper.prototype("int util_strcmp_int( char* , char* )") cfunc.strcmp_float = cwrapper.prototype("int util_strcmp_float( char* , char* )") diff --git a/ThirdParty/Ert/devel/python/python/ert/well/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/well/CMakeLists.txt index 0ca38624ff..6d71748709 100644 --- a/ThirdParty/Ert/devel/python/python/ert/well/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/well/CMakeLists.txt @@ -1 +1,10 @@ -add_python_package("Python ert.well" ${PYTHON_INSTALL_PREFIX}/ert/well "__init__.py;libwell.py;well_info.py;well.py;well_state.py;well_ts.py" True) +set(PYTHON_SOURCES + __init__.py + libwell.py + well_info.py + well.py + well_state.py + well_ts.py +) + +add_python_package("Python ert.well" ${PYTHON_INSTALL_PREFIX}/ert/well "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/well/libwell.py b/ThirdParty/Ert/devel/python/python/ert/well/libwell.py index 223cb5090a..d0f94e7195 100644 --- a/ThirdParty/Ert/devel/python/python/ert/well/libwell.py +++ b/ThirdParty/Ert/devel/python/python/ert/well/libwell.py @@ -1,3 +1,3 @@ -import ert.ecl.libecl +import ert.ecl import ert.cwrap.clib as clib lib = clib.ert_load("libecl_well.so") diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/gert_main.py b/ThirdParty/Ert/devel/python/python/ert_gui/gert_main.py index c3ace25019..0f19da4192 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/gert_main.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/gert_main.py @@ -96,7 +96,7 @@ # # in principle be shared among gert versions built for different operating # # system versions: # -# export GERT_SHARE_PATH=/opt/ert/share +# export ERT_SHARE_PATH=/opt/ert/share # # # The ERT site configuration file is assumed to be in # # /opt/ert/etc/site-config, i.e. we set the variable ERT_SITE_CONFIG as: @@ -106,7 +106,7 @@ # # Now the environment should be fully initialized, and we are ready to invoke # # the gert_main.py script, i.e. this file: # -# exec python /opt/ert/python/ert_gui/gert_main.py +# exec python /opt/ert/python/ert_gui/gert_main.py $@ # #-------------------- -------------------- @@ -142,12 +142,12 @@ def main(): splash = QtGui.QSplashScreen(resourceImage("newsplash") , QtCore.Qt.WindowStaysOnTopHint) splash.show() - splash.showMessage("Starting up...", color=QtCore.Qt.white) + splash.showMessage("Starting up...", QtCore.Qt.AlignLeft, QtCore.Qt.white) app.processEvents() window = Application() - splash.showMessage("Bootstrapping...", color=QtCore.Qt.white) + splash.showMessage("Bootstrapping...", QtCore.Qt.AlignLeft, QtCore.Qt.white) app.processEvents() ert = ErtWrapper( ) @@ -186,7 +186,7 @@ def main(): ert.bootstrap(enkf_config, site_config = site_config, strict = strict) window.setSaveFunction(ert.save) - splash.showMessage("Creating GUI...", color=QtCore.Qt.white) + splash.showMessage("Creating GUI...", QtCore.Qt.AlignLeft, QtCore.Qt.white) app.processEvents() window.addPage("Configuration", resourceIcon("config"), ConfigPages(window)) @@ -194,7 +194,7 @@ def main(): window.addPage("Run" , resourceIcon("run"), RunPanel(window)) window.addPage("Plots", resourceIcon("plot"), PlotPanel()) - splash.showMessage("Communicating with ERT...", color=QtCore.Qt.white) + splash.showMessage("Communicating with ERT...", QtCore.Qt.AlignLeft, QtCore.Qt.white) app.processEvents() ContentModel.contentModel = ert diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/ensemble.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/ensemble.py index 07cdf0a760..74fcce42af 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/ensemble.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/ensemble.py @@ -81,10 +81,10 @@ def createEnsemblePage(configPanel, parent): model = DataModel(key) output_format_value = node.data_model.get_output_format - output_format = gen_data_file_format.resolveValue(output_format_value) + output_format = enums.gen_data_file_format.resolveValue(output_format_value) input_format_value = node.data_model.get_input_format - input_format = gen_data_file_format.resolveValue(input_format_value) + input_format = enums.gen_data_file_format.resolveValue(input_format_value) template_file = node.data_model.get_template_file template_key = node.data_model.get_template_key diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initpanel.py index 7cbb0e547a..c7d892b6c3 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initpanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initpanel.py @@ -20,7 +20,7 @@ from ert_gui.widgets.tablewidgets import KeywordList from ert_gui.widgets.validateddialog import ValidatedDialog import ert.ert.ertwrapper as ertwrapper from ert_gui.widgets.combochoice import ComboChoice - +from ert.enkf.enkf_fs import EnkfFs from ert_gui.widgets.helpedwidget import HelpedWidget from ert_gui.widgets.util import resourceIcon, createSeparator, may_take_a_long_time @@ -77,8 +77,8 @@ class InitPanel(QtGui.QFrame): fs = ert.main.get_fs for case in cases: - if not fs.has_dir(case): - fs.select_write_dir(case, True) + if not ert.main.fs_exists(case): + ert.main.select_fs(case) break self.currentCase.updateList(self.get_case_list(ert)) diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/ensemblefetcher.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/ensemblefetcher.py index 8f0b5e081b..0e98043037 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/ensemblefetcher.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/ensemblefetcher.py @@ -61,7 +61,6 @@ class EnsembleFetcher(PlotDataFetcherHandler): num_realizations = ert.main.ens_size var_type_set = False user_data = parameter.getUserData() - if user_data is None: return False @@ -115,7 +114,6 @@ class EnsembleFetcher(PlotDataFetcherHandler): if config_node.get_impl_type == SummaryModel.TYPE: start_time = 1 for step in range(start_time, stop_time): - pikk = True time_map = fs.get_time_map sim_time_as_c_int = time_map.iget(step) sim_time_as_time_t = time_t(sim_time_as_c_int) @@ -128,7 +126,7 @@ class EnsembleFetcher(PlotDataFetcherHandler): x_time.append(sim_time_as_ordinal) y.append(valid.value) #else: - #print "Not valid: ", key, member, step, key_index, value, state.value() + #print "Not valid: ", key, member, step, key_index, value, state.value() if not comparison_fs is None: time_map = comparison_fs.get_time_map diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotconfig.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotconfig.py index 0917ace506..3e6f843d2c 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotconfig.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotconfig.py @@ -15,7 +15,7 @@ # for more details. -from PyQt4.QtCore import QObject, QSize +from PyQt4.QtCore import QObject, QSize, pyqtSignal from PyQt4.Qt import SIGNAL from PyQt4.QtGui import QFormLayout, QFrame, QComboBox, QHBoxLayout, QDoubleSpinBox, QWidget, QPainter, QColor, QColorDialog from PyQt4.QtGui import QCheckBox, QDialog @@ -40,6 +40,7 @@ class PlotConfig(object): def notify(self): """Tell all listeners that something has changed. Automatically called by setters.""" + #self.signal_handler.emit(plotConfigChanged) self.signal_handler.emit(SIGNAL('plotConfigChanged(PlotConfig)'), self) def get_name(self): @@ -125,11 +126,12 @@ class PlotConfigPanel(QFrame): plot_marker_styles = ["", ".", ",", "o", "*", "s", "+", "x", "p", "h", "H", "D", "d"] plot_line_styles = ["", "-", "--", "-.", ":"] + changed = pyqtSignal(object) + def __init__(self, plot_config): QFrame.__init__(self) self.plot_config = plot_config - self.connect(plot_config.signal_handler, SIGNAL('plotConfigChanged(PlotConfig)'), self._fetchValues) - + self.changed.connect( self._fetchValues ) layout = QFormLayout() layout.setRowWrapPolicy(QFormLayout.WrapLongRows) diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotdata.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotdata.py index 1c46c364ef..9d43a79ee5 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotdata.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotdata.py @@ -262,7 +262,7 @@ class PlotContextDataFetcher(ContentModel): elif type == DataModel.TYPE: data.parameters.append(Parameter(key, DataModel.TYPE)) - data.gen_data_size = 2#config_node.data_model.get_initial_size + data.gen_data_size = config_node.data_model.get_initial_size elif type == KeywordModel.TYPE: p = Parameter(key, KeywordModel.TYPE) diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotpanel.py index a78439dd77..8f7fade950 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotpanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotpanel.py @@ -30,7 +30,7 @@ import matplotlib.dates from zoomslider import ZoomSlider from ert_gui.widgets.configpanel import ConfigPanel from PyQt4.Qt import SIGNAL -from PyQt4.QtCore import QDate, Qt, QPoint +from PyQt4.QtCore import QDate, Qt, QPoint , pyqtSignal from plotconfig import PlotConfigPanel from PyQt4.QtGui import QTabWidget, QFormLayout, QFrame, QVBoxLayout, QHBoxLayout, QCheckBox, QPushButton, QToolButton, QMainWindow from PyQt4.QtGui import QCalendarWidget @@ -38,6 +38,9 @@ import plotsettings import ert.ert.erttypes as erttypes class PlotPanel(QtGui.QWidget): + + changed = pyqtSignal() + def __init__(self): QtGui.QWidget.__init__(self) @@ -87,9 +90,10 @@ class PlotPanel(QtGui.QWidget): self.setLayout(plotLayout) - self.connect(self.plot.plot_settings, QtCore.SIGNAL('plotSettingsChanged(PlotSettings)'), self.fetchSettings) - + self.changed.connect( self.fetchSettings ) + #self.connect(self.plot.plot_settings, QtCore.SIGNAL('plotSettingsChanged(PlotSettings)'), self.fetchSettings) ContentModel.modelConnect('casesUpdated()', self.updateList) + def drawPlot(self): self.plot.setData(self.plotDataFetcher.data) diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettings.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettings.py index b0bc0ec8cf..01d1fcb878 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettings.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettings.py @@ -19,7 +19,7 @@ from plotconfig import PlotConfig import matplotlib from ert.ert.erttypes import time_t import datetime -from PyQt4.QtCore import QObject, SIGNAL +from PyQt4.QtCore import QObject, SIGNAL, pyqtSignal class PlotSettings(QObject): """ @@ -33,6 +33,8 @@ class PlotSettings(QObject): refcase_color = (0/255.0, 200/255.0, 0/255.0) # green comparison_color = (199/255.0, 63/255.0, 0/255.0) # orange + changed = pyqtSignal(object) + def __init__(self): QObject.__init__(self) @@ -64,9 +66,9 @@ class PlotSettings(QObject): self.std_plot_config, self.errorbar_plot_config, self.comparison_plot_config] - - #for pc in self._plot_configs: - # self.connect(pc.signal_handler, SIGNAL('plotConfigChanged(PlotConfig)'), self.notify) + + for pc in self._plot_configs: + self.changed.connect( self.notify ) self._plot_config_dict = {} for pc in self._plot_configs: diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulation.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulation.py index 0a880b913c..c9fa8ce5b2 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulation.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulation.py @@ -344,7 +344,7 @@ class SimulationPanelController: def pause(self, pause): """Pause the job queue after the currently running jobs are finished.""" - job_queue = self.ert.main.site_config.get_job_queue + job_queue = self.ert.main.site_config.get_job_queue() if pause: self.statistics.stop() @@ -358,8 +358,9 @@ class SimulationPanelController: killAll = QtGui.QMessageBox.question(self.view, "Remove all jobs?", "Are you sure you want to remove all jobs from the queue?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if killAll == QtGui.QMessageBox.Yes: - job_queue = self.ert.main.site_config.get_job_queue - job_queue.user_exit + job_queue = self.ert.main.site_config.get_job_queue( ) + job_queue.user_exit( ) + def showSelectedSimulations(self): """Update information relating to a single job""" @@ -443,7 +444,7 @@ class Simulation: def hasFailed(self): """Has the job failed?""" - return self.checkStatus(ert_job_status_type.ALL_FAIL) + return self.checkStatus(ert_job_status_type.FAILED) def notActive(self): """Is the job active?""" @@ -451,7 +452,7 @@ class Simulation: def finishedSuccessfully(self): """Has the job finished?""" - return self.checkStatus(ert_job_status_type.ALL_OK) + return self.checkStatus(ert_job_status_type.SUCCESS) def isUserKilled(self): """Has the job been killed by the user?""" @@ -463,7 +464,7 @@ class Simulation: if len(self.statuslog) == 0 or not self.statuslog[len(self.statuslog) - 1] == status: self.statuslog.append(status) - if status == ert_job_status_type.ALL_OK: + if status == ert_job_status_type.SUCCESS: self.setFinishedTime(int(time.time())) self.status = status diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulationsdialog.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulationsdialog.py index c6f51489c1..250571ae91 100644 --- a/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulationsdialog.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulationsdialog.py @@ -100,7 +100,7 @@ class SimulationsDialog(QtGui.QDialog): selectAll = self._createAction("Select all", self.simulationList.selectAll) unselectAll = self._createAction("Unselect all", self.simulationList.clearSelection) selectRunning = self._createAction("Select all running", lambda : self.ctrl.select(ert_job_status_type.RUNNING)) - selectFailed = self._createAction("Select all failed", lambda : self.ctrl.select(ert_job_status_type.ALL_FAIL)) + selectFailed = self._createAction("Select all failed", lambda : self.ctrl.select(ert_job_status_type.FAILED)) selectUserKilled = self._createAction("Select all user killed", lambda : self.ctrl.select(ert_job_status_type.USER_KILLED)) selectWaiting = self._createAction("Select all waiting", lambda : self.ctrl.select(ert_job_status_type.WAITING, ert_job_status_type.PENDING)) @@ -209,7 +209,7 @@ class SimulationsDialogController: for member in selectedMembers: state = ert.main.iget_state(member) status = state.get_run_status - + simulations[member].simulation.setStatus(ert_job_status_type.resolveValue(status)) if not ert_job_status_type.NOT_ACTIVE == status: diff --git a/ThirdParty/Ert/devel/python/test/CMakeLists.txt b/ThirdParty/Ert/devel/python/test/CMakeLists.txt index 013b813580..8c9e3f1146 100644 --- a/ThirdParty/Ert/devel/python/test/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/test/CMakeLists.txt @@ -1,68 +1,206 @@ -add_python_package("Python test" "${PYTHON_INSTALL_PREFIX}/test" "ecl_isosurf.py;enkf_test.py;ens_config_test.py;file_test.py;fortio_test.py;grav_test.py;grdecl_test.py;grid_test0.py;grid_test.py;import_test.py;job_test.py;kw_test.py;large_mem_test.py;latex_test.py;petrel_kw.py;poly_test.py;region_test.py;restart_test.py;rft_test.py;sched_test.py;stringlist_test.py;sum_test.py;test_all.py;test_fast.py;test_util.py;troll_test.py;util_test.py;ctest_run.py" True) +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") -# The test date is located in the current source directory; that is +set(TEST_SOURCES + ert_tests/__init__.py + ert_tests/run_tests.py + ert_tests/test_ert_import.py + ert_tests/test_ert_gui_import.py + + ert_tests/config/__init__.py + ert_tests/config/test_config.py + + ert_tests/ecl/__init__.py + ert_tests/ecl/test_ecl_default.py + ert_tests/ecl/test_ecl_file.py + ert_tests/ecl/test_ecl_submit.py + ert_tests/ecl/test_fortio.py + ert_tests/ecl/test_grdecl.py + ert_tests/ecl/test_grid.py + ert_tests/ecl/test_kw.py + ert_tests/ecl/test_legacy_ecl.py + ert_tests/ecl/test_region.py + ert_tests/ecl/test_restart.py + ert_tests/ecl/test_rft.py + ert_tests/ecl/test_rft_cell.py + ert_tests/ecl/test_sum.py + + ert_tests/sched/__init__.py + ert_tests/sched/test_sched.py + + ert_tests/util/__init__.py + ert_tests/util/test_ctime.py + ert_tests/util/test_lookup_table.py + ert_tests/util/test_matrix.py + ert_tests/util/test_stat.py + ert_tests/util/test_string_list.py + ert_tests/util/test_vectors.py + + ecl_isosurf.py + enkf_test.py + ens_config_test.py + grav_test.py + grid_test0.py + job_test.py + petrel_kw.py + poly_test.py + troll_test.py + ctest_run.py +) + + +add_python_package("Python test" "${PYTHON_INSTALL_PREFIX}/test" "${TEST_SOURCES}" True) + +# The test data is located in the current source directory; that is # the reason we set that as the working directory for the test # run. The module to import should then be in the default python # module search path (i.e. current directory), whereas the location of # the actual ert package is given by the first argument to ctest. -add_test( NAME python.import_all +add_test( NAME python.ert.import_all_ert WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} import_test ) + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.test_ert_import.ErtImportTest ) -add_test( NAME python.import_local - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} import_local ) +add_test( NAME python.ert.import_all_ert_gui + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.test_ert_gui_import.ErtGuiImportTest ) -add_test( NAME python.ert.util.stringlist - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} stringlist_test ) -add_test( NAME python.ert.util.tvector +#UTIL + +add_test( NAME python.ert.util.stringlist WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} tvector_test ) + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_string_list.StringListTest ) + +add_test( NAME python.ert.util.tvector + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_vectors.UtilTest ) + +add_test( NAME python.ert.util.ctime + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_ctime.CTimeTest) + +add_test( NAME python.ert.util.latex + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_latex.LatexTest ) + +add_test( NAME python.ert.util.lookup_table + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_lookup_table.LookupTableTest ) + +add_test( NAME python.ert.util.matrix + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_matrix.MatrixTest ) + +add_test( NAME python.ert.util.stat + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_stat.StatTest ) + + +#ECL + + +add_test( NAME python.ert.ecl.ecl_default + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_default.EclDefaultTest ) + +add_test( NAME python.ert.ecl.ecl_file + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_file.FileTest) + +add_test( NAME python.ert.ecl.ecl_queue_LOCAL + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_submit.LocalSubmitTest ) + +if (NOT ${NFS_RUNPATH} STREQUAL "") + add_test( NAME python.ert.ecl.ecl_queue_LSF + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_submit.LSFSubmitTest ${NFS_RUNPATH} ) + set_property( TEST python.ert.ecl.ecl_queue_LSF PROPERTY LABELS Python:StatoilData:Slow ) + + if (NOT ${RSH_SERVERS} STREQUAL "") + add_test( NAME python.ert.ecl.ecl_queue_RSH + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_submit.RSHSubmitTest ${NFS_RUNPATH} ${RSH_SERVERS}) + set_property( TEST python.ert.ecl.ecl_queue_RSH PROPERTY LABELS Python:StatoilData:Slow ) + endif() +endif() + + +add_test( NAME python.ert.ecl.fortio + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_fortio.FortIOTest) + + +add_test( NAME python.ert.ecl.ecl_grdecl + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_grdecl.GRDECLTest ) add_test( NAME python.ert.ecl.ecl_grid WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} grid_test ) + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_grid.GridTest ) add_test( NAME python.ert.ecl.ecl_kw WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} kw_test ) + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_kw.KWTest ) -add_test( NAME python.ert.ecl.ecl_sum - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} sum_test ) +add_test( NAME python.ert.ecl.legacy_ecl + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_legacy_ecl.LegacyEclTest) -add_test( NAME python.ert.ecl.ecl_file - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} file_test False) +add_test( NAME python.ert.ecl.ecl_restart + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_restart.RestartTest) -add_test( NAME python.ert.ecl.ecl_file_slow - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} file_test True) +add_test( NAME python.ert.ecl.ecl_region + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_region.RegionTest) add_test( NAME python.ert.ecl.ecl_rft WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} rft_test) + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_rft.RFTTest) add_test( NAME python.ert.ecl.ecl_rft_cell WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} rft_cell_test) + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_rft_cell.RFTCellTest) + +add_test( NAME python.ert.ecl.ecl_sum + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_sum.SumTest) -set_property( TEST python.ert.ecl.ecl_file PROPERTY LABELS Python:StatoilData ) -set_property( TEST python.ert.ecl.ecl_file_slow PROPERTY LABELS Python:StatoilData:Slow ) -set_property( TEST python.ert.ecl.ecl_sum PROPERTY LABELS Python:StatoilData ) -set_property( TEST python.ert.ecl.ecl_kw PROPERTY LABELS Python:StatoilData ) -set_property( TEST python.ert.ecl.ecl_rft PROPERTY LABELS Python:StatoilData ) -set_property( TEST python.ert.ecl.ecl_grid PROPERTY LABELS Python:StatoilData:Slow ) -set_property( TEST python.import_local PROPERTY LABELS Python:StatoilBuild ) +#SCHED +add_test( NAME python.ert.sched.sched + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.sched.test_sched.SchedFileTest) -set_property( TEST python.import_all PROPERTY LABELS Python) -set_property( TEST python.ert.util.stringlist PROPERTY LABELS Python ) -set_property( TEST python.ert.util.tvector PROPERTY LABELS Python ) -set_property( TEST python.import_all PROPERTY ENVIRONMENT "ERT_SHARE_PATH=${PROJECT_SOURCE_PATH}/share") +#CONFIG +add_test( NAME python.ert.config + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.config.test_config.ConfigTest) + + + + +set_property( TEST python.ert.sched.sched PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.fortio PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_grdecl PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_restart PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_region PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_file PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_queue_LOCAL PROPERTY LABELS Python:StatoilData:Slow ) +set_property( TEST python.ert.ecl.ecl_sum PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_kw PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_rft PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_grid PROPERTY LABELS Python:StatoilData:Slow ) +#set_property( TEST python.import_local PROPERTY LABELS Python:StatoilBuild ) + +set_property( TEST python.ert.import_all_ert PROPERTY LABELS Python) +set_property( TEST python.ert.import_all_ert_gui PROPERTY LABELS Python) +set_property( TEST python.ert.util.stringlist PROPERTY LABELS Python ) +set_property( TEST python.ert.util.tvector PROPERTY LABELS Python ) +#set_property( TEST python.ert.import_all_ert PROPERTY ENVIRONMENT "ERT_SHARE_PATH=${PROJECT_SOURCE_PATH}/share") +set_property( TEST python.ert.import_all_ert_gui PROPERTY ENVIRONMENT "ERT_SHARE_PATH=${PROJECT_SOURCE_PATH}/share") diff --git a/ThirdParty/Ert/devel/python/test/config_test.py b/ThirdParty/Ert/devel/python/test/config_test.py deleted file mode 100644 index 3086b4f0cf..0000000000 --- a/ThirdParty/Ert/devel/python/test/config_test.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'config_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 unittest -import stat -import math -import ert -import ert.ecl.ecl as ecl -import ert.config.config as config -import ert.config.config_enums as config_enums - -import sys -from test_util import * - - - -class ConfigTest( unittest.TestCase ): - - def setUp( self ): - self.file_list = [] - - - def test_enums(self): - self.assertTrue( config_enums.content_type.CONFIG_STRING ) - self.assertTrue( config_enums.content_type.CONFIG_INVALID ) - self.assertTrue( config_enums.unrecognized.CONFIG_UNRECOGNIZED_ERROR ) - - - - def test_parse(self): - conf = config.ConfigParser() - conf.add("FIELD" , False) - schema_item = conf.add("RSH_HOST" , False) - self.assertTrue( isinstance( schema_item , config.SchemaItem )) - self.assertTrue( conf.parse("test-data/local/config/simple_config" , unrecognized = config_enums.unrecognized.CONFIG_UNRECOGNIZED_IGNORE) ) - - - content_item = conf["RSH_HOST"] - self.assertTrue( isinstance( content_item , config.ContentItem )) - self.assertTrue( conf["BJARNE"] is None ) - - self.assertTrue( len(content_item) == 1) - self.assertRaises( ValueError , content_item.__getitem__ , "BJARNE") - self.assertRaises( IndexError , content_item.__getitem__ , 10 ) - - content_node = content_item[0] - self.assertTrue( isinstance( content_node , config.ContentNode )) - - self.assertTrue( len(content_node) == 2) - self.assertRaises( ValueError , content_node.__getitem__ , "BJARNE") - self.assertRaises( IndexError , content_node.__getitem__ , 10 ) - self.assertTrue( content_node[1] == "be-lx633214:2") - - self.assertTrue( content_node.content( sep = ",") == "be-lx655082:2,be-lx633214:2") - self.assertTrue( content_node.content( ) == "be-lx655082:2 be-lx633214:2") - - - content_item = conf["FIELD"] - self.assertTrue( len(content_item) == 5) - self.assertRaises(IOError , config.ConfigParser.parse , conf , "DoesNotExits") - - - - def test_schema(self): - schema_item = config.SchemaItem("TestItem") - self.assertTrue( isinstance( schema_item , config.SchemaItem )) - self.assertTrue( schema_item.iget_type( 6 ) == config_enums.content_type.CONFIG_STRING ) - schema_item.iset_type( 0 , config_enums.content_type.CONFIG_INT ) - self.assertTrue( schema_item.iget_type( 0 ) == config_enums.content_type.CONFIG_INT ) - schema_item.set_argc_minmax( 3 , 6) - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( ConfigTest( 'test_enums' )) - suite.addTest( ConfigTest( 'test_schema' )) - suite.addTest( ConfigTest( 'test_parse' )) - return suite - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - - diff --git a/ThirdParty/Ert/devel/python/test/ctest_run.py b/ThirdParty/Ert/devel/python/test/ctest_run.py index 8ca5f144b3..7710d86349 100644 --- a/ThirdParty/Ert/devel/python/test/ctest_run.py +++ b/ThirdParty/Ert/devel/python/test/ctest_run.py @@ -1,17 +1,18 @@ #!/usr/bin/env python import sys -import os -import unittest +from unittest2 import TextTestRunner +from ert_tests.run_tests import getTestsFromTestClass -def run_suite( test_suite ): - test_result = unittest.TextTestRunner(verbosity = 0).run( test_suite ) + +def runTestCase(tests): + test_result = TextTestRunner(verbosity=0).run(tests) if test_result.errors or test_result.failures: - for (test , trace_back) in test_result.errors: + for (test, trace_back) in test_result.errors: sys.stderr.write("=================================================================\n") sys.stderr.write("Test:%s error \n" % test.id()) sys.stderr.write("%s\n" % trace_back) - for (test , trace_back) in test_result.failures: + for (test, trace_back) in test_result.failures: sys.stderr.write("=================================================================\n") sys.stderr.write("Test:%s failure \n" % test.id()) sys.stderr.write("%s\n" % trace_back) @@ -21,26 +22,22 @@ def run_suite( test_suite ): return True +if __name__ == '__main__': + PYTHONPATH = sys.argv[1] + test_class_path = sys.argv[2] + argv = [] -PYTHONPATH = sys.argv[1] -test_module = sys.argv[2] -argv = [] + sys.path.insert(0, PYTHONPATH) -sys.path.insert( 0 , PYTHONPATH ) -test_module = __import__(sys.argv[2]) + try: + argv = sys.argv[3:] + except IndexError: + pass -try: - argv = sys.argv[3:] -except: - pass + tests = getTestsFromTestClass(test_class_path, argv) -test_suite = test_module.test_suite( argv ) -if test_suite: - if run_suite( test_suite ): - sys.exit( 0 ) + if runTestCase(tests): + sys.exit(0) else: - sys.exit( 1 ) -else: - sys.exit( 0 ) - + sys.exit(1) diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/__init__.py new file mode 100644 index 0000000000..5120406b82 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/__init__.py @@ -0,0 +1,86 @@ +# Copyright (C) 2012 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. +import numbers +import os +import traceback +from unittest2 import TestCase + + +""" + This class provides some extra functionality for testing values that are almost equal. + """ + + +class ExtendedTestCase(TestCase): + def assertAlmostEqualScaled(self, first, second, msg=None): + if isinstance(first, numbers.Number) and isinstance(second, numbers.Number): + tolerance = 1e-6 + diff = abs(first - second) + scale = max(1, abs(first) + abs(second)) + + self.assertTrue(diff < tolerance * scale, msg=msg) + else: + self.assertTrue(first == second, msg=msg) + + + def assertAlmostEqualList(self, first, second, msg=None): + if len(first) != len(second): + self.fail("Lists are not of same length!") + + for index in range(len(first)): + self.assertAlmostEqualScaled(first[index], second[index], msg=msg) + + 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 __filesAreEqual(self, first, second): + buffer1 = open(first).read() + buffer2 = open(second).read() + + return buffer1 == buffer2 + + def createTestPath(self, path): + """ + @param: The test root path can be set by environment variable ERT_TEST_ROOT_PATH + """ + file_path = os.path.realpath(__file__) + default_test_root = os.path.realpath(os.path.join(os.path.dirname(file_path), "../test-data/")) + test_root = os.path.realpath(os.environ.get("ERT_TEST_ROOT_PATH", default_test_root)) + + return os.path.realpath(os.path.join(test_root, path)) + + @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" \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/config/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/config/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/config/test_config.py b/ThirdParty/Ert/devel/python/test/ert_tests/config/test_config.py new file mode 100644 index 0000000000..ddba94a7aa --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/config/test_config.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'test_config.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 unittest2 import TestSuite, TextTestRunner +from ert.config import ContentTypeEnum, UnrecognizedEnum, SchemaItem, ContentItem, ContentNode, ConfigParser +from ert_tests import ExtendedTestCase + + +class ConfigTest(ExtendedTestCase): + def setUp( self ): + self.file_list = [] + + + def test_enums(self): + self.assertTrue(ContentTypeEnum.CONFIG_STRING) + self.assertTrue(ContentTypeEnum.CONFIG_INVALID) + self.assertTrue(UnrecognizedEnum.CONFIG_UNRECOGNIZED_ERROR) + + + def test_parse(self): + conf = ConfigParser() + conf.add("FIELD", False) + schema_item = conf.add("RSH_HOST", False) + self.assertIsInstance(schema_item, SchemaItem) + test_path = self.createTestPath("local/config/simple_config") + self.assertTrue(conf.parse(test_path, unrecognized=UnrecognizedEnum.CONFIG_UNRECOGNIZED_IGNORE)) + + + content_item = conf["RSH_HOST"] + self.assertIsInstance(content_item, ContentItem) + self.assertIsNone(conf["BJARNE"]) + + self.assertEqual(len(content_item), 1) + self.assertRaises(ValueError, content_item.__getitem__, "BJARNE") + self.assertRaises(IndexError, content_item.__getitem__, 10) + + content_node = content_item[0] + self.assertIsInstance(content_node, ContentNode) + + self.assertEqual(len(content_node), 2) + self.assertRaises(ValueError, content_node.__getitem__, "BJARNE") + self.assertRaises(IndexError, content_node.__getitem__, 10) + self.assertEqual(content_node[1], "be-lx633214:2") + + self.assertEqual(content_node.content(sep=","), "be-lx655082:2,be-lx633214:2") + self.assertEqual(content_node.content(), "be-lx655082:2 be-lx633214:2") + + content_item = conf["FIELD"] + self.assertEqual(len(content_item), 5) + self.assertRaises(IOError, ConfigParser.parse, conf, "DoesNotExits") + + + def test_schema(self): + schema_item = SchemaItem("TestItem") + self.assertIsInstance(schema_item, SchemaItem) + self.assertEqual(schema_item.iget_type(6), ContentTypeEnum.CONFIG_STRING) + schema_item.iset_type(0, ContentTypeEnum.CONFIG_INT) + self.assertEqual(schema_item.iget_type(0), ContentTypeEnum.CONFIG_INT) + schema_item.set_argc_minmax(3, 6) + + +def fast_suite(): + suite = TestSuite() + suite.addTest(ConfigTest('test_enums')) + suite.addTest(ConfigTest('test_schema')) + suite.addTest(ConfigTest('test_parse')) + return suite + + +if __name__ == "__main__": + TextTestRunner().run(fast_suite()) + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_default.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_default.py new file mode 100644 index 0000000000..cfe20c6ec8 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_default.py @@ -0,0 +1,18 @@ +from unittest2 import TestCase +from ert.ecl import EclDefault + + +class EclDefaultTest(TestCase): + + def test_ecl_defaults_methods(self): + try: + import ert.ecl.ecl_local as ecl_local + + self.assertEqual(EclDefault.ecl_cmd(), ecl_local.ecl_cmd) + self.assertEqual(EclDefault.ecl_version(), ecl_local.ecl_version) + self.assertEqual(EclDefault.lsf_resource_request(), ecl_local.lsf_resource_request) + self.assertEqual(EclDefault.driver_type(), ecl_local.driver_type) + self.assertEqual(EclDefault.driver_options(), ecl_local.driver_options) + except ImportError: + self.fail("Unable to import ecl_local.py") + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_file.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_file.py new file mode 100644 index 0000000000..d850841f66 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_file.py @@ -0,0 +1,100 @@ +#!/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 unittest2 import skipIf +from ert.ecl import EclFile, FortIO +from ert.ecl.ecl_util import EclFileFlagEnum + +from ert.util import TestAreaContext +from ert_tests import ExtendedTestCase + + +class FileTest(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 test_IOError(self): + with self.assertRaises(IOError): + EclFile("No/Does/not/exist") + + + 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.writer("ECLIPSE.UNRST") + 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") 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) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_submit.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_submit.py new file mode 100644 index 0000000000..8dade805b0 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_submit.py @@ -0,0 +1,160 @@ +# #!/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 getpass +from unittest2 import TestSuite, TextTestRunner, skip, skipIf +import time +import shutil +from ert.ecl import EclQueue, EclSum +from ert.job_queue import QueueDriverEnum, RSHDriver +from ert.util import TestAreaContext +from ert_tests import ExtendedTestCase + + +path = "Statoil/ECLIPSE/Gurbat" + +base = "ECLIPSE_SHORT" +LSF_base = "ECLIPSE_SHORT_MPI" + +case = "%s/%s" % (path, base) +LSF_case = "%s/%s" % (path, LSF_base) + + + +class EclSubmitTest(ExtendedTestCase): + nfs_work_path = None + rsh_servers = None + + def setUp(self): + if hasattr(self, "argv"): + if len(self.argv) > 0: + self.nfs_work_path = self.argv[0] + + if len(self.argv) > 1: + self.rsh_servers = self.argv[1] + + def make_run_path(self, iens, LSF=False): + run_path = "run%d" % iens + if os.path.exists(run_path): + shutil.rmtree(run_path) + + os.makedirs(run_path) + shutil.copytree("%s/include" % self.createTestPath(path), "%s/include" % run_path) + if LSF: + shutil.copy("%s.DATA" % self.createTestPath(LSF_case), run_path) + else: + shutil.copy("%s.DATA" % self.createTestPath(case), run_path) + + return os.path.abspath(run_path) + + +class LSFSubmitTest(EclSubmitTest): + + def test_start_parameters(self): + self.assertIsNotNone(self.nfs_work_path, "NFS work path missing!") + self.assertIsNone(self.rsh_servers) + + + #@skip("LSF not defined!") + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow LSF job submit skipped!") + def test_LSF_submit(self): + root = os.path.join(self.nfs_work_path, getpass.getuser(), "ert-test/python/ecl_submit/LSF") + if not os.path.exists(root): + os.makedirs(root) + os.chdir(root) + + num_submit = 6 + queue = EclQueue(driver_type=QueueDriverEnum.LSF_DRIVER, max_running=4, size=num_submit) + path_list = [] + + for iens in (range(num_submit)): + run_path = self.make_run_path(iens, LSF=True) + path_list.append(run_path) + job = queue.submit("%s/%s.DATA" % (run_path, LSF_base)) + + while queue.running: + time.sleep(1) + + for path in path_list: + sum = EclSum("%s/%s" % (path, LSF_base)) + self.assertIsInstance(sum, EclSum) + self.assertEqual(2, sum.last_report) + + +class RSHSubmitTest(EclSubmitTest): + + #@skip("RSH not defined!") + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow RSH job submit skipped!") + def test_RSH_submit(self): + root = os.path.join(self.nfs_work_path, getpass.getuser(), "ert-test/python/ecl_submit/RSH") + if not os.path.exists(root): + os.makedirs(root) + os.chdir(root) + + num_submit = 6 + host_list = [] + for h in self.rsh_servers.split(): + tmp = h.split(":") + if len(tmp) > 1: + num = int(tmp[1]) + else: + num = 1 + host_list.append((tmp[0], num)) + + queue = EclQueue(RSHDriver(3, host_list), size=num_submit) + path_list = [] + + for iens in (range(num_submit)): + run_path = self.make_run_path(iens) + path_list.append(run_path) + job = queue.submit("%s/%s.DATA" % (run_path, base)) + + while queue.running: + time.sleep(1) + + for path in path_list: + sum = EclSum("%s/%s" % (path, base)) + self.assertTrue(isinstance(sum, EclSum)) + self.assertEqual(2, sum.last_report) + +class LocalSubmitTest(EclSubmitTest): + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow LOCAL job submit skipped!") + def test_LOCAL_submit(self): + #work_area = TestArea("python/ecl_submit/LOCAL", True) + + with TestAreaContext("python/ecl_submit/LOCAL", True) as work_area: + num_submit = 4 + queue = EclQueue(driver_type=QueueDriverEnum.LOCAL_DRIVER, max_running=2) + path_list = [] + + for iens in range(num_submit): + run_path = self.make_run_path(iens) + path_list.append(run_path) + job = queue.submit("%s/%s.DATA" % (run_path, base)) + + queue.submit_complete() + while queue.running: + time.sleep(1) + + for path in path_list: + sum = EclSum("%s/%s" % (path, base)) + self.assertTrue(isinstance(sum, EclSum)) + self.assertEqual(2, sum.last_report) + shutil.rmtree(path) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_fortio.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_fortio.py new file mode 100644 index 0000000000..d071f4cee6 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_fortio.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'kw_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 ert.ecl import FortIO, EclTypeEnum, EclKW +from ert_tests import ExtendedTestCase +from ert.util import TestAreaContext + + + + +class FortIOTest(ExtendedTestCase): + def setUp(self): + self.unrst_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") + self.file_list = [] + + + def test_open_read(self): + f = FortIO.reader(self.unrst_file) + self.assertTrue(f) + + + def test_open_write(self): + with TestAreaContext("python/fortio/write"): + f = FortIO.writer("newfile") + f.close() + self.assertTrue(True) + + def test_noex(self): + with self.assertRaises(IOError): + f = FortIO.reader("/tmp/does/notExist") + + def test_kw(self): + kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE) + kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE) + + kw1[0] = 99 + kw1[1] = 77 + kw2[0] = 113 + kw2[1] = 335 + + with TestAreaContext("python/fortio/write-kw"): + f = FortIO.writer("test", fmt_file=False) + kw1.fwrite(f) + f.close() + + f = FortIO.open("test", mode="a") + kw2.fwrite(f) + f.close() + + f = FortIO.open("test", fmt_file=False) + k1 = EclKW.fread(f) + k2 = EclKW.fread(f) + f.close() + + self.assertTrue(k1.equal(kw1)) + self.assertTrue(k2.equal(kw2)) + + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grdecl.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grdecl.py new file mode 100644 index 0000000000..baab05ad55 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grdecl.py @@ -0,0 +1,119 @@ +#!/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 ert.ecl import EclKW +from ert_tests 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) + + + 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/devel/python/test/ert_tests/ecl/test_grid.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grid.py new file mode 100644 index 0000000000..fe2b804f52 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grid.py @@ -0,0 +1,210 @@ +#!/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 time +from unittest2 import skipIf +from ert.ecl import EclTypeEnum, EclKW, EclGrid +from ert.util import DoubleVector, TestAreaContext +from ert_tests import ExtendedTestCase + + +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_GRID( self ): + grid = EclGrid(self.grid_file()) + self.assertTrue(grid) + + + def test_EGRID( self ): + grid = EclGrid(self.egrid_file()) + self.assertTrue(grid) + + + def create(self, filename, load_actnum=True): + fileH = open(filename, "r") + specgrid = EclKW.read_grdecl(fileH, "SPECGRID", ecl_type=EclTypeEnum.ECL_INT_TYPE, 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=EclTypeEnum.ECL_INT_TYPE) + else: + actnum = None + + mapaxes = EclKW.read_grdecl(fileH, "MAPAXES") + grid = EclGrid.create(specgrid, zcorn, coord, actnum, mapaxes=mapaxes) + return grid + + + def test_rect(self): + #work_area = TestArea("python/grid-test/testRect", True) + with TestAreaContext("python/grid-test/testRect", True): + a1 = 1.0 + a2 = 2.0 + a3 = 3.0 + grid = EclGrid.create_rectangular((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.assertAlmostEqualScaled(v, a1 * a2 * a3) + + z = grid.depth(ijk=(4, 4, 4 )) + self.assertAlmostEqualScaled(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_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): + #work_area = TestArea("python/grid-test/testSave", True) + with TestAreaContext("python/grid-test/testSave", True): + 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") + + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of dual grid skipped!") + def test_dual(self): + #work_area = TestArea("python/grid-test/testDual", True) + with TestAreaContext("python/grid-test/testDual", True): + grid = EclGrid(self.egrid_file()) + self.assertFalse(grid.dual_grid) + self.assertTrue(grid.nactive_fracture == 0) + + grid2 = EclGrid(self.grid_file()) + self.assertFalse(grid.dual_grid) + self.assertTrue(grid.nactive_fracture == 0) + + dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID")) + self.assertTrue(dgrid.nactive == dgrid.nactive_fracture) + self.assertTrue(dgrid.nactive == 46118) + + dgrid2 = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID")) + self.assertTrue(dgrid.nactive == dgrid.nactive_fracture) + self.assertTrue(dgrid.nactive == 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.nactive == 106) + self.assertTrue(dgrid.nactive_fracture == 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_GRID("DUAL_DIFF.GRID") + dgrid2 = EclGrid("DUAL_DIFF.GRID") + self.assertTrue(dgrid.equal(dgrid2)) + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of nactive large memory skipped!") + def test_nactive_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.nactive, grid2.nactive) + self.assertEqual(grid1.nactive, 34770) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_kw.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_kw.py new file mode 100644 index 0000000000..c364b0da3e --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_kw.py @@ -0,0 +1,230 @@ +#!/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 +from ert.ecl import EclKW, EclTypeEnum, EclFile +from ert.util import TestAreaContext + +from ert_tests import ExtendedTestCase + + +def copy_long(): + src = EclKW.create("NAME", 100, EclTypeEnum.ECL_FLOAT_TYPE) + copy = src.sub_copy(0, 2000) + + +def copy_offset(): + src = EclKW.create("NAME", 100, EclTypeEnum.ECL_FLOAT_TYPE) + 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.fortio_size + + stat = os.stat(unrst_file_path) + self.assertTrue(size == stat.st_size) + + + def test_equal(self): + kw1 = EclKW.new("TEST", 3, EclTypeEnum.ECL_CHAR_TYPE) + kw1[0] = "Test1" + kw1[1] = "Test13" + kw1[2] = "Test15" + + kw2 = EclKW.new("TEST", 3, EclTypeEnum.ECL_CHAR_TYPE) + 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)) + + + def kw_test( self, data_type, data, fmt ): + name1 = "file1.txt" + name2 = "file2.txt" + kw = EclKW.new("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) + + + 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, swat.size) + + self.assertTrue(swat.equal(swat1)) + self.assertTrue(swat.equal(swat2)) + + swat3 = swat.sub_copy(20000, 100, new_header="swat") + self.assertTrue(swat3.name == "swat") + self.assertTrue(swat3.size == 100) + equal = True + for i in range(swat3.size): + if swat3[i] != swat[i + 20000]: + equal = False + self.assertTrue(equal) + + self.assertRaises(IndexError, copy_long) + self.assertRaises(IndexError, copy_offset) + + + def test_fprintf( self ): + #work_area = TestArea("python.ecl_kw") + with TestAreaContext("python.ecl_kw"): + self.kw_test(EclTypeEnum.ECL_INT_TYPE, [0, 1, 2, 3, 4, 5], "%4d\n") + self.kw_test(EclTypeEnum.ECL_FLOAT_TYPE, [0.0, 1.1, 2.2, 3.3, 4.4, 5.5], "%12.6f\n") + self.kw_test(EclTypeEnum.ECL_DOUBLE_TYPE, [0.0, 1.1, 2.2, 3.3, 4.4, 5.5], "%12.6f\n") + self.kw_test(EclTypeEnum.ECL_BOOL_TYPE, [True, True, True, False, True], "%4d\n") + self.kw_test(EclTypeEnum.ECL_CHAR_TYPE, ["1", "22", "4444", "666666", "88888888"], "%-8s\n") + + +#def cutoff( x , arg ): +# if x < arg: +# return 0 +# else: +# return x +# +# +#init_file = ecl.EclFile( "data/eclipse/case/ECLIPSE.INIT" ) +#permx = init_file.iget_named_kw("PERMX" , 0 ) +#poro = init_file.iget_named_kw("PORO" , 0 ) +#pvt = init_file.iget_named_kw("PVTNUM" , 0 ) +#grid = ecl.EclGrid( "data/eclipse/case/ECLIPSE.EGRID" ) +# +# +#poro3d = grid.create3D( poro , default = -100) +# +#print "max:%g" % poro.max +#print "min:%g" % poro.min +# +#mask1 = ecl.EclRegion( grid , False ) +#mask2 = ecl.EclRegion( grid , False ) +#mask1.select_less( poro , 0.15 ) +#mask2.select_more( poro , 0.30 ) +# +#mask3 = mask1.copy() +#mask3 |= mask2 +# +#mask1.reset() +#(x,y,z) = grid.get_xyz( ijk = (grid.nx / 2 , grid.ny /2 , grid.nz / 2) ) +#mask1.select_above_plane( [0,0,1] , [x,y,z] ) +#print mask1.active_list.size +#print mask1.active_list.str( max_lines = None ) +# +#print mask2.active_list.size +#print mask3.active_list.size +# +#poro.apply( cutoff , mask = mask1 , arg = 0.05) +# +# +#poro.write_grdecl( open("/tmp/poro_cos.grdecl" , "w") ) +# +#poro.add( permx , mask = mask1) +#poro.sub( 1 ) +#poro.mul( poro ) +#poro.assign( 14.0 ) +#poro.div( 7.0 ) +# +#new_p = poro / 7.0 +# +#poro.write_grdecl( open("/tmp/poro_cos.grdecl" , "w") ) +# +#init_file = ecl.EclFile( "data/eclipse/case/ECLIPSE.INIT" ) +#permx_kw = init_file.iget_named_kw( "PERMX" , 0 ) +#permx_new = ecl.EclKW.new( "PERMX" , 3 , ecl.ECL_FLOAT_TYPE ) +#print ecl.ECL_GRID_FILE +#print ecl.ecl_file_enum +#permx_new[0] = 1 +#permx_new[1] = 2 +#permx_new[2] = 3 +# +##init_file.replace_kw( permx_kw , permx_new ) +#fortio = ecl.FortIO.writer( "/tmp/init" ) +#print fortio +#init_file.fwrite( fortio ) +#fortio.close() +# +#poro = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_poro.GRDECL" , "r") , "PORO" ) +#eqlnum = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_eqlnum.GRDECL" , "r") , "EQLNUM" ) +#dummy = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_eqlnum.GRDECL" , "r") , "BJARNE" , ecl_type = ecl.ECL_INT_TYPE) +# +#if dummy: +# print "Loading BJARNE OK" +#else: +# print "Loading BJARNE Failed (correctly)" +# +#print "Poro[100] :%g eqlnum[100]:%d" % (poro[100] , eqlnum[100]) +# +#if not eqlnum.type == ecl.ECL_INT_TYPE: +# sys.exit("Type error when loading eqlnum") +# +#p2 = poro[100:160] +#if p2: +# print p2.header +#print poro +#print pvt.str( max_lines = 8 ) +#print eqlnum +# +#print ecl.EclKW.int_kw +#poro.add_int_kw("BJARNE") +#print eqlnum.int_kw diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_legacy_ecl.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_legacy_ecl.py new file mode 100644 index 0000000000..40383b43d0 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_legacy_ecl.py @@ -0,0 +1,67 @@ +#!/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 unittest2 import TestCase +from ert.ecl import EclTypeEnum, EclFileFlagEnum, EclPhaseEnum + +import ert.ecl.ecl as ecl +import ert.ecl as new_ecl +import ert.ecl.ecl_default as ecl_default + + +class LegacyEclTest(TestCase): + + def test_classes(self): + self.assertEqual(ecl.EclSum, new_ecl.EclSum) + + self.assertEqual(ecl.EclRFTFile, new_ecl.EclRFTFile) + self.assertEqual(ecl.EclRFTCell, new_ecl.EclRFTCell) + self.assertEqual(ecl.EclPLTCell, new_ecl.EclPLTCell) + + self.assertEqual(ecl.EclKW, new_ecl.EclKW) + self.assertEqual(ecl.EclFile, new_ecl.EclFile) + + self.assertEqual(ecl.FortIO, new_ecl.FortIO) + + self.assertEqual(ecl.EclGrid, new_ecl.EclGrid) + + self.assertEqual(ecl.EclRegion, new_ecl.EclRegion) + + self.assertEqual(ecl.ecl_default.default.ecl_version, new_ecl.EclDefault.ecl_version()) + + self.assertEqual(ecl.EclQueue, new_ecl.EclQueue) + + def test_enums(self): + self.assertEqual(ecl.ECL_FLOAT_TYPE, EclTypeEnum.ECL_FLOAT_TYPE) + self.assertEqual(ecl.ECL_CHAR_TYPE, EclTypeEnum.ECL_CHAR_TYPE) + self.assertEqual(ecl.ECL_DOUBLE_TYPE, EclTypeEnum.ECL_DOUBLE_TYPE) + self.assertEqual(ecl.ECL_BOOL_TYPE, EclTypeEnum.ECL_BOOL_TYPE) + self.assertEqual(ecl.ECL_CHAR_TYPE, EclTypeEnum.ECL_CHAR_TYPE) + + self.assertEqual(ecl.ECL_FILE_WRITABLE, EclFileFlagEnum.ECL_FILE_WRITABLE) + + self.assertEqual(ecl.ECL_OIL_PHASE, EclPhaseEnum.ECL_OIL_PHASE) + self.assertEqual(ecl.ECL_GAS_PHASE, EclPhaseEnum.ECL_GAS_PHASE) + self.assertEqual(ecl.ECL_WATER_PHASE, EclPhaseEnum.ECL_WATER_PHASE) + + + + def test_ecl_defaults(self): + self.assertIsNotNone(ecl_default.default.ecl_version) + self.assertIsNotNone(ecl_default.default.driver_options) + self.assertIsNotNone(ecl_default.default.ecl_cmd) + self.assertIsNotNone(ecl_default.default.driver_type) + self.assertIsNotNone(ecl_default.default.lsf_resource_request) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_region.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_region.py new file mode 100644 index 0000000000..9579bfbc66 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_region.py @@ -0,0 +1,128 @@ +#!/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 ert.ecl import EclFile, EclGrid, EclRegion +from ert_tests 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_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 + for gi in reg.global_list: + (i, j, k) = self.grid.get_ijk(global_index=gi) + if i > 5: + OK = False + self.assertTrue(OK) + self.assertTrue(self.grid.ny * self.grid.nz * 6 == len(reg.global_list)) + + reg.select_jslice(7, 8, intersect=True) + OK = True + for gi in reg.global_list: + (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.nz * 6 == len(reg.global_list)) + + reg2 = EclRegion(self.grid, False) + reg2.select_kslice(3, 5) + reg &= reg2 + OK = True + for gi in reg.global_list: + (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.global_list)) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_restart.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_restart.py new file mode 100644 index 0000000000..8ced2e07d3 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_restart.py @@ -0,0 +1,128 @@ +#!/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 ert.ecl import EclFile +from ert_tests 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.assertAlmostEqualList(rlist, rlist0) + + f = EclFile(fname) + rlist = f.report_list + self.assertAlmostEqualList(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.name == self.u_file) + + f = EclFile(self.xfile0) + self.assertTrue(f.name == 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)) + + kw4 = f.restart_get_kw("SWAT", datetime.datetime(2009, 3, 1)) + self.assertIsNone(kw4) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft.py new file mode 100644 index 0000000000..8c2a1106e7 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# Copyright (C) 2011 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 ert.ecl import EclRFTFile, EclRFTCell, EclPLTCell +from ert_tests 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() + + + 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] diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft_cell.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft_cell.py new file mode 100644 index 0000000000..e6dccc3296 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft_cell.py @@ -0,0 +1,102 @@ +#!/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. + + +import warnings +from ert.ecl import EclRFTCell, EclPLTCell +from ert_tests 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.new(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.assertAlmostEqualScaled(pressure, cell.pressure) + self.assertAlmostEqualScaled(depth, cell.depth) + self.assertAlmostEqualScaled(swat, cell.swat) + self.assertAlmostEqualScaled(sgas, cell.sgas) + self.assertAlmostEqualScaled(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.new(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()) + + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + self.assertTrue(cell.get_i() + 1 == cell.i) + self.assertTrue(cell.get_j() + 1 == cell.j) + self.assertTrue(cell.get_k() + 1 == cell.k) + + self.assertAlmostEqualScaled(pressure, cell.pressure) + self.assertAlmostEqualScaled(depth, cell.depth) + self.assertAlmostEqualScaled(orat, cell.orat) + self.assertAlmostEqualScaled(grat, cell.grat) + self.assertAlmostEqualScaled(wrat, cell.wrat) + + self.assertAlmostEqualScaled(conn_start, cell.conn_start) + self.assertAlmostEqualScaled(conn_end, cell.conn_end) + self.assertAlmostEqualScaled(flowrate, cell.flowrate) + self.assertAlmostEqualScaled(oil_flowrate, cell.oil_flowrate) + self.assertAlmostEqualScaled(gas_flowrate, cell.gas_flowrate) + self.assertAlmostEqualScaled(water_flowrate, cell.water_flowrate) + + + + + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_sum.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_sum.py new file mode 100644 index 0000000000..9927493b7c --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_sum.py @@ -0,0 +1,263 @@ +#!/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 unittest2 import skip, skipUnless, skipIf +from ert.ecl import EclSum + +from ert.util import StringList, TestAreaContext + +from ert_tests import ExtendedTestCase + + +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_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, 800]) + self.assertAlmostEqualList([805817.11875, 1614955.34677419, 3289267.67857143, 6493021.6218035], 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]) + + + def test_wells(self): + wells = self.ecl_sum.wells() + wells.sort() + self.assertAlmostEqualList(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.assertAlmostEqualList(wells, ["OP_3", "WI_3"]) + + groups = self.ecl_sum.groups() + groups.sort() + self.assertAlmostEqualList(groups, ['GMWIN', 'OP', 'WI']) + + + def test_last( self ): + last = self.ecl_sum.get_last("FOPT") + self.assertAlmostEqual(last.value, 38006336.0) + self.assertAlmostEqual(last.days, 1826.0) + self.assertEqual(last.date, datetime.datetime(2004, 12, 31, 0, 0, 0)) + + self.assertAlmostEqual(self.ecl_sum.get_last_value("FGPT"), 6605249024.0) + + + 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))) + + 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.assertAlmostEqualScaled(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", True): + 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.is_total) + self.assertFalse(node.is_historical) + + node = sum.smspec_node("FOPR") + self.assertFalse(node.is_total) + self.assertFalse(node.is_historical) + self.assertTrue(node.keyword == "FOPR") + + node = sum.smspec_node("FOPRH") + self.assertFalse(node.is_total) + self.assertTrue(node.is_historical) + self.assertTrue(node.is_rate) + self.assertTrue(node.keyword == "FOPRH") + + node = sum.smspec_node("WOPR:OP_1") + self.assertFalse(node.is_total) + self.assertTrue(node.is_rate) + self.assertTrue(node.keyword == "WOPR") + + node = sum.smspec_node("WOPT:OP_1") + self.assertTrue(node.is_total) + self.assertFalse(node.is_rate) + 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.is_total) + self.assertFalse(node.is_rate) + self.assertIsNone(node.wgname) + + node = sum.smspec_node("FOPTH") + self.assertIsNone(node.num) + + node = sum.smspec_node("BPR:1095") + self.assertEquals(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.assertAlmostEqualList(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) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/run_tests.py b/ThirdParty/Ert/devel/python/test/ert_tests/run_tests.py new file mode 100644 index 0000000000..b232be1afd --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/run_tests.py @@ -0,0 +1,36 @@ +from unittest2 import TestLoader, TextTestRunner + + +def runTestsInDirectory(path="."): + loader = TestLoader() + tests = loader.discover(path) + testRunner = TextTestRunner() + testRunner.run(tests) + + +def runTestsInClass(classpath): + klass = importClass(classpath) + loader = TestLoader() + tests = loader.loadTestsFromTestCase(klass) + testRunner = TextTestRunner() + testRunner.run(tests) + + +def importClass(classpath): + dot = classpath.rfind(".") + classname = classpath[dot + 1:len(classpath)] + m = __import__(classpath[0:dot], globals(), locals(), [classname]) + return getattr(m, classname) + +def getTestsFromTestClass(test_class_path, argv=None): + klass = importClass(test_class_path) + klass.argv = argv + loader = TestLoader() + return loader.loadTestsFromTestCase(klass) + + +if __name__ == '__main__': + # runTestsInDirectory() + runTestsInClass("ert_tests.util.test_string_list.StringListTest") + + print(getTestsFromTestClass("ert_tests.util.test_string_list.StringListTest")) diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/sched/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/sched/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/sched/test_sched.py b/ThirdParty/Ert/devel/python/test/ert_tests/sched/test_sched.py new file mode 100644 index 0000000000..1dcbeb5462 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/sched/test_sched.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'test_sched.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 +from ert.sched import SchedFile +from ert_tests import ExtendedTestCase + + + + +class SchedFileTest(ExtendedTestCase): + def setUp(self): + src_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/target.SCH") + self.start_time = datetime.date(2000, 1, 1) + + self.sched_file = SchedFile(src_file, self.start_time) + 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): + self.assertTrue(self.sched_file, "Load failed") + + + def test_length(self): + self.assertEqual(self.sched_file.length, 63) + + + def test_write_loop(self): + self.sched_file.write("/tmp/schedule1", 62) + sched_file2 = SchedFile("/tmp/schedule1", self.start_time) + sched_file2.write("/tmp/schedule2", 62) + self.assertFilesAreEqual("/tmp/schedule1", "/tmp/schedule2") + + self.addFile("/tmp/schedule1") + self.addFile("/tmp/schedule2") diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_gui_import.py b/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_gui_import.py new file mode 100644 index 0000000000..899816a8d4 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_gui_import.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'test_ert_gui_import.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 traceback + +from ert_tests import ExtendedTestCase + + +class ErtGuiImportTest(ExtendedTestCase): + + def test_ert_gui(self): + self.assertImportable("ert_gui") + self.assertImportable("ert_gui.gert_main") + self.assertImportable("ert_gui.newconfig") + + def test_ert_gui_widgets(self): + self.assertImportable("ert_gui.widgets") + self.assertImportable("ert_gui.widgets.activelabel") + self.assertImportable("ert_gui.widgets.checkbox") + self.assertImportable("ert_gui.widgets.cogwheel") + self.assertImportable("ert_gui.widgets.combochoice") + self.assertImportable("ert_gui.widgets.configpanel") + self.assertImportable("ert_gui.widgets.help") + self.assertImportable("ert_gui.widgets.helpedwidget") + self.assertImportable("ert_gui.widgets.pathchooser") + self.assertImportable("ert_gui.widgets.reloadbutton") + self.assertImportable("ert_gui.widgets.searchablelist") + self.assertImportable("ert_gui.widgets.spinnerwidgets") + self.assertImportable("ert_gui.widgets.stringbox") + self.assertImportable("ert_gui.widgets.tablewidgets") + self.assertImportable("ert_gui.widgets.util") + self.assertImportable("ert_gui.widgets.validateddialog") + + def test_ert_gui_pages(self): + self.assertImportable("ert_gui.pages") + self.assertImportable("ert_gui.pages.application") + + def test_ert_gui_pages_init(self): + self.assertImportable("ert_gui.pages.init") + self.assertImportable("ert_gui.pages.init.initandcopy") + self.assertImportable("ert_gui.pages.init.initpanel") + + def test_ert_gui_pages_run(self): + self.assertImportable("ert_gui.pages.run") + self.assertImportable("ert_gui.pages.run.legend") + self.assertImportable("ert_gui.pages.run.runpanel") + self.assertImportable("ert_gui.pages.run.simulation") + self.assertImportable("ert_gui.pages.run.simulationsdialog") + + def test_ert_gui_pages_plot(self): + self.assertImportable("ert_gui.pages.plot") + self.assertImportable("ert_gui.pages.plot.ensemblefetcher") + self.assertImportable("ert_gui.pages.plot.fetcher") + self.assertImportable("ert_gui.pages.plot.plotconfig") + self.assertImportable("ert_gui.pages.plot.plotdata") + self.assertImportable("ert_gui.pages.plot.plotfigure") + self.assertImportable("ert_gui.pages.plot.plotgenerator") + self.assertImportable("ert_gui.pages.plot.plotpanel") + self.assertImportable("ert_gui.pages.plot.plotrenderer") + self.assertImportable("ert_gui.pages.plot.plotsettings") + self.assertImportable("ert_gui.pages.plot.plotsettingsxml") + self.assertImportable("ert_gui.pages.plot.plotview") + self.assertImportable("ert_gui.pages.plot.rftfetcher") + self.assertImportable("ert_gui.pages.plot.zoomslider") + + def test_ert_gui_pages_config(self): + self.assertImportable("ert_gui.pages.config") + self.assertImportable("ert_gui.pages.config.analysis") + self.assertImportable("ert_gui.pages.config.configpages") + self.assertImportable("ert_gui.pages.config.eclipse") + self.assertImportable("ert_gui.pages.config.ensemble") + self.assertImportable("ert_gui.pages.config.observations") + self.assertImportable("ert_gui.pages.config.plot") + self.assertImportable("ert_gui.pages.config.queuesystem") + self.assertImportable("ert_gui.pages.config.simulation") + self.assertImportable("ert_gui.pages.config.systemenv") + + def test_ert_gui_pages_config_jobs(self): + self.assertImportable("ert_gui.pages.config.jobs") + self.assertImportable("ert_gui.pages.config.jobs.forwardmodelpanel") + self.assertImportable("ert_gui.pages.config.jobs.jobsdialog") + self.assertImportable("ert_gui.pages.config.jobs.jobspanel") + + def test_ert_gui_pages_config_parameters(self): + self.assertImportable("ert_gui.pages.config.parameters") + self.assertImportable("ert_gui.pages.config.parameters.datapanel") + self.assertImportable("ert_gui.pages.config.parameters.fieldpanel") + self.assertImportable("ert_gui.pages.config.parameters.keywordpanel") + self.assertImportable("ert_gui.pages.config.parameters.parameterdialog") + self.assertImportable("ert_gui.pages.config.parameters.parametermodels") + self.assertImportable("ert_gui.pages.config.parameters.parameterpanel") + + def test_ert_gui_pages_config_simulations(self): + self.assertImportable("ert_gui.pages.config.simulations") + self.assertImportable("ert_gui.pages.config.simulations.runpathpanel") + self.assertImportable("ert_gui.pages.config.simulations.runtemplatepanel") diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_import.py b/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_import.py new file mode 100644 index 0000000000..e36e9847ad --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_import.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'test_ert_import.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 traceback + +from ert_tests import ExtendedTestCase + + +class ErtImportTest(ExtendedTestCase): + + def test_ert(self): + self.assertImportable("ert") + + def test_ert_config(self): + self.assertImportable("ert.config") + self.assertImportable("ert.config.config_enums") + self.assertImportable("ert.config.config_parser") + + def test_ert_cwrap(self): + self.assertImportable("ert.cwrap") + self.assertImportable("ert.cwrap.cclass") + self.assertImportable("ert.cwrap.cenum") + self.assertImportable("ert.cwrap.cfile") + self.assertImportable("ert.cwrap.clib") + self.assertImportable("ert.cwrap.cwrap") + + def test_ert_ecl(self): + self.assertImportable("ert.ecl") + self.assertImportable("ert.ecl.ecl") + self.assertImportable("ert.ecl.ecl_case") + self.assertImportable("ert.ecl.ecl_default") + self.assertImportable("ert.ecl.ecl_file") + self.assertImportable("ert.ecl.ecl_grav") + self.assertImportable("ert.ecl.ecl_grav_calc") + self.assertImportable("ert.ecl.ecl_grid") + self.assertImportable("ert.ecl.ecl_kw") + self.assertImportable("ert.ecl.ecl_local") + self.assertImportable("ert.ecl.ecl_queue") + self.assertImportable("ert.ecl.ecl_region") + self.assertImportable("ert.ecl.ecl_rft") + self.assertImportable("ert.ecl.ecl_rft_cell") + self.assertImportable("ert.ecl.ecl_subsidence") + self.assertImportable("ert.ecl.ecl_sum") + self.assertImportable("ert.ecl.ecl_util") + self.assertImportable("ert.ecl.fortio") + + + def test_ert_enkf(self): + self.assertImportable("ert.enkf") + self.assertImportable("ert.enkf.analysis_config") + self.assertImportable("ert.enkf.block_obs") + self.assertImportable("ert.enkf.ecl_config") + self.assertImportable("ert.enkf.enkf") + self.assertImportable("ert.enkf.enkf_config_node") + self.assertImportable("ert.enkf.enkf_enum") + self.assertImportable("ert.enkf.enkf_fs") + self.assertImportable("ert.enkf.enkf_main") + self.assertImportable("ert.enkf.enkf_node") + self.assertImportable("ert.enkf.enkf_obs") + self.assertImportable("ert.enkf.enkf_state") + self.assertImportable("ert.enkf.ens_config") + self.assertImportable("ert.enkf.ert_template") + self.assertImportable("ert.enkf.ert_templates") + self.assertImportable("ert.enkf.field") + self.assertImportable("ert.enkf.field_config") + self.assertImportable("ert.enkf.gen_data_config") + self.assertImportable("ert.enkf.gen_kw_config") + self.assertImportable("ert.enkf.libenkf") + self.assertImportable("ert.enkf.local_config") + self.assertImportable("ert.enkf.model_config") + self.assertImportable("ert.enkf.obs_vector") + self.assertImportable("ert.enkf.plot_conf") + self.assertImportable("ert.enkf.site_config") + self.assertImportable("ert.enkf.time_map") + + def test_ert_ert(self): + self.assertImportable("ert.ert") + self.assertImportable("ert.ert.c_enums") + self.assertImportable("ert.ert.enums") + self.assertImportable("ert.ert.erttypes") + self.assertImportable("ert.ert.ertwrapper") + + def test_ert_geo(self): + self.assertImportable("ert.geo") + self.assertImportable("ert.geo.geo_polygon") + + def test_ert_job_queue(self): + self.assertImportable("ert.job_queue") + self.assertImportable("ert.job_queue.driver") + self.assertImportable("ert.job_queue.ext_job") + self.assertImportable("ert.job_queue.ext_joblist") + self.assertImportable("ert.job_queue.forward_model") + self.assertImportable("ert.job_queue.job") + self.assertImportable("ert.job_queue.queue") + + def test_ert_rms(self): + self.assertImportable("ert.rms") + self.assertImportable("ert.rms.librms") + self.assertImportable("ert.rms.rms") + + def test_ert_sched(self): + self.assertImportable("ert.sched") + self.assertImportable("ert.sched.history") + self.assertImportable("ert.sched.sched_file") + + def test_ert_sched(self): + self.assertImportable("ert.util") + self.assertImportable("ert.util.buffer") + self.assertImportable("ert.util.ctime") + self.assertImportable("ert.util.hash") + self.assertImportable("ert.util.latex") + self.assertImportable("ert.util.log") + self.assertImportable("ert.util.lookup_table") + self.assertImportable("ert.util.matrix") + self.assertImportable("ert.util.stat") + self.assertImportable("ert.util.stringlist") + self.assertImportable("ert.util.test_area") + self.assertImportable("ert.util.tvector") + self.assertImportable("ert.util.util_func") + + def test_ert_well(self): + self.assertImportable("ert.well") + self.assertImportable("ert.well.libwell") + self.assertImportable("ert.well.well") + self.assertImportable("ert.well.well_info") + self.assertImportable("ert.well.well_state") + self.assertImportable("ert.well.well_ts") + + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_ctime.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_ctime.py new file mode 100644 index 0000000000..f9250f98e6 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_ctime.py @@ -0,0 +1,17 @@ +from datetime import datetime +from unittest2 import TestCase +from ert.util import ctime + + +class CTimeTest(TestCase): + + def test_c_time(self): + c_time = ctime(0) + self.assertEqual(str(c_time), "1970-01-01 01:00:00") + + date_time = ctime(datetime(1970, 1, 1, 1, 0, 0)) + self.assertEqual(c_time, date_time) + + date_time_after = ctime(datetime(1970, 1, 1, 1, 0, 5)) + + self.assertTrue(date_time_after > date_time) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_latex.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_latex.py new file mode 100644 index 0000000000..35d8d6d13a --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_latex.py @@ -0,0 +1,54 @@ +import os +from unittest2 import skip +from ert.util import LaTeX +from ert_tests import ExtendedTestCase + + +class LatexTest(ExtendedTestCase): + + def setUp(self): + self.local_path = self.createTestPath("local/util/latex") + self.statoil_path = self.createTestPath("Statoil/util/latex") + + + def test_simple_compile(self): + lx = LaTeX("%s/test_OK.tex" % self.local_path) + self.assertTrue(lx.compile()) + + lx = LaTeX("%s/test_error.tex" % self.local_path) + self.assertFalse(lx.compile()) + + @skip("Unknown errors!") + def test_cleanup( self ): + lx = LaTeX("%s/report_OK.tex" % self.statoil_path, in_place=True) + self.assertTrue(lx.in_place) + self.assertTrue(lx.compile()) + for ext in ["log", "aux", "nav", "out", "snm", "toc"]: + self.assertFalse(os.path.exists("%s/report_OK.%s" % (self.statoil_path, ext))) + + lx = LaTeX("%s/report_OK.tex" % self.statoil_path, in_place=False) + self.assertFalse(lx.in_place) + run_path = lx.runpath + self.assertTrue(lx.compile()) + self.assertFalse(os.path.exists(run_path)) + + lx = LaTeX("%s/report_OK.tex" % self.statoil_path, in_place=False) + run_path = lx.runpath + self.assertTrue(lx.compile(cleanup=False)) + self.assertTrue(os.path.exists("%s/report_OK.log" % run_path)) + + + @skip("Unknown errors!") + def test_report(self): + lx = LaTeX("%s/report_error.tex" % self.statoil_path) + lx.timeout = 4 + self.assertFalse(lx.compile()) + + lx = LaTeX("%s/report_OK.tex" % self.statoil_path) + self.assertTrue(lx.compile()) + + @skip("Unknown errors!") + def test_target(self): + lx = LaTeX("%s/report_OK.tex" % self.statoil_path) + self.assertTrue(lx.compile()) + self.assertTrue(os.path.exists(lx.target)) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_lookup_table.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_lookup_table.py new file mode 100644 index 0000000000..aa225e8ff3 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_lookup_table.py @@ -0,0 +1,40 @@ +from unittest2 import TestCase +from ert.util import LookupTable +import numpy + +class LookupTableTest(TestCase): + + def test_lookup_table_no_values(self): + lookup = LookupTable() + + self.assertTrue(numpy.isnan(lookup.max)) + self.assertTrue(numpy.isnan(lookup.min)) + self.assertTrue(numpy.isnan(lookup.arg_max)) + self.assertTrue(numpy.isnan(lookup.arg_min)) + self.assertEqual(len(lookup), 0) + + + lookup.append(0.0, 0.0) + lookup.append(1.0, 10.0) + + 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.max, 10.0) + self.assertEqual(lookup.min, 0.0) + self.assertEqual(lookup.arg_max, 1.0) + self.assertEqual(lookup.arg_min, 0.0) + self.assertEqual(len(lookup), 2) + + + 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) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_matrix.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_matrix.py new file mode 100644 index 0000000000..f1ef5c9667 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_matrix.py @@ -0,0 +1,22 @@ +from ert.util import Matrix +from unittest2 import TestCase + +class MatrixTest(TestCase): + def test_matrix(self): + m = Matrix(2, 2) + + 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 + + #todo: random crashes happens if we do this... + #m[2, 2] = 2 # no exception raised... + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_stat.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_stat.py new file mode 100644 index 0000000000..dab76c3a76 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_stat.py @@ -0,0 +1,21 @@ +import random +from ert.util import DoubleVector, quantile, quantile_sorted +from ert_tests import ExtendedTestCase + + +class StatTest(ExtendedTestCase): + def test_stat_quantiles(self): + v = DoubleVector() + for i in range(100000): + v.append(random.random()) + + 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) + # print quantile( v , 0.10 ) + # print quantile_sorted( v , 0.20 ) + # print quantile_sorted( v , 0.30 ) + # print quantile_sorted( v , 0.40 ) + # print quantile_sorted( v , 0.50 ) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_string_list.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_string_list.py new file mode 100644 index 0000000000..f5fa635290 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_string_list.py @@ -0,0 +1,75 @@ +from unittest2 import TestCase +from ert.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): + s = StringList(["A", "B"]) + s.append("C") + self.assertEqual(list(s), ["A", "B", "C"]) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_vectors.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_vectors.py new file mode 100644 index 0000000000..e056db9fea --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_vectors.py @@ -0,0 +1,216 @@ +#!/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 +from datetime import datetime +from unittest2 import TestCase + +from ert.util import DoubleVector, IntVector, BoolVector, TimeVector, ctime + + +class UtilTest(TestCase): + 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.default = 0.75 + self.assertEqual(v.default, 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_bool_vector(self): + b = BoolVector() + b.default = 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) + + active_list = IntVector.active_list("1,10,100-105X") + self.assertFalse(active_list) + + + def test_activeMask(self): + active_list = BoolVector.active_mask("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]) + + active_list = BoolVector.active_mask("1,4-7,10X") + self.assertFalse(active_list) + + + + + 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.rsort() + self.assertEqual(list(a), [5, 4, 3, 2, 1]) + + self.assertTrue(a.max, 5) + self.assertTrue(a.min, 1) + self.assertTrue(a.min_index(), 4) + + self.assertEqual(a.max_index(reverse=True), 0) + self.assertEqual(a.max_index(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 = copy.deepcopy(a) + self.assertEqual(list(a), list(copy_of_a)) + + another_copy_of_a = copy.copy(a) + 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_asPythonObject(self): + v = DoubleVector.asPythonObject(0, DoubleVector.free) + + self.assertIsInstance(v, DoubleVector) + self.assertIsNotNone(v.cfree) + + + def test_time_vector(self): + time_vector = TimeVector() + + time1 = ctime(datetime(2013, 8, 13, 0, 0, 0)) + time2 = ctime(datetime(2013, 8, 13, 1, 0, 0)) + + time_vector.default = 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) + diff --git a/ThirdParty/Ert/devel/python/test/file_test.py b/ThirdParty/Ert/devel/python/test/file_test.py deleted file mode 100644 index bf80c7219e..0000000000 --- a/ThirdParty/Ert/devel/python/test/file_test.py +++ /dev/null @@ -1,146 +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 filecmp -import datetime -import unittest -import shutil -import time -import os -import os.path -import ert -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv, file_equal - - -file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" -fmt_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.FUNRST" - -def load_missing(): - ecl.EclFile( "No/Does/not/exist") - - -class FileTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - def testIOError(self): - self.assertRaises( IOError , load_missing) - - - def test_fwrite( self ): - self.addFile( "/tmp/ECLIPSE.UNRST" ) - rst_file = ecl.EclFile( file ) - fortio = ecl.FortIO.writer("/tmp/ECLIPSE.UNRST") - rst_file.fwrite( fortio ) - fortio.close() - rst_file.close() - self.assertTrue( file_equal( "/tmp/ECLIPSE.UNRST" , file ) ) - - - def test_save(self): - self.addFile( "/tmp/ECLIPSE.UNRST" ) - shutil.copyfile( file , "/tmp/ECLIPSE.UNRST" ) - rst_file = ecl.EclFile( "/tmp/ECLIPSE.UNRST" , flags = ecl.ECL_FILE_WRITABLE ) - swat0 = rst_file["SWAT"][0] - swat0.assign( 0.75 ) - rst_file.save_kw( swat0 ) - rst_file.close( ) - self.assertFalse( file_equal( "/tmp/ECLIPSE.UNRST" , file ) ) - - rst_file1 = ecl.EclFile( file ) - rst_file2 = ecl.EclFile( "/tmp/ECLIPSE.UNRST" , flags = ecl.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.assertTrue( file_equal( "/tmp/ECLIPSE.UNRST" , file ) ) - - - def test_save_fmt(self): - self.addFile( "/tmp/ECLIPSE.FUNRST" ) - shutil.copyfile( fmt_file , "/tmp/ECLIPSE.FUNRST" ) - rst_file = ecl.EclFile( "/tmp/ECLIPSE.FUNRST" , flags = ecl.ECL_FILE_WRITABLE) - swat0 = rst_file["SWAT"][0] - swat0.assign( 0.75 ) - rst_file.save_kw( swat0 ) - rst_file.close( ) - self.assertFalse( file_equal( "/tmp/ECLIPSE.FUNRST" , fmt_file ) ) - - rst_file1 = ecl.EclFile( fmt_file ) - rst_file2 = ecl.EclFile( "/tmp/ECLIPSE.FUNRST" , flags = ecl.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.assertTrue( file_equal( "/tmp/ECLIPSE.FUNRST" , fmt_file ) ) - - - -def slow_suite(): - suite = unittest.TestSuite() - suite.addTest( FileTest( 'test_save' )) - suite.addTest( FileTest( 'test_save_fmt' )) - return suite - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( FileTest( 'testIOError' )) - suite.addTest( FileTest( 'test_fwrite' )) - return suite - - - - -def test_suite( argv ): - test_list = fast_suite() - if argv: - if argv[0][0] == "T": - for t in slow_suite(): - test_list.addTest( t ) - return test_list - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - unittest.TextTestRunner().run( slow_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/fortio_test.py b/ThirdParty/Ert/devel/python/test/fortio_test.py deleted file mode 100644 index 40bc1fed7c..0000000000 --- a/ThirdParty/Ert/devel/python/test/fortio_test.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'kw_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 unittest -import stat -import math -import ert -import ert.ecl.ecl as ecl -import sys - - -unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" - -def open_noex(): - f = ecl.FortIO.reader("/tmp/does/notExist") - - -class FortIOTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - def test_open_read(self): - f = ecl.FortIO.reader(unrst_file) - self.assertTrue( f ) - - - def test_open_write(self): - self.addFile( "/tmp/newfile" ) - f = ecl.FortIO.writer("/tmp/newfile") - f.close() - self.assertTrue( True ) - - def test_noex(self): - self.assertRaises( IOError , open_noex) - - def test_kw(self): - self.addFile( "/tmp/test" ) - kw1 = ecl.EclKW.create( "KW1" , 2 , ecl.ECL_INT_TYPE ) - kw2 = ecl.EclKW.create( "KW2" , 2 , ecl.ECL_INT_TYPE ) - - kw1[0] = 99 - kw1[1] = 77 - kw2[0] = 113 - kw2[1] = 335 - - f = ecl.FortIO.writer( "/tmp/test" , fmt_file = False) - kw1.fwrite( f ) - f.close() - - f = ecl.FortIO.open( "/tmp/test" , mode = "a") - kw2.fwrite( f ) - f.close() - - f = ecl.FortIO.open( "/tmp/test" , fmt_file = False) - k1 = ecl.EclKW.fread( f ) - k2 = ecl.EclKW.fread( f ) - f.close() - - self.assertTrue( k1.equal( kw1 )) - self.assertTrue( k2.equal( kw2 )) - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( FortIOTest('test_open_read')) - suite.addTest( FortIOTest('test_open_write')) - suite.addTest( FortIOTest('test_noex')) - suite.addTest( FortIOTest('test_kw')) - return suite - - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/grdecl_test.py b/ThirdParty/Ert/devel/python/test/grdecl_test.py deleted file mode 100644 index 5860bd30b7..0000000000 --- a/ThirdParty/Ert/devel/python/test/grdecl_test.py +++ /dev/null @@ -1,139 +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 unittest -import ert -import os -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv, file_equal - - -src_file = "test-data/Statoil/ECLIPSE/Gurbat/include/example_permx.GRDECL" - - -class GRDECLTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - - def testLoad( self ): - kw = ecl.EclKW.read_grdecl( open( src_file , "r") , "PERMX") - self.assertTrue( kw ) - - - def testReLoad( self ): - kw = ecl.EclKW.read_grdecl( open( 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 = ecl.EclKW.read_grdecl( open( tmp_file1 , "r") , "PERMX") - - fileH = open( tmp_file2 , "w") - kw1.write_grdecl( fileH ) - fileH.close() - - self.assertTrue( file_equal( tmp_file1 , tmp_file2 )) - - - - def test_fseek( self ): - file = open( src_file , "r") - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "PERMX" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMY" ) ) - file.close() - - file = open( src_file , "r") - kw1 = ecl.EclKW.read_grdecl( file , "PERMX") - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMX" ) ) - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = True) ) - file.close() - - - - def test_fseek2(self): - test_src = "test-data/local/ECLIPSE/grdecl-test/test.grdecl" - # Test kw at the the very start - file = open( test_src , "r") - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "PERMX" ) ) - - # Test commented out kw: - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMY" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMZ" ) ) - - # Test ignore not start of line: - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "MARKER" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMXYZ" ) ) - - # Test rewind - self.assertFalse(ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = False) ) - self.assertTrue(ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = True) ) - - # Test multiline comments + blanks - self.assertTrue(ecl.EclKW.fseek_grdecl( file , "LASTKW" ) ) - - - def test_fseek_dos(self): - test_src = "test-data/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( ecl.EclKW.fseek_grdecl( file , "PERMX" ) ) - - # Test commented out kw: - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMY" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMZ" ) ) - - # Test ignore not start of line: - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "MARKER" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMXYZ" ) ) - - # Test rewind - self.assertFalse(ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = False) ) - self.assertTrue(ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = True) ) - - # Test multiline comments + blanks - self.assertTrue(ecl.EclKW.fseek_grdecl( file , "LASTKW" ) ) - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( GRDECLTest( 'testLoad' )) - suite.addTest( GRDECLTest( 'testReLoad' )) - suite.addTest( GRDECLTest( 'test_fseek' )) - suite.addTest( GRDECLTest( 'test_fseek_dos' )) - return suite - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/grid_test.py b/ThirdParty/Ert/devel/python/test/grid_test.py deleted file mode 100644 index c51c868079..0000000000 --- a/ThirdParty/Ert/devel/python/test/grid_test.py +++ /dev/null @@ -1,243 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'grid_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 sys -import ert -import ert.ecl.ecl as ecl -import datetime -import time -import os -import unittest -import ert -import ert.ecl.ecl as ecl -from ert.util.tvector import DoubleVector -from ert.util.tvector import DoubleVector -from numpy import isnan -from test_util import approx_equal, approx_equalv - -egrid_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID" -grid_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID" -grdecl_file = "test-data/Statoil/ECLIPSE/Gurbat/include/example_grid_sim.GRDECL" - -def load_does_not_exist(): - g = ecl.EclGrid( "/does/not/exist.EGRID" ) - - -class GridTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - def testGRID( self ): - grid = ecl.EclGrid( grid_file ) - self.assertTrue( grid ) - - - def testEGRID( self ): - grid = ecl.EclGrid( egrid_file ) - self.assertTrue( grid ) - - - def create(self , filename , load_actnum = True): - fileH = open( filename , "r") - specgrid = ecl.EclKW.read_grdecl( fileH , "SPECGRID" , ecl_type = ecl.ECL_INT_TYPE , strict = False) - zcorn = ecl.EclKW.read_grdecl( fileH , "ZCORN" ) - coord = ecl.EclKW.read_grdecl( fileH , "COORD" ) - if load_actnum: - actnum = ecl.EclKW.read_grdecl( fileH , "ACTNUM" , ecl_type = ecl.ECL_INT_TYPE ) - else: - actnum = None - - mapaxes = ecl.EclKW.read_grdecl( fileH , "MAPAXES" ) - grid = ecl.EclGrid.create( specgrid , zcorn , coord , actnum , mapaxes = mapaxes) - return grid - - - def testRect(self): - a1 = 1.0 - a2 = 2.0 - a3 = 3.0 - grid = ecl.EclGrid.create_rectangular((9,9,9) , (a1,a2,a3)) - grid.save_EGRID( "/tmp/rect.EGRID" ) - grid2 = ecl.EclGrid( "/tmp/rect.EGRID") - self.addFile( "/tmp/rect.EGRID" ) - self.assertTrue( grid ) - self.assertTrue( grid2 ) - - (x,y,z) = grid.get_xyz( ijk=(4,4,4) ) - self.assertTrue( approx_equalv( [x,y,z],[4.5 * a1,4.5*a2,4.5*a3] )) - - v = grid.cell_volume( ijk=(4,4,4) ) - self.assertTrue( approx_equal( v , a1*a2*a3 )) - - z = grid.depth( ijk = (4,4,4 )) - self.assertTrue( approx_equal( 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.assertTrue( approx_equalv([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.assertTrue( approx_equalv( ijk , [1 , 2 , 3])) - - - - def testCreate(self): - grid = self.create( grdecl_file ) - self.assertTrue( grid ) - - - def testACTNUM(self): - g1 = self.create( grdecl_file ) - g2 = self.create( grdecl_file , load_actnum = False ) - self.assertTrue( g1.equal( g2 ) ) - - - def testTime(self): - t0 = time.clock() - g1 = ecl.EclGrid( egrid_file ) - t1 = time.clock() - t = t1 - t0 - self.assertTrue( t < 1.0 ) - - - def testSave(self): - self.addFile( "/tmp/test.EGRID" ) - self.addFile( "/tmp/test.GRID" ) - self.addFile( "/tmp/test.grdecl" ) - - g1 = ecl.EclGrid( egrid_file ) - - g1.save_EGRID( "/tmp/test.EGRID" ) - g2 = ecl.EclGrid( "/tmp/test.EGRID" ) - self.assertTrue( g1.equal( g2 ) ) - - g1.save_GRID( "/tmp/test.GRID" ) - g2 = ecl.EclGrid( "/tmp/test.GRID" ) - self.assertTrue( g1.equal( g2 ) ) - - fileH = open("/tmp/test.grdecl" , "w") - g1.save_grdecl( fileH ) - fileH.close() - g2 = self.create( "/tmp/test.grdecl" ) - self.assertTrue( g1.equal( g2 ) ) - - - def testCoarse(self): - self.addFile( "/tmp/LGC.EGRID" ) - self.addFile( "/tmp/LGC.GRID" ) - - testGRID = True - g1 = ecl.EclGrid( "test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2.EGRID" ) - - g1.save_EGRID( "/tmp/LGC.EGRID" ) - g2 = ecl.EclGrid( "/tmp/LGC.EGRID") - self.assertTrue( g1.equal(g2, verbose = True) ) - - if testGRID: - g1.save_GRID( "/tmp/LGC.GRID" ) - g3 = ecl.EclGrid( "/tmp/LGC.GRID") - self.assertTrue( g1.equal(g3 , verbose = True) ) - - self.assertTrue( g1.coarse_groups() == 3384) - - - def testRaiseIOError(self): - self.assertRaises( IOError , load_does_not_exist ) - - - - def testDual(self): - grid = ecl.EclGrid( egrid_file ) - self.assertFalse( grid.dual_grid ) - self.assertTrue( grid.nactive_fracture == 0 ) - - grid2 = ecl.EclGrid( grid_file ) - self.assertFalse( grid.dual_grid ) - self.assertTrue( grid.nactive_fracture == 0 ) - - dgrid = ecl.EclGrid( "test-data/Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID" ) - self.assertTrue( dgrid.nactive == dgrid.nactive_fracture ) - self.assertTrue( dgrid.nactive == 46118 ) - - dgrid2 = ecl.EclGrid( "test-data/Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID" ) - self.assertTrue( dgrid.nactive == dgrid.nactive_fracture ) - self.assertTrue( dgrid.nactive == 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 = ecl.EclGrid( "test-data/Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID" ) - self.assertTrue( dgrid.nactive == 106 ) - self.assertTrue( dgrid.nactive_fracture == 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 ) - - self.addFile( "/tmp/DUAL_DIFF.GRID" ) - dgrid.save_GRID("/tmp/DUAL_DIFF.GRID") - dgrid2 = ecl.EclGrid( "/tmp/DUAL_DIFF.GRID" ) - self.assertTrue( dgrid.equal( dgrid2 )) - - - - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( GridTest( 'testDual' )) - suite.addTest( GridTest( 'testGRID' )) - suite.addTest( GridTest( 'testEGRID' )) - suite.addTest( GridTest( 'testCreate' )) - - suite.addTest( GridTest( 'testSave' )) - suite.addTest( GridTest( 'testTime' )) - suite.addTest( GridTest( 'testACTNUM') ) - suite.addTest( GridTest( 'testRect' )) - suite.addTest( GridTest( 'testCoarse' )) - suite.addTest( GridTest( 'testRaiseIOError' )) - return suite - -def test_suite(argv): - return fast_suite() - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/import_local.py b/ThirdParty/Ert/devel/python/test/import_local.py deleted file mode 100644 index f946682e69..0000000000 --- a/ThirdParty/Ert/devel/python/test/import_local.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'import_local.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 - -def test_import( module ): - print "Importing: %s ..." % module , - try: - __import__( module ) - print "OK" - except: - print "failed" - sys.exit(1) - - -test_import("ert.ecl.ecl_local") - - -def test_suite( argv ): - return False diff --git a/ThirdParty/Ert/devel/python/test/import_test.py b/ThirdParty/Ert/devel/python/test/import_test.py deleted file mode 100644 index c5002ad5b6..0000000000 --- a/ThirdParty/Ert/devel/python/test/import_test.py +++ /dev/null @@ -1,220 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'import_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 sys - -def test_import( module ): - print "Importing: %s ..." % module , - __import__( module ) - print "OK" - - -test_import( "ert" ) - -test_import( "ert.config" ) -test_import( "ert.cwrap" ) -test_import( "ert.ecl" ) -test_import( "ert.enkf" ) -test_import( "ert.ert") -test_import( "ert.geo" ) -test_import( "ert.job_queue" ) -test_import( "ert.rms" ) -test_import( "ert.sched" ) -test_import( "ert.util" ) -test_import( "ert.well") - -test_import("ert.config.config") -test_import("ert.config.config_enums") -test_import("ert.config.config_parser") - -test_import("ert.cwrap.cclass") -test_import("ert.cwrap.cenum") -test_import("ert.cwrap.cfile") -test_import("ert.cwrap.clib") -test_import("ert.cwrap.cwrap") - -test_import("ert.ecl.ecl") -test_import("ert.ecl.ecl_case") -test_import("ert.ecl.ecl_default") -test_import("ert.ecl.ecl_file") -test_import("ert.ecl.ecl_grav_calc") -test_import("ert.ecl.ecl_grav") -test_import("ert.ecl.ecl_grid") -test_import("ert.ecl.ecl_kw") -test_import("ert.ecl.ecl") -test_import("ert.ecl.ecl_queue") -test_import("ert.ecl.ecl_region") -test_import("ert.ecl.ecl_rft") -test_import("ert.ecl.ecl_rft_cell") -test_import("ert.ecl.ecl_subsidence") -test_import("ert.ecl.ecl_sum") -test_import("ert.ecl.ecl_util") -test_import("ert.ecl.fortio") -test_import("ert.ecl.libecl") - -test_import("ert.enkf.enkf") -test_import("ert.enkf.analysis_config") -test_import("ert.enkf.block_obs") -test_import("ert.enkf.ecl_config") -test_import("ert.enkf.enkf_config_node") -test_import("ert.enkf.enkf_enum") -test_import("ert.enkf.enkf_fs") -test_import("ert.enkf.enkf_main") -test_import("ert.enkf.enkf_node") -test_import("ert.enkf.enkf_obs") -test_import("ert.enkf.enkf") -test_import("ert.enkf.enkf_state") -test_import("ert.enkf.ens_config") -test_import("ert.enkf.ert_template") -test_import("ert.enkf.ert_templates") -test_import("ert.enkf.field_config") -test_import("ert.enkf.field") -test_import("ert.enkf.gen_data_config") -test_import("ert.enkf.gen_kw_config") -test_import("ert.enkf.libenkf") -test_import("ert.enkf.local_config") -test_import("ert.enkf.model_config") -test_import("ert.enkf.obs_vector") -test_import("ert.enkf.plot_config") -test_import("ert.enkf.site_config") -test_import("ert.enkf.time_map") - -test_import("ert.ert.c_enums") -test_import("ert.ert.enums") -test_import("ert.ert.erttypes") -test_import("ert.ert.ertwrapper") - -test_import("ert.geo.geo_polygon") -test_import("ert.geo.geo") -test_import("ert.geo.libgeo") - -test_import("ert.job_queue.job_queue") -test_import("ert.job_queue.driver") -test_import("ert.job_queue.ext_job") -test_import("ert.job_queue.queue") -test_import("ert.job_queue.ext_joblist") -test_import("ert.job_queue.forward_model") -test_import("ert.job_queue.job") -test_import("ert.job_queue.libjob_queue") - -test_import("ert.rms.librms") -test_import("ert.rms.rms") - -test_import("ert.sched.history") -test_import("ert.sched.libsched") -test_import("ert.sched.sched_file") -test_import("ert.sched.sched") - -test_import("ert.util.ctime") -test_import("ert.util.latex") -test_import("ert.util.lookup_table") -test_import("ert.util.tvector") -test_import("ert.util.buffer") -#test_import("ert.util.hash") -test_import("ert.util.libutil") -test_import("ert.util.matrix") -test_import("ert.util.stat") -test_import("ert.util.util_func") -test_import("ert.util.log") -test_import("ert.util.stringlist") - -test_import("ert.well.libwell") -test_import("ert.well.well_info") -test_import("ert.well.well") -test_import("ert.well.well_state") -test_import("ert.well.well_ts") - -test_import("ert_gui") - -test_import("ert_gui.gert_main") -test_import("ert_gui.newconfig") -test_import("ert_gui.pages") -test_import("ert_gui.widgets") - -test_import("ert_gui.pages.application") -test_import("ert_gui.pages.config") -test_import("ert_gui.pages.init") -test_import("ert_gui.pages.plot") -test_import("ert_gui.pages.run") - -test_import("ert_gui.pages.config.analysis") -test_import("ert_gui.pages.config.configpages") -test_import("ert_gui.pages.config.eclipse") -test_import("ert_gui.pages.config.ensemble") -test_import("ert_gui.pages.config.observations") -test_import("ert_gui.pages.config.plot") -test_import("ert_gui.pages.config.queuesystem") -test_import("ert_gui.pages.config.simulation") -test_import("ert_gui.pages.config.systemenv") -test_import("ert_gui.pages.config.jobs") -test_import("ert_gui.pages.config.parameters") -test_import("ert_gui.pages.config.simulations") - -test_import("ert_gui.pages.config.jobs.forwardmodelpanel") -test_import("ert_gui.pages.config.jobs.jobsdialog") -test_import("ert_gui.pages.config.jobs.jobspanel") - -test_import("ert_gui.pages.config.parameters.datapanel") -test_import("ert_gui.pages.config.parameters.fieldpanel") -test_import("ert_gui.pages.config.parameters.keywordpanel") -test_import("ert_gui.pages.config.parameters.parameterdialog") -test_import("ert_gui.pages.config.parameters.parametermodels") -test_import("ert_gui.pages.config.parameters.parameterpanel") - -test_import("ert_gui.pages.config.simulations.runpathpanel") -test_import("ert_gui.pages.config.simulations.runtemplatepanel") - -test_import("ert_gui.pages.init.initandcopy") -test_import("ert_gui.pages.init.initpanel") - -test_import("ert_gui.pages.plot.ensemblefetcher") -test_import("ert_gui.pages.plot.fetcher") -test_import("ert_gui.pages.plot.plotconfig") -test_import("ert_gui.pages.plot.plotdata") -test_import("ert_gui.pages.plot.plotfigure") -test_import("ert_gui.pages.plot.plotgenerator") -test_import("ert_gui.pages.plot.plotpanel") -test_import("ert_gui.pages.plot.plotrenderer") -test_import("ert_gui.pages.plot.plotsettings") -test_import("ert_gui.pages.plot.plotsettingsxml") -test_import("ert_gui.pages.plot.plotview") -test_import("ert_gui.pages.plot.rftfetcher") -test_import("ert_gui.pages.plot.zoomslider") - -test_import("ert_gui.pages.run.legend") -test_import("ert_gui.pages.run.runpanel") -test_import("ert_gui.pages.run.simulation") -test_import("ert_gui.pages.run.simulationsdialog") - -test_import("ert_gui.widgets.activelabel") -test_import("ert_gui.widgets.checkbox") -test_import("ert_gui.widgets.cogwheel") -test_import("ert_gui.widgets.combochoice") -test_import("ert_gui.widgets.configpanel") -test_import("ert_gui.widgets.helpedwidget") -test_import("ert_gui.widgets.help") -test_import("ert_gui.widgets.pathchooser") -test_import("ert_gui.widgets.reloadbutton") -test_import("ert_gui.widgets.searchablelist") -test_import("ert_gui.widgets.spinnerwidgets") -test_import("ert_gui.widgets.stringbox") -test_import("ert_gui.widgets.tablewidgets") -test_import("ert_gui.widgets.util") -test_import("ert_gui.widgets.validateddialog") - - -def test_suite( argv ): - return False diff --git a/ThirdParty/Ert/devel/python/test/kw_test.py b/ThirdParty/Ert/devel/python/test/kw_test.py deleted file mode 100644 index 8b64501de3..0000000000 --- a/ThirdParty/Ert/devel/python/test/kw_test.py +++ /dev/null @@ -1,276 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'kw_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 unittest -import stat -import math -import ert -import ert.ecl.ecl as ecl -import sys -from test_util import * - -def copy_long(): - src = ecl.EclKW.create("NAME" , 100 , ecl.ECL_FLOAT_TYPE ) - copy = src.sub_copy( 0 , 2000 ) - - -def copy_offset(): - src = ecl.EclKW.create("NAME" , 100 , ecl.ECL_FLOAT_TYPE ) - copy = src.sub_copy( 200 , 100 ) - - - - -class KWTest( unittest.TestCase ): - - def setUp( self ): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - def fortio_size( self ): - unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" - file = ecl.EclFile( unrst_file ) - size = 0 - for kw in file: - size += kw.fortio_size - - stat = os.stat( unrst_file) - self.assertTrue( size == stat.st_size ) - - - def test_equal(self): - kw1 = ecl.EclKW.new( "TEST" , 3 , ecl.ECL_CHAR_TYPE ) - kw1[0] = "Test1" - kw1[1] = "Test13" - kw1[2] = "Test15" - - kw2 = ecl.EclKW.new( "TEST" , 3 , ecl.ECL_CHAR_TYPE ) - 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 = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" - file = ecl.EclFile( unrst_file ) - kw1 = 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 = 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 )) - - - def test_kw( self , type , data , fmt ): - name1 = "/tmp/file1.txt" - name2 = "/tmp/file2.txt" - kw = ecl.EclKW.new( "TEST" , len(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.assertTrue( file_equal( name1 , name2) ) - self.addFile( name1 ) - self.addFile( name2 ) - - - def testSubCopy(self): - unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" - file = ecl.EclFile( unrst_file ) - swat = file["SWAT"][0] - - swat1 = swat.sub_copy( 0 , -1 ) - swat2 = swat.sub_copy( 0 , swat.size ) - - self.assertTrue( swat.equal( swat1 )) - self.assertTrue( swat.equal( swat2 )) - - swat3 = swat.sub_copy(20000 , 100 , new_header = "swat") - self.assertTrue( swat3.name == "swat" ) - self.assertTrue( swat3.size == 100 ) - equal = True - for i in range(swat3.size): - if swat3[i] != swat[i + 20000]: - equal = False - self.assertTrue( equal ) - - self.assertRaises( IndexError , copy_long ) - self.assertRaises( IndexError , copy_offset ) - - - - - - def fprintf_test( self ): - self.test_kw( ecl.ECL_INT_TYPE , [0 , 1 , 2 , 3 , 4 , 5 ] , "%4d\n") - self.test_kw( ecl.ECL_FLOAT_TYPE , [0.0 , 1.1 , 2.2 , 3.3 , 4.4 , 5.5 ] , "%12.6f\n") - self.test_kw( ecl.ECL_DOUBLE_TYPE , [0.0 , 1.1 , 2.2 , 3.3 , 4.4 , 5.5 ] , "%12.6f\n") - self.test_kw( ecl.ECL_BOOL_TYPE , [True , True , True , False , True] , "%4d\n") - self.test_kw( ecl.ECL_CHAR_TYPE , ["1" , "22" , "4444" , "666666" , "88888888" ] , "%-8s\n") - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( KWTest( 'fortio_size' )) - suite.addTest( KWTest( 'fprintf_test' )) - suite.addTest( KWTest( 'test_equal' )) - suite.addTest( KWTest( 'testSubCopy' )) - return suite - - -def test_suite(argv): - return fast_suite() - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - - - - -#def cutoff( x , arg ): -# if x < arg: -# return 0 -# else: -# return x -# -# -#init_file = ecl.EclFile( "data/eclipse/case/ECLIPSE.INIT" ) -#permx = init_file.iget_named_kw("PERMX" , 0 ) -#poro = init_file.iget_named_kw("PORO" , 0 ) -#pvt = init_file.iget_named_kw("PVTNUM" , 0 ) -#grid = ecl.EclGrid( "data/eclipse/case/ECLIPSE.EGRID" ) -# -# -#poro3d = grid.create3D( poro , default = -100) -# -#print "max:%g" % poro.max -#print "min:%g" % poro.min -# -#mask1 = ecl.EclRegion( grid , False ) -#mask2 = ecl.EclRegion( grid , False ) -#mask1.select_less( poro , 0.15 ) -#mask2.select_more( poro , 0.30 ) -# -#mask3 = mask1.copy() -#mask3 |= mask2 -# -#mask1.reset() -#(x,y,z) = grid.get_xyz( ijk = (grid.nx / 2 , grid.ny /2 , grid.nz / 2) ) -#mask1.select_above_plane( [0,0,1] , [x,y,z] ) -#print mask1.active_list.size -#print mask1.active_list.str( max_lines = None ) -# -#print mask2.active_list.size -#print mask3.active_list.size -# -#poro.apply( cutoff , mask = mask1 , arg = 0.05) -# -# -#poro.write_grdecl( open("/tmp/poro_cos.grdecl" , "w") ) -# -#poro.add( permx , mask = mask1) -#poro.sub( 1 ) -#poro.mul( poro ) -#poro.assign( 14.0 ) -#poro.div( 7.0 ) -# -#new_p = poro / 7.0 -# -#poro.write_grdecl( open("/tmp/poro_cos.grdecl" , "w") ) -# -#init_file = ecl.EclFile( "data/eclipse/case/ECLIPSE.INIT" ) -#permx_kw = init_file.iget_named_kw( "PERMX" , 0 ) -#permx_new = ecl.EclKW.new( "PERMX" , 3 , ecl.ECL_FLOAT_TYPE ) -#print ecl.ECL_GRID_FILE -#print ecl.ecl_file_enum -#permx_new[0] = 1 -#permx_new[1] = 2 -#permx_new[2] = 3 -# -##init_file.replace_kw( permx_kw , permx_new ) -#fortio = ecl.FortIO.writer( "/tmp/init" ) -#print fortio -#init_file.fwrite( fortio ) -#fortio.close() -# -#poro = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_poro.GRDECL" , "r") , "PORO" ) -#eqlnum = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_eqlnum.GRDECL" , "r") , "EQLNUM" ) -#dummy = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_eqlnum.GRDECL" , "r") , "BJARNE" , ecl_type = ecl.ECL_INT_TYPE) -# -#if dummy: -# print "Loading BJARNE OK" -#else: -# print "Loading BJARNE Failed (correctly)" -# -#print "Poro[100] :%g eqlnum[100]:%d" % (poro[100] , eqlnum[100]) -# -#if not eqlnum.type == ecl.ECL_INT_TYPE: -# sys.exit("Type error when loading eqlnum") -# -#p2 = poro[100:160] -#if p2: -# print p2.header -#print poro -#print pvt.str( max_lines = 8 ) -#print eqlnum -# -#print ecl.EclKW.int_kw -#poro.add_int_kw("BJARNE") -#print eqlnum.int_kw diff --git a/ThirdParty/Ert/devel/python/test/large_mem_test.py b/ThirdParty/Ert/devel/python/test/large_mem_test.py deleted file mode 100644 index ba0d8bacb3..0000000000 --- a/ThirdParty/Ert/devel/python/test/large_mem_test.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'large_mem_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 unittest -import ert -import ert.ecl.ecl as ecl -from ert.util.tvector import DoubleVector -from test_util import approx_equal, approx_equalv - - -case = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE" - - -class MemTest( unittest.TestCase ): - def setUp(self): - # Funny setup to ensure that the 32 bit memory region is - # exhausted. Then we do some (grid-based) pointer - # dereferencing in the 64 bit memory region - this has been - # problematic in the past. - vecList = [] - for i in range(12500): - vec = DoubleVector() - vec[81920] = 0 - vecList.append( vec ) - - self.grid1 = ecl.EclGrid( case ) - self.grid2 = ecl.EclGrid( case ) - - - def test_nactive(self): - self.assertEqual( self.grid1.nactive , self.grid2.nactive ) - self.assertEqual( self.grid1.nactive , 34770 ) - - -def slow_suite(): - suite = unittest.TestSuite() - suite.addTest( MemTest( 'test_nactive' )) - return suite - -if __name__ == "__main__": - unittest.TextTestRunner().run( slow_suite() ) - diff --git a/ThirdParty/Ert/devel/python/test/latex_test.py b/ThirdParty/Ert/devel/python/test/latex_test.py deleted file mode 100644 index ae2de24f2f..0000000000 --- a/ThirdParty/Ert/devel/python/test/latex_test.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'latex_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 unittest -import os.path -import ert -import ert.util.latex as latex -from test_util import approx_equal, approx_equalv - -local_path = "test-data/local/util/latex" -statoil_path = "test-data/Statoil/util/latex" - -class LaTeXTest( unittest.TestCase ): - def setUp(self): - pass - - - def test1(self): - lx = latex.LaTeX( "%s/test_OK.tex" % local_path ) - self.assertTrue( lx.compile( ) ) - - lx = latex.LaTeX( "%s/test_error.tex" % local_path ) - self.assertFalse( lx.compile( ) ) - - - - def test_cleanup( self ): - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path , in_place = True ) - self.assertTrue( lx.in_place ) - self.assertTrue( lx.compile() ) - for ext in ["log" , "aux" , "nav" , "out" , "snm" , "toc"]: - self.assertFalse( os.path.exists( "%s/report_OK.%s" % (statoil_path , ext) )) - - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path , in_place = False ) - self.assertFalse( lx.in_place ) - run_path = lx.runpath - self.assertTrue( lx.compile() ) - self.assertFalse( os.path.exists( run_path ) ) - - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path , in_place = False ) - run_path = lx.runpath - self.assertTrue( lx.compile( cleanup = False) ) - self.assertTrue( os.path.exists( "%s/report_OK.log" % run_path)) - - - - def test_report(self): - lx = latex.LaTeX( "%s/report_error.tex" % statoil_path ) - lx.timeout = 4 - self.assertFalse( lx.compile() ) - - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path ) - self.assertTrue( lx.compile() ) - - - def test_target(self): - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path ) - self.assertTrue( lx.compile() ) - self.assertTrue( os.path.exists( lx.target )) - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( LaTeXTest( 'test1' )) - suite.addTest( LaTeXTest( 'test_report' )) - suite.addTest( LaTeXTest( 'test_cleanup' )) - suite.addTest( LaTeXTest( 'test_target' )) - return suite - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/region_test.py b/ThirdParty/Ert/devel/python/test/region_test.py deleted file mode 100644 index 4e99395f35..0000000000 --- a/ThirdParty/Ert/devel/python/test/region_test.py +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'region_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 unittest -import ert -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv - - -case = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE" - - -class RegionTest( unittest.TestCase ): - - def setUp(self): - self.grid = ecl.EclGrid( case ) - self.rst_file = ecl.EclFile( "%s.UNRST" % case ) - self.init_file = ecl.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 = ecl.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_kw_idiv(self): - P = self.rst_file["PRESSURE"][5] - fipnum = self.init_file["FIPNUM"][0] - fipnum_copy = fipnum.deep_copy() - - reg = ecl.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 = ecl.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 = ecl.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 = ecl.EclRegion( self.grid , False ) - reg.select_islice( 0 , 5 ) - OK = True - for gi in reg.global_list: - (i,j,k) = self.grid.get_ijk( global_index = gi ) - if i > 5: - OK = False - self.assertTrue( OK ) - self.assertTrue( self.grid.ny * self.grid.nz *6 == len(reg.global_list)) - - reg.select_jslice( 7 , 8 , intersect = True) - OK = True - for gi in reg.global_list: - (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.nz * 6 == len(reg.global_list)) - - reg2 = ecl.EclRegion( self.grid , False ) - reg2.select_kslice( 3 , 5 ) - reg &= reg2 - OK = True - for gi in reg.global_list: - (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.global_list)) - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( RegionTest( 'test_kw_imul' )) - suite.addTest( RegionTest( 'test_kw_iadd' )) - suite.addTest( RegionTest( 'test_kw_idiv' )) - suite.addTest( RegionTest( 'test_kw_isub' )) - suite.addTest( RegionTest( 'test_slice' )) - return suite - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/restart_test.py b/ThirdParty/Ert/devel/python/test/restart_test.py deleted file mode 100644 index 4aa7382244..0000000000 --- a/ThirdParty/Ert/devel/python/test/restart_test.py +++ /dev/null @@ -1,162 +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 filecmp -import datetime -import unittest -import shutil -import time -import os -import os.path -import ert -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv, file_equal - -xfile0 = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.X0000" -file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" -fmt_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.FUNRST" -grid_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID" - -def load_missing(): - ecl.EclFile( "No/Does/not/exist") - - -class RestartTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - - def test_report_file(self , fname): - self.assertTrue( ecl.EclFile.contains_report_step( fname , 4 )) - self.assertTrue( ecl.EclFile.contains_report_step( fname , 0 )) - self.assertTrue( ecl.EclFile.contains_report_step( fname , 62 )) - self.assertFalse( ecl.EclFile.contains_report_step( fname , -1 )) - self.assertFalse( ecl.EclFile.contains_report_step( fname , 100 )) - - f = ecl.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.test_report_file(file) - - - - def test_date(self): - f = ecl.EclFile( 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( ecl.EclFile.contains_sim_time( file , datetime.datetime( 2001 , 6 , 1) )) - self.assertFalse( ecl.EclFile.contains_sim_time( file , datetime.datetime( 2005 , 6 , 1) )) - self.assertFalse( ecl.EclFile.contains_sim_time( file , datetime.datetime( 1999 , 6 , 1) )) - self.assertFalse( ecl.EclFile.contains_sim_time( file , datetime.datetime( 2001 , 6 , 11) )) - - - - - def test_report_list_file(self , fname , rlist0): - rlist = ecl.EclFile.file_report_list( fname ) - self.assertTrue( approx_equalv( rlist , rlist0 )) - - f = ecl.EclFile( fname ) - rlist = f.report_list - self.assertTrue( approx_equalv( rlist , rlist0 )) - - - - def test_report_list(self): - rlist0 = range(63) - self.test_report_list_file( file , rlist0 ) - - rlist0 = [0] - self.test_report_list_file( xfile0 , rlist0 ) - - f = ecl.EclFile( grid_file ) - self.assertRaises( TypeError , ecl.EclFile.file_report_list) - - - def test_dates(self): - f = ecl.EclFile(file) - dates = f.dates - self.assertTrue( len(dates) == 63 ) - - f = ecl.EclFile(xfile0) - dates = f.dates - self.assertTrue( len(dates) == 1 ) - self.assertTrue( dates[0] == datetime.datetime(2000,1,1)) - - - - def test_name(self): - f = ecl.EclFile( file ) - self.assertTrue( f.name == file ) - - f = ecl.EclFile( xfile0 ) - self.assertTrue( f.name == xfile0 ) - - - - def test_kw( self ): - f = ecl.EclFile( 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 )) - - - kw4 = f.restart_get_kw( "SWAT" , datetime.datetime( 2009 , 3 , 1 )) - self.assertTrue( kw4 is None ) - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( RestartTest( 'test_name' )) - suite.addTest( RestartTest( 'test_report' )) - suite.addTest( RestartTest( 'test_date' )) - suite.addTest( RestartTest( 'test_kw' )) - suite.addTest( RestartTest( 'test_report_list' )) - suite.addTest( RestartTest( 'test_dates' )) - return suite - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - diff --git a/ThirdParty/Ert/devel/python/test/rft_cell_test.py b/ThirdParty/Ert/devel/python/test/rft_cell_test.py deleted file mode 100644 index 9988a1cf56..0000000000 --- a/ThirdParty/Ert/devel/python/test/rft_cell_test.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2013 Statoil ASA, Norway. -# -# The file 'rft_cell_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 unittest -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv - - -RFT_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT" -PLT_file = "test-data/Statoil/ECLIPSE/RFT/TEST1_1A.RFT" - - - - -def out_of_range(): - rftFile = ecl.EclRFTFile( RFT_file ) - rft = rftFile[100] - - - -class RFTCellTest( unittest.TestCase ): - - def RFTCell(self): - i = 10 - j = 8 - k = 100 - depth = 100 - pressure = 65 - swat = 0.56 - sgas = 0.10 - cell = ecl.EclRFTCell.new( i , j , k , depth , pressure , swat , sgas ) - - self.assertTrue( i == cell.get_i() ) - self.assertTrue( j == cell.get_j() ) - self.assertTrue( k == cell.get_k() ) - - self.assertTrue( approx_equal( pressure , cell.pressure) ) - self.assertTrue( approx_equal( depth , cell.depth )) - self.assertTrue( approx_equal( swat , cell.swat) ) - self.assertTrue( approx_equal( sgas , cell.sgas )) - self.assertTrue( approx_equal( 1 - (sgas + swat) , cell.soil )) - - - - - - def PLTCell(self): - i = 2 - j = 16 - k = 100 - depth = 100 - pressure = 65 - orat = 0.78 - grat = 88 - wrat = 97213 - conn_start = 214 - flowrate = 111 - oil_flowrate = 12 - gas_flowrate = 132 - water_flowrate = 13344 - - cell = ecl.EclPLTCell.new( i , j , k , depth , pressure , orat , grat , wrat , conn_start , flowrate , oil_flowrate , gas_flowrate , water_flowrate) - - - self.assertTrue( i == cell.get_i() ) - self.assertTrue( j == cell.get_j() ) - self.assertTrue( k == cell.get_k() ) - - self.assertTrue( cell.get_i() + 1 == cell.i ) - self.assertTrue( cell.get_j() + 1 == cell.j ) - self.assertTrue( cell.get_k() + 1 == cell.k ) - - - self.assertTrue( approx_equal( pressure , cell.pressure) ) - self.assertTrue( approx_equal( depth , cell.depth )) - self.assertTrue( approx_equal( orat , cell.orat) ) - self.assertTrue( approx_equal( grat , cell.grat )) - self.assertTrue( approx_equal( wrat , cell.wrat )) - - self.assertTrue( approx_equal( conn_start , cell.conn_start) ) - self.assertTrue( approx_equal( flowrate , cell.flowrate )) - self.assertTrue( approx_equal( oil_flowrate , cell.oil_flowrate )) - self.assertTrue( approx_equal( gas_flowrate , cell.gas_flowrate )) - self.assertTrue( approx_equal( water_flowrate , cell.water_flowrate)) - - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( RFTCellTest( 'RFTCell' )) - suite.addTest( RFTCellTest( 'PLTCell' )) - return suite - - - -def test_suite( argv ): - return fast_suite() - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - - - diff --git a/ThirdParty/Ert/devel/python/test/rft_test.py b/ThirdParty/Ert/devel/python/test/rft_test.py deleted file mode 100644 index 3d4583ccbe..0000000000 --- a/ThirdParty/Ert/devel/python/test/rft_test.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'rft_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 unittest -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv - - -RFT_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT" -PLT_file = "test-data/Statoil/ECLIPSE/RFT/TEST1_1A.RFT" - - - - -def out_of_range(): - rftFile = ecl.EclRFTFile( RFT_file ) - rft = rftFile[100] - - - -class RFTTest( unittest.TestCase ): - - def loadRFT( self ): - rftFile = ecl.EclRFTFile( RFT_file ) - - rft = rftFile[0] - cell = rft.ijkget( (32 , 53 , 0) ) - self.assertTrue( isinstance( cell , ecl.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.assertTrue( cell is None ) - - 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.assertTrue( isinstance( cell , ecl.EclRFTCell )) - - cell0 = rft.iget_sorted( 0 ) - self.assertTrue( isinstance( cell , ecl.EclRFTCell )) - rft.sort() - - - - def loadPLT( self ): - pltFile = ecl.EclRFTFile( 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.assertTrue( isinstance( cell , ecl.EclPLTCell )) - - - def exceptions( self ): - self.assertRaises( IndexError , out_of_range ) - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( RFTTest( 'loadRFT' )) - suite.addTest( RFTTest( 'loadPLT' )) - suite.addTest( RFTTest( 'exceptions' )) - return suite - - -def test_suite( argv ): - return fast_suite() - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - - - diff --git a/ThirdParty/Ert/devel/python/test/sched_test.py b/ThirdParty/Ert/devel/python/test/sched_test.py deleted file mode 100644 index 2f7cc6b24b..0000000000 --- a/ThirdParty/Ert/devel/python/test/sched_test.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'sched_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 unittest -import ert -import ert.sched.sched as sched -from test_util import approx_equal, approx_equalv, file_equal - - -src_file = "test-data/Statoil/ECLIPSE/Gurbat/target.SCH" -start_time = datetime.date(2000 , 1, 1) - -class SchedFileTest( unittest.TestCase ): - def setUp(self): - self.sched_file = sched.SchedFile( src_file , start_time ) - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - def test_load(self): - self.assertTrue( self.sched_file , "Load failed") - - - def test_length(self): - self.assertEqual( self.sched_file.length , 63 ) - - - def test_write_loop(self): - self.sched_file.write( "/tmp/schedule1" , 62) - sched_file2 = sched.SchedFile( "/tmp/schedule1" , start_time) - sched_file2.write( "/tmp/schedule2" , 62) - self.assertTrue( file_equal( "/tmp/schedule1" , "/tmp/schedule2") ) - - self.addFile( "/tmp/schedule1" ) - self.addFile( "/tmp/schedule2" ) - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( SchedFileTest( 'test_load' )) - suite.addTest( SchedFileTest( 'test_length' )) - suite.addTest( SchedFileTest( 'test_write_loop' )) - return suite - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/stringlist_test.py b/ThirdParty/Ert/devel/python/test/stringlist_test.py deleted file mode 100644 index d25225df71..0000000000 --- a/ThirdParty/Ert/devel/python/test/stringlist_test.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'stringlist_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 unittest -import stat -import math -import ert -from ert.util.stringlist import StringList -import sys -from test_util import * -import ert.ecl.ecl as ecl - -initList = ["S1" , "SABC" , "S33"] - -base = "ECLIPSE" -path = "test-data/Statoil/ECLIPSE/Gurbat" -case = "%s/%s" % (path , base) - - -def pop_empty(): - s = StringList( initial = initList ) - s.pop() - s.pop() - s.pop() - s.pop() - -def last_empty(): - s = StringList( initial = initList ) - s.pop() - s.pop() - s.pop() - s.last - - -class StringListTest( unittest.TestCase ): - - def setUp( self ): - pass - - - def create(self): - s = StringList( initial = initList ) - st = s.strings - del s - return st - - def test_pop( self ): - s = StringList( initial = initList ) - s1 = s.pop() - self.assertTrue( len(s) == 2 ) - self.assertTrue( s1 == "S33") - - s1 = s.pop() - self.assertTrue( len(s) == 1 ) - self.assertTrue( s1 == "SABC") - - s1 = s.pop() - self.assertTrue( len(s) == 0 ) - self.assertTrue( s1 == "S1") - - self.assertRaises( IndexError , pop_empty ) - - - def test_create( self ): - s = StringList() - - s = StringList( initial = initList ) - self.assertTrue( len(s) == 3 ) - for i in range(len(s)): - self.assertTrue( s[i] == initList[i] ) - - s2 = s.strings - for i in range(len(s)): - self.assertTrue( s2[i] == initList[i] ) - - s3 = self.create() - for i in range(len(s)): - self.assertTrue( s3[i] == initList[i] ) - - - def test_last( self ): - s = StringList( initial = initList ) - l = s.last - self.assertTrue( "S33" == l ) - self.assertRaises( IndexError , last_empty) - - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( StringListTest( 'test_create' )) - suite.addTest( StringListTest( 'test_pop' )) - suite.addTest( StringListTest( 'test_last' )) - return suite - - -def test_suite(argv): - return fast_suite() - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - diff --git a/ThirdParty/Ert/devel/python/test/sum_test.py b/ThirdParty/Ert/devel/python/test/sum_test.py deleted file mode 100644 index 67514ca8ea..0000000000 --- a/ThirdParty/Ert/devel/python/test/sum_test.py +++ /dev/null @@ -1,289 +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 unittest -import ert -import ert.ecl.ecl as ecl -from ert.util.stringlist import StringList -from test_util import approx_equal, approx_equalv - - -base = "ECLIPSE" -path = "test-data/Statoil/ECLIPSE/Gurbat" -case = "%s/%s" % (path , base) - - -def sum_get(*args): - sum = args[0] - key = args[1] - vec = sum[key] - - - - -class SumTest( unittest.TestCase ): - - def setUp(self): - self.case = case - self.sum = ecl.EclSum( self.case ) - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - def test_load(self): - self.assertTrue( self.sum , "Load failed") - - - def test_interp(self): - sum = self.sum - self.assertTrue( approx_equal( sum.get_interp( "WWCT:OP_3" , days = 750 ) , 0.11719122)) - self.assertTrue( approx_equal( 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 , 800] ) - self.assertTrue( approx_equalv( [805817.11875 , 1614955.34677419 , 3289267.67857143 , 6493021.6218035 ] , 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.assertTrue( approx_equalv( v , [ 8.20773632e+08 , 9.68444032e+08 , 1.02515213e+09]) ) - - - def test_wells(self): - sum = self.sum - wells = sum.wells() - wells.sort() - self.assertTrue( approx_equalv( wells , ["OP_1" , "OP_2" , "OP_3" , "OP_4" , "OP_5" , "WI_1" , "WI_2" , "WI_3"])) - - wells = sum.wells( pattern = "*_3") - wells.sort() - self.assertTrue( approx_equalv( wells , ["OP_3" , "WI_3"])) - - groups = sum.groups() - groups.sort() - self.assertTrue( approx_equalv( groups , ['GMWIN','OP','WI'])) - - - def test_last( self ): - sum = self.sum - last = sum.get_last("FOPT") - self.assertTrue( approx_equal( last.value , 38006336.0 )) - self.assertTrue( approx_equal( last.days , 1826.0 )) - self.assertEqual( last.date , datetime.datetime( 2004 , 12 , 31, 0,0,0)) - - self.assertTrue( approx_equal( sum.get_last_value("FGPT") , 6605249024.0)) - - - def test_dates( self ): - sum = self.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.assertTrue( approx_equal( mpl_dates[25] , 730820 )) - - days = sum.days - self.assertTrue( approx_equal( 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))) - - def test_keys(self): - sum = self.sum - self.assertRaises( KeyError , sum.__getitem__ , "BJARNE" ) - - v = sum["FOPT"] - self.assertEqual( len(v) , 63 ) - - - def test_index(self): - sum = self.sum - index = sum.get_key_index( "TCPUDAY") - self.assertEqual( index , 10239 ) - - - def test_report(self): - sum = self.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.assertTrue( approx_equal( 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.assertTrue( approx_equal( sum.get_from_report( "FOPT" , 10 ) , 6.67447e+06) ) - - - def test_fwrite(self): - self.sum.fwrite(ecl_case = "/tmp/CASE" ) - self.assertTrue( True ) - - - def test_block(self): - sum = self.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 = ecl.EclSum( "test-data/Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1" ) - base = ecl.EclSum( "test-data/Statoil/ECLIPSE/sum-restart/prediction/BASECASE" ) - pred = ecl.EclSum( "test-data/Statoil/ECLIPSE/sum-restart/prediction/BASECASE" , include_restart = False) - - self.assertTrue( pred ) - - - def test_case1(self ): - self.assertTrue( self.sum.path == path ) - self.assertTrue( self.sum.base == base ) - self.assertTrue( self.sum.case == case ) - self.assertTrue( self.sum.abs_path == os.path.realpath(os.path.join( os.getcwd() , path ))) - - - def test_case2( self ): - cwd = os.getcwd() - os.chdir( path ) - sum = ecl.EclSum( base ) - self.assertTrue( sum.path is None ) - self.assertTrue( sum.base == base ) - self.assertTrue( sum.case == base ) - self.assertTrue( sum.abs_path == os.path.realpath(os.path.join( cwd , path ))) - os.chdir( cwd ) - - - - - def test_var_properties( self ): - sum = self.sum - self.assertRaises( KeyError , sum.smspec_node , "BJARNE" ) - - node = sum.smspec_node( "FOPT" ) - self.assertTrue( node.is_total ) - self.assertFalse( node.is_historical ) - - node = sum.smspec_node( "FOPR" ) - self.assertFalse( node.is_total ) - self.assertFalse( node.is_historical ) - self.assertTrue( node.keyword == "FOPR" ) - - node = sum.smspec_node( "FOPRH" ) - self.assertFalse( node.is_total ) - self.assertTrue( node.is_historical ) - self.assertTrue( node.is_rate ) - self.assertTrue( node.keyword == "FOPRH" ) - - node = sum.smspec_node( "WOPR:OP_1" ) - self.assertFalse( node.is_total ) - self.assertTrue( node.is_rate ) - self.assertTrue( node.keyword == "WOPR" ) - - node = sum.smspec_node( "WOPT:OP_1" ) - self.assertTrue( node.is_total ) - self.assertFalse( node.is_rate ) - 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.is_total ) - self.assertFalse( node.is_rate ) - self.assertTrue( node.wgname is None ) - - node = sum.smspec_node( "FOPTH" ) - self.assertTrue( node.num is None ) - - node = sum.smspec_node( "BPR:1095" ) - self.assertTrue( node.num == 1095 ) - - def test_stringlist_gc(self): - sum = ecl.EclSum( case ) - wells = sum.wells() - well1 = wells[0] - del wells - self.assertTrue( well1 == "OP_1" ) - - - def test_stringlist_reference(self): - sum = ecl.EclSum( case ) - wells = sum.wells() - self.assertTrue( approx_equalv( wells , ['OP_1','OP_2','OP_3','OP_4','OP_5','WI_1','WI_2','WI_3'])) - self.assertTrue( isinstance( wells , StringList )) - - - def test_stringlist_setitem(self): - sum = ecl.EclSum( 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 fast_suite(): - suite = unittest.TestSuite() - suite.addTest( SumTest( 'test_load' )) - suite.addTest( SumTest( 'test_case1' )) - suite.addTest( SumTest( 'test_case2' )) - suite.addTest( SumTest( 'test_interp' )) - suite.addTest( SumTest( 'test_wells' )) - suite.addTest( SumTest( 'test_last' )) - suite.addTest( SumTest( 'test_dates' )) - suite.addTest( SumTest( 'test_keys' )) - suite.addTest( SumTest( 'test_index' )) - suite.addTest( SumTest( 'test_report' )) - suite.addTest( SumTest( 'test_fwrite' )) - suite.addTest( SumTest( 'test_block' )) - suite.addTest( SumTest( 'test_restart' )) - suite.addTest( SumTest( 'test_var_properties' )) - suite.addTest( SumTest( 'test_stringlist_gc')) - suite.addTest( SumTest( 'test_stringlist_reference')) - suite.addTest( SumTest( 'test_stringlist_setitem')) - return suite - - -def test_suite( argv ): - return fast_suite() - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/test_all.py b/ThirdParty/Ert/devel/python/test/test_all.py deleted file mode 100644 index e1f21e2322..0000000000 --- a/ThirdParty/Ert/devel/python/test/test_all.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -import unittest -import sys - -import troll_test -import sum_test -import sched_test -import large_mem_test -import file_test -import grdecl_test -import grid_test -import kw_test -import region_test -import latex_test -import fortio_test -import restart_test -import config_test -import stringlist_test -import tvector_test - -def run_suite(name , suite): - print "Running tests from %12s:" % name, - sys.stdout.flush() - unittest.TextTestRunner().run( suite ) - - -def run(name , module): - if hasattr(module , "fast_suite"): - run_suite( name , getattr(module , "fast_suite")()) - - if hasattr(module , "slow_suite"): - run_suite( name , getattr(module , "slow_suite")()) - -run("config" , config_test) -run("restart" , restart_test) -run("kw" , kw_test) -run("summary" , sum_test) -run("troll" , troll_test) -run("sched_file" , sched_test) -run("file_test" , file_test) -run("large_mem" , large_mem_test) -run("grdecl" , grdecl_test) -run("grid" , grid_test) -run("region" , region_test) -run("latex" , latex_test) -run("fortio" , fortio_test) -run("stringlist" , stringlist_test) -run("tvector" , tvector_test) diff --git a/ThirdParty/Ert/devel/python/test/test_fast.py b/ThirdParty/Ert/devel/python/test/test_fast.py deleted file mode 100644 index 12b0872f39..0000000000 --- a/ThirdParty/Ert/devel/python/test/test_fast.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -import unittest -import sys - -import sum_test -import sched_test -import large_mem_test -import file_test -import grdecl_test -import grid_test - -def run_suite(name , suite): - print "Running tests from %12s:" % name, - sys.stdout.flush() - unittest.TextTestRunner().run( suite ) - - -def run(name , module): - if hasattr(module , "fast_suite"): - run_suite( name , getattr(module , "fast_suite")()) - -run("kw" , kw_test) -run("summary" , sum_test) -run("sched_file" , sched_test) -run("file_test" , file_test) -run("large_mem" , large_mem_test) -run("grdecl" , grdecl_test) -run("grid" , grid_test) diff --git a/ThirdParty/Ert/devel/python/test/test_util.py b/ThirdParty/Ert/devel/python/test/test_util.py deleted file mode 100644 index 9ebe97fe9e..0000000000 --- a/ThirdParty/Ert/devel/python/test/test_util.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'test_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. -import filecmp - -def is_number(x): - try: - y = x + 1 - return True - except TypeError: - return False - -def approx_equal(a,b): - if is_number(a): - tol = 1e-6 - d = abs(a - b) - s = max(1 , abs(a) + abs(b)) - - return d < tol * s - else: - return a == b - -def approx_equalv(a,b): - equal = False - if len(a) == len(b): - equal = True - for (ai,bi) in zip(a,b): - if not approx_equal(ai,bi): - equal = False - break - return equal - - -def file_equal(f1,f2): - buffer1 = open(f1).read() - buffer2 = open(f2).read() - if buffer1 == buffer2: - return True - else: - return False - - diff --git a/ThirdParty/Ert/devel/python/test/tvector_test.py b/ThirdParty/Ert/devel/python/test/tvector_test.py deleted file mode 100644 index 71fe3bf93f..0000000000 --- a/ThirdParty/Ert/devel/python/test/tvector_test.py +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'tvector_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 unittest -import ert -from ert.util.tvector import DoubleVector -from ert.util.tvector import IntVector -from ert.util.tvector import BoolVector - -from test_util import approx_equal, approx_equalv - - -def add_size_error(): - l1 = IntVector() - l2 = IntVector() - - l1[100] = 10 - l2[10] = 1 - l1 += l2 - - -def mul_size_error(): - l1 = IntVector() - l2 = IntVector() - - l1[100] = 10 - l2[10] = 1 - l1 *= l2 - - - -class TVectorTest( unittest.TestCase ): - - - def setUp(self): - pass - - - 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) - - active_list = IntVector.active_list("1,10,100-105X") - self.assertFalse( active_list ) - - - - def test_activeMask(self): - active_list = BoolVector.active_mask("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]) - - active_list = BoolVector.active_mask("1,4-7,10X") - self.assertFalse( active_list ) - - - - def test_true(self): - l = IntVector() - self.assertFalse( l ) # Will invoke the __len__ function; could override with __nonzero__ - l[0] = 1 - self.assertTrue( l ) - - - - def test_default(self): - l = IntVector( default_value = 100 ) - self.assertTrue( l.default == 100 ) - l[10] = 1 - self.assertTrue( l[0] == 100 ) - self.assertTrue( l[9] == 100 ) - self.assertTrue( l[10] == 1 ) - - l.default = 200 - self.assertTrue( l.default == 200 ) - l[20] = 77 - self.assertTrue( l[19] == 200 ) - - - def test_copy(self): - l1 = IntVector( default_value = 77 ) - l1[99] = 100 - - l2 = l1.copy() - self.assertTrue( l1.default == l2.default ) - self.assertTrue( len(l1) == len(l2)) - self.assertTrue( l1[99] == l2[99] ) - - - def test_div(self): - l1 = IntVector( default_value = 100 ) - l1[99] = 100 - l2 = l1 / 10 - - self.assertTrue( l1.default == l2.default ) - self.assertTrue( len(l1) == len(l2)) - self.assertTrue( l2[99] == 10 ) - self.assertTrue( l2[9] == 10 ) - self.assertTrue( l2[1] == 10 ) - - - def test_add(self): - l1 = IntVector( default_value = 100 ) - l1[99] = 100 - l1 += 100 - - self.assertTrue( l1[99] == 200 ) - self.assertTrue( l1[9] == 200 ) - self.assertTrue( l1[1] == 200 ) - - l2 = IntVector( default_value = 75 ) - l2[99] = 75 - l1 += l2 - - self.assertTrue( l1[99] == 275 ) - self.assertTrue( l1[9] == 275 ) - self.assertTrue( l1[1] == 275 ) - - self.assertRaises( ValueError , add_size_error ) - - - def test_mul(self): - l1 = IntVector( default_value = 100 ) - l1[99] = 100 - l1 *= 2 - - self.assertTrue( l1[99] == 200 ) - self.assertTrue( l1[9] == 200 ) - self.assertTrue( l1[1] == 200 ) - - l2 = IntVector( default_value = 2 ) - l2[99] = 2 - l1 *= l2 - - self.assertTrue( l1[99] == 400 ) - self.assertTrue( l1[9] == 400 ) - self.assertTrue( l1[1] == 400 ) - - self.assertRaises( ValueError , mul_size_error ) - - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( TVectorTest( 'test_activeList' )) - suite.addTest( TVectorTest( 'test_activeMask' )) - suite.addTest( TVectorTest( 'test_true' )) - suite.addTest( TVectorTest( 'test_default' )) - suite.addTest( TVectorTest( 'test_copy' )) - suite.addTest( TVectorTest( 'test_div' )) - suite.addTest( TVectorTest( 'test_add' )) - suite.addTest( TVectorTest( 'test_mul' )) - return suite - -def test_suite(argv): - return fast_suite() - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - - diff --git a/ThirdParty/Ert/devel/python/test/util_test.py b/ThirdParty/Ert/devel/python/test/util_test.py deleted file mode 100644 index dc2f2a7cf4..0000000000 --- a/ThirdParty/Ert/devel/python/test/util_test.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'util_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 random -import copy - -from ert.util.tvector import DoubleVector -from ert.util.tvector import IntVector -from ert.util.tvector import BoolVector -from ert.util.stringlist import StringList -import ert.util.stat as stat -from ert.util.util_func import * - -v = DoubleVector( 0 ) -print v -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 -v.printf( ) -v.clear() - -for i in range( 100000 ): - r = random.random() - v.append( r ) - - -print stat.quantile( v , 0.10 ) -print stat.quantile_sorted( v , 0.20 ) -print stat.quantile_sorted( v , 0.30 ) -print stat.quantile_sorted( v , 0.40 ) -print stat.quantile_sorted( v , 0.50 ) - -a = v[0:10] -print a -print a[6] -print a - - -b = copy.deepcopy( a ) -c = a.copy( ) -print c -print b -print v -c = IntVector( 0 ) -c.append( 1 ) -c.append( 2 ) -c.append( 3 ) -c.append( 4 ) -c.append( 5 ) - -c.rsort() -c.printf() - -print c.max -print c.min -print c.min_index() -c[4] = 5 -print c.max_index( reverse = True ) -print c.max_index( reverse = False ) - -d = c + 1 -d.printf() - -v2 = v.copy() -v2 = v2 * 2 -v2 += v - -print v2.assign -v2.assign( 1.0 ) -print v2[77] - -v2.default = 100 -print v2.default - -B = BoolVector( True ) -B[4] = False -B.printf() - -l = ["CASE-9","CASE-10"] -print l.sort() -print l.sort( strcmp_int ) - -v.default = 13 -v[1000] = 99 -print v.size -np = v.numpy_copy() -v[0] = 77 -v[5] = 99 -print v.str( max_lines = None ) - -S = StringList(["A" , "list" ,"of" , "strings"]) - -print S - -if "A" in S: - print "S contains A" - -if not "Bjarne" in S: - print "S does not contain BJARNE" - -