#3576 ecllib upgrade from statoil repo 7f93730c08a4d981a4b738b42146d099977572ce

This commit is contained in:
Bjørn Erik Jensen 2018-10-30 13:21:11 +01:00
parent 37d5156b0d
commit 6924c20ab6
82 changed files with 1654 additions and 1481 deletions

View File

@ -18,7 +18,7 @@ set(NRLIB_GITHUB_SHA "ba35d4359882f1c6f5e9dc30eb95fe52af50fd6f")
# https://github.com/Statoil/libecl
# Note:
# Apply patches fix-synthetic-odb-cases.patch and install-ert.patch after update
set(ECL_GITHUB_SHA "1f051833c8ed819185fd334dfc7e05511ee35d5f")
set(ECL_GITHUB_SHA "7f93730c08a4d981a4b738b42146d099977572ce")
# https://github.com/OPM/opm-flowdiagnostics
set(OPM_FLOWDIAGNOSTICS_SHA "f8af0914f8b1ddcda41f040f539c945a6057f5e4")

View File

@ -54,16 +54,20 @@ install:
- if [[ $PYTHON_VERSION == 2.7 ]]; then
export TRAVIS_PYTHON_VERSION="2.7";
fi
- if [[ $PYTHON_VERSION == 3.6 ]]; then
export TRAVIS_PYTHON_VERSION="3.6";
fi
# We do this conditionally because it saves us some downloading if the version is the same.
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda2-latest-${CONDA_OS}-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-${CONDA_OS}-x86_64.sh -O miniconda.sh;
wget https://repo.continuum.io/miniconda/Miniconda3-4.4.10-${CONDA_OS}-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export CONDA_HOME="$HOME/miniconda"
- export PATH="$CONDA_HOME/bin:$PATH"
- hash -r
- python --version
- pip install -r requirements.txt
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda

View File

@ -352,9 +352,6 @@ if (ENABLE_PYTHON)
endif()
endif()
if (INSTALL_ERT)
install(EXPORT ecl-config DESTINATION share/cmake/ecl)
endif()
export(TARGETS ecl FILE eclConfig.cmake)
export(PACKAGE ecl)

7
ThirdParty/Ert/MANIFEST.in vendored Normal file
View File

@ -0,0 +1,7 @@
include README.md COPYING
global-include CMakeLists.txt *.cmake
recursive-include external/catch2 *
recursive-include lib *
recursive-include applications *
recursive-include bin *
recursive-include cmake *

View File

@ -8,53 +8,75 @@ non-unified and formatted and unformatted files are supported.
*libecl* is mainly developed on *Linux* and *OS X*, in addition there
is a portability layer which ensures that most of the functionality is
available on *Windows*. The main functionality is written in C, and
available on *Windows*. The main functionality is written in C/C++, and
should typically be linked in in other compiled programs. *libecl* was
initially developed as part of the [Ensemble Reservoir
Tool](http://github.com/Statoil/ert), other applications using
*libecl* are the reservoir simulator flow and Resinsight from the [OPM
project](http://github.com/OPM/).
In addition to the C code there are Python wrappers which make most of
the *libecl* functionality available from Python. For small interactive
scripts, forward models e.t.c. this is recommended way to use *libecl*
functionality.
In addition to the compiled C/C++ code there are Python wrappers which make most
of the *libecl* functionality available from Python. For small interactive
scripts, forward models e.t.c. this is the recommended way to use *libecl*
functionality. You decide wether to build include the Python wrappers when
configuring the `cmake` build - pass the option `-DENABLE_PYTHON=ON` to enable
Python wrappers, by default the Python wrappers are *not* included.
By default `cmake` is configured to install to a system location like
`/usr/local`, if you want to install to an alternative location that should be
configured with `-DCMAKE_INSTALL_PREFIX=/path/to/install`.
### Compiling the C code ###
### Alternative 1: Building without Python ###
*libecl* uses CMake as build system:
```bash
git clone https://github.com/Statoil/libecl.git
git clone https://github.com/Statoil/libecl
cd libecl
mkdir build
cd build
cmake ..
cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install
make
make install
```
If you intend to develop and change *libecl* you should build the tests
by passing `-DBUILD_TESTS=ON` and run the tests with `ctest`.
### Compiling the Python code ###
Python is not a compiled language, but there is a basic "build system"
which does a basic Python syntax check and configures some files to
correctly set up the interaction between the Python classes and the
shared libraries built from the C code.
You need to install some Python requirements before the Python code
will work:
### Alternative 2: Building with Python ###
To build *libecl* with Python wrappers you just pass the option
`-DENABLE_PYTHON=ON` when running `cmake`. In addition you need to install some
dependencies first. Python is not a compiled language, but the `cmake` configuration contains a
rudimentary "build system" which does a basic Python syntax check and configures some
files to correctly set up the interaction between the Python classes and the
shared libraries built from the C code:
```bash
git clone https://github.com/Statoil/libecl
cd libecl
sudo pip install -r requirements.txt
mkdir build
cd build
cmake .. -DENABLE_PYTHON=ON -DCMAKE_INSTALL_PREFIX=/path/to/install
make
make install
```
The Python + cmake interaction is handled in a separate project called
[pycmake](https://github.com/Statoil/pycmake); you can either install
that manually or use the git submodule functionality to fetch the
correct version of `pycmake` into your *libecl* code:
git submodule update --init pycmake
After you have installed the Python wrappers you must tell `Python` where to
find the package[1]:
```bash
export PYTHONPATH=/path/to/install/lib/python2.7/site-packages:$PYTHONPATH
export LD_LIBRARY_PATH=/path/to/install/lib64:$LD_LIBRARY_PATH
```
Then you can fire up your Python interpreter and try it out:
```
from ecl.summary import EclSum
import sys
summary = EclSum(sys.argv[1])
fopt = summary.numpy_vector("FOPT")
```
[1]: The exact paths here will depend on your system and Python version. The example given is for a RedHat system with Python version 2.7.

View File

@ -54,7 +54,7 @@ int main(int argc, char ** argv) {
for (int iarg=3; iarg < argc; iarg++)
stringlist_append_ref(kw_set, argv[iarg]);
stringlist_append_copy(kw_set, argv[iarg]);
if (!ecl_util_fmt_file(src_file, &fmt_src))
util_exit("Hmm - could not determine formatted/unformatted status for:%s \n",src_file);

View File

@ -1,4 +1,4 @@
ecl (2017.09-test1-1~xenial) xenial; urgency=low
ecl (2018.10-rfinal-1~xenial) xenial; urgency=low
* New release

View File

@ -12,5 +12,14 @@
%:
dh $@
override_dh_auto_clean:
dh_auto_clean --buildsystem=cmake
override_dh_auto_build:
dh_auto_build --buildsystem=cmake
override_dh_auto_configure:
DESTDIR=$$(pwd)/debian/tmp dh_auto_configure -- -DBUILD_SHARED_LIBS=1 -DBUILD_ECL_SUMMARY=1 -DENABLE_PYTHON=1 -DCMAKE_BUILD_TYPE=Release
DESTDIR=$$(pwd)/debian/tmp dh_auto_configure --buildsystem=cmake -- -DBUILD_SHARED_LIBS=1 -DBUILD_ECL_SUMMARY=1 -DENABLE_PYTHON=1 -DCMAKE_BUILD_TYPE=Release
override_dh_auto_install:
dh_auto_install --buildsystem=cmake

View File

@ -55,8 +55,7 @@ if (ZLIB_FOUND)
endif ()
if (ERT_BUILD_CXX)
list(APPEND opt_srcs util/TestArea.cpp
ecl/FortIO.cpp
list(APPEND opt_srcs ecl/FortIO.cpp
ecl/Smspec.cpp
ecl/EclFilename.cpp
)
@ -73,6 +72,7 @@ add_library(ecl util/rng.cpp
util/mzran.cpp
util/hash_node.cpp
util/hash_sll.cpp
util/path.cpp
util/hash.cpp
util/node_data.cpp
util/node_ctype.cpp
@ -90,6 +90,7 @@ add_library(ecl util/rng.cpp
util/ecl_version.cpp
util/perm_vector.cpp
util/test_util.cpp
util/cxx_string_util.cpp
${opt_srcs}
ecl/ecl_rsthead.cpp
@ -203,7 +204,7 @@ endif ()
set_target_properties(ecl PROPERTIES
VERSION ${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}
SOVERSION ${ECL_VERSION_MAJOR})
if (INSTALL_ERT)
install(TARGETS ecl
EXPORT ecl-config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
@ -228,7 +229,6 @@ if (ERT_BUILD_CXX)
PATTERN *.hpp
)
endif ()
endif()
if (NOT BUILD_TESTS)
return ()
@ -245,6 +245,7 @@ target_link_libraries(ecl3-testsuite catch2 ecl)
add_test(NAME ecl3 COMMAND ecl3-testsuite)
foreach (name ert_util_alloc_file_components
ert_util_split_path
ert_util_approx_equal
ert_util_before_after
ert_util_binary_split
@ -271,6 +272,7 @@ foreach (name ert_util_alloc_file_components
)
add_executable(${name} util/tests/${name}.cpp)
target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
target_link_libraries(${name} ecl)
add_test(NAME ${name} COMMAND ${name})
endforeach ()
@ -348,6 +350,9 @@ foreach (name ecl_alloc_cpgrid
ecl_grid_init_fwrite
ecl_grid_reset_actnum
ecl_grid_ext_actnum
ecl_sum_data_intermediate_test
ecl_grid_cell_contains
ecl_unsmry_loader_test
ecl_init_file
ecl_kw_cmp_string
ecl_kw_equal
@ -366,6 +371,7 @@ foreach (name ecl_alloc_cpgrid
ecl_sum_writer
ecl_util_filenames
ecl_util_make_date_no_shift
ecl_util_make_date_shift
ecl_util_month_range
ecl_valid_basename
test_ecl_nnc_data
@ -381,22 +387,10 @@ foreach (name ecl_alloc_cpgrid
)
add_executable(${name} ecl/tests/${name}.cpp)
target_link_libraries(${name} ecl)
target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
add_test(NAME ${name} COMMAND ${name})
endforeach ()
add_executable(ecl_unsmry_loader ecl/tests/ecl_unsmry_loader_test.cpp)
target_link_libraries(ecl_unsmry_loader ecl)
target_include_directories(ecl_unsmry_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
add_test(NAME ecl_unsmry_loader COMMAND ecl_unsmry_loader)
add_executable(ecl_sum_data_intermediate ecl/tests/ecl_sum_data_intermediate_test.cpp)
target_link_libraries(ecl_sum_data_intermediate ecl)
add_test(NAME ecl_sum_data_intermediate COMMAND ecl_sum_data_intermediate)
add_executable(ecl_grid_cell_contains ecl/tests/ecl_grid_cell_contains.cpp)
target_link_libraries(ecl_grid_cell_contains ecl)
add_test(NAME ecl_grid_cell_contains1 COMMAND ecl_grid_cell_contains)
if (HAVE_UTIL_ABORT_INTERCEPT)
add_executable(ecl_grid_corner ecl/tests/ecl_grid_corner.cpp)
target_link_libraries(ecl_grid_corner ecl)
@ -435,7 +429,7 @@ foreach (name geo_util_xlines geo_polygon geo_polygon_collection)
endforeach ()
if (ERT_BUILD_CXX)
foreach (test ert_util_unique_ptr ert_util_test_area_xx)
foreach (test ert_util_unique_ptr)
add_executable(${test} util/tests/${test}.cpp)
target_link_libraries(${test} ecl)
add_test(NAME ${test} COMMAND ${test})
@ -448,6 +442,52 @@ if (ERT_BUILD_CXX)
endforeach ()
endif ()
foreach(name ecl_coarse_test
ecl_grid_layer_contains
ecl_restart_test
ecl_nnc_export
ecl_nnc_export_get_tran
ecl_nnc_data_statoil_root
ecl_sum_case_exists
ecl_grid_lgr_name
ecl_region
ecl_grid_cell_contains_wellpath
ecl_region2region
ecl_grid_case
ecl_grid_simple
ecl_grid_volume
ecl_grid_dims
ecl_nnc_test
ecl_lgr_test
ecl_layer_statoil
ecl_dualp
ecl_grid_dx_dy_dz
ecl_sum_test
ecl_sum_report_step_equal
ecl_sum_report_step_compatible
ecl_file_statoil
ecl_fmt
ecl_rsthead
ecl_smspec
ecl_rft
ecl_grid_copy_statoil
ecl_fault_block_layer_statoil
well_state_load
well_state_load_missing_RSEG
well_segment_load
well_segment_branch_conn_load
well_info
well_conn_CF
well_conn_load
well_ts
well_dualp
well_lgr_load)
add_executable(${name} ecl/tests/${name}.cpp)
target_link_libraries(${name} ecl)
target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
endforeach()
if (NOT STATOIL_TESTDATA_ROOT)
return ()
@ -457,26 +497,21 @@ endif()
# ecl
#
add_test(NAME ecl_grid_dx_dy_dz1 COMMAND ecl_grid_dx_dy_dz ${_eclpath}/Gurbat/ECLIPSE)
add_test(NAME ecl_grid_dx_dy_dz3 COMMAND ecl_grid_dx_dy_dz ${_eclpath}/Troll/Ref2014/T07-4A-W2014-06)
add_executable(ecl_coarse_test ecl/tests/ecl_coarse_test.cpp)
target_link_libraries(ecl_coarse_test ecl)
add_test(NAME ecl_coarse_test COMMAND ecl_coarse_test
${_eclpath}/LGCcase/LGC_TESTCASE2)
add_executable(ecl_grid_layer_contains ecl/tests/ecl_grid_layer_contains.cpp)
target_link_libraries(ecl_grid_layer_contains ecl)
add_test(NAME ecl_grid_layer_contains1 COMMAND ecl_grid_layer_contains
${_eclpath}/Gurbat/ECLIPSE.EGRID)
add_test(NAME ecl_grid_layer_contains2 COMMAND ecl_grid_layer_contains
${_eclpath}/Mariner/MARINER.EGRID)
add_executable(ecl_restart_test ecl/tests/ecl_restart_test.cpp)
target_link_libraries(ecl_restart_test ecl)
add_test(NAME ecl_restart_test COMMAND ecl_restart_test
${_eclpath}/Gurbat/ECLIPSE.UNRST)
add_executable(ecl_nnc_export ecl/tests/ecl_nnc_export.cpp)
target_link_libraries(ecl_nnc_export ecl)
add_test(NAME ecl_nnc_export1 COMMAND ecl_nnc_export ${_eclpath}/Gurbat/ECLIPSE TRUE)
add_test(NAME ecl_nnc_export2 COMMAND ecl_nnc_export ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC TRUE)
add_test(NAME ecl_nnc_export3 COMMAND ecl_nnc_export ${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3 TRUE)
@ -485,81 +520,53 @@ add_test(NAME ecl_nnc_export5 COMMAND ecl_nnc_export ${_eclpath}/DualPoro/DUALPO
add_test(NAME ecl_nnc_export6 COMMAND ecl_nnc_export ${_eclpath}/nestedLGRcase/TESTCASE_NESTEDLGR TRUE)
add_test(NAME ecl_nnc_export7 COMMAND ecl_nnc_export ${_eclpath}/TYRIHANS/BASE20150218_MULTFLT FALSE)
add_executable(ecl_nnc_export_get_tran ecl/tests/ecl_nnc_export_get_tran.cpp)
target_link_libraries(ecl_nnc_export_get_tran ecl)
add_test(NAME ecl_nnc_export_get_tran COMMAND ecl_nnc_export_get_tran
${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3)
add_executable(ecl_nnc_data_statoil_root ecl/tests/test_ecl_nnc_data_statoil_root.cpp)
target_link_libraries(ecl_nnc_data_statoil_root ecl)
add_test(NAME ecl_nnc_data_statoil_root COMMAND ecl_nnc_data_statoil_root
${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3
${_eclpath}/flow-nnc/Simple4/SIMPLE_SUMMARY4
${_eclpath}/flow-nnc/Gullfaks/GF_ACT_NEW_TEMP)
add_executable(ecl_util_make_date_shift ecl/tests/ecl_util_make_date_shift.cpp)
target_link_libraries(ecl_util_make_date_shift ecl)
add_test(NAME ecl_util_make_date_shift COMMAND ecl_util_make_date_shift)
add_executable(ecl_sum_case_exists ecl/tests/ecl_sum_case_exists.cpp)
target_link_libraries(ecl_sum_case_exists ecl)
add_test(NAME ecl_sum_case_exists COMMAND ecl_sum_case_exists
${_eclpath}/Gurbat/ECLIPSE
${_eclpath}/GurbatSummary/missingHeader/ECLIPSE
${_eclpath}/GurbatSummary/missingData/ECLIPSE)
add_executable(ecl_grid_lgr_name ecl/tests/ecl_grid_lgr_name.cpp)
target_link_libraries(ecl_grid_lgr_name ecl)
add_test(NAME ecl_grid_lgr_name COMMAND ecl_grid_lgr_name
${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID)
add_executable(ecl_region ecl/tests/ecl_region.cpp)
target_link_libraries(ecl_region ecl)
add_test(NAME ecl_region COMMAND ecl_region ${_eclpath}/Gurbat/ECLIPSE.EGRID)
add_test(NAME ecl_grid_cell_contains2 COMMAND ecl_grid_cell_contains ${_eclpath}/Gurbat/ECLIPSE.EGRID)
add_test(NAME ecl_grid_cell_contains3 COMMAND ecl_grid_cell_contains ${_eclpath}/FF12/FF12_2013B2.EGRID)
add_test(NAME ecl_grid_cell_contains4 COMMAND ecl_grid_cell_contains ${_eclpath}/Brazil/R3_ICD.EGRID)
add_executable(ecl_grid_cell_contains_wellpath ecl/tests/ecl_grid_cell_contains_wellpath.cpp)
target_link_libraries(ecl_grid_cell_contains_wellpath ecl)
add_test(NAME ecl_grid_cell_contains_wellpath1
COMMAND ecl_grid_cell_contains_wellpath
${_eclpath}/CellContains/model/SMS-0.EGRID
${_eclpath}/CellContains/R_PB-4H.jira)
add_executable(ecl_region2region ecl/tests/ecl_region2region_test.cpp)
target_link_libraries(ecl_region2region ecl)
add_test(NAME ecl_region2region COMMAND ecl_region2region ${_eclpath}/R2R/R2R.SMSPEC)
add_executable(ecl_grid_case ecl/tests/ecl_grid_case.cpp)
target_link_libraries(ecl_grid_case ecl)
add_test(NAME ecl_grid_case COMMAND ecl_grid_case
${_eclpath}/Gurbat/ECLIPSE.EGRID
${_eclpath}/Gurbat/ECLIPSE)
add_executable(ecl_lgr_test ecl/tests/ecl_lgr_test.cpp)
target_link_libraries(ecl_lgr_test ecl)
add_test(NAME ecl_lgr_test1 COMMAND ecl_lgr_test ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID)
add_test(NAME ecl_lgr_test2 COMMAND ecl_lgr_test ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.GRID)
add_test(NAME ecl_lgr_test3 COMMAND ecl_lgr_test ${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID)
add_executable(ecl_grid_simple ecl/tests/ecl_grid_simple.cpp)
target_link_libraries(ecl_grid_simple ecl)
add_test(NAME ecl_grid_simple COMMAND ecl_grid_simple ${_eclpath}/Gurbat/ECLIPSE.EGRID)
add_test(NAME ecl_grid_ecl2015_2 COMMAND ecl_grid_simple
${_eclpath}/Eclipse2015_NNC_BUG/FF15_2015B2_LGRM_RDI15_HIST_RDIREAL1_20142.EGRID)
add_executable(ecl_grid_export_statoil ecl/tests/ecl_grid_export.cpp)
target_link_libraries(ecl_grid_export_statoil ecl)
add_test(NAME ecl_grid_export_statoil
COMMAND ecl_grid_export_statoil ${_eclpath}/Gurbat/ECLIPSE.EGRID)
COMMAND ecl_grid_export ${_eclpath}/Gurbat/ECLIPSE.EGRID)
add_executable(ecl_grid_volume ecl/tests/ecl_grid_volume.cpp)
target_link_libraries(ecl_grid_volume ecl)
add_test(NAME ecl_grid_volume1 COMMAND ecl_grid_volume ${_eclpath}/Gurbat/ECLIPSE)
add_test(NAME ecl_grid_volume2 COMMAND ecl_grid_volume ${_eclpath}/VolumeTest/TEST1)
add_test(NAME ecl_grid_volume3 COMMAND ecl_grid_volume ${_eclpath}/OsebergSyd/Omega/OMEGA-0)
@ -572,8 +579,6 @@ add_test(NAME ecl_grid_volume4 COMMAND ecl_grid_volume ${_eclpath}/Norne/reservo
# algorithm gets volumes ~ 0 whereas ECLIPSE reports ~10^9 for the same cell.
# add_test( ecl_grid_volume5 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_volume ${_eclpath}/Heidrun/Summary/FF12_2013B3_CLEAN_RS)
add_executable(ecl_grid_dims ecl/tests/ecl_grid_dims.cpp)
target_link_libraries(ecl_grid_dims ecl)
add_test(NAME ecl_grid_dims0 COMMAND ecl_grid_dims)
add_test(NAME ecl_grid_dims1 COMMAND ecl_grid_dims ${_eclpath}/Gurbat/ECLIPSE.EGRID ${_eclpath}/Gurbat/ECLIPSE.INIT)
add_test(NAME ecl_grid_dims2 COMMAND ecl_grid_dims ${_eclpath}/Gurbat/ECLIPSE.GRID ${_eclpath}/Gurbat/ECLIPSE.INIT)
@ -581,31 +586,20 @@ add_test(NAME ecl_grid_dims3 COMMAND ecl_grid_dims ${_eclpath}/Gurbat/ECLIPSE.EG
add_test(NAME ecl_grid_dims4 COMMAND ecl_grid_dims ${_eclpath}/Gurbat/ECLIPSE.GRID )
add_test(NAME ecl_grid_dims5 COMMAND ecl_grid_dims ${_eclpath}/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID)
add_executable(ecl_nnc_test ecl/tests/ecl_nnc_test.cpp)
target_link_libraries(ecl_nnc_test ecl)
add_test(NAME ecl_nnc_test1 COMMAND ecl_nnc_test ${_eclpath}/Gurbat/ECLIPSE.EGRID )
add_test(NAME ecl_nnc_test2 COMMAND ecl_nnc_test ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID )
add_test(NAME ecl_nnc_test3 COMMAND ecl_nnc_test ${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID)
add_test(NAME ecl_nnc_test4 COMMAND ecl_nnc_test ${_eclpath}/DualPoro/DUAL_DIFF.EGRID )
add_test(NAME ecl_nnc_test5 COMMAND ecl_nnc_test ${_eclpath}/nestedLGRcase/TESTCASE_NESTEDLGR.EGRID)
add_executable(ecl_layer_statoil ecl/tests/ecl_layer_statoil.cpp)
target_include_directories(ecl_layer_statoil PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
target_link_libraries(ecl_layer_statoil ecl)
add_test(NAME ecl_layer_statoil COMMAND ecl_layer_statoil
${_eclpath}/Mariner/MARINER.EGRID
${_eclpath}/Mariner/faultblock.grdecl)
add_executable(ecl_dualp ecl/tests/ecl_dualp.cpp)
target_link_libraries(ecl_dualp ecl)
add_test(NAME ecl_dualp COMMAND ecl_dualp ${_eclpath}/LGCcase/LGC_TESTCASE2)
add_executable(ecl_sum_test ecl/tests/ecl_sum_test.cpp)
target_link_libraries(ecl_sum_test ecl)
add_test(NAME ecl_sum_test COMMAND ecl_sum_test ${_eclpath}/Gurbat/ECLIPSE)
add_executable(ecl_sum_report_step_equal ecl/tests/ecl_sum_report_step_equal.cpp)
target_link_libraries(ecl_sum_report_step_equal ecl)
add_test(NAME ecl_sum_report_step_equal1 COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE ${_eclpath}/Snorre/SNORRE FALSE)
add_test(NAME ecl_sum_report_step_equal2 COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE ${_eclpath}/Gurbat/ECLIPSE TRUE)
add_test(NAME ecl_sum_report_step_equal3 COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE ${_eclpath}/modGurbat/extraMinistep/ECLIPSE TRUE)
@ -613,8 +607,6 @@ add_test(NAME ecl_sum_report_step_equal4 COMMAND ecl_sum_report_step_equal ${_ec
add_test(NAME ecl_sum_report_step_equal5 COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE ${_eclpath}/modGurbat/enkf/ECLIPSE FALSE)
add_test(NAME ecl_sum_report_step_equal6 COMMAND ecl_sum_report_step_equal ${_eclpath}/Snorre/SNORRE ${_eclpath}/Snorre2/SNORRE2 FALSE)
add_executable(ecl_sum_report_step_compatible ecl/tests/ecl_sum_report_step_compatible.cpp)
target_link_libraries(ecl_sum_report_step_compatible ecl)
add_test(NAME ecl_sum_report_step_compatible1 COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE ${_eclpath}/Snorre/SNORRE FALSE)
add_test(NAME ecl_sum_report_step_compatible2 COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE ${_eclpath}/Gurbat/ECLIPSE TRUE)
add_test(NAME ecl_sum_report_step_compatible3 COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE ${_eclpath}/modGurbat/extraMinistep/ECLIPSE TRUE)
@ -622,49 +614,34 @@ add_test(NAME ecl_sum_report_step_compatible4 COMMAND ecl_sum_report_step_compat
add_test(NAME ecl_sum_report_step_compatible5 COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE ${_eclpath}/modGurbat/enkf/ECLIPSE TRUE)
add_test(NAME ecl_sum_report_step_compatible6 COMMAND ecl_sum_report_step_equal ${_eclpath}/Snorre/SNORRE ${_eclpath}/Snorre2/SNORRE2 FALSE)
add_executable(ecl_file_statoil ecl/tests/ecl_file_statoil.cpp)
target_link_libraries(ecl_file_statoil ecl)
add_test(NAME ecl_file_statoil
COMMAND ecl_file_statoil ${_eclpath}/Gurbat/ECLIPSE.UNRST ECLIPSE.UNRST)
add_executable(ecl_fmt ecl/tests/ecl_fmt.cpp)
target_link_libraries(ecl_fmt ecl)
add_test(NAME ecl_fmt COMMAND ecl_fmt
${_eclpath}/Gurbat/ECLIPSE.UNRST
${_eclpath}/Gurbat/ECLIPSE.DATA)
add_executable(ecl_rsthead ecl/tests/ecl_rsthead.cpp)
target_link_libraries(ecl_rsthead ecl)
add_test(NAME ecl_rsthead COMMAND ecl_rsthead
${_eclpath}/Gurbat/ECLIPSE.UNRST
${_eclpath}/DualPoro/DUALPORO.X0005)
add_executable(ecl_smspec ecl/tests/ecl_smspec.cpp)
target_link_libraries(ecl_smspec ecl)
add_test(NAME ecl_smspec COMMAND ecl_smspec
${_eclpath}/Gurbat/ECLIPSE.SMSPEC
${_eclpath}/Heidrun/Summary/FF12_2013B3_CLEAN_RS.SMSPEC)
add_executable(ecl_rft ecl/tests/ecl_rft.cpp)
target_link_libraries(ecl_rft ecl)
add_test(NAME ecl_rft_rft COMMAND ecl_rft ${_eclpath}/Gurbat/ECLIPSE.RFT RFT)
add_test(NAME ecl_rft_rft_rw COMMAND ecl_rft ${_eclpath}/Gurbat/ECLIPSE.RFT RFT_RW)
add_test(NAME ecl_rft_plt COMMAND ecl_rft ${_eclpath}/RFT/TEST1_1A.RFT PLT)
add_test(NAME ecl_rft_mswplt COMMAND ecl_rft ${_eclpath}/RFT/RFT2.RFT MSW-PLT)
add_test(NAME ecl_rft_alloc COMMAND ecl_rft ${_eclpath}/RFT/NORNE_ATW2013_RFTPLT_V2.RFT SIMPLE)
add_executable(ecl_grid_copy_statoil ecl/tests/ecl_grid_copy_statoil.cpp)
target_link_libraries(ecl_grid_copy_statoil ecl)
add_test(NAME ecl_grid_copy_statoil1 COMMAND ecl_grid_copy_statoil ${_eclpath}/Gurbat/ECLIPSE.EGRID)
add_test(NAME ecl_grid_copy_statoil2 COMMAND ecl_grid_copy_statoil ${_eclpath}/Mariner/MARINER.EGRID)
add_test(NAME ecl_grid_copy_statoil3 COMMAND ecl_grid_copy_statoil ${_eclpath}/LGCcase/LGC_TESTCASE2.EGRID)
add_test(NAME ecl_grid_copy_statoil4 COMMAND ecl_grid_copy_statoil ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID)
add_executable(ecl_fault_block_layer_statoil ecl/tests/ecl_fault_block_layer_statoil.cpp)
target_link_libraries(ecl_fault_block_layer_statoil ecl)
add_test(NAME ecl_fault_block_layer_statoil COMMAND ecl_fault_block_layer_statoil
${_eclpath}/Mariner/MARINER.EGRID
${_eclpath}/Mariner/faultblock.grdecl)
@ -675,11 +652,6 @@ if (HAVE_UTIL_ABORT_INTERCEPT)
add_test(NAME ecl_fortio COMMAND ecl_fortio ${_eclpath}/Gurbat/ECLIPSE.UNRST)
endif()
add_executable(well_state_load ecl/tests/well_state_load.cpp)
target_link_libraries( well_state_load ecl)
add_executable(well_state_load_missing_RSEG ecl/tests/well_state_load_missing_RSEG.cpp)
target_link_libraries(well_state_load_missing_RSEG ecl)
add_test(NAME well_state_load1 COMMAND well_state_load ${_eclpath}/Gurbat/ECLIPSE.EGRID
${_eclpath}/Gurbat/ECLIPSE.X0030)
@ -698,26 +670,16 @@ add_test(NAME well_state_load_missing_RSEG2
COMMAND well_state_load_missing_RSEG ${_eclpath}/Troll/MSW/MSW.EGRID
${_eclpath}/Troll/MSW/MSW.X0123)
add_executable(well_segment_load ecl/tests/well_segment_load.cpp)
target_link_libraries(well_segment_load ecl)
add_test(NAME well_segment_load
COMMAND well_segment_load ${_eclpath}/MSWcase/MSW_CASE.X0021)
add_executable(well_segment_branch_conn_load ecl/tests/well_segment_branch_conn_load.cpp)
target_link_libraries(well_segment_branch_conn_load ecl)
add_test(NAME well_segment_branch_conn_load
COMMAND well_segment_branch_conn_load ${_eclpath}/MSWcase/MSW_CASE.X0021)
add_executable(well_info ecl/tests/well_info.cpp)
target_link_libraries(well_info ecl)
add_test(NAME well_info COMMAND well_info ${_eclpath}/Gurbat/ECLIPSE.EGRID)
add_executable(well_conn_CF ecl/tests/well_conn_CF.cpp)
target_link_libraries(well_conn_CF ecl)
add_test(NAME well_conn_CF COMMAND well_conn_CF ${_eclpath}/Gurbat/ECLIPSE.X0060)
add_executable(well_conn_load ecl/tests/well_conn_load.cpp)
target_link_libraries(well_conn_load ecl)
add_test(NAME well_conn_load1 COMMAND well_conn_load ${_eclpath}/Gurbat/ECLIPSE.X0030 F)
add_test(NAME well_conn_load2 COMMAND well_conn_load ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.X0021 F)
add_test(NAME well_conn_load3 COMMAND well_conn_load ${_eclpath}/MSWcase/MSW_CASE.X0021 T)
@ -725,18 +687,12 @@ add_test(NAME well_conn_load4 COMMAND well_conn_load ${_eclpath}/AmalgLGRcase/TE
add_test(NAME well_conn_load5 COMMAND well_conn_load ${_eclpath}/DualPoro/DUALPORO.X0009 F)
add_test(NAME well_conn_load6 COMMAND well_conn_load ${_eclpath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003 F)
add_executable(well_ts ecl/tests/well_ts.cpp)
target_link_libraries(well_ts ecl)
add_test(NAME well_ts COMMAND well_ts ${_eclpath}/CO2case/BASE_CASE)
add_executable(well_dualp ecl/tests/well_dualp.cpp)
target_link_libraries(well_dualp ecl)
add_test(NAME well_dualp COMMAND well_dualp
${_eclpath}/Gurbat/ECLIPSE.UNRST
${_eclpath}/DualPoro/DUALPORO.X0005)
add_executable(well_lgr_load ecl/tests/well_lgr_load.cpp)
target_link_libraries(well_lgr_load ecl)
add_test(NAME well_lgr_load1 COMMAND well_lgr_load ${_eclpath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.EGRID
${_eclpath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003)

View File

@ -21,195 +21,36 @@
#include <stdio.h>
#include <string.h>
#include <ert/util/util.h>
#include <algorithm>
#include <ert/ecl/ecl_box.hpp>
#include <ert/ecl/ecl_grid.hpp>
#define ECL_BOX_TYPE_ID 6610643
struct ecl_box_struct {
UTIL_TYPE_ID_DECLARATION;
int grid_nx , grid_ny , grid_nz;
int grid_sx , grid_sy , grid_sz; /* xxx_sx : x stride */
int i1,i2,j1,j2,k1,k2;
int box_nx , box_ny , box_nz;
int box_sx , box_sy , box_sz;
int box_offset;
int active_size;
int *active_list; /* This is a list with active_size elements containing the index active index of the elemtents in the box. Will be NULL if there are no active elements. */
int *global_list; /* This is a list of global indices which are present in the box. */
const ecl_grid_type * parent_grid;
};
UTIL_IS_INSTANCE_FUNCTION( ecl_box , ECL_BOX_TYPE_ID)
UTIL_SAFE_CAST_FUNCTION( ecl_box , ECL_BOX_TYPE_ID)
/**
Observe that:
1. The coordinates i1,i2...k2 are assumed to be ZERO offset.
2. The corrdinates are _INCLUSIVE_, i.e. the box is [i1..i2] x [j1..j2] x [k1..k2]
3. Coordinates are truncated to [0,ni).
4. Coordinates are interchanged, so __i1 can be greater than __i2.
*/
ecl_box_type * ecl_box_alloc(const ecl_grid_type * ecl_grid , int __i1,int __i2 , int __j1 , int __j2 , int __k1, int __k2) {
ecl_box_type * ecl_box = (ecl_box_type *)util_malloc(sizeof * ecl_box );
UTIL_TYPE_ID_INIT( ecl_box , ECL_BOX_TYPE_ID);
ecl_box->parent_grid = ecl_grid;
/* Properties of the parent grid. */
ecl_grid_get_dims( ecl_grid , &ecl_box->grid_nx , &ecl_box->grid_ny , &ecl_box->grid_nz , NULL);
ecl_box->grid_sx = 1;
ecl_box->grid_sy = ecl_box->grid_nx;
ecl_box->grid_sz = ecl_box->grid_nx * ecl_box->grid_ny;
namespace ecl {
ecl_box::ecl_box(const ecl_grid_type * grid, int i1, int i2, int j1, int j2, int k1, int k2) :
grid(grid),
i1(std::min(i1,i2)),
i2(std::max(i1,i2)),
j1(std::min(j1,j2)),
j2(std::max(j1,j2)),
k1(std::min(k1,k2)),
k2(std::max(k1,k2))
{
int i1 = util_int_max( util_int_min(__i1 , __i2 ) , 0);
int i2 = util_int_min( util_int_max(__i1 , __i2 ) , ecl_box->grid_nx - 1);
int j1 = util_int_max( util_int_min(__j1 , __j2 ) , 0 );
int j2 = util_int_min( util_int_max(__j1 , __j2 ) , ecl_box->grid_ny - 1);
int k1 = util_int_max( util_int_min(__k1 , __k2 ) , 0 );
int k2 = util_int_min( util_int_max(__k1 , __k2 ) , ecl_box->grid_nz - 1);
ecl_box->i1 = i1;
ecl_box->i2 = i2;
ecl_box->j1 = j1;
ecl_box->j2 = j2;
ecl_box->k1 = k1;
ecl_box->k2 = k2;
/*Properties of the box: */
ecl_box->box_nx = i2 - i1 + 1;
ecl_box->box_ny = j2 - j1 + 1;
ecl_box->box_nz = k2 - k1 + 1;
ecl_box->box_sx = 1;
ecl_box->box_sy = ecl_box->box_nx;
ecl_box->box_sz = ecl_box->box_nx * ecl_box->box_ny;
ecl_box->box_offset = i1 * ecl_box->box_sx + j1 * ecl_box->box_sy + k1 * ecl_box->box_sz;
/* Counting the number of active elements in the box */
{
int global_counter = 0;
int i,j,k;
ecl_box->active_size = 0;
ecl_box->active_list = (int*)util_calloc( ecl_box->box_nx * ecl_box->box_ny * ecl_box->box_nz , sizeof * ecl_box->active_list );
ecl_box->global_list = (int*)util_calloc( ecl_box->box_nx * ecl_box->box_ny * ecl_box->box_nz , sizeof * ecl_box->global_list );
for (k=k1; k <= k2; k++)
for (j=j1; j <= j2; j++)
for (i=i1; i <= i2; i++) {
{
int global_index = ecl_grid_get_global_index3( ecl_box->parent_grid , i , j , k);
ecl_box->global_list[global_counter] = global_index;
global_counter++;
}
{
int active_index = ecl_grid_get_active_index3( ecl_box->parent_grid , i,j,k);
if (active_index >= 0) {
ecl_box->active_list[ecl_box->active_size] = active_index;
ecl_box->active_size++;
}
}
}
ecl_box->active_list = (int*)util_realloc( ecl_box->active_list , ecl_box->active_size * sizeof * ecl_box->active_list );
}
}
return ecl_box;
}
/**
Returns true if the box contains the point (i,j,k). Observe the
following:
ijk: These are zero offset.
ijk: Which are ON one of the box surfaces will return true.
*/
bool ecl_box_contains(const ecl_box_type * box , int i , int j , int k) {
return (( box->i1 >= i ) && (i <= box->i2) &&
( box->j1 >= j ) && (j <= box->j2) &&
( box->k1 >= k ) && (k <= box->k2));
}
void ecl_box_free(ecl_box_type * ecl_box) {
free(ecl_box->active_list );
free(ecl_box->global_list );
free(ecl_box);
}
/*
void ecl_kw_merge(ecl_kw_type * main_kw , const ecl_kw_type * sub_kw , const ecl_box_type * ecl_box) {
if (main_kw->sizeof_ctype != sub_kw->sizeof_ctype)
util_abort("%s: trying to combine two different underlying datatypes - aborting \n",__func__);
if (ecl_kw_get_size(main_kw) != ecl_box_get_total_size(ecl_box))
util_abort("%s box size and total_kw mismatch - aborting \n",__func__);
if (ecl_kw_get_size(sub_kw) != ecl_box_get_box_size(ecl_box))
util_abort("%s box size and total_kw mismatch - aborting \n",__func__);
ecl_box_set_values(ecl_box , ecl_kw_get_data_ref(main_kw) , ecl_kw_get_data_ref(sub_kw) , main_kw->sizeof_ctype);
}
*/
void ecl_box_set_values(const ecl_box_type * ecl_box , char * main_field , const char * sub_field , int element_size) {
int i,j,k;
for (k=0; k < ecl_box->box_nz; k++)
for(j=0; j < ecl_box->box_ny; j++)
for (i=0; i < ecl_box->box_nx; i++) {
int grid_index = k*ecl_box->grid_sz + j*ecl_box->grid_sy + i*ecl_box->grid_sx + ecl_box->box_offset;
int box_index = k*ecl_box->box_sz + j*ecl_box->box_sy + i*ecl_box->box_sx;
memcpy(&main_field[grid_index * element_size] , &sub_field[box_index * element_size] , element_size);
for (int k=this->k1; k <= this->k2; k++)
for (int j=this->j1; j <= this->j2; j++)
for (int i=this->i1; i <= this->i2; i++) {
int active_index = ecl_grid_get_active_index3(this->grid, i, j , k);
if (active_index >= 0)
this->active_index_list.push_back(active_index);
this->global_index_list.push_back(ecl_grid_get_global_index3(this->grid, i, j, k));
}
}
/*
Return the number of active element in the box.
*/
int ecl_box_get_active_size( const ecl_box_type * ecl_box ) {
return ecl_box->active_size;
const std::vector<int>& ecl_box::active_list() const {
return this->active_index_list;
}
const int * ecl_box_get_active_list( const ecl_box_type * ecl_box ) {
return ecl_box->active_list;
}
/*
Return the number of global element in the box.
*/
int ecl_box_get_global_size( const ecl_box_type * ecl_box ) {
return ecl_box->box_nx * ecl_box->box_ny * ecl_box->box_nz;
}
const int * ecl_box_get_global_list( const ecl_box_type * ecl_box ) {
return ecl_box->global_list;
}

View File

@ -505,24 +505,26 @@ ecl_file_view_type * ecl_file_get_summary_view( ecl_file_type * ecl_file , int r
*/
/**
The ecl_file_scan() function will scan through the whole file and
build up an index of all the kewyords. The map created from this
scan will be stored under the 'global_view' field; and all
subsequent lookup operations will ultimately be based on the global
map.
The ecl_file_scan() function will scan through the whole file and build up an
index of all the kewyords. The map created from this scan will be stored
under the 'global_view' field; and all subsequent lookup operations will
ultimately be based on the global map.
The ecl_file_scan function will scan through the file as long as it finds
valid ecl_kw instances on the disk; it will return when EOF is encountered or
an invalid ecl_kw instance is detected. This implies that for a partly broken
file the ecl_file_scan function will index the valid keywords which are in
the file, possible garbage at the end will be ignored.
*/
static bool ecl_file_scan( ecl_file_type * ecl_file ) {
bool scan_ok = false;
static void ecl_file_scan( ecl_file_type * ecl_file ) {
fortio_fseek( ecl_file->fortio , 0 , SEEK_SET );
{
ecl_kw_type * work_kw = ecl_kw_alloc_new("WORK-KW" , 0 , ECL_INT , NULL);
while (true) {
if (fortio_read_at_eof(ecl_file->fortio)) {
scan_ok = true;
if (fortio_read_at_eof(ecl_file->fortio))
break;
}
{
offset_type current_offset = fortio_ftell( ecl_file->fortio );
@ -542,10 +544,7 @@ static bool ecl_file_scan( ecl_file_type * ecl_file ) {
ecl_kw_free( work_kw );
}
if (scan_ok)
ecl_file_view_make_index( ecl_file->global_view );
return scan_ok;
}
@ -590,19 +589,16 @@ ecl_file_type * ecl_file_open( const char * filename , int flags) {
ecl_file->fortio = fortio;
ecl_file->global_view = ecl_file_view_alloc( ecl_file->fortio , &ecl_file->flags , ecl_file->inv_view , true );
if (ecl_file_scan( ecl_file )) {
ecl_file_scan( ecl_file );
ecl_file_select_global( ecl_file );
if (ecl_file_view_check_flags( ecl_file->flags , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( ecl_file->fortio );
return ecl_file;
} else {
ecl_file_close( ecl_file );
return NULL;
}
} else
return NULL;
}

View File

@ -17,9 +17,11 @@
*/
#include <vector>
#include <string>
#include <ert/util/vector.hpp>
#include <ert/util/hash.hpp>
#include <ert/util/stringlist.hpp>
#include <ert/ecl/fortio.h>
#include <ert/ecl/ecl_kw.hpp>
@ -33,7 +35,7 @@
struct ecl_file_view_struct {
vector_type * kw_list; /* This is a vector of ecl_file_kw instances corresponding to the content of the file. */
hash_type * kw_index; /* A hash table with integer vectors of indices - see comment below. */
stringlist_type * distinct_kw; /* A stringlist of the keywords occuring in the file - each string occurs ONLY ONCE. */
std::vector<std::string> distinct_kw; /* A list of the keywords occuring in the file - each string occurs ONLY ONCE. */
fortio_type * fortio; /* The same fortio instance pointer as in the ecl_file styructure. */
bool owner; /* Is this map the owner of the ecl_file_kw instances; only true for the global_map. */
inv_map_type * inv_map; /* Shared reference owned by the ecl_file structure. */
@ -71,15 +73,16 @@ const char * ecl_file_view_get_src_file( const ecl_file_view_type * file_view )
ecl_file_view_type * ecl_file_view_alloc( fortio_type * fortio , int * flags , inv_map_type * inv_map , bool owner ) {
ecl_file_view_type * ecl_file_view = (ecl_file_view_type*)util_malloc( sizeof * ecl_file_view );
ecl_file_view_type * ecl_file_view = new ecl_file_view_type();
ecl_file_view->kw_list = vector_alloc_new();
ecl_file_view->kw_index = hash_alloc();
ecl_file_view->distinct_kw = stringlist_alloc_new();
ecl_file_view->child_list = vector_alloc_new();
ecl_file_view->owner = owner;
ecl_file_view->fortio = fortio;
ecl_file_view->inv_map = inv_map;
ecl_file_view->flags = flags;
return ecl_file_view;
}
@ -101,7 +104,7 @@ int ecl_file_view_get_global_index( const ecl_file_view_type * ecl_file_view , c
void ecl_file_view_make_index( ecl_file_view_type * ecl_file_view ) {
stringlist_clear( ecl_file_view->distinct_kw );
ecl_file_view->distinct_kw.clear();
hash_clear( ecl_file_view->kw_index );
{
int i;
@ -111,7 +114,7 @@ void ecl_file_view_make_index( ecl_file_view_type * ecl_file_view ) {
if ( !hash_has_key( ecl_file_view->kw_index , header )) {
int_vector_type * index_vector = int_vector_alloc( 0 , -1 );
hash_insert_hash_owned_ref( ecl_file_view->kw_index , header , index_vector , int_vector_free__);
stringlist_append_copy( ecl_file_view->distinct_kw , header);
ecl_file_view->distinct_kw.push_back(header);
}
{
@ -200,11 +203,12 @@ int ecl_file_view_find_kw_value( const ecl_file_view_type * ecl_file_view , cons
}
const char * ecl_file_view_iget_distinct_kw( const ecl_file_view_type * ecl_file_view , int index) {
return stringlist_iget( ecl_file_view->distinct_kw , index);
const std::string& string = ecl_file_view->distinct_kw[index];
return string.c_str();
}
int ecl_file_view_get_num_distinct_kw( const ecl_file_view_type * ecl_file_view ) {
return stringlist_get_size( ecl_file_view->distinct_kw );
return ecl_file_view->distinct_kw.size();
}
int ecl_file_view_get_size( const ecl_file_view_type * ecl_file_view ) {
@ -301,9 +305,9 @@ void ecl_file_view_add_kw( ecl_file_view_type * ecl_file_view , ecl_file_kw_type
void ecl_file_view_free( ecl_file_view_type * ecl_file_view ) {
vector_free( ecl_file_view->child_list );
hash_free( ecl_file_view->kw_index );
stringlist_free( ecl_file_view->distinct_kw );
vector_free( ecl_file_view->kw_list );
free( ecl_file_view );
delete ecl_file_view;
}
void ecl_file_view_free__( void * arg ) {

View File

@ -28,12 +28,12 @@
#include <ert/ecl/ecl_util.hpp>
#include <ert/ecl/ecl_file.hpp>
#include <ert/ecl/ecl_grid.hpp>
#include <ert/ecl/ecl_grid_cache.hpp>
#include <ert/ecl/ecl_region.hpp>
#include <ert/ecl/ecl_grav.hpp>
#include <ert/ecl/ecl_kw_magic.hpp>
#include <ert/ecl/ecl_grav_common.hpp>
#include "detail/ecl/ecl_grid_cache.hpp"
/**
This file contains datastructures for calculating changes in
@ -67,7 +67,7 @@ typedef struct ecl_grav_phase_struct ecl_grav_phase_type;
struct ecl_grav_struct {
const ecl_file_type * init_file; /* The init file - a shared reference owned by calling scope. */
ecl_grid_cache_type * grid_cache; /* An internal specialized structure to facilitate fast grid lookup. */
ecl::ecl_grid_cache * grid_cache; /* An internal specialized structure to facilitate fast grid lookup. */
bool * aquifer_cell; /* Numerical aquifer cells should be ignored. */
hash_type * surveys; /* A hash table containg ecl_grav_survey_type instances; one instance
for each interesting time. */
@ -88,7 +88,7 @@ struct ecl_grav_struct {
#define ECL_GRAV_SURVEY_ID 88517
struct ecl_grav_survey_struct {
UTIL_TYPE_ID_DECLARATION;
const ecl_grid_cache_type * grid_cache;
const ecl::ecl_grid_cache * grid_cache;
const bool * aquifer_cell;
char * name; /* Name of the survey - arbitrary string. */
double * porv; /* Reference shared by the ecl_grav_phase structures - i.e. it must not be updated. */
@ -104,7 +104,7 @@ struct ecl_grav_survey_struct {
#define ECL_GRAV_PHASE_TYPE_ID 1066652
struct ecl_grav_phase_struct {
UTIL_TYPE_ID_DECLARATION;
const ecl_grid_cache_type * grid_cache;
const ecl::ecl_grid_cache * grid_cache;
const bool * aquifer_cell;
double * fluid_mass; /* The total fluid in place (mass) of this phase - for each active cell.*/
double * work; /* Temporary used in the summation over all cells. */
@ -157,7 +157,7 @@ static const char * get_den_kw( ecl_phase_enum phase , ecl_version_enum ecl_vers
static void ecl_grav_phase_ensure_work( ecl_grav_phase_type * grav_phase) {
if (grav_phase->work == NULL)
grav_phase->work = (double*)util_calloc( ecl_grid_cache_get_size( grav_phase->grid_cache ) , sizeof * grav_phase->work );
grav_phase->work = (double*)util_calloc( grav_phase->grid_cache->size() , sizeof * grav_phase->work );
}
@ -168,7 +168,7 @@ static double ecl_grav_phase_eval( ecl_grav_phase_type * base_phase ,
ecl_grav_phase_ensure_work( base_phase );
if ((monitor_phase == NULL) || (base_phase->phase == monitor_phase->phase)) {
const ecl_grid_cache_type * grid_cache = base_phase->grid_cache;
const ecl::ecl_grid_cache& grid_cache = *(base_phase->grid_cache);
const bool * aquifer = base_phase->aquifer_cell;
double * mass_diff = base_phase->work;
double deltag;
@ -179,10 +179,10 @@ static double ecl_grav_phase_eval( ecl_grav_phase_type * base_phase ,
{
int index;
if (monitor_phase == NULL) {
for (index = 0; index < ecl_grid_cache_get_size( grid_cache ); index++)
for (index = 0; index < grid_cache.size(); index++)
mass_diff[index] = - base_phase->fluid_mass[index];
} else {
for (index = 0; index < ecl_grid_cache_get_size( grid_cache ); index++)
for (index = 0; index < grid_cache.size(); index++)
mass_diff[index] = monitor_phase->fluid_mass[index] - base_phase->fluid_mass[index];
}
}
@ -210,11 +210,11 @@ static ecl_grav_phase_type * ecl_grav_phase_alloc( ecl_grav_type * ecl_grav ,
grav_calc_type calc_type) {
const ecl_file_type * init_file = ecl_grav->init_file;
const ecl_grid_cache_type * grid_cache = ecl_grav->grid_cache;
const ecl::ecl_grid_cache * grid_cache = ecl_grav->grid_cache;
const char * sat_kw_name = ecl_util_get_phase_name( phase );
{
ecl_grav_phase_type * grav_phase = (ecl_grav_phase_type*)util_malloc( sizeof * grav_phase );
const int size = ecl_grid_cache_get_size( grid_cache );
const int size = grid_cache->size();
UTIL_TYPE_ID_INIT( grav_phase , ECL_GRAV_PHASE_TYPE_ID );
grav_phase->grid_cache = grid_cache;
@ -358,7 +358,7 @@ static ecl_grav_survey_type * ecl_grav_survey_alloc_empty(const ecl_grav_type *
survey->phase_map = hash_alloc();
if (calc_type & GRAV_CALC_USE_PORV)
survey->porv = (double*)util_calloc( ecl_grid_cache_get_size( ecl_grav->grid_cache ) , sizeof * survey->porv );
survey->porv = (double*)util_calloc( ecl_grav->grid_cache->size() , sizeof * survey->porv );
else
survey->porv = NULL;
@ -375,17 +375,17 @@ static UTIL_SAFE_CAST_FUNCTION( ecl_grav_survey , ECL_GRAV_SURVEY_ID )
*/
static void ecl_grav_survey_assert_RPORV( const ecl_grav_survey_type * survey , const ecl_file_type * init_file ) {
const ecl_grid_cache_type * grid_cache = survey->grid_cache;
int active_size = ecl_grid_cache_get_size( grid_cache );
const ecl::ecl_grid_cache& grid_cache = *(survey->grid_cache);
int active_size = grid_cache.size();
const ecl_kw_type * init_porv_kw = ecl_file_iget_named_kw( init_file , PORV_KW , 0);
int check_points = 100;
int check_nr = 0;
const std::vector<int>& global_index = grid_cache.global_index();
while (check_nr < check_points) {
int active_index = rand() % active_size;
int global_index = ecl_grid_cache_iget_global_index( grid_cache , active_index );
double init_porv = ecl_kw_iget_as_double( init_porv_kw , global_index ); /* NB - this uses global indexing. */
double init_porv = ecl_kw_iget_as_double( init_porv_kw , global_index[active_index] ); /* NB - this uses global indexing. */
if (init_porv > 0) {
double rporv = survey->porv[ active_index ];
double log_pormod = log10( rporv / init_porv );
@ -479,12 +479,12 @@ static ecl_grav_survey_type * ecl_grav_survey_alloc_RPORV(ecl_grav_type * ecl_gr
static ecl_grav_survey_type * ecl_grav_survey_alloc_PORMOD(ecl_grav_type * ecl_grav ,
const ecl_file_view_type * restart_file ,
const char * name ) {
ecl_grid_cache_type * grid_cache = ecl_grav->grid_cache;
ecl::ecl_grid_cache& grid_cache = *(ecl_grav->grid_cache);
ecl_grav_survey_type * survey = ecl_grav_survey_alloc_empty( ecl_grav , name , GRAV_CALC_PORMOD);
ecl_kw_type * init_porv_kw = ecl_file_iget_named_kw( ecl_grav->init_file , PORV_KW , 0 ); /* Global indexing */
ecl_kw_type * pormod_kw = ecl_file_view_iget_named_kw( restart_file , PORMOD_KW , 0 ); /* Active indexing */
const int size = ecl_grid_cache_get_size( grid_cache );
const int * global_index = ecl_grid_cache_get_global_index( grid_cache );
const int size = grid_cache.size();
const auto& global_index = grid_cache.global_index();
int active_index;
for (active_index = 0; active_index < size; active_index++)
@ -572,8 +572,8 @@ static double ecl_grav_survey_eval( const ecl_grav_survey_type * base_survey,
ecl_grav_type * ecl_grav_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file) {
ecl_grav_type * ecl_grav = (ecl_grav_type*)util_malloc( sizeof * ecl_grav );
ecl_grav->init_file = init_file;
ecl_grav->grid_cache = ecl_grid_cache_alloc( ecl_grid );
ecl_grav->aquifer_cell = ecl_grav_common_alloc_aquifer_cell( ecl_grav->grid_cache , ecl_grav->init_file );
ecl_grav->grid_cache = new ecl::ecl_grid_cache(ecl_grid);
ecl_grav->aquifer_cell = ecl_grav_common_alloc_aquifer_cell( *(ecl_grav->grid_cache) , ecl_grav->init_file );
ecl_grav->surveys = hash_alloc();
ecl_grav->std_density = hash_alloc();
@ -687,7 +687,7 @@ void ecl_grav_add_std_density( ecl_grav_type * grav , ecl_phase_enum phase , int
void ecl_grav_free( ecl_grav_type * ecl_grav ) {
ecl_grid_cache_free( ecl_grav->grid_cache );
delete ecl_grav->grid_cache;
free( ecl_grav->aquifer_cell );
hash_free( ecl_grav->surveys );
hash_free( ecl_grav->std_density );

View File

@ -26,27 +26,27 @@
#include <ert/ecl/ecl_kw.hpp>
#include <ert/ecl/ecl_file.hpp>
#include <ert/ecl/ecl_region.hpp>
#include <ert/ecl/ecl_grid_cache.hpp>
#include <ert/ecl/ecl_kw_magic.hpp>
#include <ert/ecl/ecl_grav_common.hpp>
#include "detail/ecl/ecl_grid_cache.hpp"
/*
This file contains code which is common to both the ecl_grav
implementation for gravity changes, and the ecl_subsidence
implementation for changes in subsidence.
*/
bool * ecl_grav_common_alloc_aquifer_cell( const ecl_grid_cache_type * grid_cache , const ecl_file_type * init_file) {
bool * aquifer_cell = (bool*)util_calloc( ecl_grid_cache_get_size( grid_cache ) , sizeof * aquifer_cell );
bool * ecl_grav_common_alloc_aquifer_cell( const ecl::ecl_grid_cache& grid_cache , const ecl_file_type * init_file) {
bool * aquifer_cell = (bool*) util_calloc( grid_cache.size() , sizeof * aquifer_cell );
for (int active_index = 0; active_index < ecl_grid_cache_get_size( grid_cache ); active_index++)
for (int active_index = 0; active_index < grid_cache.size(); active_index++)
aquifer_cell[ active_index ] = false;
if (ecl_file_has_kw( init_file , AQUIFER_KW)) {
ecl_kw_type * aquifer_kw = ecl_file_iget_named_kw( init_file , AQUIFER_KW , 0);
const int * aquifer_data = ecl_kw_get_int_ptr( aquifer_kw );
for (int active_index = 0; active_index < ecl_grid_cache_get_size( grid_cache ); active_index++) {
for (int active_index = 0; active_index < grid_cache.size(); active_index++) {
if (aquifer_data[ active_index ] < 0)
aquifer_cell[ active_index ] = true;
}
@ -57,13 +57,13 @@ bool * ecl_grav_common_alloc_aquifer_cell( const ecl_grid_cache_type * grid_cach
double ecl_grav_common_eval_biot_savart( const ecl_grid_cache_type * grid_cache , ecl_region_type * region , const bool * aquifer , const double * weight , double utm_x , double utm_y , double depth) {
const double * xpos = ecl_grid_cache_get_xpos( grid_cache );
const double * ypos = ecl_grid_cache_get_ypos( grid_cache );
const double * zpos = ecl_grid_cache_get_zpos( grid_cache );
double ecl_grav_common_eval_biot_savart( const ecl::ecl_grid_cache& grid_cache , ecl_region_type * region , const bool * aquifer , const double * weight , double utm_x , double utm_y , double depth) {
const auto& xpos = grid_cache.xpos();
const auto& ypos = grid_cache.ypos();
const auto& zpos = grid_cache.zpos();
double sum = 0;
if (region == NULL) {
const int size = ecl_grid_cache_get_size( grid_cache );
const int size = grid_cache.size();
int index;
for ( index = 0; index < size; index++) {
if (!aquifer[index]) {
@ -125,18 +125,18 @@ static inline double ecl_grav_common_eval_geertsma_kernel(int index, const doubl
}
double ecl_grav_common_eval_geertsma( const ecl_grid_cache_type * grid_cache , ecl_region_type * region , const bool * aquifer , const double * weight , double utm_x , double utm_y , double depth, double poisson_ratio, double seabed) {
const double * xpos = ecl_grid_cache_get_xpos( grid_cache );
const double * ypos = ecl_grid_cache_get_ypos( grid_cache );
const double * zpos = ecl_grid_cache_get_zpos( grid_cache );
double ecl_grav_common_eval_geertsma( const ecl::ecl_grid_cache& grid_cache , ecl_region_type * region , const bool * aquifer , const double * weight , double utm_x , double utm_y , double depth, double poisson_ratio, double seabed) {
const auto& xpos = grid_cache.xpos();
const auto& ypos = grid_cache.ypos();
const auto& zpos = grid_cache.zpos();
double sum = 0;
if (region == NULL) {
const int size = ecl_grid_cache_get_size( grid_cache );
const int size = grid_cache.size();
int index;
for ( index = 0; index < size; index++) {
if (!aquifer[index]) {
double displacement = ecl_grav_common_eval_geertsma_kernel( index, xpos , ypos , zpos, utm_x, utm_y , depth, poisson_ratio, seabed);
double displacement = ecl_grav_common_eval_geertsma_kernel( index, xpos.data() , ypos.data() , zpos.data(), utm_x, utm_y , depth, poisson_ratio, seabed);
/**
For numerical precision it might be benficial to use the
@ -153,7 +153,7 @@ double ecl_grav_common_eval_geertsma( const ecl_grid_cache_type * grid_cache , e
for (i = 0; i < size; i++) {
index = index_list[i];
if (!aquifer[index]) {
double displacement = ecl_grav_common_eval_geertsma_kernel( index, xpos , ypos , zpos, utm_x, utm_y , depth , poisson_ratio, seabed);
double displacement = ecl_grav_common_eval_geertsma_kernel( index, xpos.data() , ypos.data() , zpos.data(), utm_x, utm_y , depth , poisson_ratio, seabed);
sum += weight[index] * displacement;
}
}

View File

@ -5152,12 +5152,16 @@ double ecl_grid_get_cell_dx1A( const ecl_grid_type * grid , int active_index) {
/*
The current algorithm for calculating the cell dimensions DX,DY and
DZ reproduces the Eclipse results from the INIT file, but we are in
general *not* guaranteed to satisfy the relationship:
The current algorithm for calculating the cell dimensions DX,DY and DZ
reproduces the Eclipse results from the INIT file quite well, relative error
on the order 1e-4 for DX and DY and 1e-3 for DZ.
Observe that the DX, DY and DZ values are not tied to the cell volume; i.e.
the relationship:
DX * DY * DZ = V
does generally not hold.
*/
double ecl_grid_get_cell_dy1( const ecl_grid_type * grid , int global_index ) {
@ -7086,4 +7090,79 @@ ecl_kw_type * ecl_grid_alloc_volume_kw( const ecl_grid_type * grid , bool active
else
return ecl_grid_alloc_volume_kw_global( grid );
}
//This function is meant to be used w/ pandas datafram and numpy
//Note: global_index must be allocated w/ ecl_grid->total_active or ecl_grid->global_size int32 data points
// index_data must be allocated w/ (4 * ecl_grid->total_active or ecl_grid->global_size) int32 data points.
void ecl_grid_export_index(const ecl_grid_type * grid, int * global_index, int * index_data , bool active_only) {
int pos_indx = 0;
int pos_data = 0;
for (int k = 0; k < grid->nz; k++)
for (int j = 0; j < grid->ny; j++)
for (int i = 0; i < grid->nx; i++) {
int g = ecl_grid_get_global_index__(grid, i, j, k);
if (!active_only || grid->cells[g].active_index[0] >= 0) {
global_index[pos_indx++] = g;
index_data[pos_data++] = i;
index_data[pos_data++] = j;
index_data[pos_data++] = k;
index_data[pos_data++] = grid->cells[g].active_index[0];
}
}
}
//This function is meant to be used w/ pandas datafram and numpy
//Note: index_size must equal allocated size of output
void ecl_grid_export_data_as_int( int index_size, const int * data_index, const ecl_kw_type * kw, int * output) {
int * input = ecl_kw_get_int_ptr(kw);
for (int i=0; i < index_size; i++) {
int di = data_index[i];
if (di >= 0)
output[i] = input[di];
}
}
//This function is meant to be used w/ pandas datafram and numpy
//Note: index_size must equal allocated size of output
void ecl_grid_export_data_as_double( int index_size, const int * data_index, const ecl_kw_type * kw, double * output) {
for (int i=0; i < index_size; i++) {
int di = data_index[i];
if (di >= 0)
output[i] = ecl_kw_iget_as_double(kw, di);
}
}
//This function is meant to be used w/ pandas datafram and numpy
void ecl_grid_export_volume( const ecl_grid_type * grid, int index_size, const int * global_index, double * output ) {
for (int i = 0; i < index_size; i++) {
int g = global_index[i];
output[i] = ecl_grid_get_cell_volume1(grid, g);
}
}
//This function is meant to be used w/ pandas datafram and numpy
void ecl_grid_export_position( const ecl_grid_type * grid, int index_size, const int * global_index, double * output) {
for (int i = 0; i < index_size; i++) {
int g = global_index[i];
int j = 3 * i;
ecl_grid_get_xyz1(grid, g, &output[j], &output[j+1], &output[j+2]);
}
}
//This function is meant to be used w/ pandas dataframe and numpy
void export_corners( const ecl_grid_type * grid, int index_size, const int * global_index, double * output) {
double x[8], y[8], z[8];
int pos = 0;
for (int i = 0; i < index_size; i++) {
int g = global_index[i];
ecl_grid_export_cell_corners1(grid, g, x, y, z);
for (int j = 0; j < 8; j++) {
output[pos++] = x[j];
output[pos++] = y[j];
output[pos++] = z[j];
}
}
}
//

View File

@ -27,7 +27,8 @@
#include <ert/ecl/ecl_util.hpp>
#include <ert/ecl/ecl_file.hpp>
#include <ert/ecl/ecl_grid.hpp>
#include <ert/ecl/ecl_grid_cache.hpp>
#include "detail/ecl/ecl_grid_cache.hpp"
@ -39,94 +40,31 @@
coordinates of a cell.
*/
struct ecl_grid_cache_struct {
int size; /* The length of the vectors, equal to the number of active elements in the grid. */
double * xpos;
double * ypos;
double * zpos;
double * volume; /* Will be initialized on demand. */
int * global_index; /* Maps from active index (i.e. natural index in this context) - to the corresponding global index. */
const ecl_grid_type * grid;
};
ecl_grid_cache_type * ecl_grid_cache_alloc( const ecl_grid_type * grid ) {
ecl_grid_cache_type * grid_cache = (ecl_grid_cache_type*)util_malloc( sizeof * grid_cache );
grid_cache->grid = grid;
grid_cache->volume = NULL;
grid_cache->size = ecl_grid_get_active_size( grid );
grid_cache->xpos = (double*)util_calloc( grid_cache->size , sizeof * grid_cache->xpos );
grid_cache->ypos = (double*)util_calloc( grid_cache->size , sizeof * grid_cache->ypos );
grid_cache->zpos = (double*)util_calloc( grid_cache->size , sizeof * grid_cache->zpos );
grid_cache->global_index = (int*)util_calloc( grid_cache->size , sizeof * grid_cache->global_index );
namespace ecl {
ecl_grid_cache::ecl_grid_cache(const ecl_grid_type * grid) :
grid(grid)
{
int active_index;
for (int active_index = 0; active_index < ecl_grid_get_active_size(this->grid); active_index++) {
double x,y,z;
int global_index = ecl_grid_get_global_index1A(this->grid, active_index);
ecl_grid_get_xyz1(this->grid, global_index, &x, &y, &z);
/* Go trough all the active cells and extract the cell center
position and store it in xpos/ypos/zpos. */
for (active_index = 0; active_index < grid_cache->size; active_index++) {
int global_index = ecl_grid_get_global_index1A( grid , active_index );
grid_cache->global_index[ active_index ] = global_index;
ecl_grid_get_xyz1( grid , global_index ,
&grid_cache->xpos[ active_index ] ,
&grid_cache->ypos[ active_index ] ,
&grid_cache->zpos[ active_index ]);
this->gi.push_back(global_index);
this->xp.push_back(x);
this->yp.push_back(y);
this->zp.push_back(z);
}
}
return grid_cache;
}
int ecl_grid_cache_get_size( const ecl_grid_cache_type * grid_cache ) {
return grid_cache->size;
}
int ecl_grid_cache_iget_global_index( const ecl_grid_cache_type * grid_cache , int active_index) {
return grid_cache->global_index[ active_index ];
}
const int * ecl_grid_cache_get_global_index( const ecl_grid_cache_type * grid_cache) {
return grid_cache->global_index;
const std::vector<double>& ecl_grid_cache::volume() const {
if (this->v.empty()) {
for (int active_index = 0; active_index < this->size(); active_index++)
this->v.push_back( ecl_grid_get_cell_volume1A(this->grid, active_index));
}
return this->v;
}
const double * ecl_grid_cache_get_xpos( const ecl_grid_cache_type * grid_cache ) {
return grid_cache->xpos;
}
const double * ecl_grid_cache_get_ypos( const ecl_grid_cache_type * grid_cache ) {
return grid_cache->ypos;
}
const double * ecl_grid_cache_get_zpos( const ecl_grid_cache_type * grid_cache ) {
return grid_cache->zpos;
}
const double * ecl_grid_cache_get_volume( const ecl_grid_cache_type * grid_cache ) {
if (!grid_cache->volume) {
// C++ style const cast.
ecl_grid_cache_type * gc = (ecl_grid_cache_type *) grid_cache;
gc->volume = (double*)util_calloc( gc->size , sizeof * gc->volume );
for (int active_index = 0; active_index < grid_cache->size; active_index++)
gc->volume[active_index] = ecl_grid_get_cell_volume1A( gc->grid , active_index );
}
return grid_cache->volume;
}
void ecl_grid_cache_free( ecl_grid_cache_type * grid_cache ) {
free( grid_cache->xpos );
free( grid_cache->ypos );
free( grid_cache->zpos );
free( grid_cache->global_index );
free( grid_cache->volume );
free( grid_cache );
}

View File

@ -633,26 +633,14 @@ void ecl_region_cmp_deselect_more( ecl_region_type * ecl_region , const ecl_kw_t
input and create a temporary box object.
*/
static void ecl_region_select_from_box__( ecl_region_type * region , const ecl_box_type * ecl_box , bool select) {
const int box_size = ecl_box_get_global_size( ecl_box );
const int * active_list = ecl_box_get_global_list( ecl_box );
int box_index;
for (box_index = 0; box_index < box_size; box_index++)
region->active_mask[ active_list[box_index] ] = select;
static void ecl_region_select_from_box__( ecl_region_type * region , const ecl::ecl_box& ecl_box , bool select) {
for (auto global_index : ecl_box.active_list())
region->active_mask[ global_index ] = select;
ecl_region_invalidate_index_list( region );
}
void ecl_region_select_from_box( ecl_region_type * region , const ecl_box_type * ecl_box ) {
ecl_region_select_from_box__( region , ecl_box , true );
}
void ecl_region_deselect_from_box( ecl_region_type * region , const ecl_box_type * ecl_box ) {
ecl_region_select_from_box__( region , ecl_box , false );
}
/*****************************************************************/
/**
@ -665,9 +653,8 @@ void ecl_region_deselect_from_box( ecl_region_type * region , const ecl_box_type
*/
static void ecl_region_select_from_ijkbox__( ecl_region_type * region , int i1 , int i2 , int j1 , int j2 , int k1 , int k2 , bool select) {
ecl_box_type * tmp_box = ecl_box_alloc( region->parent_grid , i1 , i2 , j1 , j2 , k1 , k2);
ecl::ecl_box tmp_box(region->parent_grid, i1, i2, j1, j2, k1, k2);
ecl_region_select_from_box__( region , tmp_box , select );
ecl_box_free( tmp_box );
}

View File

@ -88,10 +88,7 @@ ecl_rsthead_type * ecl_rsthead_alloc_from_kw( int report_step , const ecl_kw_typ
// The only derived quantity
rsthead->sim_time = rsthead_date( rsthead->day , rsthead->month , rsthead->year );
}
if (doubhead_kw)
rsthead->sim_days = ecl_kw_iget_double( doubhead_kw , DOUBHEAD_DAYS_INDEX );
if (logihead_kw)
rsthead->dualp = ecl_kw_iget_bool( logihead_kw , LOGIHEAD_DUALP_INDEX);
@ -112,15 +109,12 @@ ecl_rsthead_type * ecl_rsthead_alloc_from_kw( int report_step , const ecl_kw_typ
ecl_rsthead_type * ecl_rsthead_alloc( const ecl_file_view_type * rst_view, int report_step) {
const ecl_kw_type * intehead_kw = ecl_file_view_iget_named_kw( rst_view , INTEHEAD_KW , 0);
const ecl_kw_type * doubhead_kw = NULL;
const ecl_kw_type * doubhead_kw = ecl_file_view_iget_named_kw( rst_view , DOUBHEAD_KW , 0);
const ecl_kw_type * logihead_kw = NULL;
if (ecl_file_view_has_kw(rst_view, LOGIHEAD_KW))
logihead_kw = ecl_file_view_iget_named_kw( rst_view , LOGIHEAD_KW , 0);
if (ecl_file_view_has_kw(rst_view, DOUBHEAD_KW))
doubhead_kw = ecl_file_view_iget_named_kw(rst_view, DOUBHEAD_KW, 0);
if (ecl_file_view_has_kw( rst_view , SEQNUM_KW)) {
const ecl_kw_type * seqnum_kw = ecl_file_view_iget_named_kw( rst_view , SEQNUM_KW , 0);
report_step = ecl_kw_iget_int( seqnum_kw , 0);

View File

@ -32,10 +32,10 @@
#include <ert/ecl/ecl_grid.hpp>
#include <ert/ecl/ecl_region.hpp>
#include <ert/ecl/ecl_subsidence.hpp>
#include <ert/ecl/ecl_grid_cache.hpp>
#include <ert/ecl/ecl_kw_magic.hpp>
#include <ert/ecl/ecl_grav_common.hpp>
#include "detail/ecl/ecl_grid_cache.hpp"
/**
This file contains datastructures for calculating changes in
@ -52,7 +52,7 @@
struct ecl_subsidence_struct {
const ecl_file_type * init_file; /* The init file - a shared reference owned by calling scope. */
ecl_grid_cache_type * grid_cache; /* An internal specialized structure to facilitate fast grid lookup. */
ecl::ecl_grid_cache * grid_cache;
bool * aquifer_cell;
hash_type * surveys; /* A hash table containg ecl_subsidence_survey_type instances; one instance
for each interesting time. */
@ -70,7 +70,7 @@ struct ecl_subsidence_struct {
#define ECL_SUBSIDENCE_SURVEY_ID 88517
struct ecl_subsidence_survey_struct {
UTIL_TYPE_ID_DECLARATION;
const ecl_grid_cache_type * grid_cache;
const ecl::ecl_grid_cache * grid_cache;
const bool * aquifer_cell; /* Is this cell a numerical aquifer cell - must be disregarded. */
char * name; /* Name of the survey - arbitrary string. */
double * porv; /* Reference pore volume */
@ -90,8 +90,8 @@ static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_empty(const ecl_
survey->aquifer_cell = sub->aquifer_cell;
survey->name = util_alloc_string_copy( name );
survey->porv = (double*)util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->porv );
survey->pressure = (double*)util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->pressure );
survey->porv = (double*) util_calloc( sub->grid_cache->size() , sizeof * survey->porv );
survey->pressure = (double*) util_calloc( sub->grid_cache->size() , sizeof * survey->pressure );
return survey;
}
@ -103,9 +103,10 @@ static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_PRESSURE(ecl_sub
const char * name ) {
ecl_subsidence_survey_type * survey = ecl_subsidence_survey_alloc_empty( ecl_subsidence , name );
ecl_grid_cache_type * grid_cache = ecl_subsidence->grid_cache;
const int * global_index = ecl_grid_cache_get_global_index( grid_cache );
const int size = ecl_grid_cache_get_size( grid_cache );
const ecl::ecl_grid_cache& grid_cache = *(ecl_subsidence->grid_cache);
const auto& global_index = grid_cache.global_index();
const int size = grid_cache.size();
int active_index;
ecl_kw_type * init_porv_kw = ecl_file_iget_named_kw( ecl_subsidence->init_file , PORV_KW , 0); /*Global indexing*/
ecl_kw_type * pressure_kw = ecl_file_view_iget_named_kw( restart_view , PRESSURE_KW , 0); /*Active indexing*/
@ -142,8 +143,8 @@ static double ecl_subsidence_survey_eval( const ecl_subsidence_survey_type * bas
double utm_x , double utm_y , double depth,
double compressibility, double poisson_ratio) {
const ecl_grid_cache_type * grid_cache = base_survey->grid_cache;
const int size = ecl_grid_cache_get_size( grid_cache );
const ecl::ecl_grid_cache& grid_cache = *(base_survey->grid_cache);
const int size = grid_cache.size();
double * weight = (double*)util_calloc( size , sizeof * weight );
double deltaz;
int index;
@ -170,9 +171,9 @@ static double ecl_subsidence_survey_eval_geertsma( const ecl_subsidence_survey_t
double utm_x , double utm_y , double depth,
double youngs_modulus, double poisson_ratio, double seabed) {
const ecl_grid_cache_type * grid_cache = base_survey->grid_cache;
const double * cell_volume = ecl_grid_cache_get_volume( grid_cache );
const int size = ecl_grid_cache_get_size( grid_cache );
const ecl::ecl_grid_cache& grid_cache = *(base_survey->grid_cache);
const auto& cell_volume = grid_cache.volume();
const int size = grid_cache.size();
double scale_factor = 1e4 *(1 + poisson_ratio) * ( 1 - 2*poisson_ratio) / ( 4*M_PI*( 1 - poisson_ratio) * youngs_modulus );
double * weight = (double*)util_calloc( size , sizeof * weight );
double deltaz;
@ -204,8 +205,8 @@ static double ecl_subsidence_survey_eval_geertsma( const ecl_subsidence_survey_t
ecl_subsidence_type * ecl_subsidence_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file) {
ecl_subsidence_type * ecl_subsidence = (ecl_subsidence_type*)util_malloc( sizeof * ecl_subsidence );
ecl_subsidence->init_file = init_file;
ecl_subsidence->grid_cache = ecl_grid_cache_alloc( ecl_grid );
ecl_subsidence->aquifer_cell = ecl_grav_common_alloc_aquifer_cell( ecl_subsidence->grid_cache , init_file );
ecl_subsidence->grid_cache = new ecl::ecl_grid_cache(ecl_grid);
ecl_subsidence->aquifer_cell = ecl_grav_common_alloc_aquifer_cell( *(ecl_subsidence->grid_cache) , init_file );
ecl_subsidence->surveys = hash_alloc();
return ecl_subsidence;
@ -254,7 +255,8 @@ double ecl_subsidence_eval_geertsma( const ecl_subsidence_type * subsidence , co
}
void ecl_subsidence_free( ecl_subsidence_type * ecl_subsidence ) {
ecl_grid_cache_free( ecl_subsidence->grid_cache );
delete ecl_subsidence->grid_cache;
free( ecl_subsidence->aquifer_cell );
hash_free( ecl_subsidence->surveys );
free( ecl_subsidence );

View File

@ -41,6 +41,7 @@
#include <ert/ecl/ecl_sum_data.hpp>
#include <ert/ecl/smspec_node.hpp>
#include "detail/util/path.hpp"
/**
The ECLIPSE summary data is organised in a header file (.SMSPEC)
@ -131,22 +132,31 @@ void ecl_sum_set_case( ecl_sum_type * ecl_sum , const char * input_arg) {
free( ecl_sum->base );
free( ecl_sum->ext );
{
char *path , *base, *ext;
std::string path = ecl::util::path::dirname(input_arg);
std::string base = ecl::util::path::basename(input_arg);
std::string ext = ecl::util::path::extension(input_arg);
util_alloc_file_components( input_arg, &path , &base , &ext);
ecl_sum->ecl_case = util_alloc_filename(path.c_str(), base.c_str(), NULL);
if (path.size())
ecl_sum->path = util_alloc_string_copy( path.c_str() );
else
ecl_sum->path = NULL;
ecl_sum->ecl_case = util_alloc_filename( path, base, NULL );
ecl_sum->path = util_alloc_string_copy( path );
ecl_sum->base = util_alloc_string_copy( base );
ecl_sum->ext = util_alloc_string_copy( ext );
if (path != NULL)
ecl_sum->abs_path = util_alloc_abs_path( path );
if (base.size())
ecl_sum->base = util_alloc_string_copy( base.c_str() );
else
ecl_sum->base = NULL;
if (ext.size())
ecl_sum->ext = util_alloc_string_copy( ext.c_str() );
else
ecl_sum->ext = NULL;
if (path.size() > 0)
ecl_sum->abs_path = util_alloc_abs_path( path.c_str() );
else
ecl_sum->abs_path = util_alloc_cwd();
free( base );
free( path );
free( ext );
}
}

View File

@ -35,7 +35,7 @@ unsmry_loader::unsmry_loader(const ecl_smspec_type * smspec, const std::string&
this->date_index = {{ ecl_smspec_get_date_day_index(smspec),
ecl_smspec_get_date_month_index(smspec),
ecl_smspec_get_date_year_index(smspec) }};
this->file = ecl_file_open(filename.c_str(), 0);
this->file = file;
this->file_view = ecl_file_get_global_view( this->file );
this->m_length = ecl_file_view_get_num_named_kw(this->file_view, PARAMS_KW);
}

View File

@ -21,6 +21,10 @@
#include <math.h>
#include <time.h>
#include <string>
#include <set>
#include <array>
#include <ert/util/hash.hpp>
#include <ert/util/util.h>
#include <ert/util/vector.hpp>
@ -35,7 +39,7 @@
#include <ert/ecl/ecl_file.hpp>
#include <ert/ecl/ecl_kw_magic.hpp>
#include "detail/util/string_util.hpp"
/**
@ -51,19 +55,19 @@
struct smspec_node_struct {
UTIL_TYPE_ID_DECLARATION;
char * wgname; /* The value of the WGNAMES vector for this element. */
char * keyword; /* The value of the KEYWORDS vector for this elements. */
char * unit; /* The value of the UNITS vector for this elements. */
std::string wgname;
std::string keyword; /* The value of the KEYWORDS vector for this elements. */
std::string unit; /* The value of the UNITS vector for this elements. */
int num; /* The value of the NUMS vector for this elements - NB this will have the value SMSPEC_NUMS_INVALID if the smspec file does not have a NUMS vector. */
char * lgr_name; /* The lgr name of the current variable - will be NULL for non-lgr variables. */
int * lgr_ijk; /* The (i,j,k) coordinate, in the local grid, if this is a LGR variable. WIll be NULL for no-lgr variables. */
std::string lgr_name; /* The lgr name of the current variable - will be NULL for non-lgr variables. */
std::array<int,3> lgr_ijk;
/*------------------------------------------- All members below this line are *derived* quantities. */
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. Some of the region_2_region elements will have both a xxx:num and a xxx:r2-r2 key. Mostly NULL. */
std::string gen_key1; /* The main composite key, i.e. WWCT:OP3 for this element. */
std::string gen_key2; /* Some of the ijk based elements will have both a xxx:i,j,k and a xxx:num key. Some of the region_2_region elements will have both a xxx:num and a xxx:r2-r2 key. Mostly NULL. */
ecl_smspec_var_type var_type; /* The variable type */
int * ijk; /* The ijk coordinates (NB: OFFSET 1) corresponding to the nums value - will be NULL if not relevant. */
std::array<int,3> ijk; /* The ijk coordinates (NB: OFFSET 1) corresponding to the nums value - will be NULL if not relevant. */
bool rate_variable; /* Is this a rate variable (i.e. WOPR) or a state variable (i.e. BPR). Relevant when doing time interpolation. */
bool total_variable; /* Is this a total variable like WOPT? */
bool historical; /* Does the name end with 'H'? */
@ -123,70 +127,64 @@ UTIL_SAFE_CAST_FUNCTION( smspec_node , SMSPEC_TYPE_ID )
static UTIL_SAFE_CAST_FUNCTION_CONST( smspec_node , SMSPEC_TYPE_ID )
char * smspec_alloc_block_num_key( const char * join_string , const char * keyword , int num) {
return util_alloc_sprintf(ECL_SUM_KEYFMT_BLOCK_NUM,
keyword ,
std::string smspec_alloc_block_num_key( const char * join_string , const std::string& keyword , int num) {
return ecl::util::string_format(ECL_SUM_KEYFMT_BLOCK_NUM,
keyword.c_str() ,
join_string ,
num );
}
char * smspec_alloc_aquifer_key( const char * join_string , const char * keyword , int num) {
return util_alloc_sprintf(ECL_SUM_KEYFMT_AQUIFER,
keyword ,
std::string smspec_alloc_aquifer_key( const char * join_string , const std::string& keyword , int num) {
return ecl::util::string_format(ECL_SUM_KEYFMT_AQUIFER,
keyword.c_str(),
join_string ,
num );
}
char * smspec_alloc_local_block_key( const char * join_string , const char * keyword , const char * lgr_name , int i , int j , int k) {
return util_alloc_sprintf(ECL_SUM_KEYFMT_LOCAL_BLOCK ,
keyword ,
std::string smspec_alloc_local_block_key( const char * join_string , const std::string& keyword , const std::string& lgr_name , int i , int j , int k) {
return ecl::util::string_format(ECL_SUM_KEYFMT_LOCAL_BLOCK ,
keyword.c_str() ,
join_string ,
lgr_name ,
lgr_name.c_str() ,
join_string ,
i,j,k);
}
char * smspec_alloc_region_key( const char * join_string , const char * keyword , int num) {
return util_alloc_sprintf(ECL_SUM_KEYFMT_REGION ,
keyword ,
std::string smspec_alloc_region_key( const char * join_string , const std::string& keyword , int num) {
return ecl::util::string_format(ECL_SUM_KEYFMT_REGION ,
keyword.c_str(),
join_string ,
num );
}
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,
std::string smspec_alloc_region_2_region_r1r2_key( const char * join_string , const std::string& keyword , int r1, int r2) {
return ecl::util::string_format(ECL_SUM_KEYFMT_REGION_2_REGION_R1R2,
keyword.c_str(),
join_string,
r1,
r2);
}
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 ,
std::string smspec_alloc_region_2_region_num_key( const char * join_string , const std::string& keyword , int num) {
return ecl::util::string_format(ECL_SUM_KEYFMT_REGION_2_REGION_NUM,
keyword.c_str() ,
join_string ,
num);
}
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,
std::string smspec_alloc_completion_ijk_key( const char * join_string , const std::string& keyword, const std::string& wgname , int i , int j , int k) {
if (wgname.size() > 0)
return ecl::util::string_format( ECL_SUM_KEYFMT_COMPLETION_IJK ,
keyword.c_str() ,
join_string ,
i,j,k);
}
char * smspec_alloc_completion_ijk_key( const char * join_string , const char * keyword, const char * wgname , int i , int j , int k) {
if (wgname != NULL)
return util_alloc_sprintf( ECL_SUM_KEYFMT_COMPLETION_IJK ,
keyword ,
join_string ,
wgname ,
wgname.c_str(),
join_string ,
i , j , k );
else
@ -195,12 +193,12 @@ char * smspec_alloc_completion_ijk_key( const char * join_string , const char *
char * smspec_alloc_completion_num_key( const char * join_string , const char * keyword, const char * wgname , int num) {
if (wgname != NULL)
return util_alloc_sprintf(ECL_SUM_KEYFMT_COMPLETION_NUM,
keyword ,
std::string smspec_alloc_completion_num_key( const char * join_string , const std::string& keyword, const std::string& wgname , int num) {
if (wgname.size() > 0)
return ecl::util::string_format(ECL_SUM_KEYFMT_COMPLETION_NUM,
keyword.c_str() ,
join_string ,
wgname ,
wgname.c_str() ,
join_string ,
num );
else
@ -211,33 +209,59 @@ char * smspec_alloc_completion_num_key( const char * join_string , const char *
To support ECLIPSE behaviour where new wells/groups can be created
during the simulation it must be possible to create a smspec node
with an initially unknown well/group name; all gen_key formats which
use the wgname value must therefore accept a NULL value for wgname.
use the wgname value must therefore accept a NULL value for wgname. HMM: Uncertain about this?
*/
static char * smspec_alloc_wgname_key( const char * join_string , const char * keyword , const char * wgname) {
if (wgname != NULL)
static std::string smspec_alloc_wgname_key( const char * join_string , const std::string& keyword , const std::string& wgname) {
if (wgname.size() > 0)
return ecl::util::string_format(ECL_SUM_KEYFMT_WELL,
keyword.c_str() ,
join_string ,
wgname.c_str() );
else
return "";
}
std::string smspec_alloc_group_key( const char * join_string , const std::string& keyword , const std::string& wgname) {
return smspec_alloc_wgname_key( join_string , keyword , wgname );
}
std::string smspec_alloc_well_key( const char * join_string , const std::string& keyword , const std::string& wgname) {
return smspec_alloc_wgname_key( join_string , keyword , wgname );
}
/*
The smspec_alloc_well_key and smspec_alloc_block_ijk_key() require C linkage due to external use.
*/
char * smspec_alloc_well_key( const char * join_string , const char * keyword , const char * wgname) {
return util_alloc_sprintf( ECL_SUM_KEYFMT_WELL,
keyword,
join_string,
wgname);
else
return NULL;
}
char * smspec_alloc_group_key( const char * join_string , const char * keyword , const char * wgname) {
return smspec_alloc_wgname_key( join_string , keyword , wgname );
}
char * smspec_alloc_well_key( const char * join_string , const char * keyword , const char * wgname) {
return smspec_alloc_wgname_key( join_string , keyword , wgname );
}
char * smspec_alloc_segment_key( const char * join_string , const char * keyword , const char * wgname , int num) {
if (wgname != NULL)
return util_alloc_sprintf(ECL_SUM_KEYFMT_SEGMENT ,
char * smspec_alloc_block_ijk_key( const char * join_string , const char * keyword , int i , int j , int k) {
return util_alloc_sprintf(ECL_SUM_KEYFMT_BLOCK_IJK,
keyword,
join_string,
wgname ,
i,j,k);
}
std::string smspec_alloc_block_ijk_key( const char * join_string , const std::string& keyword , int i , int j , int k) {
return ecl::util::string_format(ECL_SUM_KEYFMT_BLOCK_IJK ,
keyword.c_str(),
join_string ,
i,j,k);
}
std::string smspec_alloc_segment_key( const char * join_string , const std::string& keyword , const std::string& wgname , int num) {
if (wgname.size() > 0)
return ecl::util::string_format(ECL_SUM_KEYFMT_SEGMENT ,
keyword.c_str() ,
join_string ,
wgname.c_str(),
join_string ,
num );
else
@ -245,26 +269,26 @@ char * smspec_alloc_segment_key( const char * join_string , const char * keyword
}
char * smspec_alloc_local_well_key( const char * join_string , const char * keyword , const char * lgr_name , const char * wgname) {
if (wgname != NULL)
return util_alloc_sprintf( ECL_SUM_KEYFMT_LOCAL_WELL ,
keyword ,
std::string smspec_alloc_local_well_key( const char * join_string , const std::string& keyword , const std::string& lgr_name , const std::string& wgname) {
if (wgname.size() > 0)
return ecl::util::string_format( ECL_SUM_KEYFMT_LOCAL_WELL ,
keyword.c_str() ,
join_string ,
lgr_name ,
lgr_name.c_str() ,
join_string ,
wgname);
wgname.c_str());
else
return NULL;
}
char * smspec_alloc_local_completion_key( const char * join_string, const char * keyword , const char * lgr_name , const char * wgname , int i , int j , int k) {
if (wgname != NULL)
return util_alloc_sprintf(ECL_SUM_KEYFMT_LOCAL_COMPLETION ,
keyword ,
std::string smspec_alloc_local_completion_key( const char * join_string, const std::string& keyword , const std::string& lgr_name , const std::string& wgname , int i , int j , int k) {
if (wgname.size() > 0)
return ecl::util::string_format(ECL_SUM_KEYFMT_LOCAL_COMPLETION ,
keyword.c_str(),
join_string ,
lgr_name ,
lgr_name.c_str() ,
join_string ,
wgname ,
wgname.c_str(),
join_string ,
i,j,k);
else
@ -273,12 +297,12 @@ char * smspec_alloc_local_completion_key( const char * join_string, const char *
/*****************************************************************/
static void smspec_node_set_keyword( smspec_node_type * smspec_node , const char * keyword ) {
static void smspec_node_set_keyword( smspec_node_type * smspec_node , const std::string& keyword ) {
// ECLIPSE Standard: Max eight characters - everything beyond is silently dropped
// This function can __ONLY__ be called on time; run-time chaning of keyword is not
// allowed.
if (smspec_node->keyword == NULL)
smspec_node->keyword = util_alloc_substring_copy( keyword , 0 , 8);
if (smspec_node->keyword.size() == 0)
smspec_node->keyword = keyword;
else
util_abort("%s: fatal error - attempt to change keyword runtime detected - aborting\n",__func__);
}
@ -290,9 +314,6 @@ static void smspec_node_set_invalid_flags( smspec_node_type * smspec_node) {
smspec_node->historical = false;
}
static char LAST_CHAR(const char * s) {
return s[ strlen(s) - 1];
}
bool smspec_node_identify_rate(const char * keyword) {
@ -357,10 +378,10 @@ static void smspec_node_set_flags( smspec_node_type * smspec_node) {
Check if this is a rate variabel - that info is used when
interpolating results to true_time between ministeps.
*/
smspec_node->rate_variable = smspec_node_identify_rate(smspec_node->keyword);
if (LAST_CHAR(smspec_node->keyword) == 'H')
smspec_node->rate_variable = smspec_node_identify_rate(smspec_node->keyword.c_str());
if (smspec_node->keyword.back() == 'H')
smspec_node->historical = true;
smspec_node->total_variable = smspec_node_identify_total(smspec_node->keyword, smspec_node->var_type);
smspec_node->total_variable = smspec_node_identify_total(smspec_node->keyword.c_str(), smspec_node->var_type);
}
/**
@ -380,44 +401,30 @@ float smspec_node_get_default( const smspec_node_type * smspec_node ) {
smspec_node_type * smspec_node_alloc_new(int params_index, float default_value) {
smspec_node_type * node = (smspec_node_type*)util_malloc( sizeof * node );
smspec_node_type * node = new smspec_node_type();
UTIL_TYPE_ID_INIT( node , SMSPEC_TYPE_ID);
node->params_index = params_index;
smspec_node_set_default( node , default_value );
node->wgname = NULL;
node->ijk = NULL;
node->gen_key1 = NULL;
node->gen_key2 = NULL;
node->var_type = ECL_SMSPEC_INVALID_VAR;
node->unit = NULL;
node->keyword = NULL;
node->lgr_name = NULL;
node->lgr_ijk = NULL;
smspec_node_set_invalid_flags( node );
return node; // This is NOT usable
}
static void smspec_node_set_wgname( smspec_node_type * index , const char * wgname ) {
index->wgname = util_realloc_string_copy(index->wgname , wgname );
index->wgname = wgname;
}
static void smspec_node_set_lgr_name( smspec_node_type * index , const char * lgr_name ) {
index->lgr_name = util_realloc_string_copy(index->lgr_name , lgr_name);
static void smspec_node_set_lgr_name( smspec_node_type * index , const std::string& lgr_name ) {
index->lgr_name = lgr_name;
}
static void smspec_node_set_lgr_ijk( smspec_node_type * index , int lgr_i , int lgr_j , int lgr_k) {
if (index->lgr_ijk == NULL)
index->lgr_ijk = (int*)util_calloc( 3 , sizeof * index->lgr_ijk );
index->lgr_ijk[0] = lgr_i;
index->lgr_ijk[1] = lgr_j;
index->lgr_ijk[2] = lgr_k;
@ -446,8 +453,6 @@ static void smspec_node_set_num( smspec_node_type * index , const int grid_dims[
index->num = num;
if ((index->var_type == ECL_SMSPEC_COMPLETION_VAR) || (index->var_type == ECL_SMSPEC_BLOCK_VAR)) {
int global_index = num - 1;
index->ijk = (int*)util_calloc( 3 , sizeof * index->ijk );
index->ijk[2] = global_index / ( grid_dims[0] * grid_dims[1] ); global_index -= index->ijk[2] * (grid_dims[0] * grid_dims[1]);
index->ijk[1] = global_index / grid_dims[0] ; global_index -= index->ijk[1] * grid_dims[0];
index->ijk[0] = global_index;
@ -489,7 +494,7 @@ static void smspec_node_set_gen_keys( smspec_node_type * smspec_node , const cha
break;
case(ECL_SMSPEC_FIELD_VAR):
// KEYWORD
smspec_node->gen_key1 = util_alloc_string_copy( smspec_node->keyword );
smspec_node->gen_key1 = util_alloc_string_copy( smspec_node->keyword.c_str() );
break;
case(ECL_SMSPEC_GROUP_VAR):
// KEYWORD:WGNAME
@ -519,7 +524,7 @@ static void smspec_node_set_gen_keys( smspec_node_type * smspec_node , const cha
case(ECL_SMSPEC_MISC_VAR):
// KEYWORD
/* Misc variable - i.e. date or CPU time ... */
smspec_node->gen_key1 = util_alloc_string_copy( smspec_node->keyword );
smspec_node->gen_key1 = smspec_node->keyword;
break;
case(ECL_SMSPEC_BLOCK_VAR):
// KEYWORD:NUM
@ -560,9 +565,9 @@ static void smspec_node_set_gen_keys( smspec_node_type * smspec_node , const cha
static void smspec_node_common_init( smspec_node_type * node , ecl_smspec_var_type var_type , const char * keyword , const char * unit ) {
static void smspec_node_common_init( smspec_node_type * node , ecl_smspec_var_type var_type , const char * keyword , const std::string& unit ) {
if (node->var_type == ECL_SMSPEC_INVALID_VAR) {
smspec_node_set_unit( node , unit );
smspec_node_set_unit( node , unit.c_str() );
smspec_node_set_keyword( node , keyword);
node->var_type = var_type;
smspec_node_set_flags( node );
@ -811,28 +816,18 @@ smspec_node_type* smspec_node_alloc_copy( const smspec_node_type* node ) {
if( !node ) return NULL;
{
smspec_node_type* copy = (smspec_node_type*)util_malloc( sizeof * copy );
smspec_node_type * copy = new smspec_node_type();
UTIL_TYPE_ID_INIT( copy, SMSPEC_TYPE_ID );
copy->gen_key1 = util_alloc_string_copy( node->gen_key1 );
copy->gen_key2 = util_alloc_string_copy( node->gen_key2 );
copy->gen_key1 = node->gen_key1;
copy->gen_key2 = node->gen_key2;
copy->var_type = node->var_type;
copy->wgname = util_alloc_string_copy( node->wgname );
copy->keyword = util_alloc_string_copy( node->keyword );
copy->unit = util_alloc_string_copy( node->unit );
copy->wgname = node->wgname;
copy->keyword = node->keyword;
copy->unit = node->unit;
copy->num = node->num;
copy->ijk = NULL;
if( node->ijk ) {
copy->ijk = (int*)util_calloc( 3 , sizeof * node->ijk );
memcpy( copy->ijk, node->ijk, 3 * sizeof( * node->ijk ) );
}
copy->lgr_name = util_alloc_string_copy( node->lgr_name );
copy->lgr_ijk = NULL;
if( node->lgr_ijk ) {
copy->lgr_ijk = (int*)util_calloc( 3 , sizeof * node->lgr_ijk );
memcpy( copy->lgr_ijk, node->lgr_ijk, 3 * sizeof( * node->lgr_ijk ) );
}
copy->ijk = node->ijk;
copy->lgr_name = node->lgr_name;
copy->lgr_ijk = node->lgr_ijk;
copy->rate_variable = node->rate_variable;
copy->total_variable = node->total_variable;
@ -844,15 +839,7 @@ smspec_node_type* smspec_node_alloc_copy( const smspec_node_type* node ) {
}
void smspec_node_free( smspec_node_type * index ) {
free( index->unit );
free( index->keyword );
free( index->ijk );
free( index->gen_key1 );
free( index->gen_key2 );
free( index->wgname );
free( index->lgr_name );
free( index->lgr_ijk );
free( index );
delete index;
}
void smspec_node_free__( void * arg ) {
@ -874,21 +861,33 @@ void smspec_node_set_params_index( smspec_node_type * smspec_node , int params_i
smspec_node->params_index = params_index;
}
namespace {
const char * get_cstring(const std::string& s) {
if (s.empty())
return NULL;
else
return s.c_str();
}
}
const char * smspec_node_get_gen_key1( const smspec_node_type * smspec_node) {
return smspec_node->gen_key1;
return get_cstring( smspec_node->gen_key1 );
}
const char * smspec_node_get_gen_key2( const smspec_node_type * smspec_node) {
return smspec_node->gen_key2;
return get_cstring( smspec_node->gen_key2 );
}
const char * smspec_node_get_wgname( const smspec_node_type * smspec_node) {
return smspec_node->wgname;
return get_cstring( smspec_node->wgname );
}
const char * smspec_node_get_keyword( const smspec_node_type * smspec_node) {
return smspec_node->keyword;
return get_cstring( smspec_node->keyword );
}
@ -915,29 +914,28 @@ bool smspec_node_is_historical( const smspec_node_type * smspec_node ){
}
const char * smspec_node_get_unit( const smspec_node_type * smspec_node) {
return smspec_node->unit;
return smspec_node->unit.c_str();
}
void smspec_node_set_unit( smspec_node_type * smspec_node , const char * unit) {
// ECLIPSE Standard: Max eight characters - everything beyond is silently dropped
free( smspec_node->unit );
smspec_node->unit = util_alloc_substring_copy( unit , 0 , 8);
std::string tmp = unit;
smspec_node->unit = tmp.substr(0,8);
}
// Will be NULL for smspec_nodes which do not have i,j,k
// Will be garbage for smspec_nodes which do not have i,j,k
const int* smspec_node_get_ijk( const smspec_node_type * smspec_node ) {
return smspec_node->ijk;
return smspec_node->ijk.data();
}
// Will be NULL for smspec_nodes which are not related to an LGR.
const char* smspec_node_get_lgr_name( const smspec_node_type * smspec_node ) {
return smspec_node->lgr_name;
return smspec_node->lgr_name.c_str();
}
// Will be NULL for smspec_nodes which are not related to an LGR.
// Will be garbage for smspec_nodes which are not related to an LGR.
const int* smspec_node_get_lgr_ijk( const smspec_node_type * smspec_node ) {
return smspec_node->lgr_ijk;
return smspec_node->lgr_ijk.data();
}
/*
@ -989,16 +987,16 @@ bool smspec_node_need_nums( const smspec_node_type * smspec_node ) {
void smspec_node_fprintf( const smspec_node_type * smspec_node , FILE * stream) {
fprintf(stream, "KEYWORD: %s \n",smspec_node->keyword);
fprintf(stream, "WGNAME : %s \n",smspec_node->wgname);
fprintf(stream, "UNIT : %s \n",smspec_node->unit);
fprintf(stream, "KEYWORD: %s \n",smspec_node->keyword.c_str());
fprintf(stream, "WGNAME : %s \n",smspec_node->wgname.c_str());
fprintf(stream, "UNIT : %s \n",smspec_node->unit.c_str());
fprintf(stream, "TYPE : %d \n",smspec_node->var_type);
fprintf(stream, "NUM : %d \n\n",smspec_node->num);
}
static bool smspec_node_equal_MISC( const smspec_node_type * node1, const smspec_node_type * node2) {
return util_string_equal( node1->keyword , node2->keyword);
return node1->keyword == node2->keyword;
}
@ -1008,34 +1006,22 @@ static bool smspec_node_equal_MISC( const smspec_node_type * node1, const smspec
*/
static int smspec_node_cmp_MISC( const smspec_node_type * node1, const smspec_node_type * node2) {
static const char* early_vars[] = {"TIME",
"DAYS",
"DAY",
"MONTH",
"YEAR",
"YEARS"};
static const std::set<std::string> early_vars = {"TIME", "DAYS", "DAY", "MONTH", "YEAR", "YEARS"};
if (smspec_node_equal_MISC( node1, node2) )
return 0;
bool node1_early = false;
bool node2_early = false;
bool node1_early = !( early_vars.find(node1->keyword) == early_vars.end() );
bool node2_early = !( early_vars.find(node2->keyword) == early_vars.end() );
for (int i=0; i < 6; i++) {
if (util_string_equal( node1->keyword, early_vars[i] ))
node1_early = true;
if (util_string_equal( node2->keyword, early_vars[i] ))
node2_early = true;
}
if (node1_early && !node2_early)
return -1;
if (!node1_early && node2_early)
return 1;
return strcmp( node1->keyword, node2->keyword);
return node1->keyword.compare(node2->keyword);
}
@ -1063,11 +1049,11 @@ static int smspec_node_cmp_LGRIJK( const smspec_node_type * node1, const smspec_
static int smspec_node_cmp_KEYWORD_LGR_LGRIJK( const smspec_node_type * node1, const smspec_node_type * node2) {
int keyword_cmp = strcmp( node1->keyword , node2->keyword);
int keyword_cmp = node1->keyword.compare(node2->keyword);
if (keyword_cmp != 0)
return keyword_cmp;
int lgr_cmp = strcmp( node1->lgr_name , node2->lgr_name);
int lgr_cmp = node1->lgr_name.compare( node2->lgr_name );
if (lgr_cmp != 0)
return lgr_cmp;
@ -1076,11 +1062,11 @@ static int smspec_node_cmp_KEYWORD_LGR_LGRIJK( const smspec_node_type * node1, c
static int smspec_node_cmp_KEYWORD_WGNAME_NUM( const smspec_node_type * node1, const smspec_node_type * node2) {
int keyword_cmp = strcmp( node1->keyword , node2->keyword);
int keyword_cmp = node1->keyword.compare(node2->keyword);
if (keyword_cmp != 0)
return keyword_cmp;
int wgname_cmp = strcmp( node1->wgname , node2->wgname);
int wgname_cmp = node1->wgname.compare(node2->wgname);
if (wgname_cmp != 0)
return wgname_cmp;
@ -1088,28 +1074,28 @@ static int smspec_node_cmp_KEYWORD_WGNAME_NUM( const smspec_node_type * node1, c
}
static int smspec_node_cmp_KEYWORD_WGNAME_LGR( const smspec_node_type * node1, const smspec_node_type * node2) {
int keyword_cmp = strcmp( node1->keyword , node2->keyword);
int keyword_cmp = node1->keyword.compare(node2->keyword);
if (keyword_cmp != 0)
return keyword_cmp;
int wgname_cmp = strcmp( node1->wgname , node2->wgname);
int wgname_cmp = node1->wgname.compare(node2->wgname);
if (wgname_cmp != 0)
return wgname_cmp;
return strcmp( node1->lgr_name , node2->lgr_name);
return node1->lgr_name.compare(node2->lgr_name);
}
static int smspec_node_cmp_KEYWORD_WGNAME_LGR_LGRIJK( const smspec_node_type * node1, const smspec_node_type * node2) {
int keyword_cmp = strcmp( node1->keyword , node2->keyword);
int keyword_cmp = node1->keyword.compare(node2->keyword);
if (keyword_cmp != 0)
return keyword_cmp;
int wgname_cmp = strcmp( node1->wgname , node2->wgname);
int wgname_cmp = node1->wgname.compare(node2->wgname);
if (wgname_cmp != 0)
return wgname_cmp;
int lgr_cmp = strcmp( node1->lgr_name , node2->lgr_name);
int lgr_cmp = node1->lgr_name.compare(node2->lgr_name);
if (lgr_cmp != 0)
return lgr_cmp;
@ -1120,26 +1106,26 @@ static int smspec_node_cmp_KEYWORD_WGNAME_LGR_LGRIJK( const smspec_node_type * n
static int smspec_node_cmp_KEYWORD_WGNAME( const smspec_node_type * node1, const smspec_node_type * node2) {
int keyword_cmp = strcmp( node1->keyword , node2->keyword);
int keyword_cmp = node1->keyword.compare(node2->keyword);
if (keyword_cmp != 0)
return keyword_cmp;
if (IS_DUMMY_WELL( node1->wgname )) {
if (IS_DUMMY_WELL( node2->wgname ))
if (IS_DUMMY_WELL( node1->wgname.c_str() )) {
if (IS_DUMMY_WELL( node2->wgname.c_str() ))
return 0;
else
return 1;
}
if (IS_DUMMY_WELL( node2->wgname ))
if (IS_DUMMY_WELL( node2->wgname.c_str() ))
return -1;
return strcmp( node1->wgname , node2->wgname);
return node1->wgname.compare(node2->wgname);
}
static int smspec_node_cmp_KEYWORD_NUM( const smspec_node_type * node1, const smspec_node_type * node2) {
int keyword_cmp = strcmp( node1->keyword , node2->keyword);
int keyword_cmp = node1->keyword.compare(node2->keyword);
if (keyword_cmp != 0)
return keyword_cmp;
@ -1148,19 +1134,19 @@ static int smspec_node_cmp_KEYWORD_NUM( const smspec_node_type * node1, const sm
static int smspec_node_cmp_KEYWORD( const smspec_node_type * node1, const smspec_node_type * node2) {
return strcmp( node1->keyword , node2->keyword );
return node1->keyword.compare(node2->keyword);
}
static int smspec_node_cmp_key1( const smspec_node_type * node1, const smspec_node_type * node2) {
if (!node1->gen_key1) {
if (!node2->gen_key1)
if (node1->gen_key1.empty()) {
if (node2->gen_key1.empty())
return 0;
else
return -1;
} else if (!node2->gen_key1) {
} else if (node2->gen_key1.empty()) {
return 1;
}
return util_strcmp_int( node1->gen_key1 , node2->gen_key1 );
return util_strcmp_int( node1->gen_key1.c_str() , node2->gen_key1.c_str() );
}

View File

@ -59,6 +59,7 @@ void test_writable(size_t data_size) {
void test_truncated() {
test_work_area_type * work_area = test_work_area_alloc("ecl_file_truncated" );
int num_kw;
{
ecl_grid_type * grid = ecl_grid_alloc_rectangular(20,20,20,1,1,1,NULL);
ecl_grid_fwrite_EGRID2( grid , "TEST.EGRID", ECL_METRIC_UNITS );
@ -67,6 +68,7 @@ void test_truncated() {
{
ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
test_assert_true( ecl_file_is_instance( ecl_file ) );
num_kw = ecl_file_get_size( ecl_file );
ecl_file_close( ecl_file );
}
@ -78,7 +80,8 @@ void test_truncated() {
}
{
ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
test_assert_NULL( ecl_file );
test_assert_true( ecl_file_get_size( ecl_file) < num_kw );
ecl_file_close( ecl_file );
}
test_work_area_free( work_area );
}

View File

@ -132,32 +132,6 @@ void test_writable(const char * src_file ) {
void test_truncated() {
test_work_area_type * work_area = test_work_area_alloc("ecl_file_truncated" );
{
ecl_grid_type * grid = ecl_grid_alloc_rectangular(20,20,20,1,1,1,NULL);
ecl_grid_fwrite_EGRID2( grid , "TEST.EGRID", ECL_METRIC_UNITS );
ecl_grid_free( grid );
}
{
ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
test_assert_true( ecl_file_is_instance( ecl_file ) );
ecl_file_close( ecl_file );
}
{
offset_type file_size = util_file_size( "TEST.EGRID");
FILE * stream = util_fopen("TEST.EGRID" , "r+");
util_ftruncate( stream , file_size / 2 );
fclose( stream );
}
{
ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
test_assert_NULL( ecl_file );
}
test_work_area_free( work_area );
}
int main( int argc , char ** argv) {
const char * src_file = argv[1];
@ -175,6 +149,5 @@ int main( int argc , char ** argv) {
test_work_area_free( work_area );
}
test_truncated();
exit(0);
}

View File

@ -0,0 +1,79 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'ecl_grid_dims.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 <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
#include <math.h>
#include <string>
#include <ert/util/test_util.hpp>
#include <ert/util/util.h>
#include <ert/ecl/ecl_grid.hpp>
#include <ert/ecl/ecl_file.hpp>
double err(double a, double b) {
return (a - b) / a;
}
void test_dxdydz(const std::string& grid_fname, const std::string& init_fname) {
double eps_x = 1e-4;
double eps_y = 1e-4;
double eps_z = 1e-3;
ecl_grid_type * grid = ecl_grid_alloc( grid_fname.c_str() );
ecl_file_type * init_file = ecl_file_open( init_fname.c_str(), 0);
ecl_kw_type * dx = ecl_file_iget_named_kw( init_file, "DX", 0);
ecl_kw_type * dy = ecl_file_iget_named_kw( init_file, "DY", 0);
ecl_kw_type * dz = ecl_file_iget_named_kw( init_file, "DZ", 0);
for(int a=0; a < ecl_grid_get_active_size(grid); a+= 100) {
int g = ecl_grid_get_global_index1A(grid, a);
double dxg = ecl_grid_get_cell_dx1(grid, g);
double dyg = ecl_grid_get_cell_dy1(grid, g);
double dzg = ecl_grid_get_cell_dz1(grid, g);
double dxi = ecl_kw_iget_float(dx, a);
double dyi = ecl_kw_iget_float(dy, a);
double dzi = ecl_kw_iget_float(dz, a);
double err_x = fabs(err(dxg, dxi));
double err_y = fabs(err(dyg, dyi));
double err_z = fabs(err(dzg, dzi));
test_assert_true( err_x < eps_x );
test_assert_true( err_y < eps_y );
test_assert_true( err_z < eps_z );
}
ecl_file_close(init_file);
ecl_grid_free( grid );
}
int main(int argc , char ** argv) {
const std::string ecl_case = argv[1];
std::string grid_file = ecl_case + ".EGRID";
std::string init_file = ecl_case + ".INIT";
test_dxdydz(grid_file, init_file);
exit(0);
}

View File

@ -60,6 +60,7 @@ void verify_CASE1() {
for (int j=0; j < 4; j++) {
test_assert_double_equal( double_vector_iget(d, j), (i - 1)*10 + (j + 1)*100);
}
double_vector_free(d);
}
ecl_sum_free(sum);
}
@ -103,6 +104,7 @@ void verify_CASE2() {
//test_assert_int_equal(4, double_vector_size(d));
for (int j=1; j < 4; j++)
test_assert_double_equal( double_vector_iget(d, j-1), (1 - i)*100 + j*1000);
double_vector_free(d);
}
ecl_sum_free(sum);
@ -112,7 +114,6 @@ void verify_CASE2() {
for (int i=0; i < 2; i++) {
double_vector_type * d = ecl_sum_alloc_data_vector(sum, i+1, false);
//test_assert_int_equal(double_vector_size(d), 7);
double_vector_fprintf(d, stdout, "d", "%g");
ieq(d,0,(1 - i)*10 + 100);
ieq(d,1,(1 - i)*10 + 200);
ieq(d,2,(1 - i)*10 + 300);
@ -162,6 +163,7 @@ void verify_CASE3() {
for (int j=0; j < 4; j++) {
test_assert_double_equal( double_vector_iget(d, j), (2 - i)*1000 + (j + 1)*10000);
}
double_vector_free(d);
}
ecl_sum_free(sum);

View File

@ -1,6 +1,6 @@
#include <vector>
#include <ert/util/TestArea.hpp>
#include <ert/util/test_work_area.hpp>
#include <ert/util/test_util.hpp>
#include <ert/ecl/ecl_sum.hpp>
@ -36,7 +36,7 @@ ecl_sum_type * write_ecl_sum() {
}
void test_load() {
ERT::TestArea work_area("unsmry_loader");
test_work_area_type * work_area = test_work_area_alloc("unsmry_loader");
ecl_sum_type * ecl_sum = write_ecl_sum();
test_assert_true( util_file_exists("CASE.SMSPEC") );
test_assert_true( util_file_exists("CASE.UNSMRY") );
@ -52,6 +52,7 @@ void test_load() {
delete loader;
ecl_sum_free(ecl_sum);
test_work_area_free(work_area);
}
int main() {

View File

@ -21,14 +21,14 @@
#include <fstream>
#include <ert/util/TestArea.hpp>
#include <ert/util/test_work_area.hpp>
#include <ert/util/test_util.hpp>
#include <ert/ecl/EclKW.hpp>
#include <ert/ecl/FortIO.hpp>
void test_open() {
ERT::TestArea work_area("fortio");
test_work_area_type * work_area = test_work_area_alloc("FORTIO");
ERT::FortIO fortio;
fortio.open( "new_file" , std::fstream::out );
@ -67,11 +67,12 @@ void test_open() {
}
test_assert_false( fortio.ftruncate( 0 ));
fortio.close();
test_work_area_free(work_area);
}
void test_fortio() {
ERT::TestArea ta("fortio");
test_work_area_type * work_area = test_work_area_alloc("FORTIO");
ERT::FortIO fortio("new_file" , std::fstream::out );
{
std::vector<int> data;
@ -96,11 +97,12 @@ void test_fortio() {
fortio.close();
test_assert_throw( ERT::FortIO fortio("file/does/not/exists" , std::fstream::in) , std::invalid_argument );
test_work_area_free(work_area);
}
void test_fortio_kw() {
ERT::TestArea ta("fortio");
test_work_area_type * work_area = test_work_area_alloc("FORTIO");
std::vector< int > vec( 1000 );
for (size_t i =0 ; i < vec.size(); i++)
@ -126,6 +128,7 @@ void test_fortio_kw() {
test_assert_throw( ERT::EclKW<float>::load(fortio) , std::invalid_argument );
fortio.close();
}
test_work_area_free(work_area);
}

View File

@ -26,7 +26,7 @@
#include <ert/ecl/EclKW.hpp>
#include <ert/ecl/FortIO.hpp>
#include <ert/util/TestArea.hpp>
#include <ert/util/test_work_area.hpp>
void test_kw_name() {
ERT::EclKW< int > kw1( "short", 1 );
@ -170,7 +170,7 @@ void test_read_write() {
std::vector<std::string> s_data = {"S1", "S2", "S3"};
{
ERT::TestArea ta("test_fwrite");
test_work_area_type * work_area = test_work_area_alloc("READ_WRITE");
{
ERT::FortIO f("test_file", std::ios_base::out);
ERT::write_kw(f, "DOUBLE", d_data);
@ -208,6 +208,7 @@ void test_read_write() {
}
ecl_file_close(f);
test_work_area_free(work_area);
}
}
}

View File

@ -20,7 +20,6 @@
#include <fstream>
#include <ert/util/TestArea.hpp>
#include <ert/util/test_util.hpp>
#include <ert/ecl/ecl_type.hpp>
#include <ert/ecl/FortIO.hpp>

View File

@ -19,10 +19,12 @@
#include <time.h>
#include <stdbool.h>
#include <string>
#include <vector>
#include <ert/util/util.h>
#include <ert/util/hash.hpp>
#include <ert/util/int_vector.hpp>
#include <ert/util/stringlist.hpp>
#include <ert/ecl/ecl_rsthead.hpp>
#include <ert/ecl/ecl_file.hpp>
@ -181,7 +183,7 @@
struct well_info_struct {
hash_type * wells; /* Hash table of well_ts_type instances; indexed by well name. */
stringlist_type * well_names; /* A list of all the well names. */
std::vector<std::string> well_names; /* A list of all the well names. */
const ecl_grid_type * grid;
};
@ -192,9 +194,8 @@ struct well_info_struct {
*/
well_info_type * well_info_alloc( const ecl_grid_type * grid) {
well_info_type * well_info = (well_info_type*)util_malloc( sizeof * well_info );
well_info_type * well_info = new well_info_type();
well_info->wells = hash_alloc();
well_info->well_names = stringlist_alloc_new();
well_info->grid = grid;
return well_info;
}
@ -211,7 +212,7 @@ well_ts_type * well_info_get_ts( const well_info_type * well_info , const char *
static void well_info_add_new_ts( well_info_type * well_info , const char * well_name) {
well_ts_type * well_ts = well_ts_alloc( well_name ) ;
hash_insert_hash_owned_ref( well_info->wells , well_name , well_ts , well_ts_free__);
stringlist_append_copy( well_info->well_names , well_name );
well_info->well_names.push_back( well_name );
}
static void well_info_add_state( well_info_type * well_info , well_state_type * well_state) {
@ -353,8 +354,7 @@ void well_info_load_rst_eclfile( well_info_type * well_info , ecl_file_type * ec
void well_info_free( well_info_type * well_info ) {
hash_free( well_info->wells );
stringlist_free( well_info->well_names );
free( well_info );
delete well_info;
}
int well_info_get_well_size( const well_info_type * well_info , const char * well_name ) {
@ -381,16 +381,17 @@ well_state_type * well_info_iget_state( const well_info_type * well_info , const
}
well_state_type * well_info_iiget_state( const well_info_type * well_info , int well_index , int time_index) {
const char * well_name = stringlist_iget( well_info->well_names , well_index );
return well_info_iget_state( well_info , well_name , time_index );
const std::string& well_name = well_info->well_names[well_index];
return well_info_iget_state( well_info , well_name.c_str() , time_index );
}
/*****************************************************************/
int well_info_get_num_wells( const well_info_type * well_info ) {
return stringlist_get_size( well_info->well_names );
return well_info->well_names.size();
}
const char * well_info_iget_well_name( const well_info_type * well_info, int well_index) {
return stringlist_iget( well_info->well_names , well_index);
const std::string& well_name = well_info->well_names[well_index];
return well_name.c_str();
}

View File

@ -1,9 +0,0 @@
/*
Warning: The libecl code has changed to be compiled as a C++ project. This
header file is retained for a period for compatibility, but you are encouraged
to switch to include the new hpp header directly in your code.
*/
#include <ert/ecl/ecl_box.hpp>

View File

@ -19,30 +19,23 @@
#ifndef ERT_ECL_BOX_H
#define ERT_ECL_BOX_H
#include <vector>
#include <ert/ecl/ecl_grid.hpp>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ecl_box_struct ecl_box_type;
namespace ecl {
class ecl_box {
public:
ecl_box(const ecl_grid_type * grid, int i1, int i2, int j1, int j2, int k1, int k2);
const std::vector<int>& active_list() const;
private:
const ecl_grid_type * grid;
void ecl_box_set_size (ecl_box_type * , int , int , int , int , int , int );
ecl_box_type * ecl_box_alloc(const ecl_grid_type * ecl_grid , int i1,int i2 , int j1 , int j2 , int k1, int k2);
void ecl_box_free (ecl_box_type * );
void ecl_box_set_values(const ecl_box_type * , char * , const char * , int );
int ecl_box_get_total_size(const ecl_box_type * );
int ecl_box_get_active_size( const ecl_box_type * ecl_box );
const int * ecl_box_get_active_list( const ecl_box_type * ecl_box );
int ecl_box_get_global_size( const ecl_box_type * ecl_box );
const int * ecl_box_get_global_list( const ecl_box_type * ecl_box );
bool ecl_box_contains(const ecl_box_type * box , int i , int j , int k);
int i1,i2,j1,j2,k1,k2;
std::vector<int> active_index_list;
std::vector<int> global_index_list;
};
UTIL_IS_INSTANCE_HEADER( ecl_box );
UTIL_SAFE_CAST_HEADER( ecl_box );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -20,18 +20,19 @@
#ifndef ERT_ECL_GRAV_COMMON_H
#define ERT_ECL_GRAV_COMMON_H
#include <stdbool.h>
#include <ert/ecl/ecl_file.hpp>
#include "detail/ecl/ecl_grid_cache.hpp"
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <ert/ecl/ecl_grid_cache.hpp>
#include <ert/ecl/ecl_file.hpp>
bool * ecl_grav_common_alloc_aquifer_cell(const ecl_grid_cache_type * grid_cache,
bool * ecl_grav_common_alloc_aquifer_cell(const ecl::ecl_grid_cache& grid_cache,
const ecl_file_type * init_file);
double ecl_grav_common_eval_biot_savart(const ecl_grid_cache_type * grid_cache,
double ecl_grav_common_eval_biot_savart(const ecl::ecl_grid_cache& grid_cache,
ecl_region_type * region,
const bool * aquifer,
const double * weight,
@ -39,7 +40,7 @@ double ecl_grav_common_eval_biot_savart(const ecl_grid_cache_type * grid_cache,
double utm_y,
double depth);
double ecl_grav_common_eval_geertsma(const ecl_grid_cache_type * grid_cache,
double ecl_grav_common_eval_geertsma(const ecl::ecl_grid_cache& grid_cache,
ecl_region_type * region,
const bool * aquifer,
const double * weight,

View File

@ -261,6 +261,12 @@ extern "C" {
void ecl_grid_export_cell_corners1(const ecl_grid_type * grid, int global_index, double *x, double *y, double *z);
ert_ecl_unit_enum ecl_grid_get_unit_system(const ecl_grid_type * grid);
void ecl_grid_export_index(const ecl_grid_type * grid, int * global_index, int * index_data , bool active_only);
void ecl_grid_export_data_as_int( int index_size, const int * global_index, const ecl_kw_type * kw, int * output);
void ecl_grid_export_data_as_double( int index_size, const int * data_index, const ecl_kw_type * kw, double * output);
void ecl_grid_export_volume( const ecl_grid_type * grid, int index_size, const int * global_index, double * output );
void ecl_grid_export_position( const ecl_grid_type * grid, int index_size, const int * global_index, double * output);
void export_corners( const ecl_grid_type * grid, int index_size, const int * global_index, double * output);
UTIL_IS_INSTANCE_HEADER( ecl_grid );
UTIL_SAFE_CAST_HEADER( ecl_grid );

View File

@ -1,9 +0,0 @@
/*
Warning: The libecl code has changed to be compiled as a C++ project. This
header file is retained for a period for compatibility, but you are encouraged
to switch to include the new hpp header directly in your code.
*/
#include <ert/ecl/ecl_grid_cache.hpp>

View File

@ -1,47 +0,0 @@
/*
Copyright (C) 2011 Statoil ASA, Norway.
The file 'ecl_grid_cache.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 <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#ifndef ERT_ECL_GRID_CACHE_H
#define ERT_ECL_GRID_CACHE_H
#include <ert/ecl/ecl_grid.hpp>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ecl_grid_cache_struct ecl_grid_cache_type;
ecl_grid_cache_type * ecl_grid_cache_alloc( const ecl_grid_type * grid );
int ecl_grid_cache_get_size( const ecl_grid_cache_type * grid_cache );
int ecl_grid_cache_iget_global_index( const ecl_grid_cache_type * grid_cache , int active_index);
const int * ecl_grid_cache_get_global_index( const ecl_grid_cache_type * grid_cache );
const double * ecl_grid_cache_get_xpos( const ecl_grid_cache_type * grid_cache );
const double * ecl_grid_cache_get_ypos( const ecl_grid_cache_type * grid_cache );
const double * ecl_grid_cache_get_zpos( const ecl_grid_cache_type * grid_cache );
const double * ecl_grid_cache_get_volume( const ecl_grid_cache_type * grid_cache );
void ecl_grid_cache_free( ecl_grid_cache_type * grid_cache );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -24,7 +24,6 @@
#include <ert/geometry/geo_polygon.hpp>
#include <ert/ecl/ecl_box.hpp>
#include <ert/ecl/ecl_grid.hpp>
#include <ert/ecl/layer.hpp>
@ -89,9 +88,6 @@ typedef struct ecl_region_struct ecl_region_type;
void ecl_region_select_active_cells( ecl_region_type * region );
void ecl_region_deselect_active_cells( ecl_region_type * region );
void ecl_region_select_from_box( ecl_region_type * region , const ecl_box_type * ecl_box );
void ecl_region_deselect_from_box( ecl_region_type * region , const ecl_box_type * ecl_box );
void ecl_region_select_from_ijkbox( ecl_region_type * region , int i1 , int i2 , int j1 , int j2 , int k1 , int k2);
void ecl_region_deselect_from_ijkbox( ecl_region_type * region , int i1 , int i2 , int j1 , int j2 , int k1 , int k2);

View File

@ -1,101 +0,0 @@
/*
Copyright (C) 2016 Statoil ASA, Norway.
This is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or1
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#ifndef ERT_TEST_AREA_CXX
#define ERT_TEST_AREA_CXX
#include <string>
#include <ert/util/test_work_area.hpp>
#include <ert/util/ert_unique_ptr.hpp>
/*
The TestArea class will create a random temporary and call chdir()
into this directory. When the TestArea instance goes out of scope
the directory will be removed.
In addition to the cleanup the main feature of the TestArea
implementation are in the copyXXX() methods, these methods all
interpret the input argument relative to the original cwd. This is
quite convenient when you need to copy input files to the test
directory.
*/
namespace ERT {
class TestArea {
public:
TestArea( );
TestArea( const std::string& name );
void enter(const std::string& name );
/* Will copy one file into work area. */
void copyFile( const std::string& filename) const;
/* Will copy a directory with all content recursively into the
work area. */
void copyDirectory( const std::string& directory) const;
/*
Will copy all the content of a directory into the work area, i.e.
if your directory looks like:
path0/file1.txt
path0/file2.txt
path0/subdir/file3.txt
copyDirectoryContet( "path0" ) will copy the files file1.txt,
file2.txt and the directory subdir into work area.
*/
void copyDirectoryContent( const std::string& directory) const;
/*
Will determine the directory holding the input entry, and copy
the content of that directory, i.e. the following are
equivalent:
copyDirectoryContent("path0") <=> copyParentContent("path0/file1.txt")
*/
void copyParentContent( const std::string& entry ) const;
/*
Will call copyDircetory( ) with the directory holding this
entry:
copyDirectory("path0") <=> copyParentDirectory("path0/file1.txt")
*/
void copyParentDirectory( const std::string& entry ) const;
std::string getCwd() const;
std::string getOriginalCwd() const;
void setStore(bool store);
private:
std::string inputPath( const std::string& path) const;
void assertOpen( ) const;
void assertFileExists( const std::string& ) const;
void assertDirectoryExists( const std::string& ) const;
void assertEntryExists( const std::string& ) const;
ert_unique_ptr<test_work_area_type , test_work_area_free> c_ptr;
};
}
#endif

View File

@ -27,12 +27,11 @@ extern "C" {
typedef struct path_stack_struct path_stack_type;
path_stack_type * path_stack_alloc();
const char * path_stack_pop( path_stack_type * path_stack );
void path_stack_pop( path_stack_type * path_stack );
void path_stack_push_cwd( path_stack_type * path_stack );
bool path_stack_push( path_stack_type * path_stack , const char * path );
void path_stack_free( path_stack_type * path_stack );
int path_stack_size( const path_stack_type * path_stack );
const char * path_stack_peek( const path_stack_type * path_stack );
#ifdef __cplusplus
}

View File

@ -50,8 +50,6 @@ typedef bool ( file_pred_ftype) (const char *, const void *);
void stringlist_clear(stringlist_type * );
void stringlist_append_copy(stringlist_type * , const char *);
void stringlist_append_ref(stringlist_type * , const char *);
void stringlist_append_owned_ref(stringlist_type * , const char *);
const char * stringlist_safe_iget( const stringlist_type * stringlist , int index);
bool stringlist_unique(const stringlist_type * stringlist );
@ -86,14 +84,10 @@ typedef bool ( file_pred_ftype) (const char *, const void *);
stringlist_type * stringlist_alloc_argv_copy(const char ** , int );
stringlist_type * stringlist_alloc_argv_ref (const char ** , int );
stringlist_type * stringlist_alloc_argv_owned_ref(const char ** argv , int argc);
stringlist_type * stringlist_alloc_shallow_copy(const stringlist_type *);
stringlist_type * stringlist_alloc_shallow_copy_with_offset(const stringlist_type * stringlist, int offset);
stringlist_type * stringlist_alloc_shallow_copy_with_limits(const stringlist_type * stringlist, int offset , int num_strings);
stringlist_type * stringlist_alloc_from_split( const char * input_string , const char * sep );
stringlist_type * stringlist_fread_alloc(FILE * );
void stringlist_append_stringlist_copy(stringlist_type * , const stringlist_type * );
void stringlist_append_stringlist_ref(stringlist_type * , const stringlist_type * );
void stringlist_insert_stringlist_copy(stringlist_type * , const stringlist_type *, int);
bool stringlist_equal(const stringlist_type * , const stringlist_type *);

View File

@ -0,0 +1,49 @@
/*
Copyright (C) 2011 Statoil ASA, Norway.
The file 'ecl_grid_cache.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 <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#ifndef ERT_ECL_GRID_CACHE_H
#define ERT_ECL_GRID_CACHE_H
#include <vector>
#include <ert/ecl/ecl_grid.hpp>
namespace ecl {
class ecl_grid_cache {
public:
ecl_grid_cache(const ecl_grid_type * grid);
const std::vector<double>& volume() const;
const std::vector<double>& xpos() const { return this->xp; }
const std::vector<double>& ypos() const { return this->yp; }
const std::vector<double>& zpos() const { return this->zp; }
const std::vector<int>& global_index( ) const { return this->gi; }
int size() const { return this->xp.size(); }
private:
const ecl_grid_type * grid;
std::vector<int> gi;
std::vector<double> xp;
std::vector<double> yp;
std::vector<double> zp;
mutable std::vector<double> v;
};
}
#endif

View File

@ -0,0 +1,32 @@
#ifndef PATH_UTIL
#define PATH_UTIL
#include <string>
namespace ecl {
namespace util {
namespace path {
/*
Observe that these functions are purely based on string inspection; i.e.
the actual filesystem is *never* consulted. Furthermore the functions
interpret the argument as a *filename* - that implies the (maybe
surprising) semantics:
dirname("/tmp") => "/"
basename("/tmp") => "tmp"
Although if you actually checked the filesystem you would of course
discover that /tmp actually is a directory. This is the same behaviour
as the os.path.dirname() and os.path.basename() functions in the Python
library.
*/
std::string dirname(const std::string& fname);
std::string basename(const std::string& fname);
std::string extension(const std::string& fname);
}
}
}
#endif

View File

@ -0,0 +1,13 @@
#ifndef ECL_STRING_UTIL
#define ECL_STRING_UTIL
#include <string>
namespace ecl {
namespace util {
std::string string_format(const char * fmt, ...);
}
}
#endif

View File

@ -1,123 +0,0 @@
/*
Copyright (C) 2016 Statoil ASA, Norway.
This is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or1
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <string>
#include <ert/util/util.h>
#include <ert/util/TestArea.hpp>
#include <cstdlib>
#include <memory>
#include <stdexcept>
namespace ERT {
TestArea::TestArea( )
{
}
TestArea::TestArea( const std::string& name )
{
enter( name );
}
void TestArea::enter( const std::string& name ) {
c_ptr.reset( test_work_area_alloc( name.c_str() ));
}
void TestArea::setStore(bool store) {
assertOpen();
test_work_area_set_store( c_ptr.get() , store );
}
std::string TestArea::getOriginalCwd() const {
assertOpen();
std::string orgCwd( test_work_area_get_original_cwd( c_ptr.get() ));
return orgCwd;
}
std::string TestArea::getCwd() const {
char * cwd_ptr = util_alloc_cwd( );
std::string cwd( cwd_ptr );
free( cwd_ptr );
return cwd;
}
std::string TestArea::inputPath( const std::string& path) const {
assertOpen();
{
char * ptr = test_work_area_alloc_input_path( c_ptr.get() , path.c_str());
std::string input_path( ptr );
free( ptr );
return input_path;
}
}
void TestArea::assertOpen() const {
if (!c_ptr)
throw std::runtime_error("Must call TestArea::enter( \"name\" ) before invoking copy operations");
}
void TestArea::assertFileExists( const std::string& filename ) const {
std::string input_file = inputPath( filename );
if (!util_is_file( input_file.c_str() ))
throw std::invalid_argument("File " + filename + " does not exist ");
}
void TestArea::assertDirectoryExists( const std::string& directory ) const {
std::string input_dir = inputPath( directory );
if (!util_is_directory( input_dir.c_str() ))
throw std::invalid_argument("Directory " + directory + " does not exist ");
}
void TestArea::assertEntryExists( const std::string& entry ) const {
std::string input_entry = inputPath( entry );
if (!util_entry_exists( input_entry.c_str() ))
throw std::invalid_argument("Entry " + entry+ " does not exist ");
}
void TestArea::copyFile( const std::string& filename ) const {
assertFileExists( filename );
test_work_area_copy_file( c_ptr.get() , filename.c_str() );
}
void TestArea::copyDirectory( const std::string& directory) const {
assertDirectoryExists( directory );
test_work_area_copy_directory( c_ptr.get() , directory.c_str() );
}
void TestArea::copyDirectoryContent( const std::string& directory) const {
assertDirectoryExists( directory );
test_work_area_copy_directory_content( c_ptr.get() , directory.c_str() );
}
void TestArea::copyParentContent( const std::string& entry ) const {
assertEntryExists( entry );
test_work_area_copy_parent_content( c_ptr.get() , entry.c_str() );
}
void TestArea::copyParentDirectory( const std::string& entry ) const {
assertEntryExists( entry );
test_work_area_copy_parent_directory( c_ptr.get() , entry.c_str() );
}
}

View File

@ -0,0 +1,45 @@
/*
Copyright (C) 2018 Equinor Statoil ASA, Norway.
The file 'cxx_string_util.cpp' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <string>
#include <stdarg.h>
namespace ecl {
namespace util {
std::string string_format(const char* fmt, ...) {
int length;
std::string s;
{
va_list va;
va_start(va, fmt);
length = vsnprintf(NULL, 0, fmt, va);
va_end(va);
}
s.resize(length + 1);
{
va_list va;
va_start(va, fmt);
vsprintf((char *) s.data(), fmt, va);
va_end(va);
}
return s;
}
}
}

View File

@ -453,8 +453,10 @@ stringlist_type * hash_alloc_stringlist(const hash_type * hash) {
stringlist_type * stringlist = stringlist_alloc_new();
char ** keylist = hash_alloc_keylist__(hash);
int i;
for (i = 0; i < hash_get_size( hash ); i++)
stringlist_append_owned_ref( stringlist , keylist[i] );
for (i = 0; i < hash_get_size( hash ); i++) {
stringlist_append_copy( stringlist , keylist[i] );
free(keylist[i]);
}
free( keylist );
return stringlist;

View File

@ -405,8 +405,9 @@ stringlist_type * basic_parser_tokenize_buffer(
if( is_in_quoters( buffer[position], parser ) ) {
int length = length_of_quotation( &buffer[position] );
char * token = alloc_quoted_token( &buffer[position], length, strip_quote_marks );
stringlist_append_owned_ref( tokens, token );
stringlist_append_copy( tokens, token );
position += length;
free(token);
continue;
}
@ -452,9 +453,9 @@ stringlist_type * basic_parser_tokenize_buffer(
if (token_length > 0) { /* We do not insert empty tokens. */
token[token_length] = '\0';
stringlist_append_owned_ref( tokens, token );
} else
free( token ); /* The whole thing is discarded. */
stringlist_append_copy( tokens, token );
}
free( token );
position += length;
continue;

82
ThirdParty/Ert/lib/util/path.cpp vendored Normal file
View File

@ -0,0 +1,82 @@
/*
Copyright (C) 2012 Statoil ASA, Norway.
The file 'path_stack.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 <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <string>
#include <ert/util/util.h>
#include "detail/util/path.hpp"
namespace ecl {
namespace util {
namespace path {
/*
The bizarre dive down into c_str() is to avoid inadvertendtly
introducing a symbol which is creates a ABI compatibility issue between
the libstdc++ librararies. A bug in the devtoolset compiler?
*/
std::string dirname(const std::string& fname) {
size_t last_slash = fname.rfind(UTIL_PATH_SEP_CHAR);
if (last_slash == std::string::npos)
return "";
if (last_slash == 0)
return fname.substr(0,1);
else
return fname.substr(0, last_slash);
}
std::string basename(const std::string& fname) {
size_t end_pos = fname.rfind('.');
size_t offset = fname.rfind(UTIL_PATH_SEP_CHAR);
if (offset == std::string::npos)
offset = 0;
else
offset += 1;
{
const char * c_str = fname.c_str();
if (end_pos == std::string::npos || end_pos < offset)
return util_alloc_string_copy( &c_str[offset] );
return util_alloc_substring_copy(c_str, offset, end_pos - offset);
}
}
std::string extension(const std::string& fname) {
size_t end_pos = fname.rfind('.');
size_t last_slash = fname.rfind(UTIL_PATH_SEP_CHAR);
if (end_pos == std::string::npos)
return "";
if (last_slash == std::string::npos || end_pos > last_slash) {
const char * c_str = fname.c_str();
return util_alloc_substring_copy( c_str, end_pos + 1, fname.size() - end_pos - 1);
}
return "";
}
}
}
}

View File

@ -23,6 +23,10 @@
#include <unistd.h>
#include <errno.h>
#include <vector>
#include <string>
#include <stack>
#include <ert/util/stringlist.hpp>
#include <ert/util/util.h>
#include <ert/util/path_stack.hpp>
@ -41,8 +45,7 @@
struct path_stack_struct {
stringlist_type * stack;
stringlist_type * storage;
std::stack<std::string, std::vector<std::string>> stack;
};
@ -52,24 +55,12 @@ struct path_stack_struct {
*/
path_stack_type * path_stack_alloc() {
path_stack_type * path_stack = (path_stack_type*)util_malloc( sizeof * path_stack );
path_stack->stack = stringlist_alloc_new();
path_stack->storage = stringlist_alloc_new();
path_stack_type * path_stack = new path_stack_type();
return path_stack;
}
/*
This will destroy the storage taken by the current path_stack
instance. This function will NOT pop any elements off the stack; so
if you have not manully clerad the stack with the right number of
path_stack_pop() calls, you will (probably) destroy the path stack
instance with an incorrect value of cwd.
*/
void path_stack_free( path_stack_type * path_stack ) {
stringlist_free( path_stack->stack );
stringlist_free( path_stack->storage );
free( path_stack );
delete path_stack;
}
@ -94,28 +85,24 @@ bool path_stack_push( path_stack_type * path_stack , const char * path ) {
void path_stack_push_cwd( path_stack_type * path_stack ) {
char * cwd = util_alloc_cwd();
stringlist_append_owned_ref( path_stack->storage , cwd);
stringlist_append_ref( path_stack->stack , cwd );
path_stack->stack.push(cwd);
free(cwd);
}
const char * path_stack_pop( path_stack_type * path_stack ) {
char * path = stringlist_pop( path_stack->stack );
if (util_chdir( path ) == 0)
return path;
else {
void path_stack_pop( path_stack_type * path_stack ) {
const std::string& path = path_stack->stack.top();
if (util_chdir( path.c_str() ) != 0)
// The directory has become inaccesible ...
util_abort("%s: could not pop back to directory:%s Error:%s\n", __func__ , path , strerror( errno ));
return NULL;
}
util_abort("%s: could not pop back to directory:%s Error:%s\n", __func__ , path.c_str() , strerror( errno ));
path_stack->stack.pop();
}
int path_stack_size( const path_stack_type * path_stack ) {
return stringlist_get_size( path_stack->stack );
return path_stack->stack.size();
}
const char * path_stack_peek( const path_stack_type * path_stack ) {
return stringlist_get_last( path_stack->stack );
}

View File

@ -94,15 +94,10 @@ void stringlist_fprintf_fmt(const stringlist_type * stringlist, const stringlist
This function appends a copy of s into the stringlist.
*/
void stringlist_append_copy(stringlist_type * stringlist , const char * s) {
if (s)
vector_append_buffer(stringlist->strings , s , strlen(s) + 1);
}
void stringlist_append_ref(stringlist_type * stringlist , const char * s) {
vector_append_ref(stringlist->strings , s);
}
void stringlist_append_owned_ref(stringlist_type * stringlist , const char * s) {
vector_append_owned_ref(stringlist->strings , s , free);
else
vector_append_ref(stringlist->strings, NULL );
}
/*****************************************************************/
@ -167,54 +162,7 @@ stringlist_type * stringlist_alloc_argv_copy(const char ** argv , int argc) {
}
stringlist_type * stringlist_alloc_argv_ref(const char ** argv , int argc) {
int iarg;
stringlist_type * stringlist = stringlist_alloc_empty( true );
for (iarg = 0; iarg < argc; iarg++)
stringlist_append_ref( stringlist , argv[iarg]);
return stringlist;
}
stringlist_type * stringlist_alloc_argv_owned_ref(const char ** argv , int argc) {
int iarg;
stringlist_type * stringlist = stringlist_alloc_empty( true );
for (iarg = 0; iarg < argc; iarg++)
stringlist_append_owned_ref( stringlist , argv[iarg]);
return stringlist;
}
/**
Allocates a new stringlist instance where all the new string are
references to the string found in the existing stringlist
instance.
*/
stringlist_type * stringlist_alloc_shallow_copy(const stringlist_type * src) {
stringlist_type * copy = stringlist_alloc_empty( false );
copy->strings = vector_alloc_copy( src->strings , false);
return copy;
}
/**
Allocates a new stringlist where the strings are references to the
num_strings found in stringlist from start.
*/
stringlist_type * stringlist_alloc_shallow_copy_with_limits(const stringlist_type * stringlist, int offset, int num_strings) {
stringlist_type * copy = stringlist_alloc_empty( true );
int i;
for( i=0; i<num_strings; i++)
{
const char * str = stringlist_iget(stringlist, i + offset);
vector_append_ref(copy->strings, str);
}
return copy;
}
/*
@ -251,12 +199,6 @@ void stringlist_append_stringlist_copy(stringlist_type * stringlist , const stri
}
void stringlist_append_stringlist_ref(stringlist_type * stringlist , const stringlist_type * src) {
int i;
for (i = 0; i < stringlist_get_size( src ); i++)
stringlist_append_ref(stringlist , stringlist_iget(src , i));
}
/**
Insert a copy of a stringlist in some position.
@ -277,10 +219,10 @@ void stringlist_insert_stringlist_copy(stringlist_type * stringlist, const strin
int i;
for( i=0; i<pos; i++)
stringlist_append_ref(start, stringlist_iget(stringlist, i));
stringlist_append_copy(start, stringlist_iget(stringlist, i));
for( i=pos; i<size_old; i++)
stringlist_append_ref(end , stringlist_iget(stringlist, i));
stringlist_append_copy(end , stringlist_iget(stringlist, i));
stringlist_append_stringlist_copy(newList, start);
stringlist_append_stringlist_copy(newList, src );
@ -643,8 +585,11 @@ void stringlist_fread(stringlist_type * s, FILE * stream) {
int size = util_fread_int(stream);
int i;
stringlist_clear(s);
for (i=0; i < size; i++)
stringlist_append_owned_ref( s , util_fread_alloc_string( stream ));
for (i=0; i < size; i++) {
char * tmp = util_fread_alloc_string(stream);
stringlist_append_copy( s , tmp);
free(tmp);
}
}
@ -750,7 +695,8 @@ int stringlist_select_matching_files(stringlist_type * names , const char * path
if (file_handle != INVALID_HANDLE_VALUE) {
do {
char * full_path = util_alloc_filename( path , file_data.cFileName , NULL);
stringlist_append_owned_ref( names , full_path );
stringlist_append_copy( names , full_path );
free( full_path );
} while (FindNextFile( file_handle , &file_data) != 0);
}
FindClose( file_handle );
@ -787,7 +733,11 @@ int stringlist_select_files(stringlist_type * names, const char * path, file_pre
if (predicate && !predicate(entry->d_name, pred_arg))
continue;
stringlist_append_owned_ref(names, util_alloc_filename(path, entry->d_name, NULL));
{
char * fname = util_alloc_filename(path, entry->d_name, NULL);
stringlist_append_copy(names, fname);
free(fname);
}
}
closedir(dir);
@ -809,8 +759,11 @@ int stringlist_select_files(stringlist_type * names, const char * path, file_pre
if (predicate && !predicate(file_data.cFileName, pred_arg))
continue;
stringlist_append_owned_ref(names, util_alloc_filename(path, file_data.cFileName, NULL));
{
char * tmp_fname = util_alloc_filename(path, file_data.cFileName, NULL);
stringlist_append_copy(names, tmp_fname);
free(tmp_fname);
}
} while (FindNextFile( file_handle , &file_data) != 0);
FindClose( file_handle );
}
@ -849,7 +802,7 @@ static int void_strcmp(const void* s1, const void *s2) {
bool stringlist_unique(const stringlist_type * stringlist )
{
bool unique = true;
stringlist_type * cpy = stringlist_alloc_shallow_copy(stringlist);
stringlist_type * cpy = stringlist_alloc_deep_copy(stringlist);
stringlist_sort(cpy, void_strcmp);
for (int i = 0; i < stringlist_get_size(cpy) - 1; i++) {

View File

@ -48,16 +48,10 @@ int main(int argc , char ** argv) {
if (util_is_cwd( path1 ))
test_error_exit("Failed to chdir(%s) \n",path2 );
{
if (path_stack_size( path_stack ) != 2)
test_error_exit("Wrong stack size");
if (strcmp( path1 , path_stack_peek( path_stack )) != 0)
test_error_exit("peek error");
}
path_stack_pop( path_stack );
printf("After pop: cwd:%s path1:%s \n",util_alloc_cwd() , path1);
if (!util_is_cwd( path1 ))
test_error_exit("path_stack_pop failed \n");

View File

@ -161,7 +161,8 @@ void test_spawn_redirect_threaded() {
util_make_path( path );
char * script = util_alloc_filename( path , "script" , NULL);
make_script(script, stdout_msg, stderr_msg);
stringlist_append_owned_ref(script_fullpaths, script);
stringlist_append_copy(script_fullpaths, script);
free(script);
free(path);
}

View File

@ -0,0 +1,50 @@
/*
Copyright (C) 2018 Statoil ASA, Norway.
The file 'ert_util_split_path.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 <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <ert/util/test_util.hpp>
#include "detail/util/path.hpp"
using namespace ecl::util;
int main(int argc , char ** argv) {
test_assert_std_string_equal( std::string(""), path::dirname("entry"));
test_assert_std_string_equal( std::string("entry") , path::basename("entry"));
test_assert_std_string_equal( std::string(""), path::extension("entry"));
test_assert_std_string_equal( std::string("path"), path::dirname("path/base.ext"));
test_assert_std_string_equal( std::string("base") , path::basename("path/base.ext"));
test_assert_std_string_equal( std::string("ext"), path::extension("path/base.ext"));
test_assert_std_string_equal( std::string("/tmp"), path::dirname("/tmp/file"));
test_assert_std_string_equal( std::string("file") , path::basename("/tmp/file"));
test_assert_std_string_equal( std::string(""), path::extension("/tmp/file"));
test_assert_std_string_equal( std::string("/"), path::dirname("/tmp"));
test_assert_std_string_equal( std::string("tmp") , path::basename("/tmp"));
test_assert_std_string_equal( std::string(""), path::extension("/tmp"));
test_assert_std_string_equal( std::string("/tmp/user.ext"), path::dirname("/tmp/user.ext/file.ext"));
test_assert_std_string_equal( std::string("file") , path::basename("/tmp/user.ext/file.ext"));
test_assert_std_string_equal( std::string("ext"), path::extension("/tmp/user.ext/file.ext"));
test_assert_std_string_equal( std::string("/tmp/user.ext"), path::dirname("/tmp/user.ext/"));
test_assert_std_string_equal( std::string("") , path::basename("/tmp/user.ext/"));
test_assert_std_string_equal( std::string(""), path::extension("/tmp/user.ext/"));
}

View File

@ -29,19 +29,15 @@ void test_char() {
const char * S2 = "S2";
const char * S3 = "S3";
stringlist_type * s = stringlist_alloc_new();
stringlist_append_ref( s , S1 );
stringlist_append_ref( s , S2 );
stringlist_append_ref( s , S3 );
stringlist_append_copy( s , S1 );
stringlist_append_copy( s , S2 );
stringlist_append_copy( s , S3 );
{
char ** ref = stringlist_alloc_char_ref( s );
char ** copy = stringlist_alloc_char_copy( s );
int i;
for (i=0; i < stringlist_get_size( s ); i++) {
if (ref[i] != stringlist_iget(s , i))
exit(1);
if (strcmp( stringlist_iget( s , i ) , copy[i]) != 0)
exit(1);
@ -67,9 +63,9 @@ void test_join() {
test_assert_string_equal("", empty_join);
}
stringlist_append_ref( s , elt0 );
stringlist_append_ref( s , elt1 );
stringlist_append_ref( s , elt2 );
stringlist_append_copy( s , elt0 );
stringlist_append_copy( s , elt1 );
stringlist_append_copy( s , elt2 );
const char * sep0 = "";
const char * sep1 = "!!!";
@ -84,18 +80,18 @@ void test_join() {
test_assert_string_equal( j2, "AAA abc BBB abc CCC");
stringlist_type * s1 = stringlist_alloc_new();
stringlist_append_ref( s1 , elt0 );
stringlist_append_copy( s1 , elt0 );
test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep0));
test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep1));
test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep2));
stringlist_type * sub = stringlist_alloc_new();
stringlist_append_ref( sub , elt0 );
stringlist_append_ref( sub , elt1 );
stringlist_append_ref( sub , elt2 );
stringlist_append_ref( sub , elt3 );
stringlist_append_ref( sub , elt4 );
stringlist_append_ref( sub , elt5 );
stringlist_append_copy( sub , elt0 );
stringlist_append_copy( sub , elt1 );
stringlist_append_copy( sub , elt2 );
stringlist_append_copy( sub , elt3 );
stringlist_append_copy( sub , elt4 );
stringlist_append_copy( sub , elt5 );
test_assert_string_equal( "CCC:DDD:EEE", stringlist_alloc_joined_substring( sub, 2, 5, ":"));
}
@ -107,9 +103,9 @@ void test_reverse() {
const char *s2 = "CCC";
stringlist_type * s = stringlist_alloc_new();
stringlist_append_ref( s , s0 );
stringlist_append_ref( s , s1 );
stringlist_append_ref( s , s2 );
stringlist_append_copy( s , s0 );
stringlist_append_copy( s , s1 );
stringlist_append_copy( s , s2 );
stringlist_reverse(s);
@ -121,9 +117,9 @@ void test_reverse() {
void test_iget_as_int() {
stringlist_type * s = stringlist_alloc_new();
stringlist_append_ref(s , "1000" );
stringlist_append_ref(s , "1000X" );
stringlist_append_ref(s , "XXXX" );
stringlist_append_copy(s , "1000" );
stringlist_append_copy(s , "1000X" );
stringlist_append_copy(s , "XXXX" );
{
int value;
@ -145,9 +141,9 @@ void test_iget_as_int() {
void test_iget_as_double() {
stringlist_type * s = stringlist_alloc_new();
stringlist_append_ref(s , "1000.90" );
stringlist_append_ref(s , "1000" );
stringlist_append_ref(s , "XXXX" );
stringlist_append_copy(s , "1000.90" );
stringlist_append_copy(s , "1000" );
stringlist_append_copy(s , "XXXX" );
{
double value;
@ -170,20 +166,20 @@ void test_iget_as_double() {
void test_iget_as_bool() {
stringlist_type * s = stringlist_alloc_new();
stringlist_append_ref(s , "TRUE" );
stringlist_append_ref(s , "True" );
stringlist_append_ref(s , "true" );
stringlist_append_ref(s , "T" );
stringlist_append_ref(s , "1" );
stringlist_append_copy(s , "TRUE" );
stringlist_append_copy(s , "True" );
stringlist_append_copy(s , "true" );
stringlist_append_copy(s , "T" );
stringlist_append_copy(s , "1" );
stringlist_append_ref(s , "FALSE" );
stringlist_append_ref(s , "False" );
stringlist_append_ref(s , "false" );
stringlist_append_ref(s , "F" );
stringlist_append_ref(s , "0" );
stringlist_append_copy(s , "FALSE" );
stringlist_append_copy(s , "False" );
stringlist_append_copy(s , "false" );
stringlist_append_copy(s , "F" );
stringlist_append_copy(s , "0" );
stringlist_append_ref(s , "not_so_bool" );
stringlist_append_ref(s , "8" );
stringlist_append_copy(s , "not_so_bool" );
stringlist_append_copy(s , "8" );
{
@ -353,7 +349,7 @@ bool not_FILE_predicate(const char * name, const void * arg) {
void test_predicate_matching() {
test_work_area_type * work_area = test_work_area_alloc("predicate_test");
stringlist_type * s = stringlist_alloc_new();
stringlist_append_ref(s, "s");
stringlist_append_copy(s, "s");
stringlist_select_files(s, "does/not/exist", NULL, NULL);
test_assert_int_equal(stringlist_get_size(s), 0);
@ -395,13 +391,13 @@ void test_unique() {
test_assert_true( stringlist_unique( s ));
stringlist_append_ref( s, "S1");
stringlist_append_copy( s, "S1");
test_assert_true( stringlist_unique( s ));
stringlist_append_ref( s, "S2");
stringlist_append_copy( s, "S2");
test_assert_true( stringlist_unique( s ));
stringlist_append_ref( s, "S2");
stringlist_append_copy( s, "S2");
test_assert_false( stringlist_unique( s ));
}

View File

@ -1,86 +0,0 @@
/*
Copyright (C) 2016 Statoil ASA, Norway.
This is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or1
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <ert/util/test_util.hpp>
#include <ert/util/util.h>
#include <ert/util/TestArea.hpp>
// Warning: this test hardcodes an assumption of the name
// of the executable running as argv[0].
#define LOCAL_ARGV0 "ert_util_test_area_xx"
void test_enter( const char* argv0 ) {
ERT::TestArea ta;
test_assert_throw( ta.copyFile( argv0 ) , std::runtime_error );
ta.enter("test/enter");
ta.copyFile( argv0 );
test_assert_true( util_file_exists( LOCAL_ARGV0 ));
}
void test_copy( const char* argv0 ) {
ERT::TestArea ta("test/copy");
test_assert_throw( ta.copyFile( "does/not/exist" ) , std::invalid_argument );
test_assert_throw( ta.copyDirectory( argv0 ) , std::invalid_argument );
ta.copyFile( argv0 );
test_assert_true( util_file_exists( LOCAL_ARGV0 ));
util_unlink_existing( LOCAL_ARGV0 );
test_assert_false( util_file_exists( LOCAL_ARGV0));
ta.copyParentContent( argv0 );
test_assert_true( util_file_exists( LOCAL_ARGV0));
{
ERT::TestArea ta2("test2/copy");
ta2.copyFile( LOCAL_ARGV0 );
test_assert_true( util_file_exists( LOCAL_ARGV0));
}
}
void test_create() {
char * cwd0 = util_alloc_cwd();
char * cwd1;
{
ERT::TestArea ta("test/area");
cwd1 = util_alloc_cwd();
test_assert_string_not_equal( cwd0 , cwd1 );
test_assert_string_equal( cwd1 , ta.getCwd().c_str());
test_assert_string_equal( cwd0 , ta.getOriginalCwd( ).c_str() );
}
test_assert_false( util_is_directory(cwd1) );
free( cwd1 );
free( cwd0 );
}
int main(int argc , char **argv) {
test_create();
test_assert_true( util_file_exists( argv[0] ));
test_copy( argv[0] );
test_enter( argv[0] );
}

View File

@ -1,5 +1,3 @@
install( DIRECTORY cmake DESTINATION share )
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
include(init_python)
init_python( 2.7 )

View File

@ -13,6 +13,11 @@ add_subdirectory(summary)
add_subdirectory(util)
add_subdirectory(well)
if (INSTALL_ERT_LEGACY)
add_subdirectory(ecl)
endif()
configure_file(ecl_lib_info_build.py.in ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl/__ecl_lib_info.py )
configure_file(ecl_lib_info_install.py.in ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl_lib_info_install.py )
install(FILES ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl_lib_info_install.py DESTINATION ${PYTHON_INSTALL_PREFIX}/ecl RENAME __ecl_lib_info.py)

View File

@ -111,12 +111,16 @@ if ecl_lib_path:
if not os.path.isdir( ecl_lib_path ):
ecl_lib_path = None
if sys.hexversion < required_version_hex:
raise Exception("ERT Python requires Python 2.7.")
def load(name):
try:
return cwrapload(name, path=ecl_lib_path, so_version=ert_so_version)
except ImportError:
# For pip installs, setup.py puts the shared lib in this directory
own_dir=os.path.dirname(os.path.abspath(__file__))
return cwrapload(name, path=own_dir, so_version=ert_so_version)
class EclPrototype(Prototype):
lib = load("libecl")

View File

@ -0,0 +1,5 @@
set(PYTHON_SOURCES
__init__.py
)
add_python_package("python.ecl.ecl" ${PYTHON_INSTALL_PREFIX}/ecl/ecl "${PYTHON_SOURCES}" True)

View File

@ -0,0 +1,12 @@
# The structure of the python packages have been reorganized several times,
# unfortunately we have not managed to deprecate properly and guide users over
# to the new layout. We therefor now have two(?) varietes of old layout which
# must(?) be supported for a while.
#
# from ert.ecl import EclEgrid
# from ecl.ecl import EclGrid
#
# Both of these legacy forms are controlled by the cmake switch
# INSTALL_ERT_LEGACY.
from ert.ecl import *

View File

@ -13,6 +13,7 @@
#
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from __future__ import absolute_import
from cwrap import BaseCClass, BaseCEnum
from ecl import EclPrototype

View File

@ -24,7 +24,7 @@ BaseCEnum class from cwrap.
In addition to the enum definitions there are a few stateless
functions from ecl_util.c which are not bound to any class type.
"""
from __future__ import absolute_import
import ctypes
from cwrap import BaseCEnum

View File

@ -27,6 +27,7 @@ import ctypes
import warnings
import numpy
import pandas
import sys
import os.path
import math
@ -36,7 +37,7 @@ from cwrap import CFILE, BaseCClass, load, open as copen
from ecl import EclPrototype
from ecl.util.util import monkey_the_camel
from ecl.util.util import IntVector
from ecl import EclDataType, EclUnitTypeEnum
from ecl import EclDataType, EclUnitTypeEnum, EclTypeEnum
from ecl.eclfile import EclKW, FortIO
from ecl.grid import Cell
@ -116,6 +117,12 @@ class EclGrid(BaseCClass):
_export_actnum = EclPrototype("ecl_kw_obj ecl_grid_alloc_actnum_kw(ecl_grid)")
_export_mapaxes = EclPrototype("ecl_kw_obj ecl_grid_alloc_mapaxes_kw(ecl_grid)")
_get_unit_system = EclPrototype("ecl_unit_enum ecl_grid_get_unit_system(ecl_grid)")
_export_index_frame = EclPrototype("void ecl_grid_export_index(ecl_grid, int*, int*, bool)")
_export_data_as_int = EclPrototype("void ecl_grid_export_data_as_int(int, int*, ecl_kw, int*)", bind = False)
_export_data_as_double = EclPrototype("void ecl_grid_export_data_as_double(int, int*, ecl_kw, double*)", bind = False)
_export_volume = EclPrototype("void ecl_grid_export_volume(ecl_grid, int, int*, double*)")
_export_position = EclPrototype("void ecl_grid_export_position(ecl_grid, int, int*, double*)")
_export_corners = EclPrototype("void export_corners(ecl_grid, int, int*, double*)")
@ -1254,6 +1261,136 @@ class EclGrid(BaseCClass):
return self._create_volume_keyword(active_size)
def export_index(self, active_only = False):
"""
Exports a pandas dataframe containing index data of grid cells.
The global_index of the cells is used as index in the pandas frame.
columns 0, 1, 2 are i, j, k, respectively
column 3 contains the active_index
if active_only == True, only active cells are listed,
otherwise all cells are listed.
This index frame should typically be passed to the epxport_data(),
export_volume() and export_corners() functions.
"""
if active_only:
size = self.get_num_active()
else:
size = self.get_global_size()
indx = numpy.zeros(size, dtype=numpy.int32)
data = numpy.zeros([size, 4], dtype=numpy.int32)
self._export_index_frame( indx.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)), data.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)), active_only )
df = pandas.DataFrame(data=data, index=indx, columns=['i', 'j', 'k', 'active'])
return df
def export_data(self, index_frame, kw, default = 0):
"""
Exports keywoard data to a numpy vector.
Index_fram must be a pandas dataframe with the same structure
as obtained from export_index.
kw must have size of either global_size or num_active.
The length of the numpy vector is the number of rows in index_frame.
If kw is of length num_active, values in the output vector
corresponding to inactive cells are set to default.
"""
if not isinstance(index_frame, pandas.DataFrame):
raise TypeError("index_frame must be pandas.DataFrame")
if len(kw) == self.get_global_size():
index = numpy.array( index_frame.index, dtype=numpy.int32 )
elif len(kw) == self.get_num_active():
index = numpy.array( index_frame["active"], dtype=numpy.int32 )
else:
raise ValueError("The keyword must have a 3D compatible length")
if kw.type is EclTypeEnum.ECL_INT_TYPE:
data = numpy.full( len(index), default, dtype=numpy.int32 )
self._export_data_as_int( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
kw,
data.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)) )
return data
elif kw.type is EclTypeEnum.ECL_FLOAT_TYPE or kw.type is EclTypeEnum.ECL_DOUBLE_TYPE:
data = numpy.full( len(index), default, dtype=numpy.float64 )
self._export_data_as_double( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
kw,
data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) )
return data
else:
raise TypeError("Keyword must be either int, float or double.")
def export_volume(self, index_frame):
"""
Exports cell volume data to a numpy vector.
Index_fram must be a pandas dataframe with the same structure
as obtained from export_index.
"""
index = numpy.array( index_frame.index, dtype=numpy.int32 )
data = numpy.zeros( len(index ), dtype=numpy.float64 )
self._export_volume( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) )
return data
def export_position(self, index_frame):
"""Exports cell position coordinates to a numpy vector (matrix), with columns
0, 1, 2 denoting coordinates x, y, and z, respectively.
Index_fram must be a pandas dataframe with the same structure
as obtained from export_index.
"""
index = numpy.array( index_frame.index, dtype=numpy.int32 )
data = numpy.zeros( [len(index), 3], dtype=numpy.float64 )
self._export_position( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) )
return data
def export_corners(self, index_frame):
"""Exports cell corner position coordinates to a numpy vector (matrix).
Index_fram must be a pandas dataframe with the same structure
as obtained from export_index.
Example of a row of the output matrix:
0 1 2 .... 21 22 23
x1 y1 z1 .... x8 y8 z8
In total there are eight 8 corners. They are described as follows:
The corners in a cell are numbered 0 - 7, where corners 0-3 constitute
one layer and the corners 4-7 consitute the other layer. Observe
that the numbering does not follow a consistent rotation around the face:
j
6---7 /|\
| | |
4---5 |
|
o----------> i
2---3
| |
0---1
Many grids are left-handed, i.e. the direction of increasing z will
point down towards the center of the earth. Hence in the figure above
the layer 4-7 will be deeper down in the reservoir than layer 0-3, and
also have higher z-value.
Warning: The main author of this code suspects that the coordinate
system can be right-handed as well, giving a z axis which will
increase 'towards the sky'; the safest way is probably to check this
explicitly if it matters for the case at hand.
"""
index = numpy.array( index_frame.index, dtype=numpy.int32 )
data = numpy.zeros( [len(index), 24], dtype=numpy.float64 )
self._export_corners( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) )
return data
def export_coord(self):
return self._export_coord()

View File

@ -1,6 +1,7 @@
set(TEST_SOURCES
__init__.py
test_deprecation.py
test_ecl_ecl.py
test_removed.py
test_ecl_3dkw.py
test_ecl_file_statoil.py
@ -17,8 +18,12 @@ set(TEST_SOURCES
test_grdecl_statoil.py
test_grdecl.py
test_grid.py
test_grid_pandas.py
test_cell.py
test_grid_statoil.py
test_grid_statoil_coarse.py
test_grid_statoil_dual.py
test_grid_statoil_large_case.py
test_grid_generator.py
test_indexed_read.py
test_ecl_kw_statoil.py
@ -49,6 +54,7 @@ add_python_package("python.tests.ecl_tests" ${PYTHON_INSTALL_PREFIX}/tests/ecl_
addPythonTest(tests.ecl_tests.test_fk_user_data.FKTest)
addPythonTest(tests.ecl_tests.test_cell.CellTest)
addPythonTest(tests.ecl_tests.test_grid.GridTest LABELS SLOW_1)
addPythonTest(tests.ecl_tests.test_grid_pandas.GridPandasTest)
addPythonTest(tests.ecl_tests.test_grid_generator.GridGeneratorTest LABELS SLOW_2)
addPythonTest(tests.ecl_tests.test_ecl_kw.KWTest LABELS SLOW_2)
addPythonTest(tests.ecl_tests.test_kw_function.KWFunctionTest)
@ -72,11 +78,18 @@ addPythonTest(tests.ecl_tests.test_ecl_type.EclDataTypeTest)
addPythonTest(tests.ecl_tests.test_region.RegionTest)
addPythonTest(tests.ecl_tests.test_debug.DebugTest)
if (INSTALL_ERT_LEGACY)
addPythonTest(tests.ecl_tests.test_ecl_ecl.EclEclTest)
endif()
addPythonTest(tests.ecl_tests.test_ecl_file_statoil.EclFileStatoilTest)
addPythonTest(tests.ecl_tests.test_grdecl_statoil.GRDECLStatoilTest)
addPythonTest(tests.ecl_tests.test_grdecl.GRDECLTest)
addPythonTest(tests.ecl_tests.test_grid_statoil.GridTest)
addPythonTest(tests.ecl_tests.test_grid_statoil_coarse.GridCoarceTest)
addPythonTest(tests.ecl_tests.test_grid_statoil_dual.GridDualTest)
addPythonTest(tests.ecl_tests.test_grid_statoil_large_case.GridLargeCaseTest)
addPythonTest(tests.ecl_tests.test_ecl_kw_statoil.KWTest)
addPythonTest(tests.ecl_tests.test_ecl_init_file.InitFileTest)
addPythonTest(tests.ecl_tests.test_ecl_restart_file.RestartFileTest)

View File

@ -0,0 +1,15 @@
from tests import EclTest
class EclEclTest(EclTest):
def test_import(self):
import ecl.ecl as ecl
grid = ecl.EclGrid
sum = ecl.EclSum
f = ecl.EclFile
rft = ecl.EclRFTFile
def test_import2(self):
from ecl.ecl import EclFile
from ecl.ecl import EclGrid
from ecl.ecl import EclSum

View File

@ -183,10 +183,32 @@ class EclFileTest(EclTest):
with TestAreaContext("test_broken_file"):
with open("CASE.FINIT", "w") as f:
f.write("This - is not a ECLISPE file\nsdlcblhcdbjlwhc\naschscbasjhcasc\nascasck c s s aiasic asc")
with self.assertRaises(IOError):
f = EclFile("CASE.FINIT")
self.assertEqual(len(f), 0)
kw = EclKW("HEADER", 100, EclDataType.ECL_INT)
with openFortIO("FILE",mode=FortIO.WRITE_MODE) as f:
kw.fwrite(f)
kw.fwrite(f)
with open("FILE", "a+") as f:
f.write("Seom random gibberish")
f = EclFile("FILE")
self.assertEqual(len(f), 2)
with openFortIO("FILE",mode=FortIO.WRITE_MODE) as f:
kw.fwrite(f)
kw.fwrite(f)
file_size = os.path.getsize("FILE")
with open("FILE", "a+") as f:
f.truncate(file_size * 0.75)
f = EclFile("FILE")
self.assertEqual(len(f), 1)
def test_block_view(self):

View File

@ -137,19 +137,6 @@ class EclFileStatoilTest(EclTest):
self.assertFilesAreEqual("ECLIPSE.FUNRST", self.test_fmt_file)
def test_truncated(self):
with TestAreaContext("python/ecl_file/truncated") as work_area:
work_area.copy_file(self.test_file)
size = os.path.getsize("ECLIPSE.UNRST")
with open("ECLIPSE.UNRST" , "r+") as f:
f.truncate( size / 2 )
with self.assertRaises(IOError):
rst_file = EclFile("ECLIPSE.UNRST")
with self.assertRaises(IOError):
rst_file = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
def test_restart_view(self):
f = EclFile( self.test_file )
with self.assertRaises(ValueError):

View File

@ -16,7 +16,7 @@
# for more details.
import os.path
import six
from unittest import skipIf
from unittest import skipIf, skip
import time
import itertools
from numpy import linspace
@ -235,6 +235,10 @@ class GridTest(EclTest):
self.assertEqual( p7 , (10,20,30))
# The broken file was previously handled by the ecl_file_open() call internally
# in the ecl_grid implementation. That will now not fail for a broken file, and then
# the grid class needs to do more/better checking itself.
@skip("Needs better error checking inside in the ecl_grid")
def test_truncated_file(self):
grid = GridGen.createRectangular( (10,20,30) , (1,1,1) )
with TestAreaContext("python/ecl_grid/truncated"):

View File

@ -0,0 +1,114 @@
#!/usr/bin/env python
# Copyright (C) 2018 Statoil ASA, Norway.
#
# The file 'test_grid.pandas' is part of ERT - Ensemble based Reservoir Tool.
#
# ERT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ERT is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.
#
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
import numpy as np
import pandas as pd
from ecl import EclTypeEnum
from ecl.eclfile import EclKW
from ecl.grid import EclGrid
from tests import EclTest
class GridPandasTest(EclTest):
def test_dataframe_actnum(self):
grid = EclGrid.create_rectangular( (2,3,1), (1,1,1) , actnum=[1, 1, 0, 0, 1, 1])
df = grid.export_index(True)
index_matrix = np.array([ [0, 0, 0, 0],
[1, 0, 0, 1],
[0, 2, 0, 2],
[1, 2, 0, 3] ])
assert( np.array_equal(df.values, index_matrix) )
kw_int_active = EclKW('int_act', 4, EclTypeEnum.ECL_INT_TYPE)
kw_int_active[0] = 9
kw_int_active[1] = 8
kw_int_active[2] = 7
kw_int_active[3] = 6
data = grid.export_data(df, kw_int_active)
assert( len(data) == 4 )
assert( np.array_equal(data, np.array([9, 8, 7, 6])) )
kw_float_active = EclKW('float_at', 4, EclTypeEnum.ECL_FLOAT_TYPE)
kw_float_active[0] = 10.5
kw_float_active[1] = 9.25
kw_float_active[2] = 2.0
kw_float_active[3] = 1.625
data = grid.export_data(df, kw_float_active)
assert( len(data) == 4 )
assert( np.array_equal(data, np.array([10.5, 9.25, 2.0, 1.625])) )
kw_int_global = EclKW('int_glob', 6, EclTypeEnum.ECL_INT_TYPE)
kw_int_global[0] = 0
kw_int_global[1] = 2
kw_int_global[2] = 4
kw_int_global[3] = 6
kw_int_global[4] = 8
kw_int_global[5] = 9
data = grid.export_data(df, kw_int_global)
assert( len(data) == 4)
assert( np.array_equal(data, np.array([0, 2, 8, 9])) )
kw_double_global = EclKW('double_g', 6, EclTypeEnum.ECL_DOUBLE_TYPE)
kw_double_global[0] = 1.1
kw_double_global[1] = 2.2
kw_double_global[2] = 3.3
kw_double_global[3] = 4.4
kw_double_global[4] = 5.5
kw_double_global[5] = 6.6
data = grid.export_data(df, kw_double_global)
assert( np.array_equal(data, np.array([1.1, 2.2, 5.5, 6.6])) )
df = grid.export_index() #DataFrame has now 6 rows
global_index = df.index;
assert( np.array_equal(global_index, np.array([0, 1, 2, 3, 4, 5])) )
data = grid.export_data(df, kw_int_active, 9999)
assert( np.array_equal(data, np.array([9, 8, 9999, 9999, 7, 6])) )
data = grid.export_data(df, kw_float_active, 2222.0)
assert( np.array_equal(data, np.array([10.5, 9.25, 2222.0, 2222.0, 2.0, 1.625])) )
def test_dataframe_grid_data(self):
grid = EclGrid.create_rectangular( (2,3,1), (1,1,1) , actnum=[1, 1, 0, 0, 1, 1])
index_frame = grid.export_index()
volume_data = grid.export_volume(index_frame)
assert( len(volume_data) == 6 )
assert( np.array_equal(volume_data, np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0])) )
position_data = grid.export_position(index_frame)
x_pos = position_data[:, 0]
y_pos = position_data[:, 1]
z_pos = position_data[:, 2]
assert( np.array_equal(x_pos, np.array([0.5, 1.5, 0.5, 1.5, 0.5, 1.5])) )
assert( np.array_equal(y_pos, np.array([0.5, 0.5, 1.5, 1.5, 2.5, 2.5])) )
assert( np.array_equal(z_pos, np.array([0.5, 0.5, 0.5, 0.5, 0.5, 0.5])) )
corner_data = grid.export_corners(index_frame)
compare = np.array([[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0],
[1.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0, 1.0, 0.0, 2.0, 1.0, 0.0, 1.0, 0.0, 1.0, 2.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0],
[0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 2.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 2.0, 1.0, 1.0, 2.0, 1.0],
[1.0, 1.0, 0.0, 2.0, 1.0, 0.0, 1.0, 2.0, 0.0, 2.0, 2.0, 0.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 1.0],
[0.0, 2.0, 0.0, 1.0, 2.0, 0.0, 0.0, 3.0, 0.0, 1.0, 3.0, 0.0, 0.0, 2.0, 1.0, 1.0, 2.0, 1.0, 0.0, 3.0, 1.0, 1.0, 3.0, 1.0],
[1.0, 2.0, 0.0, 2.0, 2.0, 0.0, 1.0, 3.0, 0.0, 2.0, 3.0, 0.0, 1.0, 2.0, 1.0, 2.0, 2.0, 1.0, 1.0, 3.0, 1.0, 2.0, 3.0, 1.0]])
assert( np.array_equal(corner_data, compare) )

View File

@ -242,24 +242,6 @@ class GridTest(EclTest):
g2 = self.create("test.grdecl")
self.assertTrue(g1.equal(g2))
@skipIf(EclTest.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):
@ -293,52 +275,6 @@ class GridTest(EclTest):
self.assertEqual( bbox , ((3,3) , (7,3) , (7,7) , (3,7)))
@skipIf(EclTest.slowTestShouldNotRun(), "Slow test of dual grid skipped!")
def test_dual(self):
with TestAreaContext("python/grid-test/testDual"):
grid = EclGrid(self.egrid_file())
self.assertFalse(grid.dualGrid())
self.assertTrue(grid.getNumActiveFracture() == 0)
grid2 = EclGrid(self.grid_file())
self.assertFalse(grid.dualGrid())
self.assertTrue(grid.getNumActiveFracture() == 0)
dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID"))
self.assertTrue(dgrid.getNumActive() == dgrid.getNumActiveFracture())
self.assertTrue(dgrid.getNumActive() == 46118)
dgrid2 = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID"))
self.assertTrue(dgrid.getNumActive() == dgrid.getNumActiveFracture())
self.assertTrue(dgrid.getNumActive() == 46118)
self.assertTrue(dgrid.equal(dgrid2))
# The DUAL_DIFF grid has been manipulated to create a
# situation where some cells are only matrix active, and some
# cells are only fracture active.
dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID"))
self.assertTrue(dgrid.getNumActive() == 106)
self.assertTrue(dgrid.getNumActiveFracture() == 105)
self.assertTrue(dgrid.get_active_fracture_index(global_index=0) == -1)
self.assertTrue(dgrid.get_active_fracture_index(global_index=2) == -1)
self.assertTrue(dgrid.get_active_fracture_index(global_index=3) == 0)
self.assertTrue(dgrid.get_active_fracture_index(global_index=107) == 104)
self.assertTrue(dgrid.get_active_index(global_index=1) == 1)
self.assertTrue(dgrid.get_active_index(global_index=105) == 105)
self.assertTrue(dgrid.get_active_index(global_index=106) == -1)
self.assertTrue(dgrid.get_global_index1F(2) == 5)
dgrid.save_EGRID("DUAL_DIFF.EGRID")
dgrid2 = EclGrid("DUAL_DIFF.EGRID")
self.assertTrue(dgrid.equal(dgrid2 , verbose = True))
@skipIf(EclTest.slowTestShouldNotRun(), "Slow test of numActive large memory skipped!")
def test_num_active_large_memory(self):
case = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE")
@ -391,12 +327,6 @@ class GridTest(EclTest):
self.assertEqual( volume , grid.cell_volume( global_index = global_index ))
def test_large_case(self):
grdecl_file = self.createTestPath("Statoil/ECLIPSE/1.6.0_issueGrdecl/test_aug2016_gridOnly.grdecl")
grid = EclGrid.loadFromGrdecl( grdecl_file )
def test_lgr_get(self):
grid = EclGrid(self.createTestPath("Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID"))
for (nr,name) in [ ( 104 , "LG003017"),

View File

@ -0,0 +1,42 @@
# Copyright (C) 2018 Statoil ASA, Norway.
#
# The file 'test_grid_statoil_coarse.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 <http://www.gnu.org/licenses/gpl.html>
# for more details.
import math
from ecl.util.test import TestAreaContext
from ecl.grid import EclGrid
from tests import EclTest, statoil_test
@statoil_test()
class GridCoarceTest(EclTest):
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)

View File

@ -0,0 +1,71 @@
# Copyright (C) 2018 Statoil ASA, Norway.
#
# The file 'test_grid_statoil_dual.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 <http://www.gnu.org/licenses/gpl.html>
# for more details.
import math
from ecl.util.test import TestAreaContext
from ecl.grid import EclGrid
from tests import EclTest, statoil_test
@statoil_test()
class GridDualTest(EclTest):
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 test_dual(self):
with TestAreaContext("python/grid-test/testDual"):
grid = EclGrid(self.egrid_file())
self.assertFalse(grid.dualGrid())
self.assertTrue(grid.getNumActiveFracture() == 0)
grid2 = EclGrid(self.grid_file())
self.assertFalse(grid.dualGrid())
self.assertTrue(grid.getNumActiveFracture() == 0)
dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID"))
self.assertTrue(dgrid.getNumActive() == dgrid.getNumActiveFracture())
self.assertTrue(dgrid.getNumActive() == 46118)
dgrid2 = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID"))
self.assertTrue(dgrid.getNumActive() == dgrid.getNumActiveFracture())
self.assertTrue(dgrid.getNumActive() == 46118)
self.assertTrue(dgrid.equal(dgrid2))
# The DUAL_DIFF grid has been manipulated to create a
# situation where some cells are only matrix active, and some
# cells are only fracture active.
dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID"))
self.assertTrue(dgrid.getNumActive() == 106)
self.assertTrue(dgrid.getNumActiveFracture() == 105)
self.assertTrue(dgrid.get_active_fracture_index(global_index=0) == -1)
self.assertTrue(dgrid.get_active_fracture_index(global_index=2) == -1)
self.assertTrue(dgrid.get_active_fracture_index(global_index=3) == 0)
self.assertTrue(dgrid.get_active_fracture_index(global_index=107) == 104)
self.assertTrue(dgrid.get_active_index(global_index=1) == 1)
self.assertTrue(dgrid.get_active_index(global_index=105) == 105)
self.assertTrue(dgrid.get_active_index(global_index=106) == -1)
self.assertTrue(dgrid.get_global_index1F(2) == 5)
dgrid.save_EGRID("DUAL_DIFF.EGRID")
dgrid2 = EclGrid("DUAL_DIFF.EGRID")
self.assertTrue(dgrid.equal(dgrid2 , verbose = True))

View File

@ -0,0 +1,29 @@
# Copyright (C) 2018 Statoil ASA, Norway.
#
# The file 'test_grid_statoil_large_case.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 <http://www.gnu.org/licenses/gpl.html>
# for more details.
import math
from ecl.util.test import TestAreaContext
from ecl.grid import EclGrid
from tests import EclTest, statoil_test
@statoil_test()
class GridLargeCaseTest(EclTest):
def test_large_case(self):
grdecl_file = self.createTestPath("Statoil/ECLIPSE/1.6.0_issueGrdecl/test_aug2016_gridOnly.grdecl")
grid = EclGrid.loadFromGrdecl( grdecl_file )

View File

@ -576,3 +576,12 @@ class SumTest(EclTest):
self.assertFalse(case.can_write())
with self.assertRaises(NotImplementedError):
case.fwrite( )
def test_directory_conflict(self):
with TestAreaContext("dir_conflict"):
case = create_case("UNITS")
case.fwrite()
os.mkdir("UNITS")
case2 = EclSum("./UNITS")

View File

@ -528,3 +528,10 @@ class SumTest(EclTest):
def test_summary_units(self):
self.assertEqual(self.ecl_sum.unit_system, EclUnitTypeEnum.ECL_METRIC_UNITS)
# The case loaded in this test originates in a simulation
# which was shut down brutally. This test verifies that we
# can create a valid ecl_sum instance from what we find.
def test_broken_case(self):
ecl_sum = EclSum( self.createTestPath("Statoil/ECLIPSE/SummaryFail3/COMBINED-AUTUMN2018_CARBSENS-0"))

View File

@ -5,7 +5,7 @@
%define tag final
Name: ecl
Version: 2018.04
Version: 2018.10
Release: 0
Summary: ECL library
License: GPL-3+

View File

@ -13,7 +13,7 @@ def getPRList( api_token, pr1, pr2):
sys.stderr.write("Downloading PR: ")
while True:
url = url_fmt % pr
response = requests.get( url , {"access_token" : api_token})
response = requests.get( url , params = {"access_token" : api_token})
for i in range(prev_len):
sys.stdout.write("\b")
@ -38,11 +38,14 @@ def printPRList( pr_list , fileH):
title = pr["title"]
body = pr["body"]
nr = pr["number"]
url = "https://github.com/Statoil/libecl/pull/{}/".format(nr)
try:
fileH.write( "[%d] *%s*\n\n" % (nr , title))
title = str(title)
except UnicodeEncodeError:
fileH.write(" [%d] : UnicodeError")
title = "UnicodeError"
fileH.write( "[`{nr} <{url}>`] : {title}".format(nr = nr, url=url, title = title))
try:
fileH.write( "%s\n\n\n" % body )
@ -63,7 +66,7 @@ def main():
filename = "/tmp/relnotes-%d-%d" % (pr1 , pr2)
printPRList( pr_list , open(filename , "w"))
print "Have created file: %s which can be a starting point for release notes" % filename
print "\nHave created file: %s which can be a starting point for release notes" % filename

52
ThirdParty/Ert/setup.py vendored Normal file
View File

@ -0,0 +1,52 @@
import os
import subprocess
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext
from distutils.version import LooseVersion
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def run(self):
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
cmake_args = [] # Fill in extra stuff we may need
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir]
cfg = 'Debug' if self.debug else 'Release'
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
build_args = ['--config', cfg, '--', '-j2']
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
env = os.environ.copy()
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
setup(
name='statoil_libecl',
version='0.1.1',
author_email='chandan.nath@gmail.com',
description='libecl',
long_description=open("README.md", "r").read(),
long_description_content_type="text/markdown",
url="https://github.com/statoil/libecl",
license="GNU General Public License, Version 3, 29 June 2007",
packages=find_packages(where='python', exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
package_dir={'': 'python'},
ext_package='ecl',
ext_modules=[CMakeExtension('libecl')],
cmdclass=dict(build_ext=CMakeBuild),
install_requires=[
'cwrap',
'numpy',
'pandas',
],
)