#996 Updated ERT to 2016.10

This commit is contained in:
Magne Sjaastad 2016-11-22 12:50:28 +01:00
parent 3d66d1698a
commit 9178659449
69 changed files with 2191 additions and 1549 deletions

View File

@ -80,10 +80,10 @@ endif()
if (MSVC)
add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4996" )
else()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
endif()
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
find_package(CXX11Features)
if (ERT_USE_OPENMP)
find_package(OpenMP)
@ -106,7 +106,6 @@ set( CMAKE_CXX_FLAGS_main ${CMAKE_CXX_FLAGS} )
if (NOT ERT_WINDOWS)
set( CMAKE_C_FLAGS_main "${CMAKE_C_FLAGS} -std=gnu99" )
set( CMAKE_CXX_FLAGS_main "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
set( ERT_EXTERNAL_UTIL_LIBS "" )

View File

@ -0,0 +1,19 @@
#
# Module that checks for supported C++11 (former C++0x) features.
#
if(CMAKE_VERSION VERSION_LESS 3.1)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if(NOT ERT_WINDOWS)
set( CMAKE_CXX_FLAGS_main "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
else()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
set(CXX11FEATURES_FOUND TRUE)

View File

@ -1,3 +1,9 @@
ert.ecl (2016.10-rfinal-1~xenial) xenial; urgency=medium
* New release
-- Arne Morten Kvarving <arne.morten.kvarving@sintef.no> Wed, 26 Oct 2016 09:46:18 +0200
ert.ecl (1.0-4) precise; urgency=low
* Unmark -dev package as architecture independent due to library symlink

View File

@ -21,6 +21,25 @@ add_custom_target(doc_out ALL
DEPENDS enkf)
INSTALL( DIRECTORY ${PROJECT_BINARY_DIR}/tmp_doc/_build/ DESTINATION ${CMAKE_INSTALL_PREFIX}/documentation )
if (ERT_DOC_INSTALL_PATH)
INSTALL( DIRECTORY ${PROJECT_BINARY_DIR}/tmp_doc/_build/ DESTINATION ${ERT_DOC_INSTALL_PATH} )
endif()
find_package(Doxygen)
if (DOXYGEN_FOUND)
message(STATUS "Creating doxygen target")
if (DOXYGEN_DOT_FOUND)
message(STATUS "Found graphviz, will run doxygen with graphics")
set( DOXYGEN_HAVE_DOT "YES" )
else()
message(STATUS "Graphviz not found, disabling dot")
set( DOXYGEN_HAVE_DOT "NO" )
endif()
configure_file(doxygen.cfg.in ${PROJECT_BINARY_DIR}/doxygen.cfg)
add_custom_target(doxy
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/doxygen.cfg
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/../
COMMENT "Generating doxygen documentation")
endif()

42
ThirdParty/Ert/docs/doxygen.cfg.in vendored Normal file
View File

@ -0,0 +1,42 @@
# This is a slightly modified standard doxygen config file
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Ert"
PROJECT_NUMBER = ${ERT_VERSION_MAJOR}.${ERT_VERSION_MINOR}
PROJECT_BRIEF = "ERT is a software initially developed by Statoil which main feature is to handle several ECLIPSE simulations in an Ensemble setting. --- http://ert.nr.no/ert"
PROJECT_LOGO =
OUTPUT_DIRECTORY = ${PROJECT_BINARY_DIR}/doxy
CREATE_SUBDIRS = NO
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
TAB_SIZE = 2
EXTRACT_ALL = YES
EXTRACT_PACKAGE = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
CASE_SENSE_NAMES = YES
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = NO
WARN_IF_DOC_ERROR = NO
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
INPUT = ${PROJECT_SOURCE_DIR}/libanalysis ${PROJECT_SOURCE_DIR}/libconfig ${PROJECT_SOURCE_DIR}/libecl ${PROJECT_SOURCE_DIR}/libecl_well ${PROJECT_SOURCE_DIR}/libeclxx ${PROJECT_SOURCE_DIR}/libenkf ${PROJECT_SOURCE_DIR}/libert_util ${PROJECT_SOURCE_DIR}/libert_utilxx ${PROJECT_SOURCE_DIR}/libgeometry ${PROJECT_SOURCE_DIR}/libjob_queue ${PROJECT_SOURCE_DIR}/librms ${PROJECT_SOURCE_DIR}/libsched
RECURSIVE = YES
EXCLUDE_PATTERNS = */test/* */build/* */test-data/* */docs/* */python*/
HAVE_DOT = ${DOXYGEN_HAVE_DOT}
DOT_GRAPH_MAX_NODES = 1000
GENERATE_HTML = YES
CLASS_DIAGRAMS = YES
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = NO
CALL_GRAPH = YES
DOT_IMAGE_FORMAT = png
INTERACTIVE_SVG = NO

View File

@ -66,16 +66,18 @@ void unpack_file(const char * filename) {
while (true) {
ecl_file_view_type * active_view;
if (block_index == size)
break;
if (target_type == ECL_SUMMARY_FILE) {
ecl_file_select_block( src_file , SEQHDR_KW , block_index );
active_view = ecl_file_alloc_global_blockview(src_file, SEQHDR_KW, block_index);
report_step += 1;
offset = 0;
} else {
ecl_kw_type * seqnum_kw;
ecl_file_select_block( src_file , SEQNUM_KW , block_index );
active_view = ecl_file_alloc_global_blockview(src_file, SEQNUM_KW, block_index);
seqnum_kw = ecl_file_iget_named_kw( src_file , SEQNUM_KW , 0);
report_step = ecl_kw_iget_int( seqnum_kw , 0);
offset = 1;
@ -92,12 +94,13 @@ void unpack_file(const char * filename) {
char * target_file = ecl_util_alloc_filename( NULL , base , target_type , fmt_file , report_step);
fortio_type * fortio_target = fortio_open_writer( target_file , fmt_file , ECL_ENDIAN_FLIP );
msg_update(msg , target_file);
ecl_file_fwrite_fortio( src_file , fortio_target , offset);
ecl_file_view_fwrite( active_view , fortio_target , offset);
fortio_fclose(fortio_target);
free(target_file);
}
block_index++;
ecl_file_view_free( active_view );
}
ecl_file_close( src_file );
util_safe_free(path);

View File

@ -29,22 +29,10 @@ extern "C" {
#include <ert/ecl/ecl_kw.h>
#include <ert/ecl/ecl_file_kw.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/fortio.h>
#include <ert/ecl/ecl_util.h>
typedef enum {
ECL_FILE_CLOSE_STREAM = 1 , /*
This flag will close the underlying FILE object between each access; this is
mainly to save filedescriptors in cases where many ecl_file instances are open at
the same time. */
//
ECL_FILE_WRITABLE = 2 /*
This flag opens the file in a mode where it can be updated and modified, but it
must still exist and be readable. I.e. this should not compared with the normal:
fopen(filename , "w") where an existing file is truncated to zero upon successfull
open.
*/
} ecl_file_flag_type;
#define ECL_FILE_FLAGS_ENUM_DEFS \
@ -57,8 +45,6 @@ extern "C" {
typedef struct ecl_file_struct ecl_file_type;
bool ecl_file_load_all( ecl_file_type * ecl_file );
void ecl_file_push_block( ecl_file_type * ecl_file );
void ecl_file_pop_block( ecl_file_type * ecl_file );
ecl_file_type * ecl_file_open( const char * filename , int flags);
void ecl_file_close( ecl_file_type * ecl_file );
void ecl_file_fortio_detach( ecl_file_type * ecl_file );
@ -98,10 +84,9 @@ extern "C" {
int ecl_file_iget_named_size( const ecl_file_type * file , const char * kw , int ith);
void ecl_file_indexed_read(const ecl_file_type * file , const char * kw, int index, const int_vector_type * index_map, char* buffer);
bool ecl_file_subselect_block( ecl_file_type * ecl_file , const char * kw , int occurence);
bool ecl_file_select_block( ecl_file_type * ecl_file , const char * kw , int occurence);
void ecl_file_select_global( ecl_file_type * ecl_file );
ecl_file_view_type * ecl_file_alloc_global_blockview( ecl_file_type * ecl_file , const char * kw , int occurence);
ecl_file_view_type * ecl_file_get_global_view( ecl_file_type * ecl_file );
ecl_file_view_type * ecl_file_get_active_view( ecl_file_type * ecl_file );
//bool ecl_file_writable( const ecl_file_type * ecl_file );
bool ecl_file_save_kw( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw);
bool ecl_file_has_kw_ptr( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw);
@ -116,26 +101,31 @@ extern "C" {
bool ecl_file_has_sim_time( const ecl_file_type * ecl_file , time_t sim_time);
void ecl_file_close_fortio_stream(ecl_file_type * ecl_file);
ecl_file_view_type * ecl_file_get_restart_view( ecl_file_type * ecl_file , int input_index, int report_step , time_t sim_time, double sim_days);
ecl_file_view_type * ecl_file_get_summary_view( ecl_file_type * ecl_file , int report_step );
/*****************************************************************/
/* SUMMARY FILES */
UTIL_IS_INSTANCE_HEADER( ecl_file );
//Deprecated:
void ecl_file_push_block( ecl_file_type * ecl_file );
void ecl_file_pop_block( ecl_file_type * ecl_file );
bool ecl_file_subselect_block( ecl_file_type * ecl_file , const char * kw , int occurence);
bool ecl_file_select_block( ecl_file_type * ecl_file , const char * kw , int occurence);
bool ecl_file_select_rstblock_sim_time( ecl_file_type * ecl_file , time_t sim_time);
bool ecl_file_select_rstblock_report_step( ecl_file_type * ecl_file , int report_step);
bool ecl_file_iselect_rstblock( ecl_file_type * ecl_file , int seqnum_index );
void ecl_file_close_fortio_stream(ecl_file_type * ecl_file);
ecl_file_type * ecl_file_open_rstblock_report_step( const char * filename , int report_step , int flags);
ecl_file_type * ecl_file_open_rstblock_sim_time( const char * filename , time_t sim_time , int flags);
ecl_file_type * ecl_file_iopen_rstblock( const char * filename , int seqnum_index , int flags);
/*****************************************************************/
/* SUMMARY FILES */
bool ecl_file_select_smryblock( ecl_file_type * ecl_file , int ministep_nr );
ecl_file_type * ecl_file_open_smryblock( const char * filename , int ministep_nr , int flags);
UTIL_IS_INSTANCE_HEADER( ecl_file );
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,107 @@
/*
Copyright (C) 2016 Statoil ASA, Norway.
This file is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#ifndef ERT_ECL_FILE_VIEW_H
#define ERT_ECL_FILE_VIEW_H
#include <stdlib.h>
#include <stdbool.h>
#include <ert/ecl/ecl_kw.h>
#include <ert/ecl/ecl_file_kw.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
ECL_FILE_CLOSE_STREAM = 1 , /*
This flag will close the underlying FILE object between each access; this is
mainly to save filedescriptors in cases where many ecl_file instances are open at
the same time. */
//
ECL_FILE_WRITABLE = 2 /*
This flag opens the file in a mode where it can be updated and modified, but it
must still exist and be readable. I.e. this should not compared with the normal:
fopen(filename , "w") where an existing file is truncated to zero upon successfull
open.
*/
} ecl_file_flag_type;
typedef struct ecl_file_view_struct ecl_file_view_type;
bool ecl_file_view_flags_set( const ecl_file_view_type * file_view, int query_flags);
bool ecl_file_view_check_flags( int state_flags , int query_flags);
ecl_file_view_type * ecl_file_view_alloc( fortio_type * fortio , int * flags , inv_map_type * inv_map , bool owner );
int ecl_file_view_get_global_index( const ecl_file_view_type * ecl_file_view , const char * kw , int ith);
void ecl_file_view_make_index( ecl_file_view_type * ecl_file_view );
bool ecl_file_view_has_kw( const ecl_file_view_type * ecl_file_view, const char * kw);
ecl_file_kw_type * ecl_file_view_iget_file_kw( const ecl_file_view_type * ecl_file_view , int global_index);
ecl_file_kw_type * ecl_file_view_iget_named_file_kw( const ecl_file_view_type * ecl_file_view , const char * kw, int ith);
ecl_kw_type * ecl_file_view_iget_kw( const ecl_file_view_type * ecl_file_view , int index);
void ecl_file_view_index_fload_kw(const ecl_file_view_type * ecl_file_view, const char* kw, int index, const int_vector_type * index_map, char* buffer);
int ecl_file_view_find_kw_value( const ecl_file_view_type * ecl_file_view , const char * kw , const void * value);
const char * ecl_file_view_iget_distinct_kw( const ecl_file_view_type * ecl_file_view , int index);
int ecl_file_view_get_num_distinct_kw( const ecl_file_view_type * ecl_file_view );
int ecl_file_view_get_size( const ecl_file_view_type * ecl_file_view );
ecl_type_enum ecl_file_view_iget_type( const ecl_file_view_type * ecl_file_view , int index);
int ecl_file_view_iget_size( const ecl_file_view_type * ecl_file_view , int index);
const char * ecl_file_view_iget_header( const ecl_file_view_type * ecl_file_view , int index);
ecl_kw_type * ecl_file_view_iget_named_kw( const ecl_file_view_type * ecl_file_view , const char * kw, int ith);
ecl_type_enum ecl_file_view_iget_named_type( const ecl_file_view_type * ecl_file_view , const char * kw , int ith);
int ecl_file_view_iget_named_size( const ecl_file_view_type * ecl_file_view , const char * kw , int ith);
void ecl_file_view_replace_kw( ecl_file_view_type * ecl_file_view , ecl_kw_type * old_kw , ecl_kw_type * new_kw , bool insert_copy);
bool ecl_file_view_load_all( ecl_file_view_type * ecl_file_view );
void ecl_file_view_add_kw( ecl_file_view_type * ecl_file_view , ecl_file_kw_type * file_kw);
void ecl_file_view_free( ecl_file_view_type * ecl_file_view );
void ecl_file_view_free__( void * arg );
int ecl_file_view_get_num_named_kw(const ecl_file_view_type * ecl_file_view , const char * kw);
void ecl_file_view_fwrite( const ecl_file_view_type * ecl_file_view , fortio_type * target , int offset);
int ecl_file_view_iget_occurence( const ecl_file_view_type * ecl_file_view , int global_index);
void ecl_file_view_fprintf_kw_list(const ecl_file_view_type * ecl_file_view , FILE * stream);
ecl_file_view_type * ecl_file_view_add_blockview(const ecl_file_view_type * ecl_file_view , const char * header, int occurence);
ecl_file_view_type * ecl_file_view_add_blockview2(const ecl_file_view_type * ecl_file_view , const char * start_kw, const char * end_kw, int occurence);
ecl_file_view_type * ecl_file_view_add_restart_view(ecl_file_view_type * file_view , int seqnum_index, int report_step , time_t sim_time, double sim_days);
ecl_file_view_type * ecl_file_view_alloc_blockview(const ecl_file_view_type * ecl_file_view , const char * header, int occurence);
ecl_file_view_type * ecl_file_view_alloc_blockview2(const ecl_file_view_type * ecl_file_view , const char * start_kw, const char * end_kw, int occurence);
void ecl_file_view_add_child( ecl_file_view_type * parent , ecl_file_view_type * child);
bool ecl_file_view_drop_flag( ecl_file_view_type * file_view , int flag);
void ecl_file_view_add_flag( ecl_file_view_type * file_view , int flag);
int ecl_file_view_seqnum_index_from_sim_time( ecl_file_view_type * parent_map , time_t sim_time);
bool ecl_file_view_has_sim_time( const ecl_file_view_type * ecl_file_view , time_t sim_time);
int ecl_file_view_find_sim_time(const ecl_file_view_type * ecl_file_view , time_t sim_time);
double ecl_file_view_iget_restart_sim_days(const ecl_file_view_type * ecl_file_view , int seqnum_index);
time_t ecl_file_view_iget_restart_sim_date(const ecl_file_view_type * ecl_file_view , int seqnum_index);
bool ecl_file_view_has_report_step( const ecl_file_view_type * ecl_file_view , int report_step);
ecl_file_view_type * ecl_file_view_add_summary_view( ecl_file_view_type * file_view , int report_step );
const char * ecl_file_view_get_src_file( const ecl_file_view_type * file_view );
void ecl_file_view_fclose_stream( ecl_file_view_type * file_view );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -23,6 +23,7 @@ extern "C" {
#endif
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/ecl_region.h>
@ -32,9 +33,9 @@ typedef struct ecl_grav_survey_struct ecl_grav_survey_type;
void ecl_grav_free( ecl_grav_type * ecl_grav_config );
ecl_grav_type * ecl_grav_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file );
ecl_grav_survey_type * ecl_grav_add_survey_FIP( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file );
ecl_grav_survey_type * ecl_grav_add_survey_PORMOD( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file );
ecl_grav_survey_type * ecl_grav_add_survey_RPORV( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file );
ecl_grav_survey_type * ecl_grav_add_survey_FIP( ecl_grav_type * grav , const char * name , const ecl_file_view_type * restart_file );
ecl_grav_survey_type * ecl_grav_add_survey_PORMOD( ecl_grav_type * grav , const char * name , const ecl_file_view_type * restart_file );
ecl_grav_survey_type * ecl_grav_add_survey_RPORV( ecl_grav_type * grav , const char * name , const ecl_file_view_type * restart_file );
double ecl_grav_eval( const ecl_grav_type * grav , const char * base, const char * monitor , ecl_region_type * region , double utm_x, double utm_y , double depth, int phase_mask);
void ecl_grav_new_std_density( ecl_grav_type * grav , ecl_phase_enum phase , double default_density);
void ecl_grav_add_std_density( ecl_grav_type * grav , ecl_phase_enum phase , int pvtnum , double density);

View File

@ -23,6 +23,7 @@ extern "C" {
#endif
#include <stdbool.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_rft_cell.h>
@ -37,7 +38,7 @@ const ecl_rft_cell_type * ecl_rft_node_iget_cell_sorted( ecl_rft_node_type * rft
const ecl_rft_cell_type * ecl_rft_node_iget_cell( const ecl_rft_node_type * rft_node , int index);
const ecl_rft_cell_type * ecl_rft_node_lookup_ijk( const ecl_rft_node_type * rft_node , int i, int j , int k);
void ecl_rft_node_fprintf_rft_obs(const ecl_rft_node_type * , double , const char * , const char * , double );
ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_type * file_map );
ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_view_type * rft_view );
void ecl_rft_node_free(ecl_rft_node_type * );
void ecl_rft_node_free__(void * );
time_t ecl_rft_node_get_date(const ecl_rft_node_type * );

View File

@ -26,6 +26,7 @@ extern "C" {
#include <time.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_kw.h>
@ -81,8 +82,7 @@ extern "C" {
void ecl_rsthead_free( ecl_rsthead_type * rsthead );
ecl_rsthead_type * ecl_rsthead_alloc_from_kw( int report_step , const ecl_kw_type * intehead_kw , const ecl_kw_type * doubhead_kw , const ecl_kw_type * logihead_kw );
ecl_rsthead_type * ecl_rsthead_ialloc( const ecl_file_type * rst_file , int occurence);
ecl_rsthead_type * ecl_rsthead_alloc( const ecl_file_type * rst_file );
ecl_rsthead_type * ecl_rsthead_alloc( const ecl_file_view_type * rst_file , int report_step);
ecl_rsthead_type * ecl_rsthead_alloc_empty();
time_t ecl_rsthead_date( const ecl_kw_type * intehead_kw );
void ecl_rsthead_fprintf( const ecl_rsthead_type * header , FILE * stream);

View File

@ -24,6 +24,7 @@ extern "C" {
#endif
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/ecl_region.h>
@ -34,7 +35,9 @@ extern "C" {
void ecl_subsidence_free( ecl_subsidence_type * ecl_subsidence_config );
ecl_subsidence_type * ecl_subsidence_alloc( const ecl_grid_type * ecl_grid, const ecl_file_type * init_file );
ecl_subsidence_survey_type * ecl_subsidence_add_survey_PRESSURE( ecl_subsidence_type * subsidence ,
const char * name , const ecl_file_type * restart_file );
const char * name , const ecl_file_view_type * restart_view );
bool ecl_subsidence_has_survey( const ecl_subsidence_type * subsidence , const char * name);
double ecl_subsidence_eval( const ecl_subsidence_type * subsidence ,
const char * base, const char * monitor ,
ecl_region_type * region ,

View File

@ -11,6 +11,7 @@ set( source_files
smspec_node.c
ecl_kw_grdecl.c
ecl_file_kw.c
ecl_file_view.c
ecl_grav.c
ecl_grav_calc.c
ecl_smspec.c
@ -67,6 +68,7 @@ set( header_files
ecl_grid.h
ecl_io_config.h
ecl_file.h
ecl_file_view.h
ecl_region.h
ecl_kw_magic.h
ecl_subsidence.h

View File

@ -31,12 +31,12 @@
#include <ert/ecl/fortio.h>
#include <ert/ecl/ecl_kw.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_endian_flip.h>
#include <ert/ecl/ecl_kw_magic.h>
#include <ert/ecl/ecl_rsthead.h>
#include <ert/ecl/ecl_file_kw.h>
/**
This file implements functionality to load an ECLIPSE file in
ecl_kw format. The implementation works by first searching through
@ -53,10 +53,10 @@
The main datatype here is the ecl_file type, but in addition each
ecl_kw instance is wrapped in an ecl_file_kw (implemented in
ecl_file_kw.c) structure and all the indexing is implemented with
the file_map type. The file_map type is not used outside this file.
the ecl_file_view type. The ecl_file_view type is not used outside this file.
When the file is opened an index of all the keywords is created and
stored in the field global_map, and the field active_map is set to
stored in the field global_map, and the field active_view is set to
point to global_map, i.e. all query/get operations on the ecl_file
will be based on the complete index:
@ -124,16 +124,6 @@
typedef struct file_map_struct file_map_type;
struct file_map_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. */
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. */
int * flags;
};
struct ecl_file_struct {
@ -141,13 +131,12 @@ struct ecl_file_struct {
fortio_type * fortio; /* The source of all the keywords - must be retained
open for reading for the entire lifetime of the
ecl_file object. */
file_map_type * global_map; /* The index of all the ecl_kw instances in the file. */
file_map_type * active_map; /* The currently active index. */
vector_type * map_list; /* Storage container for the map instances. */
ecl_file_view_type * global_view; /* The index of all the ecl_kw instances in the file. */
ecl_file_view_type * active_view; /* The currently active index. */
bool read_only;
int flags;
vector_type * map_stack;
inv_map_type * inv_map;
inv_map_type * inv_view;
};
@ -176,335 +165,6 @@ struct ecl_file_struct {
*/
/*****************************************************************/
/* Here comes the functions related to the index file_map. These
functions are all of them static.
*/
static bool FILE_FLAGS_SET( int state_flags , int query_flags) {
if ((state_flags & query_flags) == query_flags)
return true;
else
return false;
}
static file_map_type * file_map_alloc( fortio_type * fortio , int * flags , inv_map_type * inv_map , bool owner ) {
file_map_type * file_map = util_malloc( sizeof * file_map );
file_map->kw_list = vector_alloc_new();
file_map->kw_index = hash_alloc();
file_map->distinct_kw = stringlist_alloc_new();
file_map->owner = owner;
file_map->fortio = fortio;
file_map->inv_map = inv_map;
file_map->flags = flags;
return file_map;
}
static int file_map_get_global_index( const file_map_type * file_map , const char * kw , int ith) {
const int_vector_type * index_vector = hash_get(file_map->kw_index , kw);
int global_index = int_vector_iget( index_vector , ith);
return global_index;
}
/**
This function iterates over the kw_list vector and builds the
internal index fields 'kw_index' and 'distinct_kw'. This function
must be called every time the content of the kw_list vector is
modified (otherwise the ecl_file instance will be in an
inconsistent state).
*/
static void file_map_make_index( file_map_type * file_map ) {
stringlist_clear( file_map->distinct_kw );
hash_clear( file_map->kw_index );
{
int i;
for (i=0; i < vector_get_size( file_map->kw_list ); i++) {
const ecl_file_kw_type * file_kw = vector_iget_const( file_map->kw_list , i);
const char * header = ecl_file_kw_get_header( file_kw );
if ( !hash_has_key( file_map->kw_index , header )) {
int_vector_type * index_vector = int_vector_alloc( 0 , -1 );
hash_insert_hash_owned_ref( file_map->kw_index , header , index_vector , int_vector_free__);
stringlist_append_copy( file_map->distinct_kw , header);
}
{
int_vector_type * index_vector = hash_get( file_map->kw_index , header);
int_vector_append( index_vector , i);
}
}
}
}
static bool file_map_has_kw( const file_map_type * file_map, const char * kw) {
return hash_has_key( file_map->kw_index , kw );
}
static ecl_file_kw_type * file_map_iget_file_kw( const file_map_type * file_map , int global_index) {
ecl_file_kw_type * file_kw = vector_iget( file_map->kw_list , global_index);
return file_kw;
}
static ecl_file_kw_type * file_map_iget_named_file_kw( const file_map_type * file_map , const char * kw, int ith) {
int global_index = file_map_get_global_index( file_map , kw , ith);
ecl_file_kw_type * file_kw = file_map_iget_file_kw( file_map , global_index );
return file_kw;
}
static ecl_kw_type * file_map_iget_kw( const file_map_type * file_map , int index) {
ecl_file_kw_type * file_kw = file_map_iget_file_kw( file_map , index );
ecl_kw_type * ecl_kw = ecl_file_kw_get_kw_ptr( file_kw , file_map->fortio , file_map->inv_map);
if (!ecl_kw) {
if (fortio_assert_stream_open( file_map->fortio )) {
ecl_kw = ecl_file_kw_get_kw( file_kw , file_map->fortio , file_map->inv_map);
if (FILE_FLAGS_SET( file_map->flags[0] , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( file_map->fortio );
}
}
return ecl_kw;
}
static void file_map_index_fload_kw(const file_map_type * file_map, const char* kw, int index, const int_vector_type * index_map, char* buffer) {
ecl_file_kw_type * file_kw = file_map_iget_named_file_kw( file_map , kw , index);
if (fortio_assert_stream_open( file_map->fortio )) {
offset_type offset = ecl_file_kw_get_offset(file_kw);
ecl_type_enum ecl_type = ecl_file_kw_get_type(file_kw);
int element_count = ecl_file_kw_get_size(file_kw);
ecl_kw_fread_indexed_data(file_map->fortio, offset + ECL_KW_HEADER_FORTIO_SIZE, ecl_type, element_count, index_map, buffer);
}
}
static int file_map_find_kw_value( const file_map_type * file_map , const char * kw , const void * value) {
int global_index = -1;
if ( file_map_has_kw( file_map , kw)) {
const int_vector_type * index_list = hash_get( file_map->kw_index , kw );
int index = 0;
while (index < int_vector_size( index_list )) {
const ecl_kw_type * ecl_kw = file_map_iget_kw( file_map , int_vector_iget( index_list , index ));
if (ecl_kw_data_equal( ecl_kw , value )) {
global_index = int_vector_iget( index_list , index );
break;
}
index++;
}
}
return global_index;
}
static const char * file_map_iget_distinct_kw( const file_map_type * file_map , int index) {
return stringlist_iget( file_map->distinct_kw , index);
}
static int file_map_get_num_distinct_kw( const file_map_type * file_map ) {
return stringlist_get_size( file_map->distinct_kw );
}
static int file_map_get_size( const file_map_type * file_map ) {
return vector_get_size( file_map->kw_list );
}
static ecl_type_enum file_map_iget_type( const file_map_type * file_map , int index) {
ecl_file_kw_type * file_kw = file_map_iget_file_kw( file_map , index );
return ecl_file_kw_get_type( file_kw );
}
static int file_map_iget_size( const file_map_type * file_map , int index) {
ecl_file_kw_type * file_kw = file_map_iget_file_kw( file_map , index );
return ecl_file_kw_get_size( file_kw );
}
static const char * file_map_iget_header( const file_map_type * file_map , int index) {
ecl_file_kw_type * file_kw = file_map_iget_file_kw( file_map , index );
return ecl_file_kw_get_header( file_kw );
}
static ecl_kw_type * file_map_iget_named_kw( const file_map_type * file_map , const char * kw, int ith) {
ecl_file_kw_type * file_kw = file_map_iget_named_file_kw( file_map , kw , ith);
ecl_kw_type * ecl_kw = ecl_file_kw_get_kw_ptr( file_kw , file_map->fortio , file_map->inv_map );
if (!ecl_kw) {
if (fortio_assert_stream_open( file_map->fortio )) {
ecl_kw = ecl_file_kw_get_kw( file_kw , file_map->fortio , file_map->inv_map);
if (FILE_FLAGS_SET( file_map->flags[0] , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( file_map->fortio );
}
}
return ecl_kw;
}
static ecl_type_enum file_map_iget_named_type( const file_map_type * file_map , const char * kw , int ith) {
ecl_file_kw_type * file_kw = file_map_iget_named_file_kw( file_map , kw, ith);
return ecl_file_kw_get_type( file_kw );
}
static int file_map_iget_named_size( const file_map_type * file_map , const char * kw , int ith) {
ecl_file_kw_type * file_kw = file_map_iget_named_file_kw( file_map , kw , ith );
return ecl_file_kw_get_size( file_kw );
}
static void file_map_replace_kw( file_map_type * file_map , ecl_kw_type * old_kw , ecl_kw_type * new_kw , bool insert_copy) {
int index = 0;
while (index < vector_get_size( file_map->kw_list )) {
ecl_file_kw_type * ikw = vector_iget( file_map->kw_list , index );
if (ecl_file_kw_ptr_eq( ikw , old_kw)) {
/*
Found it; observe that the vector_iset() function will
automatically invoke the destructor on the old_kw.
*/
ecl_kw_type * insert_kw = new_kw;
if (insert_copy)
insert_kw = ecl_kw_alloc_copy( new_kw );
ecl_file_kw_replace_kw( ikw , file_map->fortio , insert_kw );
file_map_make_index( file_map );
return;
}
index++;
}
util_abort("%s: could not find ecl_kw ptr: %p \n",__func__ , old_kw);
}
static bool file_map_load_all( file_map_type * file_map ) {
bool loadOK = false;
if (fortio_assert_stream_open( file_map->fortio )) {
int index;
for (index = 0; index < vector_get_size( file_map->kw_list); index++) {
ecl_file_kw_type * ikw = vector_iget( file_map->kw_list , index );
ecl_file_kw_get_kw( ikw , file_map->fortio , file_map->inv_map);
}
loadOK = true;
}
if (FILE_FLAGS_SET( file_map->flags[0] , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( file_map->fortio );
return loadOK;
}
/*****************************************************************/
static void file_map_add_kw( file_map_type * file_map , ecl_file_kw_type * file_kw) {
if (file_map->owner)
vector_append_owned_ref( file_map->kw_list , file_kw , ecl_file_kw_free__ );
else
vector_append_ref( file_map->kw_list , file_kw);
}
static void file_map_free( file_map_type * file_map ) {
hash_free( file_map->kw_index );
stringlist_free( file_map->distinct_kw );
vector_free( file_map->kw_list );
free( file_map );
}
static void file_map_free__( void * arg ) {
file_map_type * file_map = ( file_map_type * ) arg;
file_map_free( file_map );
}
static int file_map_get_num_named_kw(const file_map_type * file_map , const char * kw) {
if (hash_has_key(file_map->kw_index , kw)) {
const int_vector_type * index_vector = hash_get(file_map->kw_index , kw);
return int_vector_size( index_vector );
} else
return 0;
}
static void file_map_fwrite( const file_map_type * file_map , fortio_type * target , int offset) {
int index;
for (index = offset; index < vector_get_size( file_map->kw_list ); index++) {
ecl_kw_type * ecl_kw = file_map_iget_kw( file_map , index );
ecl_kw_fwrite( ecl_kw , target );
}
}
static int file_map_iget_occurence( const file_map_type * file_map , int global_index) {
const ecl_file_kw_type * file_kw = vector_iget_const( file_map->kw_list , global_index);
const char * header = ecl_file_kw_get_header( file_kw );
const int_vector_type * index_vector = hash_get( file_map->kw_index , header );
const int * index_data = int_vector_get_const_ptr( index_vector );
int occurence = -1;
{
/* Manual reverse lookup. */
int i;
for (i=0; i < int_vector_size( index_vector ); i++)
if (index_data[i] == global_index)
occurence = i;
}
if (occurence < 0)
util_abort("%s: internal error ... \n" , __func__);
return occurence;
}
static void file_map_fprintf_kw_list(const file_map_type * file_map , FILE * stream) {
int i;
for (i=0; i < vector_get_size( file_map->kw_list ); i++) {
const ecl_file_kw_type * file_kw = vector_iget_const( file_map->kw_list , i );
fprintf(stream , "%-8s %7d:%s\n",
ecl_file_kw_get_header( file_kw ) ,
ecl_file_kw_get_size( file_kw ) ,
ecl_util_get_type_name( ecl_file_kw_get_type( file_kw )));
}
}
/**
Will return NULL if the block which is asked for is not present.
*/
static file_map_type * file_map_alloc_blockmap(const file_map_type * file_map , const char * header, int occurence) {
if (file_map_get_num_named_kw( file_map , header ) > occurence) {
file_map_type * block_map = file_map_alloc( file_map->fortio , file_map->flags , file_map->inv_map , false);
if (file_map_has_kw( file_map , header )) {
int kw_index = file_map_get_global_index( file_map , header , occurence );
ecl_file_kw_type * file_kw = vector_iget( file_map->kw_list , kw_index );
while (true) {
file_map_add_kw( block_map , file_kw );
kw_index++;
if (kw_index == vector_get_size( file_map->kw_list ))
break;
else {
file_kw = vector_iget(file_map->kw_list , kw_index);
if (strcmp( header , ecl_file_kw_get_header( file_kw )) == 0)
break;
}
}
}
file_map_make_index( block_map );
return block_map;
} else
return NULL;
}
/*****************************************************************/
@ -519,9 +179,8 @@ UTIL_IS_INSTANCE_FUNCTION( ecl_file , ECL_FILE_ID)
ecl_file_type * ecl_file_alloc_empty( int flags ) {
ecl_file_type * ecl_file = util_malloc( sizeof * ecl_file );
UTIL_TYPE_ID_INIT(ecl_file , ECL_FILE_ID);
ecl_file->map_list = vector_alloc_new();
ecl_file->map_stack = vector_alloc_new();
ecl_file->inv_map = inv_map_alloc( );
ecl_file->inv_view = inv_map_alloc( );
ecl_file->flags = flags;
return ecl_file;
}
@ -531,7 +190,7 @@ ecl_file_type * ecl_file_alloc_empty( int flags ) {
/* fwrite functions */
void ecl_file_fwrite_fortio(const ecl_file_type * ecl_file , fortio_type * target, int offset) {
file_map_fwrite( ecl_file->active_map , target , offset );
ecl_file_view_fwrite( ecl_file->active_view , target , offset );
}
@ -654,7 +313,7 @@ void ecl_file_fwrite(const ecl_file_type * ecl_file , const char * filename, boo
void ecl_file_replace_kw( ecl_file_type * ecl_file , ecl_kw_type * old_kw , ecl_kw_type * new_kw , bool insert_copy) {
file_map_replace_kw( ecl_file->active_map , old_kw , new_kw , insert_copy );
ecl_file_view_replace_kw( ecl_file->active_view , old_kw , new_kw , insert_copy );
}
@ -672,7 +331,7 @@ ecl_kw_type * ecl_file_icopy_named_kw( const ecl_file_type * ecl_file , const ch
*/
int ecl_file_get_num_named_kw(const ecl_file_type * ecl_file , const char * kw) {
return file_map_get_num_named_kw( ecl_file->active_map , kw);
return ecl_file_view_get_num_named_kw( ecl_file->active_view , kw);
}
@ -701,7 +360,7 @@ int ecl_file_get_num_named_kw(const ecl_file_type * ecl_file , const char * kw)
int ecl_file_iget_occurence( const ecl_file_type * ecl_file , int index) {
return file_map_iget_occurence( ecl_file->active_map , index );
return ecl_file_view_iget_occurence( ecl_file->active_view , index );
}
@ -710,7 +369,7 @@ int ecl_file_iget_occurence( const ecl_file_type * ecl_file , int index) {
instance.
*/
int ecl_file_get_size( const ecl_file_type * ecl_file ){
return file_map_get_size( ecl_file->active_map );
return ecl_file_view_get_size( ecl_file->active_view );
}
@ -719,17 +378,17 @@ int ecl_file_get_size( const ecl_file_type * ecl_file ){
ecl_kw 'kw'.
*/
bool ecl_file_has_kw( const ecl_file_type * ecl_file , const char * kw) {
return file_map_has_kw( ecl_file->active_map , kw );
return ecl_file_view_has_kw( ecl_file->active_view , kw );
}
int ecl_file_get_num_distinct_kw(const ecl_file_type * ecl_file) {
return file_map_get_num_distinct_kw( ecl_file->active_map );
return ecl_file_view_get_num_distinct_kw( ecl_file->active_view );
}
const char * ecl_file_iget_distinct_kw(const ecl_file_type * ecl_file, int index) {
return file_map_iget_distinct_kw( ecl_file->active_map , index );
return ecl_file_view_iget_distinct_kw( ecl_file->active_view , index );
}
@ -739,36 +398,36 @@ const char * ecl_file_get_src_file( const ecl_file_type * ecl_file ) {
void ecl_file_fprintf_kw_list( const ecl_file_type * ecl_file , FILE * stream ) {
file_map_fprintf_kw_list( ecl_file->active_map , stream );
ecl_file_view_fprintf_kw_list( ecl_file->active_view , stream );
}
/*****************************************************************/
ecl_file_kw_type * ecl_file_iget_file_kw( const ecl_file_type * file , int global_index) {
return file_map_iget_file_kw( file->active_map , global_index);
return ecl_file_view_iget_file_kw( file->active_view , global_index);
}
ecl_file_kw_type * ecl_file_iget_named_file_kw( const ecl_file_type * file , const char * kw, int ith) {
return file_map_iget_named_file_kw( file->active_map , kw, ith);
return ecl_file_view_iget_named_file_kw( file->active_view , kw, ith);
}
/* ---- */
ecl_kw_type * ecl_file_iget_kw( const ecl_file_type * file , int global_index) {
return file_map_iget_kw( file->active_map , global_index);
return ecl_file_view_iget_kw( file->active_view , global_index);
}
ecl_type_enum ecl_file_iget_type( const ecl_file_type * file , int global_index) {
return file_map_iget_type( file->active_map , global_index);
return ecl_file_view_iget_type( file->active_view , global_index);
}
int ecl_file_iget_size( const ecl_file_type * file , int global_index) {
return file_map_iget_size( file->active_map , global_index);
return ecl_file_view_iget_size( file->active_view , global_index);
}
const char * ecl_file_iget_header( const ecl_file_type * file , int global_index) {
return file_map_iget_header( file->active_map , global_index);
return ecl_file_view_iget_header( file->active_view , global_index);
}
/* ---------- */
@ -780,43 +439,65 @@ const char * ecl_file_iget_header( const ecl_file_type * file , int global_index
*/
ecl_kw_type * ecl_file_iget_named_kw( const ecl_file_type * file , const char * kw, int ith) {
return file_map_iget_named_kw( file->active_map , kw , ith);
return ecl_file_view_iget_named_kw( file->active_view , kw , ith);
}
void ecl_file_indexed_read(const ecl_file_type * file , const char * kw, int index, const int_vector_type * index_map, char* buffer) {
file_map_index_fload_kw(file->active_map, kw, index, index_map, buffer);
ecl_file_view_index_fload_kw(file->active_view, kw, index, index_map, buffer);
}
ecl_type_enum ecl_file_iget_named_type( const ecl_file_type * file , const char * kw , int ith) {
return file_map_iget_named_type( file->active_map , kw , ith );
return ecl_file_view_iget_named_type( file->active_view , kw , ith );
}
int ecl_file_iget_named_size( const ecl_file_type * file , const char * kw , int ith) {
return file_map_iget_named_size( file->active_map , kw , ith );
return ecl_file_view_iget_named_size( file->active_view , kw , ith );
}
/*****************************************************************/
static void ecl_file_add_map( ecl_file_type * ecl_file , file_map_type * file_map) {
vector_append_owned_ref(ecl_file->map_list , file_map , file_map_free__ );
ecl_file_view_type * ecl_file_get_global_view( ecl_file_type * ecl_file ) {
return ecl_file->global_view;
}
// Very deprecated ...
ecl_file_view_type * ecl_file_get_active_view( ecl_file_type * ecl_file ) {
return ecl_file->active_view;
}
ecl_file_view_type * ecl_file_get_global_blockview( ecl_file_type * ecl_file , const char * kw , int occurence) {
ecl_file_view_type * view = ecl_file_view_add_blockview( ecl_file->global_view , kw , occurence );
return view;
}
static file_map_type * ecl_file_get_blockmap( ecl_file_type * ecl_file , const char * kw , int occurence , bool use_global) {
file_map_type * blockmap;
if (use_global)
blockmap = file_map_alloc_blockmap( ecl_file->global_map , kw , occurence );
else
blockmap = file_map_alloc_blockmap( ecl_file->active_map , kw , occurence );
if (blockmap != NULL)
ecl_file_add_map( ecl_file , blockmap );
return blockmap;
ecl_file_view_type * ecl_file_alloc_global_blockview2( ecl_file_type * ecl_file , const char * start_kw , const char * end_kw, int occurence) {
ecl_file_view_type * view = ecl_file_view_alloc_blockview2( ecl_file->global_view , start_kw , end_kw, occurence );
return view;
}
ecl_file_view_type * ecl_file_alloc_global_blockview( ecl_file_type * ecl_file , const char * kw , int occurence) {
return ecl_file_alloc_global_blockview2( ecl_file , kw , kw , occurence );
}
ecl_file_view_type * ecl_file_get_restart_view( ecl_file_type * ecl_file , int input_index, int report_step , time_t sim_time, double sim_days) {
ecl_file_view_type * view = ecl_file_view_add_restart_view( ecl_file->global_view , input_index , report_step , sim_time , sim_days);
return view;
}
ecl_file_view_type * ecl_file_get_summary_view( ecl_file_type * ecl_file , int report_step ) {
ecl_file_view_type * view = ecl_file_view_add_summary_view( ecl_file->global_view , report_step );
return view;
}
/*****************************************************************/
/*
Different functions to open and close a file.
@ -825,7 +506,7 @@ static file_map_type * ecl_file_get_blockmap( ecl_file_type * ecl_file , const c
/**
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_map' field; and all
scan will be stored under the 'global_view' field; and all
subsequent lookup operations will ultimately be based on the global
map.
*/
@ -847,7 +528,7 @@ static bool ecl_file_scan( ecl_file_type * ecl_file ) {
if (ecl_kw_fread_header( work_kw , ecl_file->fortio)) {
ecl_file_kw_type * file_kw = ecl_file_kw_alloc( work_kw , current_offset);
if (ecl_file_kw_fskip_data( file_kw , ecl_file->fortio ))
file_map_add_kw( ecl_file->global_map , file_kw );
ecl_file_view_add_kw( ecl_file->global_view , file_kw );
else
break;
} else
@ -858,22 +539,23 @@ static bool ecl_file_scan( ecl_file_type * ecl_file ) {
ecl_kw_free( work_kw );
}
if (scan_ok)
file_map_make_index( ecl_file->global_map );
ecl_file_view_make_index( ecl_file->global_view );
return scan_ok;
}
void ecl_file_select_global( ecl_file_type * ecl_file ) {
ecl_file->active_map = ecl_file->global_map;
ecl_file->active_view = ecl_file->global_view;
}
/**
The fundamental open file function; all alternative open()
functions start by calling this one. This function will read
through the complete file, extract all the keyword headers and
create the map/index stored in the global_map field of the ecl_file
create the map/index stored in the global_view field of the ecl_file
structure. No keyword data will be loaded from the file.
The ecl_file instance will retain an open fortio reference to the
@ -886,9 +568,8 @@ ecl_file_type * ecl_file_open( const char * filename , int flags) {
bool fmt_file;
ecl_util_fmt_file( filename , &fmt_file);
//flags |= ECL_FILE_CLOSE_STREAM; // DEBUG DEBUG DEBUG
if (FILE_FLAGS_SET(flags , ECL_FILE_WRITABLE))
if (ecl_file_view_check_flags(flags , ECL_FILE_WRITABLE))
fortio = fortio_open_readwrite( filename , fmt_file , ECL_ENDIAN_FLIP);
else
fortio = fortio_open_reader( filename , fmt_file , ECL_ENDIAN_FLIP);
@ -896,13 +577,12 @@ ecl_file_type * ecl_file_open( const char * filename , int flags) {
if (fortio) {
ecl_file_type * ecl_file = ecl_file_alloc_empty( flags );
ecl_file->fortio = fortio;
ecl_file->global_map = file_map_alloc( ecl_file->fortio , &ecl_file->flags , ecl_file->inv_map , true );
ecl_file->global_view = ecl_file_view_alloc( ecl_file->fortio , &ecl_file->flags , ecl_file->inv_view , true );
ecl_file_add_map( ecl_file , ecl_file->global_map );
if (ecl_file_scan( ecl_file )) {
ecl_file_select_global( ecl_file );
if (FILE_FLAGS_SET( ecl_file->flags , ECL_FILE_CLOSE_STREAM))
if (ecl_file_view_check_flags( ecl_file->flags , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( ecl_file->fortio );
return ecl_file;
@ -927,42 +607,18 @@ void ecl_file_set_flags( ecl_file_type * ecl_file, int flags ) {
}
bool ecl_file_flags_set( const ecl_file_type * ecl_file , int flags) {
return FILE_FLAGS_SET( ecl_file->flags , flags );
return ecl_file_view_check_flags( ecl_file->flags , flags );
}
bool ecl_file_writable( const ecl_file_type * ecl_file ) {
return FILE_FLAGS_SET( ecl_file->flags , ECL_FILE_WRITABLE );
return ecl_file_view_check_flags( ecl_file->flags , ECL_FILE_WRITABLE );
}
void ecl_file_push_block( ecl_file_type * ecl_file ) {
vector_append_ref( ecl_file->map_stack , ecl_file->active_map );
}
void ecl_file_pop_block( ecl_file_type * ecl_file ) {
ecl_file->active_map = vector_pop_back( ecl_file->map_stack );
}
bool ecl_file_subselect_block( ecl_file_type * ecl_file , const char * kw , int occurence) {
file_map_type * blockmap = ecl_file_get_blockmap( ecl_file , kw , occurence , false);
if (blockmap != NULL) {
ecl_file->active_map = blockmap;
return true;
} else
return false;
}
bool ecl_file_select_block( ecl_file_type * ecl_file , const char * kw , int occurence ) {
file_map_type * blockmap = ecl_file_get_blockmap( ecl_file , kw , occurence , true);
if (blockmap != NULL) {
ecl_file->active_map = blockmap;
return true;
} else
return false;
}
/**
The ecl_file_close() function will close the fortio instance and
@ -974,8 +630,8 @@ void ecl_file_close(ecl_file_type * ecl_file) {
if (ecl_file->fortio != NULL)
fortio_fclose( ecl_file->fortio );
inv_map_free( ecl_file->inv_map );
vector_free( ecl_file->map_list );
ecl_file_view_free( ecl_file->global_view );
inv_map_free( ecl_file->inv_view );
vector_free( ecl_file->map_stack );
free( ecl_file );
}
@ -1005,7 +661,7 @@ void ecl_file_fortio_detach( ecl_file_type * ecl_file ) {
bool ecl_file_load_all( ecl_file_type * ecl_file ) {
return file_map_load_all( ecl_file->active_map );
return ecl_file_view_load_all( ecl_file->active_view );
}
@ -1015,14 +671,12 @@ void ecl_file_free__(void * arg) {
/****************************************************************************/
/* Here we include two files with functions specialized to work with
restart and summary files. Observe that the files ecl_rstfile.c and
ecl_smryfile are compiled as part of the same compilation unit as
ecl_file.c
/* Here we include a file with functions specialized to work with
restart files. Observe that the files ecl_rstfile.c is compiled as
part of the same compilation unit as ecl_file.c
*/
#include "ecl_rstfile.c"
#include "ecl_smryfile.c"
/*****************************************************************/
/* Two small lookup functions which consider the INTEHEAD keyword,
@ -1085,7 +739,7 @@ bool ecl_file_writable( const ecl_file_type * ecl_file ) {
*/
bool ecl_file_has_kw_ptr( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw) {
ecl_file_kw_type * file_kw = inv_map_get_file_kw( ecl_file->inv_map , ecl_kw );
ecl_file_kw_type * file_kw = inv_map_get_file_kw( ecl_file->inv_view , ecl_kw );
if (file_kw == NULL)
return false;
else
@ -1111,13 +765,13 @@ bool ecl_file_has_kw_ptr( const ecl_file_type * ecl_file , const ecl_kw_type * e
*/
bool ecl_file_save_kw( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_kw) {
ecl_file_kw_type * file_kw = inv_map_get_file_kw( ecl_file->inv_map , ecl_kw ); // We just verify that the input ecl_kw points to an ecl_kw
ecl_file_kw_type * file_kw = inv_map_get_file_kw( ecl_file->inv_view , ecl_kw ); // We just verify that the input ecl_kw points to an ecl_kw
if (file_kw != NULL) { // we manage; from then on we use the reference contained in
if (fortio_assert_stream_open( ecl_file->fortio )) { // the corresponding ecl_file_kw instance.
ecl_file_kw_inplace_fwrite( file_kw , ecl_file->fortio );
if (FILE_FLAGS_SET( ecl_file->flags , ECL_FILE_CLOSE_STREAM))
if (ecl_file_view_check_flags( ecl_file->flags , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( ecl_file->fortio );
return true;
@ -1130,3 +784,4 @@ bool ecl_file_save_kw( const ecl_file_type * ecl_file , const ecl_kw_type * ecl_
}
#include "ecl_file_deprecated.c"

View File

@ -0,0 +1,117 @@
void ecl_file_push_block( ecl_file_type * ecl_file ) {
vector_append_ref( ecl_file->map_stack , ecl_file->active_view );
}
void ecl_file_pop_block( ecl_file_type * ecl_file ) {
ecl_file->active_view = vector_pop_back( ecl_file->map_stack );
}
static ecl_file_view_type * ecl_file_get_relative_blockview( ecl_file_type * ecl_file , const char * kw , int occurence) {
ecl_file_view_type * view = ecl_file_view_add_blockview( ecl_file->active_view , kw , occurence );
return view;
}
bool ecl_file_subselect_block( ecl_file_type * ecl_file , const char * kw , int occurence) {
ecl_file_view_type * blockmap = ecl_file_get_relative_blockview( ecl_file , kw , occurence);
if (blockmap != NULL) {
ecl_file->active_view = blockmap;
return true;
} else
return false;
}
bool ecl_file_select_block( ecl_file_type * ecl_file , const char * kw , int occurence ) {
ecl_file_view_type * blockmap = ecl_file_get_global_blockview( ecl_file , kw , occurence);
if (blockmap != NULL) {
ecl_file->active_view = blockmap;
return true;
} else
return false;
}
/*
Will select restart block nr @seqnum_index - without considering
report_steps or simulation time.
*/
bool ecl_file_iselect_rstblock( ecl_file_type * ecl_file , int seqnum_index ) {
return ecl_file_select_block( ecl_file , SEQNUM_KW , seqnum_index );
}
bool ecl_file_select_rstblock_sim_time( ecl_file_type * ecl_file , time_t sim_time) {
int seqnum_index = ecl_file_view_seqnum_index_from_sim_time( ecl_file->global_view , sim_time );
if (seqnum_index >= 0)
return ecl_file_iselect_rstblock( ecl_file , seqnum_index);
else
return false;
}
bool ecl_file_select_rstblock_report_step( ecl_file_type * ecl_file , int report_step) {
int global_index = ecl_file_view_find_kw_value( ecl_file->global_view , SEQNUM_KW , &report_step);
if ( global_index >= 0) {
int seqnum_index = ecl_file_view_iget_occurence( ecl_file->global_view , global_index );
return ecl_file_iselect_rstblock( ecl_file , seqnum_index);
} else
return false;
}
/******************************************************************/
static ecl_file_type * ecl_file_open_rstblock_report_step__( const char * filename , int report_step , int flags) {
ecl_file_type * ecl_file = ecl_file_open( filename , flags );
if (ecl_file) {
if (!ecl_file_select_rstblock_report_step( ecl_file , report_step )) {
ecl_file_close( ecl_file );
ecl_file = NULL;
}
}
return ecl_file;
}
ecl_file_type * ecl_file_open_rstblock_report_step( const char * filename , int report_step , int flags) {
return ecl_file_open_rstblock_report_step__(filename , report_step , flags );
}
/******************************************************************/
static ecl_file_type * ecl_file_open_rstblock_sim_time__( const char * filename , time_t sim_time, int flags ) {
ecl_file_type * ecl_file = ecl_file_open( filename , flags );
if (ecl_file) {
if (!ecl_file_select_rstblock_sim_time( ecl_file , sim_time)) {
ecl_file_close( ecl_file );
ecl_file = NULL;
}
}
return ecl_file;
}
ecl_file_type * ecl_file_open_rstblock_sim_time( const char * filename , time_t sim_time, int flags) {
return ecl_file_open_rstblock_sim_time__( filename , sim_time , flags );
}
/******************************************************************/
static ecl_file_type * ecl_file_iopen_rstblock__( const char * filename , int seqnum_index, int flags ) {
ecl_file_type * ecl_file = ecl_file_open( filename , flags );
if (ecl_file) {
if (!ecl_file_iselect_rstblock( ecl_file , seqnum_index )) {
ecl_file_close( ecl_file );
ecl_file = NULL;
}
}
return ecl_file;
}
ecl_file_type * ecl_file_iopen_rstblock( const char * filename , int seqnum_index , int flags) {
return ecl_file_iopen_rstblock__(filename , seqnum_index , flags );
}

View File

@ -0,0 +1,776 @@
/*
Copyright (C) 2016 Statoil ASA, Norway.
The file 'ecl_file_view.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/vector.h>
#include <ert/util/hash.h>
#include <ert/util/stringlist.h>
#include <ert/ecl/fortio.h>
#include <ert/ecl/ecl_kw.h>
#include <ert/ecl/ecl_kw_magic.h>
#include <ert/ecl/ecl_file_kw.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_rsthead.h>
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. */
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. */
vector_type * child_list;
int * flags;
};
/*****************************************************************/
/* Here comes the functions related to the index ecl_file_view. These
functions are all of them static.
*/
bool ecl_file_view_check_flags( int state_flags , int query_flags) {
if ((state_flags & query_flags) == query_flags)
return true;
else
return false;
}
bool ecl_file_view_flags_set( const ecl_file_view_type * file_view , int query_flags) {
return ecl_file_view_check_flags( *file_view->flags , query_flags );
}
const char * ecl_file_view_get_src_file( const ecl_file_view_type * file_view ) {
return fortio_filename_ref( file_view->fortio );
}
ecl_file_view_type * ecl_file_view_alloc( fortio_type * fortio , int * flags , inv_map_type * inv_map , bool owner ) {
ecl_file_view_type * ecl_file_view = util_malloc( sizeof * ecl_file_view );
ecl_file_view->kw_list = vector_alloc_new();
ecl_file_view->kw_index = hash_alloc();
ecl_file_view->distinct_kw = stringlist_alloc_new();
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;
}
int ecl_file_view_get_global_index( const ecl_file_view_type * ecl_file_view , const char * kw , int ith) {
const int_vector_type * index_vector = hash_get(ecl_file_view->kw_index , kw);
int global_index = int_vector_iget( index_vector , ith);
return global_index;
}
/**
This function iterates over the kw_list vector and builds the
internal index fields 'kw_index' and 'distinct_kw'. This function
must be called every time the content of the kw_list vector is
modified (otherwise the ecl_file instance will be in an
inconsistent state).
*/
void ecl_file_view_make_index( ecl_file_view_type * ecl_file_view ) {
stringlist_clear( ecl_file_view->distinct_kw );
hash_clear( ecl_file_view->kw_index );
{
int i;
for (i=0; i < vector_get_size( ecl_file_view->kw_list ); i++) {
const ecl_file_kw_type * file_kw = vector_iget_const( ecl_file_view->kw_list , i);
const char * header = ecl_file_kw_get_header( file_kw );
if ( !hash_has_key( ecl_file_view->kw_index , header )) {
int_vector_type * index_vector = int_vector_alloc( 0 , -1 );
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);
}
{
int_vector_type * index_vector = hash_get( ecl_file_view->kw_index , header);
int_vector_append( index_vector , i);
}
}
}
}
bool ecl_file_view_has_kw( const ecl_file_view_type * ecl_file_view, const char * kw) {
return hash_has_key( ecl_file_view->kw_index , kw );
}
ecl_file_kw_type * ecl_file_view_iget_file_kw( const ecl_file_view_type * ecl_file_view , int global_index) {
ecl_file_kw_type * file_kw = vector_iget( ecl_file_view->kw_list , global_index);
return file_kw;
}
ecl_file_kw_type * ecl_file_view_iget_named_file_kw( const ecl_file_view_type * ecl_file_view , const char * kw, int ith) {
int global_index = ecl_file_view_get_global_index( ecl_file_view , kw , ith);
ecl_file_kw_type * file_kw = ecl_file_view_iget_file_kw( ecl_file_view , global_index );
return file_kw;
}
bool ecl_file_view_drop_flag( ecl_file_view_type * file_view , int flag) {
bool flag_set = ecl_file_view_flags_set( file_view , flag );
if (flag_set)
*file_view->flags -= flag;
return flag_set;
}
void ecl_file_view_add_flag( ecl_file_view_type * file_view , int flag) {
*file_view->flags |= flag;
}
ecl_kw_type * ecl_file_view_iget_kw( const ecl_file_view_type * ecl_file_view , int index) {
ecl_file_kw_type * file_kw = ecl_file_view_iget_file_kw( ecl_file_view , index );
ecl_kw_type * ecl_kw = ecl_file_kw_get_kw_ptr( file_kw , ecl_file_view->fortio , ecl_file_view->inv_map);
if (!ecl_kw) {
if (fortio_assert_stream_open( ecl_file_view->fortio )) {
ecl_kw = ecl_file_kw_get_kw( file_kw , ecl_file_view->fortio , ecl_file_view->inv_map);
if (ecl_file_view_flags_set( ecl_file_view , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( ecl_file_view->fortio );
}
}
return ecl_kw;
}
void ecl_file_view_index_fload_kw(const ecl_file_view_type * ecl_file_view, const char* kw, int index, const int_vector_type * index_map, char* buffer) {
ecl_file_kw_type * file_kw = ecl_file_view_iget_named_file_kw( ecl_file_view , kw , index);
if (fortio_assert_stream_open( ecl_file_view->fortio )) {
offset_type offset = ecl_file_kw_get_offset(file_kw);
ecl_type_enum ecl_type = ecl_file_kw_get_type(file_kw);
int element_count = ecl_file_kw_get_size(file_kw);
ecl_kw_fread_indexed_data(ecl_file_view->fortio, offset + ECL_KW_HEADER_FORTIO_SIZE, ecl_type, element_count, index_map, buffer);
}
}
int ecl_file_view_find_kw_value( const ecl_file_view_type * ecl_file_view , const char * kw , const void * value) {
int global_index = -1;
if ( ecl_file_view_has_kw( ecl_file_view , kw)) {
const int_vector_type * index_list = hash_get( ecl_file_view->kw_index , kw );
int index = 0;
while (index < int_vector_size( index_list )) {
const ecl_kw_type * ecl_kw = ecl_file_view_iget_kw( ecl_file_view , int_vector_iget( index_list , index ));
if (ecl_kw_data_equal( ecl_kw , value )) {
global_index = int_vector_iget( index_list , index );
break;
}
index++;
}
}
return global_index;
}
const char * ecl_file_view_iget_distinct_kw( const ecl_file_view_type * ecl_file_view , int index) {
return stringlist_iget( ecl_file_view->distinct_kw , index);
}
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 );
}
int ecl_file_view_get_size( const ecl_file_view_type * ecl_file_view ) {
return vector_get_size( ecl_file_view->kw_list );
}
ecl_type_enum ecl_file_view_iget_type( const ecl_file_view_type * ecl_file_view , int index) {
ecl_file_kw_type * file_kw = ecl_file_view_iget_file_kw( ecl_file_view , index );
return ecl_file_kw_get_type( file_kw );
}
int ecl_file_view_iget_size( const ecl_file_view_type * ecl_file_view , int index) {
ecl_file_kw_type * file_kw = ecl_file_view_iget_file_kw( ecl_file_view , index );
return ecl_file_kw_get_size( file_kw );
}
const char * ecl_file_view_iget_header( const ecl_file_view_type * ecl_file_view , int index) {
ecl_file_kw_type * file_kw = ecl_file_view_iget_file_kw( ecl_file_view , index );
return ecl_file_kw_get_header( file_kw );
}
ecl_kw_type * ecl_file_view_iget_named_kw( const ecl_file_view_type * ecl_file_view , const char * kw, int ith) {
ecl_file_kw_type * file_kw = ecl_file_view_iget_named_file_kw( ecl_file_view , kw , ith);
ecl_kw_type * ecl_kw = ecl_file_kw_get_kw_ptr( file_kw , ecl_file_view->fortio , ecl_file_view->inv_map );
if (!ecl_kw) {
if (fortio_assert_stream_open( ecl_file_view->fortio )) {
ecl_kw = ecl_file_kw_get_kw( file_kw , ecl_file_view->fortio , ecl_file_view->inv_map);
if (ecl_file_view_flags_set( ecl_file_view , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( ecl_file_view->fortio );
}
}
return ecl_kw;
}
ecl_type_enum ecl_file_view_iget_named_type( const ecl_file_view_type * ecl_file_view , const char * kw , int ith) {
ecl_file_kw_type * file_kw = ecl_file_view_iget_named_file_kw( ecl_file_view , kw, ith);
return ecl_file_kw_get_type( file_kw );
}
int ecl_file_view_iget_named_size( const ecl_file_view_type * ecl_file_view , const char * kw , int ith) {
ecl_file_kw_type * file_kw = ecl_file_view_iget_named_file_kw( ecl_file_view , kw , ith );
return ecl_file_kw_get_size( file_kw );
}
void ecl_file_view_replace_kw( ecl_file_view_type * ecl_file_view , ecl_kw_type * old_kw , ecl_kw_type * new_kw , bool insert_copy) {
int index = 0;
while (index < vector_get_size( ecl_file_view->kw_list )) {
ecl_file_kw_type * ikw = vector_iget( ecl_file_view->kw_list , index );
if (ecl_file_kw_ptr_eq( ikw , old_kw)) {
/*
Found it; observe that the vector_iset() function will
automatically invoke the destructor on the old_kw.
*/
ecl_kw_type * insert_kw = new_kw;
if (insert_copy)
insert_kw = ecl_kw_alloc_copy( new_kw );
ecl_file_kw_replace_kw( ikw , ecl_file_view->fortio , insert_kw );
ecl_file_view_make_index( ecl_file_view );
return;
}
index++;
}
util_abort("%s: could not find ecl_kw ptr: %p \n",__func__ , old_kw);
}
bool ecl_file_view_load_all( ecl_file_view_type * ecl_file_view ) {
bool loadOK = false;
if (fortio_assert_stream_open( ecl_file_view->fortio )) {
int index;
for (index = 0; index < vector_get_size( ecl_file_view->kw_list); index++) {
ecl_file_kw_type * ikw = vector_iget( ecl_file_view->kw_list , index );
ecl_file_kw_get_kw( ikw , ecl_file_view->fortio , ecl_file_view->inv_map);
}
loadOK = true;
}
if (ecl_file_view_flags_set( ecl_file_view , ECL_FILE_CLOSE_STREAM))
fortio_fclose_stream( ecl_file_view->fortio );
return loadOK;
}
/*****************************************************************/
void ecl_file_view_add_kw( ecl_file_view_type * ecl_file_view , ecl_file_kw_type * file_kw) {
if (ecl_file_view->owner)
vector_append_owned_ref( ecl_file_view->kw_list , file_kw , ecl_file_kw_free__ );
else
vector_append_ref( ecl_file_view->kw_list , file_kw);
}
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 );
}
void ecl_file_view_free__( void * arg ) {
ecl_file_view_type * ecl_file_view = ( ecl_file_view_type * ) arg;
ecl_file_view_free( ecl_file_view );
}
int ecl_file_view_get_num_named_kw(const ecl_file_view_type * ecl_file_view , const char * kw) {
if (hash_has_key(ecl_file_view->kw_index , kw)) {
const int_vector_type * index_vector = hash_get(ecl_file_view->kw_index , kw);
return int_vector_size( index_vector );
} else
return 0;
}
void ecl_file_view_fwrite( const ecl_file_view_type * ecl_file_view , fortio_type * target , int offset) {
int index;
for (index = offset; index < vector_get_size( ecl_file_view->kw_list ); index++) {
ecl_kw_type * ecl_kw = ecl_file_view_iget_kw( ecl_file_view , index );
ecl_kw_fwrite( ecl_kw , target );
}
}
int ecl_file_view_iget_occurence( const ecl_file_view_type * ecl_file_view , int global_index) {
const ecl_file_kw_type * file_kw = vector_iget_const( ecl_file_view->kw_list , global_index);
const char * header = ecl_file_kw_get_header( file_kw );
const int_vector_type * index_vector = hash_get( ecl_file_view->kw_index , header );
const int * index_data = int_vector_get_const_ptr( index_vector );
int occurence = -1;
{
/* Manual reverse lookup. */
int i;
for (i=0; i < int_vector_size( index_vector ); i++)
if (index_data[i] == global_index)
occurence = i;
}
if (occurence < 0)
util_abort("%s: internal error ... \n" , __func__);
return occurence;
}
void ecl_file_view_fprintf_kw_list(const ecl_file_view_type * ecl_file_view , FILE * stream) {
int i;
for (i=0; i < vector_get_size( ecl_file_view->kw_list ); i++) {
const ecl_file_kw_type * file_kw = vector_iget_const( ecl_file_view->kw_list , i );
fprintf(stream , "%-8s %7d:%s\n",
ecl_file_kw_get_header( file_kw ) ,
ecl_file_kw_get_size( file_kw ) ,
ecl_util_get_type_name( ecl_file_kw_get_type( file_kw )));
}
}
ecl_file_view_type * ecl_file_view_alloc_blockview2(const ecl_file_view_type * ecl_file_view , const char * start_kw, const char * end_kw, int occurence) {
if ((start_kw != NULL) && ecl_file_view_get_num_named_kw( ecl_file_view , start_kw ) <= occurence)
return NULL;
ecl_file_view_type * block_map = ecl_file_view_alloc( ecl_file_view->fortio , ecl_file_view->flags , ecl_file_view->inv_map , false);
int kw_index = 0;
if (start_kw)
kw_index = ecl_file_view_get_global_index( ecl_file_view , start_kw , occurence );
{
ecl_file_kw_type * file_kw = vector_iget( ecl_file_view->kw_list , kw_index );
while (true) {
ecl_file_view_add_kw( block_map , file_kw );
kw_index++;
if (kw_index == vector_get_size( ecl_file_view->kw_list ))
break;
else {
if (end_kw) {
file_kw = vector_iget(ecl_file_view->kw_list , kw_index);
if (strcmp( end_kw , ecl_file_kw_get_header( file_kw )) == 0)
break;
}
}
}
}
ecl_file_view_make_index( block_map );
return block_map;
}
/**
Will return NULL if the block which is asked for is not present.
*/
ecl_file_view_type * ecl_file_view_alloc_blockview(const ecl_file_view_type * ecl_file_view , const char * header, int occurence) {
return ecl_file_view_alloc_blockview2( ecl_file_view , header , header , occurence );
}
ecl_file_view_type * ecl_file_view_add_blockview(const ecl_file_view_type * file_view , const char * header, int occurence) {
ecl_file_view_type * child = ecl_file_view_alloc_blockview2(file_view, header, header, occurence);
if (child)
vector_append_owned_ref( file_view->child_list , child , ecl_file_view_free__ );
return child;
}
ecl_file_view_type * ecl_file_view_add_blockview2(const ecl_file_view_type * ecl_file_view , const char * start_kw, const char * end_kw, int occurence) {
ecl_file_view_type * child = ecl_file_view_alloc_blockview2(ecl_file_view, start_kw , end_kw , occurence);
if (child)
vector_append_owned_ref( ecl_file_view->child_list , child , ecl_file_view_free__ );
return child;
}
/*****************************************************************/
/* R E S T A R T F I L E S */
/*****************************************************************/
/*
There is no special datastructure for working with restart files,
they are 100% stock ecl_file instances with the following limited
structure:
* They are organized in blocks; where each block starts with a
SEQNUM keyword, which contains the report step.
* Each block contains an INTEHEAD keyword, immediately after the
SEQNUM keyword, which contains the true simulation date of of the
block, and also some other data. Observe that also INIT files and
GRID files contain an INTEHEAD keyword; and that for files with
LGRs there is one INTEHEAD keyword for each LGR. This creates an
extra level of mess.
The natural time ordering when working with the file data is just
the running index in the file; however from a user perspective the
natural way to indicate time coordinate is through the report step
or the true simulation time (i.e. 22.th of October 2009). This file
is all about converting the natural input unit time and report_step
to the internal indexing. This is achieved by consulting the value
of the INTEHEAD and SEQNUM keywords respectively.
*/
/*
About the time-direction
========================
For the following discussion we will focus on the following simplified
unified restart file. The leading number is the global index of the
keyword, the value in [] corresponds to the relevant part of the
content of the keyword on the line, the labels A,B,C,D,E are used for
references in the text below.
0 | SEQNUM [0] \ A
1 | INTEHEAD [01.01.2005] |
2 | PRESSURE [... ] |
3 | SWAT [...] |
| -----------------------+
4 | SEQNUM [5] | B
5 | INTEHEAD [01.06.2005] |
6 | PRESSURE [... ] |
7 | SWAT [...] |
|------------------------+
8 | SEQNUM [10] | C
9 | INTEHEAD [01.12.2006] |
10 | PRESSURE [...] |
11 | SWAT [...] |
|------------------------+
12 | SEQNUM [20] | D
13 | INTEHEAD [01.12.2007] |
14 | PRESSURE [...] |
15 | SWAT [...] |
16 | OIL_DEN [...] |
|------------------------+
17 | SEQNUM [40] | E
18 | INTEHEAD [01.12.2009] |
19 | PRESSURE [...] |
20 | SWAT [...] /
This restart file has the following features:
o It contains in total 16 keywords.
o It contains 5 blocks of collected keywords corresponding to one
time instant, each of these blocks is called a report_step,
typcially coming from one DATES keyword in the ECLIPSE
datafile. Observe that the file does not have the block structure
visualized on this figure, the only thing separating the blocks in
the file is the occurence of a SEQNUM keyword.
o Only a few of the report steps are present, namely 0, 5, 10, 20 and
40.
o The different blocks are not equally long, the fourth block has an
extra keyword OIL_DEN.
To adress these keywords and blocks using different time coordinates
we have introduced the following concepts:
report_step: This corresponds to the value of the SEQNUM keword,
i.e. to do queries based on the report_step we must load the
seqnum kewyord and read the value.
ecl_file_get_unrstmap_report_step( ecl_file , 0 ) => A
ecl_file_get_unrstmap_report_step( ecl_file , 1 ) => NULL
ecl_file_has_report_step( ecl_file , 5 ) => True
ecl_file_has_report_step( ecl_file , 2 ) => False
sim_time: This correpsonds to the true simulation time of the report
step, the simulation time is stored as integers DAY, MONTH, YEAR
in the INTEHEAD keyword; the function INTEHEAD_date() will extract
the DAY, MONTH and YEAR values from an INTEHEAD keyword instance
and convert to a time_t instance. The functions:
ecl_file_get_unrstmap_sim_time() and ecl_file_has_has_sim_time()
can be used to query for simulation times and get the
corresponding block maps.
index/global_index : This is typically the global running index of
the keyword in the file; this is the unique address of the keyword
which is used for the final lookup.
occurence: The nth' time a particular keyword has occured in the
file, i.e. the SEQNUM keyword in block C is the third occurence of
SEQNUM. Instead of occurence xxxx_index is also used to indicate
the occurence of keyword xxxx. The occurence number is the integer
argument to the xxx_iget_named_kw() function, and also the final
call to create blockmaps.
*/
bool ecl_file_view_has_report_step( const ecl_file_view_type * ecl_file_view , int report_step) {
int global_index = ecl_file_view_find_kw_value( ecl_file_view , SEQNUM_KW , &report_step );
if (global_index >= 0)
return true;
else
return false;
}
time_t ecl_file_view_iget_restart_sim_date(const ecl_file_view_type * ecl_file_view , int seqnum_index) {
time_t sim_time = -1;
ecl_file_view_type * seqnum_map = seqnum_map = ecl_file_view_alloc_blockview( ecl_file_view , SEQNUM_KW , seqnum_index);
if (seqnum_map != NULL) {
ecl_kw_type * intehead_kw = ecl_file_view_iget_named_kw( seqnum_map , INTEHEAD_KW , 0);
sim_time = ecl_rsthead_date( intehead_kw );
ecl_file_view_free( seqnum_map );
}
return sim_time;
}
double ecl_file_view_iget_restart_sim_days(const ecl_file_view_type * ecl_file_view , int seqnum_index) {
double sim_days = 0;
ecl_file_view_type * seqnum_map = ecl_file_view_alloc_blockview( ecl_file_view , SEQNUM_KW , seqnum_index);
if (seqnum_map != NULL) {
ecl_kw_type * doubhead_kw = ecl_file_view_iget_named_kw( seqnum_map , DOUBHEAD_KW , 0);
sim_days = ecl_kw_iget_double( doubhead_kw , DOUBHEAD_DAYS_INDEX);
ecl_file_view_free( seqnum_map );
}
return sim_days;
}
int ecl_file_view_find_sim_time(const ecl_file_view_type * ecl_file_view , time_t sim_time) {
int seqnum_index = -1;
if ( ecl_file_view_has_kw( ecl_file_view , INTEHEAD_KW)) {
const int_vector_type * intehead_index_list = hash_get( ecl_file_view->kw_index , INTEHEAD_KW );
int index = 0;
while (index < int_vector_size( intehead_index_list )) {
const ecl_kw_type * intehead_kw = ecl_file_view_iget_kw( ecl_file_view , int_vector_iget( intehead_index_list , index ));
if (ecl_rsthead_date( intehead_kw ) == sim_time) {
seqnum_index = index;
break;
}
index++;
}
}
return seqnum_index;
}
/**
This function will scan through the ecl_file looking for INTEHEAD
headers corresponding to sim_time. If sim_time is found the
function will return the INTEHEAD occurence number, i.e. for a
unified restart file like:
INTEHEAD / 01.01.2000
...
PRESSURE
SWAT
...
INTEHEAD / 01.03.2000
...
PRESSURE
SWAT
...
INTEHEAD / 01.05.2000
...
PRESSURE
SWAT
....
The function call:
ecl_file_get_restart_index( restart_file , (time_t) "01.03.2000")
will return 1. Observe that this will in general NOT agree with the
DATES step number.
If the sim_time can not be found the function will return -1, that
includes the case when the file in question is not a restart file
at all, and no INTEHEAD headers can be found.
Observe that the function requires on-the-second-equality; which is
of course quite strict.
Each report step only has one occurence of SEQNUM, but one INTEHEAD
for each LGR; i.e. one should call iselect_rstblock() prior to
calling this function.
*/
bool ecl_file_view_has_sim_time( const ecl_file_view_type * ecl_file_view , time_t sim_time) {
int num_INTEHEAD = ecl_file_view_get_num_named_kw( ecl_file_view , INTEHEAD_KW );
if (num_INTEHEAD == 0)
return false; /* We have no INTEHEAD headers - probably not a restart file at all. */
else {
int intehead_index = 0;
while (true) {
time_t itime = ecl_file_view_iget_restart_sim_date( ecl_file_view , intehead_index );
if (itime == sim_time) /* Perfect hit. */
return true;
if (itime > sim_time) /* We have gone past the target_time - i.e. we do not have it. */
return false;
intehead_index++;
if (intehead_index == num_INTEHEAD) /* We have iterated through the whole thing without finding sim_time. */
return false;
}
}
}
bool ecl_file_view_has_sim_days( const ecl_file_view_type * ecl_file_view , double sim_days) {
int num_DOUBHEAD = ecl_file_view_get_num_named_kw( ecl_file_view , DOUBHEAD_KW );
if (num_DOUBHEAD == 0)
return false; /* We have no DOUBHEAD headers - probably not a restart file at all. */
else {
int doubhead_index = 0;
while (true) {
double file_sim_days = ecl_file_view_iget_restart_sim_days( ecl_file_view , doubhead_index );
if (util_double_approx_equal(sim_days, file_sim_days)) /* Perfect hit. */
return true;
if (file_sim_days > sim_days) /* We have gone past the target_time - i.e. we do not have it. */
return false;
doubhead_index++;
if (doubhead_index == num_DOUBHEAD) /* We have iterated through the whole thing without finding sim_time. */
return false;
}
}
}
int ecl_file_view_seqnum_index_from_sim_time( ecl_file_view_type * parent_map , time_t sim_time) {
int num_seqnum = ecl_file_view_get_num_named_kw( parent_map , SEQNUM_KW );
ecl_file_view_type * seqnum_map;
for (int s_idx = 0; s_idx < num_seqnum; s_idx++) {
seqnum_map = ecl_file_view_alloc_blockview( parent_map , SEQNUM_KW , s_idx );
if (!seqnum_map)
continue;
bool sim = ecl_file_view_has_sim_time( seqnum_map , sim_time);
ecl_file_view_free( seqnum_map );
if (sim)
return s_idx;
}
return -1;
}
int ecl_file_view_seqnum_index_from_sim_days( ecl_file_view_type * file_view , double sim_days) {
int num_seqnum = ecl_file_view_get_num_named_kw( file_view , SEQNUM_KW );
int seqnum_index = 0;
ecl_file_view_type * seqnum_map;
while (true) {
seqnum_map = ecl_file_view_alloc_blockview( file_view , SEQNUM_KW , seqnum_index);
if (seqnum_map != NULL) {
if (ecl_file_view_has_sim_days( seqnum_map , sim_days)) {
ecl_file_view_free( seqnum_map );
return seqnum_index;
} else {
ecl_file_view_free( seqnum_map );
seqnum_index++;
}
}
if (num_seqnum == seqnum_index)
return -1;
}
}
/*
Will mulitplex on the four input arguments.
*/
ecl_file_view_type * ecl_file_view_add_restart_view( ecl_file_view_type * file_view , int input_index, int report_step , time_t sim_time, double sim_days) {
ecl_file_view_type * child = NULL;
int seqnum_index = -1;
if (input_index >= 0)
seqnum_index = input_index;
else if (report_step >= 0) {
int global_index = ecl_file_view_find_kw_value( file_view , SEQNUM_KW , &report_step);
if ( global_index >= 0)
seqnum_index = ecl_file_view_iget_occurence( file_view , global_index );
} else if (sim_time != -1)
seqnum_index = ecl_file_view_seqnum_index_from_sim_time( file_view , sim_time );
else if (sim_days >= 0)
seqnum_index = ecl_file_view_seqnum_index_from_sim_days( file_view , sim_days );
if (seqnum_index >= 0)
child = ecl_file_view_add_blockview( file_view , SEQNUM_KW , seqnum_index );
return child;
}
ecl_file_view_type * ecl_file_view_add_summary_view( ecl_file_view_type * file_view , int report_step ) {
ecl_file_view_type * child = ecl_file_view_add_blockview( file_view , SEQHDR_KW , report_step );
return child;
}
void ecl_file_view_fclose_stream( ecl_file_view_type * file_view ) {
fortio_fclose_stream( file_view->fortio );
}

View File

@ -206,7 +206,7 @@ static double ecl_grav_phase_eval( ecl_grav_phase_type * base_phase ,
static ecl_grav_phase_type * ecl_grav_phase_alloc( ecl_grav_type * ecl_grav ,
ecl_grav_survey_type * survey ,
ecl_phase_enum phase ,
const ecl_file_type * restart_file,
const ecl_file_view_type * restart_file,
grav_calc_type calc_type) {
const ecl_file_type * init_file = ecl_grav->init_file;
@ -229,11 +229,11 @@ static ecl_grav_phase_type * ecl_grav_phase_alloc( ecl_grav_type * ecl_grav ,
ecl_kw_type * fip_kw;
if ( phase == ECL_OIL_PHASE)
fip_kw = ecl_file_iget_named_kw( restart_file , FIPOIL_KW , 0 );
fip_kw = ecl_file_view_iget_named_kw( restart_file , FIPOIL_KW , 0 );
else if (phase == ECL_GAS_PHASE)
fip_kw = ecl_file_iget_named_kw( restart_file , FIPGAS_KW , 0 );
fip_kw = ecl_file_view_iget_named_kw( restart_file , FIPGAS_KW , 0 );
else
fip_kw = ecl_file_iget_named_kw( restart_file , FIPWAT_KW , 0 );
fip_kw = ecl_file_view_iget_named_kw( restart_file , FIPWAT_KW , 0 );
{
int iactive;
@ -246,16 +246,16 @@ static ecl_grav_phase_type * ecl_grav_phase_alloc( ecl_grav_type * ecl_grav ,
} else {
ecl_version_enum ecl_version = ecl_file_get_ecl_version( init_file );
const char * den_kw_name = get_den_kw( phase , ecl_version );
const ecl_kw_type * den_kw = ecl_file_iget_named_kw( restart_file , den_kw_name , 0 );
const ecl_kw_type * den_kw = ecl_file_view_iget_named_kw( restart_file , den_kw_name , 0 );
if (calc_type == GRAV_CALC_RFIP) {
ecl_kw_type * rfip_kw;
if ( phase == ECL_OIL_PHASE)
rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPOIL_KW , 0 );
rfip_kw = ecl_file_view_iget_named_kw( restart_file , RFIPOIL_KW , 0 );
else if (phase == ECL_GAS_PHASE)
rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPGAS_KW , 0 );
rfip_kw = ecl_file_view_iget_named_kw( restart_file , RFIPGAS_KW , 0 );
else
rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPWAT_KW , 0 );
rfip_kw = ecl_file_view_iget_named_kw( restart_file , RFIPWAT_KW , 0 );
{
int iactive;
@ -269,17 +269,17 @@ static ecl_grav_phase_type * ecl_grav_phase_alloc( ecl_grav_type * ecl_grav ,
/* (calc_type == GRAV_CALC_RPORV) || (calc_type == GRAV_CALC_PORMOD) */
ecl_kw_type * sat_kw;
bool private_sat_kw = false;
if (ecl_file_has_kw( restart_file , sat_kw_name ))
sat_kw = ecl_file_iget_named_kw( restart_file , sat_kw_name , 0 );
if (ecl_file_view_has_kw( restart_file , sat_kw_name ))
sat_kw = ecl_file_view_iget_named_kw( restart_file , sat_kw_name , 0 );
else {
/* We are targeting the residual phase, e.g. the OIL phase in a three phase system. */
const ecl_kw_type * swat_kw = ecl_file_iget_named_kw( restart_file , "SWAT" , 0 );
const ecl_kw_type * swat_kw = ecl_file_view_iget_named_kw( restart_file , "SWAT" , 0 );
sat_kw = ecl_kw_alloc_copy( swat_kw );
ecl_kw_scalar_set_float( sat_kw , 1.0 );
ecl_kw_inplace_sub( sat_kw , swat_kw ); /* sat = 1 - SWAT */
if (ecl_file_has_kw( restart_file , "SGAS" )) {
const ecl_kw_type * sgas_kw = ecl_file_iget_named_kw( restart_file , "SGAS" , 0 );
if (ecl_file_view_has_kw( restart_file , "SGAS" )) {
const ecl_kw_type * sgas_kw = ecl_file_view_iget_named_kw( restart_file , "SGAS" , 0 );
ecl_kw_inplace_sub( sat_kw , sgas_kw ); /* sat -= SGAS */
}
private_sat_kw = true;
@ -327,7 +327,7 @@ static void ecl_grav_survey_add_phase( ecl_grav_survey_type * survey, ecl_phase_
}
static void ecl_grav_survey_add_phases( ecl_grav_type * ecl_grav , ecl_grav_survey_type * survey, const ecl_file_type * restart_file , grav_calc_type calc_type) {
static void ecl_grav_survey_add_phases( ecl_grav_type * ecl_grav , ecl_grav_survey_type * survey, const ecl_file_view_type * restart_file , grav_calc_type calc_type) {
int phases = ecl_file_get_phases( ecl_grav->init_file );
if (phases & ECL_OIL_PHASE) {
ecl_grav_phase_type * oil_phase = ecl_grav_phase_alloc( ecl_grav , survey , ECL_OIL_PHASE , restart_file , calc_type);
@ -455,11 +455,11 @@ static void ecl_grav_survey_assert_RPORV( const ecl_grav_survey_type * survey ,
static ecl_grav_survey_type * ecl_grav_survey_alloc_RPORV(ecl_grav_type * ecl_grav ,
const ecl_file_type * restart_file ,
const ecl_file_view_type * restart_file ,
const char * name ) {
ecl_grav_survey_type * survey = ecl_grav_survey_alloc_empty( ecl_grav , name , GRAV_CALC_RPORV);
if (ecl_file_has_kw( restart_file , RPORV_KW)) {
ecl_kw_type * rporv_kw = ecl_file_iget_named_kw( restart_file , RPORV_KW , 0);
if (ecl_file_view_has_kw( restart_file , RPORV_KW)) {
ecl_kw_type * rporv_kw = ecl_file_view_iget_named_kw( restart_file , RPORV_KW , 0);
int iactive;
for (iactive = 0; iactive < ecl_kw_get_size( rporv_kw ); iactive++)
survey->porv[ iactive ] = ecl_kw_iget_as_double( rporv_kw , iactive );
@ -477,12 +477,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_type * restart_file ,
const ecl_file_view_type * restart_file ,
const char * name ) {
ecl_grid_cache_type * 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_iget_named_kw( restart_file , PORMOD_KW , 0 ); /* Active 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 );
int active_index;
@ -504,7 +504,7 @@ static ecl_grav_survey_type * ecl_grav_survey_alloc_PORMOD(ecl_grav_type * ecl_g
*/
static ecl_grav_survey_type * ecl_grav_survey_alloc_FIP(ecl_grav_type * ecl_grav ,
const ecl_file_type * restart_file ,
const ecl_file_view_type * restart_file ,
const char * name ) {
ecl_grav_survey_type * survey = ecl_grav_survey_alloc_empty( ecl_grav , name , GRAV_CALC_FIP);
@ -516,7 +516,7 @@ static ecl_grav_survey_type * ecl_grav_survey_alloc_FIP(ecl_grav_type * ecl_grav
static ecl_grav_survey_type * ecl_grav_survey_alloc_RFIP(ecl_grav_type * ecl_grav ,
const ecl_file_type * restart_file ,
const ecl_file_view_type * restart_file ,
const char * name ) {
ecl_grav_survey_type * survey = ecl_grav_survey_alloc_empty( ecl_grav , name , GRAV_CALC_RFIP);
@ -587,27 +587,27 @@ static void ecl_grav_add_survey__( ecl_grav_type * grav , const char * name , ec
}
ecl_grav_survey_type * ecl_grav_add_survey_RPORV( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file ) {
ecl_grav_survey_type * ecl_grav_add_survey_RPORV( ecl_grav_type * grav , const char * name , const ecl_file_view_type * restart_file ) {
ecl_grav_survey_type * survey = ecl_grav_survey_alloc_RPORV( grav , restart_file , name );
ecl_grav_add_survey__( grav , name , survey );
return survey;
}
ecl_grav_survey_type * ecl_grav_add_survey_FIP( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file ) {
ecl_grav_survey_type * ecl_grav_add_survey_FIP( ecl_grav_type * grav , const char * name , const ecl_file_view_type * restart_file ) {
ecl_grav_survey_type * survey = ecl_grav_survey_alloc_FIP( grav , restart_file , name );
ecl_grav_add_survey__( grav , name , survey );
return survey;
}
ecl_grav_survey_type * ecl_grav_add_survey_RFIP( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file ) {
ecl_grav_survey_type * ecl_grav_add_survey_RFIP( ecl_grav_type * grav , const char * name , const ecl_file_view_type * restart_file ) {
ecl_grav_survey_type * survey = ecl_grav_survey_alloc_RFIP( grav , restart_file , name );
ecl_grav_add_survey__( grav , name , survey );
return survey;
}
ecl_grav_survey_type * ecl_grav_add_survey_PORMOD( ecl_grav_type * grav , const char * name , const ecl_file_type * restart_file ) {
ecl_grav_survey_type * ecl_grav_add_survey_PORMOD( ecl_grav_type * grav , const char * name , const ecl_file_view_type * restart_file ) {
ecl_grav_survey_type * survey = ecl_grav_survey_alloc_PORMOD( grav , restart_file , name );
ecl_grav_add_survey__( grav , name , survey );
return survey;

View File

@ -2656,15 +2656,13 @@ static void ecl_grid_init_nnc(ecl_grid_type * main_grid, ecl_file_type * ecl_fil
}
for (i = 0; i < num_nnchead_kw; i++) {
ecl_file_push_block(ecl_file); /* <---------------------------------------------------------------- */
ecl_file_select_block(ecl_file , NNCHEAD_KW , i);
{
ecl_kw_type * nnchead_kw = ecl_file_iget_named_kw(ecl_file, NNCHEAD_KW, 0);
ecl_file_view_type * lgr_view = ecl_file_alloc_global_blockview(ecl_file , NNCHEAD_KW , i);
ecl_kw_type * nnchead_kw = ecl_file_view_iget_named_kw(lgr_view, NNCHEAD_KW, 0);
int lgr_nr = ecl_kw_iget_int(nnchead_kw, NNCHEAD_LGR_INDEX);
if (ecl_file_has_kw(ecl_file , NNC1_KW)) {
const ecl_kw_type * nnc1 = ecl_file_iget_named_kw(ecl_file, NNC1_KW, 0);
const ecl_kw_type * nnc2 = ecl_file_iget_named_kw(ecl_file, NNC2_KW, 0);
if (ecl_file_view_has_kw(lgr_view , NNC1_KW)) {
const ecl_kw_type * nnc1 = ecl_file_view_iget_named_kw(lgr_view, NNC1_KW, 0);
const ecl_kw_type * nnc2 = ecl_file_view_iget_named_kw(lgr_view, NNC2_KW, 0);
{
ecl_grid_type * grid = (lgr_nr > 0) ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid;
@ -2672,16 +2670,16 @@ static void ecl_grid_init_nnc(ecl_grid_type * main_grid, ecl_file_type * ecl_fil
}
}
if (ecl_file_has_kw(ecl_file , NNCL_KW)) {
const ecl_kw_type * nncl = ecl_file_iget_named_kw(ecl_file, NNCL_KW, 0);
const ecl_kw_type * nncg = ecl_file_iget_named_kw(ecl_file, NNCG_KW, 0);
if (ecl_file_view_has_kw(lgr_view , NNCL_KW)) {
const ecl_kw_type * nncl = ecl_file_view_iget_named_kw(lgr_view, NNCL_KW, 0);
const ecl_kw_type * nncg = ecl_file_view_iget_named_kw(lgr_view, NNCG_KW, 0);
{
ecl_grid_type * grid = (lgr_nr > 0) ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid;
ecl_grid_init_nnc_cells(main_grid, grid , nncg, nncl);
}
}
}
ecl_file_pop_block( ecl_file ); /* <------------------------------------------------------------------ */
ecl_file_view_free( lgr_view );
}
}

View File

@ -96,8 +96,10 @@ ecl_rft_file_type * ecl_rft_file_alloc(const char * filename) {
int block_nr = 0;
while (true) {
if (ecl_file_select_block( ecl_file , TIME_KW , block_nr)) {
ecl_rft_node_type * rft_node = ecl_rft_node_alloc( ecl_file );
ecl_file_view_type * rft_view = ecl_file_alloc_global_blockview(ecl_file, TIME_KW, block_nr);
if (rft_view) {
ecl_rft_node_type * rft_node = ecl_rft_node_alloc( rft_view );
if (rft_node != NULL) {
const char * well_name = ecl_rft_node_get_well_name( rft_node );
ecl_rft_file_add_node(rft_vector , rft_node);
@ -111,7 +113,9 @@ ecl_rft_file_type * ecl_rft_file_alloc(const char * filename) {
}
} else
break;
block_nr++;
ecl_file_view_free( rft_view );
}
ecl_file_close( ecl_file );
return rft_vector;

View File

@ -31,6 +31,7 @@
#include <ert/ecl/ecl_kw.h>
#include <ert/ecl/ecl_kw_magic.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_rft_node.h>
#include <ert/ecl/ecl_rft_cell.h>
@ -151,27 +152,27 @@ void ecl_rft_node_append_cell( ecl_rft_node_type * rft_node , ecl_rft_cell_type
}
static ecl_kw_type * ecl_rft_node_get_pressure_kw( ecl_rft_node_type * rft_node , const ecl_file_type * rft ) {
static ecl_kw_type * ecl_rft_node_get_pressure_kw( ecl_rft_node_type * rft_node , const ecl_file_view_type * rft ) {
if (rft_node->data_type == RFT)
return ecl_file_iget_named_kw( rft , PRESSURE_KW , 0);
return ecl_file_view_iget_named_kw( rft , PRESSURE_KW , 0);
else {
ecl_kw_type * conpres_kw = ecl_file_iget_named_kw( rft , CONPRES_KW , 0);
ecl_kw_type * conpres_kw = ecl_file_view_iget_named_kw( rft , CONPRES_KW , 0);
if (ecl_kw_element_sum_float( conpres_kw ) > 0.0 )
return conpres_kw;
else
return ecl_file_iget_named_kw( rft , PRESSURE_KW , 0);
return ecl_file_view_iget_named_kw( rft , PRESSURE_KW , 0);
}
}
static void ecl_rft_node_init_RFT_cells( ecl_rft_node_type * rft_node , const ecl_file_type * rft) {
const ecl_kw_type * conipos = ecl_file_iget_named_kw( rft , CONIPOS_KW , 0);
const ecl_kw_type * conjpos = ecl_file_iget_named_kw( rft , CONJPOS_KW , 0);
const ecl_kw_type * conkpos = ecl_file_iget_named_kw( rft , CONKPOS_KW , 0);
const ecl_kw_type * depth_kw = ecl_file_iget_named_kw( rft , DEPTH_KW , 0);
const ecl_kw_type * swat_kw = ecl_file_iget_named_kw( rft , SWAT_KW , 0);
const ecl_kw_type * sgas_kw = ecl_file_iget_named_kw( rft , SGAS_KW , 0);
const ecl_kw_type * pressure_kw = ecl_rft_node_get_pressure_kw( rft_node , rft );
static void ecl_rft_node_init_RFT_cells( ecl_rft_node_type * rft_node , const ecl_file_view_type * rft_view) {
const ecl_kw_type * conipos = ecl_file_view_iget_named_kw( rft_view , CONIPOS_KW , 0);
const ecl_kw_type * conjpos = ecl_file_view_iget_named_kw( rft_view , CONJPOS_KW , 0);
const ecl_kw_type * conkpos = ecl_file_view_iget_named_kw( rft_view , CONKPOS_KW , 0);
const ecl_kw_type * depth_kw = ecl_file_view_iget_named_kw( rft_view , DEPTH_KW , 0);
const ecl_kw_type * swat_kw = ecl_file_view_iget_named_kw( rft_view , SWAT_KW , 0);
const ecl_kw_type * sgas_kw = ecl_file_view_iget_named_kw( rft_view , SGAS_KW , 0);
const ecl_kw_type * pressure_kw = ecl_rft_node_get_pressure_kw( rft_node , rft_view );
const float * SW = ecl_kw_get_float_ptr( swat_kw );
const float * SG = ecl_kw_get_float_ptr( sgas_kw );
@ -196,34 +197,34 @@ static void ecl_rft_node_init_RFT_cells( ecl_rft_node_type * rft_node , const ec
static void ecl_rft_node_init_PLT_cells( ecl_rft_node_type * rft_node , const ecl_file_type * rft) {
static void ecl_rft_node_init_PLT_cells( ecl_rft_node_type * rft_node , const ecl_file_view_type * rft_view) {
/* For PLT there is quite a lot of extra information which is not yet internalized. */
const ecl_kw_type * conipos = ecl_file_iget_named_kw( rft , CONIPOS_KW , 0);
const ecl_kw_type * conjpos = ecl_file_iget_named_kw( rft , CONJPOS_KW , 0);
const ecl_kw_type * conkpos = ecl_file_iget_named_kw( rft , CONKPOS_KW , 0);
const ecl_kw_type * conipos = ecl_file_view_iget_named_kw( rft_view , CONIPOS_KW , 0);
const ecl_kw_type * conjpos = ecl_file_view_iget_named_kw( rft_view , CONJPOS_KW , 0);
const ecl_kw_type * conkpos = ecl_file_view_iget_named_kw( rft_view , CONKPOS_KW , 0);
const int * i = ecl_kw_get_int_ptr( conipos );
const int * j = ecl_kw_get_int_ptr( conjpos );
const int * k = ecl_kw_get_int_ptr( conkpos );
const float * WR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONWRAT_KW , 0));
const float * GR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONGRAT_KW , 0));
const float * OR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONORAT_KW , 0));
const float * P = ecl_kw_get_float_ptr( ecl_rft_node_get_pressure_kw( rft_node , rft ));
const float * depth = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONDEPTH_KW , 0));
const float * flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONVTUB_KW , 0));
const float * oil_flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONOTUB_KW , 0));
const float * gas_flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONGTUB_KW , 0));
const float * water_flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONWTUB_KW , 0));
const float * WR = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONWRAT_KW , 0));
const float * GR = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONGRAT_KW , 0));
const float * OR = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONORAT_KW , 0));
const float * P = ecl_kw_get_float_ptr( ecl_rft_node_get_pressure_kw( rft_node , rft_view ));
const float * depth = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONDEPTH_KW , 0));
const float * flowrate = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONVTUB_KW , 0));
const float * oil_flowrate = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONOTUB_KW , 0));
const float * gas_flowrate = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONGTUB_KW , 0));
const float * water_flowrate = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONWTUB_KW , 0));
const float * connection_start = NULL;
const float * connection_end = NULL;
/* The keywords CONLENST_KW and CONLENEN_KW are ONLY present if we are dealing with a MSW well. */
if (ecl_file_has_kw( rft , CONLENST_KW))
connection_start = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONLENST_KW , 0));
if (ecl_file_view_has_kw( rft_view , CONLENST_KW))
connection_start = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONLENST_KW , 0));
if (ecl_file_has_kw( rft , CONLENEN_KW))
connection_end = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONLENEN_KW , 0));
if (ecl_file_view_has_kw( rft_view , CONLENEN_KW))
connection_end = ecl_kw_get_float_ptr( ecl_file_view_iget_named_kw( rft_view , CONLENEN_KW , 0));
{
int c;
@ -250,22 +251,22 @@ static void ecl_rft_node_init_PLT_cells( ecl_rft_node_type * rft_node , const ec
static void ecl_rft_node_init_cells( ecl_rft_node_type * rft_node , const ecl_file_type * rft ) {
static void ecl_rft_node_init_cells( ecl_rft_node_type * rft_node , const ecl_file_view_type * rft_view ) {
if (rft_node->data_type == RFT)
ecl_rft_node_init_RFT_cells( rft_node , rft );
ecl_rft_node_init_RFT_cells( rft_node , rft_view );
else if (rft_node->data_type == PLT)
ecl_rft_node_init_PLT_cells( rft_node , rft );
ecl_rft_node_init_PLT_cells( rft_node , rft_view );
}
ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_type * rft) {
ecl_kw_type * welletc = ecl_file_iget_named_kw(rft , WELLETC_KW , 0);
ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_view_type * rft_view) {
ecl_kw_type * welletc = ecl_file_view_iget_named_kw(rft_view , WELLETC_KW , 0);
ecl_rft_node_type * rft_node = ecl_rft_node_alloc_empty(ecl_kw_iget_ptr(welletc , WELLETC_TYPE_INDEX));
if (rft_node != NULL) {
ecl_kw_type * date_kw = ecl_file_iget_named_kw( rft , DATE_KW , 0);
ecl_kw_type * date_kw = ecl_file_view_iget_named_kw( rft_view , DATE_KW , 0);
rft_node->well_name = util_alloc_strip_copy( ecl_kw_iget_ptr(welletc , WELLETC_NAME_INDEX));
/* Time information. */
@ -273,13 +274,13 @@ ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_type * rft) {
int * time = ecl_kw_get_int_ptr( date_kw );
rft_node->recording_date = ecl_util_make_date( time[DATE_DAY_INDEX] , time[DATE_MONTH_INDEX] , time[DATE_YEAR_INDEX] );
}
rft_node->days = ecl_kw_iget_float( ecl_file_iget_named_kw( rft , TIME_KW , 0 ) , 0);
if (ecl_file_has_kw( rft , CONLENST_KW))
rft_node->days = ecl_kw_iget_float( ecl_file_view_iget_named_kw( rft_view , TIME_KW , 0 ) , 0);
if (ecl_file_view_has_kw( rft_view , CONLENST_KW))
rft_node->MSW = true;
else
rft_node->MSW = false;
ecl_rft_node_init_cells( rft_node , rft );
ecl_rft_node_init_cells( rft_node , rft_view );
}
return rft_node;
}

View File

@ -16,282 +16,6 @@
for more details.
*/
/*****************************************************************/
/* R E S T A R T F I L E S */
/*****************************************************************/
/*
This file is included from the ecl_file.c file with a #include
statement, i.e. it is the same compilation unit as ecl_file. The
separation is only to increase readability.
*/
/*
There is no special datastructure for working with restart files,
they are 100% stock ecl_file instances with the following limited
structure:
* They are organized in blocks; where each block starts with a
SEQNUM keyword, which contains the report step.
* Each block contains an INTEHEAD keyword, immediately after the
SEQNUM keyword, which contains the true simulation date of of the
block, and also some other data. Observe that also INIT files and
GRID files contain an INTEHEAD keyword; and that for files with
LGRs there is one INTEHEAD keyword for each LGR. This creates an
extra level of mess.
The natural time ordering when working with the file data is just
the running index in the file; however from a user perspective the
natural way to indicate time coordinate is through the report step
or the true simulation time (i.e. 22.th of October 2009). This file
is all about converting the natural input unit time and report_step
to the internal indexing. This is achieved by consulting the value
of the INTEHEAD and SEQNUM keywords respectively.
*/
/*
About the time-direction
========================
For the following discussion we will focus on the following simplified
unified restart file. The leading number is the global index of the
keyword, the value in [] corresponds to the relevant part of the
content of the keyword on the line, the labels A,B,C,D,E are used for
references in the text below.
0 | SEQNUM [0] \ A
1 | INTEHEAD [01.01.2005] |
2 | PRESSURE [... ] |
3 | SWAT [...] |
| -----------------------+
4 | SEQNUM [5] | B
5 | INTEHEAD [01.06.2005] |
6 | PRESSURE [... ] |
7 | SWAT [...] |
|------------------------+
8 | SEQNUM [10] | C
9 | INTEHEAD [01.12.2006] |
10 | PRESSURE [...] |
11 | SWAT [...] |
|------------------------+
12 | SEQNUM [20] | D
13 | INTEHEAD [01.12.2007] |
14 | PRESSURE [...] |
15 | SWAT [...] |
16 | OIL_DEN [...] |
|------------------------+
12 | SEQNUM [40] | E
13 | INTEHEAD [01.12.2009] |
14 | PRESSURE [...] |
15 | SWAT [...] /
This restart file has the following features:
o It contains in total 16 keywords.
o It contains 5 blocks of collected keywords corresponding to one
time instant, each of these blocks is called a report_step,
typcially coming from one DATES keyword in the ECLIPSE
datafile. Observe that the file does not have the block structure
visualized on this figure, the only thing separating the blocks in
the file is the occurence of a SEQNUM keyword.
o Only a few of the report steps are present, namely 0, 5, 10, 20 and
40.
o The different blocks are not equally long, the fourth block has an
extra keyword OIL_DEN.
To adress these keywords and blocks using different time coordinates
we have introduced the following concepts:
report_step: This corresponds to the value of the SEQNUM keword,
i.e. to do queries based on the report_step we must load the
seqnum kewyord and read the value.
ecl_file_get_unrstmap_report_step( ecl_file , 0 ) => A
ecl_file_get_unrstmap_report_step( ecl_file , 1 ) => NULL
ecl_file_has_report_step( ecl_file , 5 ) => True
ecl_file_has_report_step( ecl_file , 2 ) => False
sim_time: This correpsonds to the true simulation time of the report
step, the simulation time is stored as integers DAY, MONTH, YEAR
in the INTEHEAD keyword; the function INTEHEAD_date() will extract
the DAY, MONTH and YEAR values from an INTEHEAD keyword instance
and convert to a time_t instance. The functions:
ecl_file_get_unrstmap_sim_time() and ecl_file_has_has_sim_time()
can be used to query for simulation times and get the
corresponding block maps.
index/global_index : This is typically the global running index of
the keyword in the file; this is the unique address of the keyword
which is used for the final lookup.
occurence: The nth' time a particular keyword has occured in the
file, i.e. the SEQNUM keyword in block C is the third occurence of
SEQNUM. Instead of occurence xxxx_index is also used to indicate
the occurence of keyword xxxx. The occurence number is the integer
argument to the xxx_iget_named_kw() function, and also the final
call to create blockmaps.
*/
static bool file_map_has_report_step( const file_map_type * file_map , int report_step) {
int global_index = file_map_find_kw_value( file_map , SEQNUM_KW , &report_step );
if (global_index >= 0)
return true;
else
return false;
}
static time_t file_map_iget_restart_sim_date(const file_map_type * file_map , int seqnum_index) {
time_t sim_time = -1;
file_map_type * seqnum_map = seqnum_map = file_map_alloc_blockmap( file_map , SEQNUM_KW , seqnum_index);
if (seqnum_map != NULL) {
ecl_kw_type * intehead_kw = file_map_iget_named_kw( seqnum_map , INTEHEAD_KW , 0);
sim_time = ecl_rsthead_date( intehead_kw );
file_map_free( seqnum_map );
}
return sim_time;
}
static double file_map_iget_restart_sim_days(const file_map_type * file_map , int seqnum_index) {
double sim_days = 0;
file_map_type * seqnum_map = seqnum_map = file_map_alloc_blockmap( file_map , SEQNUM_KW , seqnum_index);
if (seqnum_map != NULL) {
ecl_kw_type * doubhead_kw = file_map_iget_named_kw( seqnum_map , DOUBHEAD_KW , 0);
sim_days = ecl_kw_iget_double( doubhead_kw , DOUBHEAD_DAYS_INDEX);
file_map_free( seqnum_map );
}
return sim_days;
}
static int file_map_find_sim_time(const file_map_type * file_map , time_t sim_time) {
int seqnum_index = -1;
if ( file_map_has_kw( file_map , INTEHEAD_KW)) {
const int_vector_type * intehead_index_list = hash_get( file_map->kw_index , INTEHEAD_KW );
int index = 0;
while (index < int_vector_size( intehead_index_list )) {
const ecl_kw_type * intehead_kw = file_map_iget_kw( file_map , int_vector_iget( intehead_index_list , index ));
if (ecl_rsthead_date( intehead_kw ) == sim_time) {
seqnum_index = index;
break;
}
index++;
}
}
return seqnum_index;
}
/**
This function will scan through the ecl_file looking for INTEHEAD
headers corresponding to sim_time. If sim_time is found the
function will return the INTEHEAD occurence number, i.e. for a
unified restart file like:
INTEHEAD / 01.01.2000
...
PRESSURE
SWAT
...
INTEHEAD / 01.03.2000
...
PRESSURE
SWAT
...
INTEHEAD / 01.05.2000
...
PRESSURE
SWAT
....
The function call:
ecl_file_get_restart_index( restart_file , (time_t) "01.03.2000")
will return 1. Observe that this will in general NOT agree with the
DATES step number.
If the sim_time can not be found the function will return -1, that
includes the case when the file in question is not a restart file
at all, and no INTEHEAD headers can be found.
Observe that the function requires on-the-second-equality; which is
of course quite strict.
Each report step only has one occurence of SEQNUM, but one INTEHEAD
for each LGR; i.e. one should call iselect_rstblock() prior to
calling this function.
*/
static bool file_map_has_sim_time( const file_map_type * file_map , time_t sim_time) {
int num_INTEHEAD = file_map_get_num_named_kw( file_map , INTEHEAD_KW );
if (num_INTEHEAD == 0)
return false; /* We have no INTEHEAD headers - probably not a restart file at all. */
else {
/*
Should probably do something smarter than a linear search; but I dare not
take the chance that all INTEHEAD headers are properly set. This is from
Schlumberger after all.
*/
int intehead_index = 0;
while (true) {
time_t itime = file_map_iget_restart_sim_date( file_map , intehead_index );
if (itime == sim_time) /* Perfect hit. */
return true;
if (itime > sim_time) /* We have gone past the target_time - i.e. we do not have it. */
return false;
intehead_index++;
if (intehead_index == num_INTEHEAD) /* We have iterated through the whole thing without finding sim_time. */
return false;
}
}
}
static int file_map_seqnum_index_from_sim_time( file_map_type * parent_map , time_t sim_time) {
int num_seqnum = file_map_get_num_named_kw( parent_map , SEQNUM_KW );
int seqnum_index = 0;
file_map_type * seqnum_map;
while (true) {
seqnum_map = file_map_alloc_blockmap( parent_map , SEQNUM_KW , seqnum_index);
if (seqnum_map != NULL) {
if (file_map_has_sim_time( seqnum_map , sim_time)) {
file_map_free( seqnum_map );
return seqnum_index;
} else {
file_map_free( seqnum_map );
seqnum_index++;
}
}
if (num_seqnum == seqnum_index)
return -1;
}
}
/******************************************************************/
@ -307,7 +31,7 @@ static int file_map_seqnum_index_from_sim_time( file_map_type * parent_map , tim
bool ecl_file_has_sim_time( const ecl_file_type * ecl_file , time_t sim_time) {
return file_map_has_sim_time( ecl_file->active_map , sim_time );
return ecl_file_view_has_sim_time( ecl_file->active_view , sim_time );
}
@ -348,7 +72,7 @@ bool ecl_file_has_sim_time( const ecl_file_type * ecl_file , time_t sim_time) {
*/
int ecl_file_get_restart_index( const ecl_file_type * ecl_file , time_t sim_time) {
int active_index = file_map_find_sim_time( ecl_file->active_map , sim_time );
int active_index = ecl_file_view_find_sim_time( ecl_file->active_view , sim_time );
return active_index;
}
@ -360,7 +84,7 @@ int ecl_file_get_restart_index( const ecl_file_type * ecl_file , time_t sim_time
*/
bool ecl_file_has_report_step( const ecl_file_type * ecl_file , int report_step) {
return file_map_has_report_step( ecl_file->active_map , report_step );
return ecl_file_view_has_report_step( ecl_file->active_view , report_step );
}
@ -372,11 +96,11 @@ bool ecl_file_has_report_step( const ecl_file_type * ecl_file , int report_step)
*/
time_t ecl_file_iget_restart_sim_date( const ecl_file_type * restart_file , int index ) {
return file_map_iget_restart_sim_date( restart_file->active_map , index );
return ecl_file_view_iget_restart_sim_date( restart_file->active_view , index );
}
double ecl_file_iget_restart_sim_days( const ecl_file_type * restart_file , int index ) {
return file_map_iget_restart_sim_days( restart_file->active_map , index );
return ecl_file_view_iget_restart_sim_days( restart_file->active_view , index );
}
@ -386,86 +110,7 @@ double ecl_file_iget_restart_sim_days( const ecl_file_type * restart_file , int
*/
/*
Will select restart block nr @seqnum_index - without considering
report_steps or simulation time.
*/
bool ecl_file_iselect_rstblock( ecl_file_type * ecl_file , int seqnum_index ) {
return ecl_file_select_block( ecl_file , SEQNUM_KW , seqnum_index );
}
bool ecl_file_select_rstblock_sim_time( ecl_file_type * ecl_file , time_t sim_time) {
int seqnum_index = file_map_seqnum_index_from_sim_time( ecl_file->global_map , sim_time );
if (seqnum_index >= 0)
return ecl_file_iselect_rstblock( ecl_file , seqnum_index);
else
return false;
}
bool ecl_file_select_rstblock_report_step( ecl_file_type * ecl_file , int report_step) {
int global_index = file_map_find_kw_value( ecl_file->global_map , SEQNUM_KW , &report_step);
if ( global_index >= 0) {
int seqnum_index = file_map_iget_occurence( ecl_file->global_map , global_index );
return ecl_file_iselect_rstblock( ecl_file , seqnum_index);
} else
return false;
}
/******************************************************************/
static ecl_file_type * ecl_file_open_rstblock_report_step__( const char * filename , int report_step , int flags) {
ecl_file_type * ecl_file = ecl_file_open( filename , flags );
if (ecl_file) {
if (!ecl_file_select_rstblock_report_step( ecl_file , report_step )) {
ecl_file_close( ecl_file );
ecl_file = NULL;
}
}
return ecl_file;
}
ecl_file_type * ecl_file_open_rstblock_report_step( const char * filename , int report_step , int flags) {
return ecl_file_open_rstblock_report_step__(filename , report_step , flags );
}
/******************************************************************/
static ecl_file_type * ecl_file_open_rstblock_sim_time__( const char * filename , time_t sim_time, int flags ) {
ecl_file_type * ecl_file = ecl_file_open( filename , flags );
if (ecl_file) {
if (!ecl_file_select_rstblock_sim_time( ecl_file , sim_time)) {
ecl_file_close( ecl_file );
ecl_file = NULL;
}
}
return ecl_file;
}
ecl_file_type * ecl_file_open_rstblock_sim_time( const char * filename , time_t sim_time, int flags) {
return ecl_file_open_rstblock_sim_time__( filename , sim_time , flags );
}
/******************************************************************/
static ecl_file_type * ecl_file_iopen_rstblock__( const char * filename , int seqnum_index, int flags ) {
ecl_file_type * ecl_file = ecl_file_open( filename , flags );
if (ecl_file) {
if (!ecl_file_iselect_rstblock( ecl_file , seqnum_index )) {
ecl_file_close( ecl_file );
ecl_file = NULL;
}
}
return ecl_file;
}
ecl_file_type * ecl_file_iopen_rstblock( const char * filename , int seqnum_index , int flags) {
return ecl_file_iopen_rstblock__(filename , seqnum_index , flags );
}

View File

@ -20,6 +20,7 @@
#include <ert/util/util.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_kw.h>
#include <ert/ecl/ecl_rsthead.h>
#include <ert/ecl/ecl_kw_magic.h>
@ -86,7 +87,6 @@ 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);
@ -95,35 +95,35 @@ ecl_rsthead_type * ecl_rsthead_alloc_from_kw( int report_step , const ecl_kw_typ
}
ecl_rsthead_type * ecl_rsthead_ialloc( const ecl_file_type * rst_file , int occurence) {
if (ecl_file_get_num_named_kw( rst_file , INTEHEAD_KW) > occurence) {
const ecl_kw_type * intehead_kw = ecl_file_iget_named_kw( rst_file , INTEHEAD_KW , occurence);
const ecl_kw_type * doubhead_kw = NULL;
/*
- If the rst_view corresponds to a block of an underlying unified
restart file the report_step value will be inferred from the
SEQNUM keyword.
- If the rst_view corresponds to an underlying non-unified restart
file the report step must have been inferred from the filename
*prior* to calling this function.
*/
ecl_rsthead_type * ecl_rsthead_alloc( const ecl_file_view_type * rst_view, int report_step) {
const ecl_kw_type * intehead_kw = ecl_file_view_iget_named_kw( rst_view , INTEHEAD_KW , 0);
const ecl_kw_type * doubhead_kw = ecl_file_view_iget_named_kw( rst_view , DOUBHEAD_KW , 0);
const ecl_kw_type * logihead_kw = NULL;
int report_step;
if (ecl_file_get_num_named_kw(rst_file, LOGIHEAD_KW) > occurence)
logihead_kw = ecl_file_iget_named_kw( rst_file , LOGIHEAD_KW , occurence);
if (ecl_file_get_num_named_kw(rst_file, DOUBHEAD_KW) > occurence) {
doubhead_kw = ecl_file_iget_named_kw(rst_file, DOUBHEAD_KW, occurence);
}
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_get_num_named_kw( rst_file , SEQNUM_KW) > occurence) {
const ecl_kw_type * seqnum_kw = ecl_file_iget_named_kw( rst_file , SEQNUM_KW , occurence );
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);
} else
ecl_util_get_file_type( ecl_file_get_src_file(rst_file) , NULL , &report_step);
}
return ecl_rsthead_alloc_from_kw( report_step , intehead_kw , doubhead_kw , logihead_kw );
} else
return NULL;
}
ecl_rsthead_type * ecl_rsthead_alloc( const ecl_file_type * rst_file) {
return ecl_rsthead_ialloc( rst_file , 0 );
}

View File

@ -1,41 +0,0 @@
/*
Copyright (C) 2011 Statoil ASA, Norway.
The file 'ecl_rstfile.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.
*/
/*****************************************************************/
/* S U M M A R Y F I L E S */
/*****************************************************************/
bool ecl_file_select_smryblock( ecl_file_type * ecl_file , int report_step ) {
return ecl_file_select_block( ecl_file , SEQHDR_KW , report_step );
}
ecl_file_type * ecl_file_open_smryblock( const char * filename , int report_step , int flags) {
ecl_file_type * ecl_file = ecl_file_open( filename , flags );
if (ecl_file) {
if (!ecl_file_select_smryblock( ecl_file , report_step )) {
ecl_file_close( ecl_file );
ecl_file = NULL;
}
}
return ecl_file;
}

View File

@ -816,6 +816,8 @@ static void ecl_smspec_install_special_keys( ecl_smspec_type * ecl_smspec , smsp
break;
case(ECL_SMSPEC_REGION_2_REGION_VAR):
break;
case(ECL_SMSPEC_AQUIFER_VAR):
break;
default:
util_abort("%: Internal error - should never be here ?? \n",__func__);
break;

View File

@ -98,7 +98,7 @@ static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_empty(const ecl_
static UTIL_SAFE_CAST_FUNCTION( ecl_subsidence_survey , ECL_SUBSIDENCE_SURVEY_ID )
static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_PRESSURE(ecl_subsidence_type * ecl_subsidence ,
const ecl_file_type * restart_file ,
const ecl_file_view_type * restart_view ,
const char * name ) {
ecl_subsidence_survey_type * survey = ecl_subsidence_survey_alloc_empty( ecl_subsidence , name );
@ -107,7 +107,7 @@ static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_PRESSURE(ecl_sub
const int size = ecl_grid_cache_get_size( grid_cache );
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_iget_named_kw( restart_file , PRESSURE_KW , 0); /*Active indexing*/
ecl_kw_type * pressure_kw = ecl_file_view_iget_named_kw( restart_view , PRESSURE_KW , 0); /*Active indexing*/
for (active_index = 0; active_index < size; active_index++){
survey->porv[ active_index ] = ecl_kw_iget_float( init_porv_kw , global_index[active_index] );
@ -186,30 +186,22 @@ static void ecl_subsidence_add_survey__( ecl_subsidence_type * subsidence , cons
hash_insert_hash_owned_ref( subsidence->surveys , name , survey , ecl_subsidence_survey_free__ );
}
ecl_subsidence_survey_type * ecl_subsidence_add_survey_PRESSURE( ecl_subsidence_type * subsidence , const char * name , const ecl_file_type * restart_file ) {
ecl_subsidence_survey_type * survey = ecl_subsidence_survey_alloc_PRESSURE( subsidence , restart_file , name );
ecl_subsidence_survey_type * ecl_subsidence_add_survey_PRESSURE( ecl_subsidence_type * subsidence , const char * name , const ecl_file_view_type * restart_view ) {
ecl_subsidence_survey_type * survey = ecl_subsidence_survey_alloc_PRESSURE( subsidence , restart_view , name );
ecl_subsidence_add_survey__( subsidence , name , survey );
return survey;
}
bool ecl_subsidence_has_survey( const ecl_subsidence_type * subsidence , const char * name) {
return hash_has_key( subsidence->surveys , name );
}
static ecl_subsidence_survey_type * ecl_subsidence_get_survey( const ecl_subsidence_type * subsidence , const char * name) {
if (name == NULL)
return NULL; // Calling scope must determine if this is OK?
else {
if (hash_has_key( subsidence->surveys , name))
else
return hash_get( subsidence->surveys , name );
else {
hash_iter_type * survey_iter = hash_iter_alloc( subsidence->surveys );
fprintf(stderr,"Survey name:%s not registered. Available surveys are: \n\n " , name);
while (!hash_iter_is_complete( survey_iter )) {
const char * survey = hash_iter_get_next_key( survey_iter );
fprintf(stderr,"%s ",survey);
}
fprintf(stderr,"\n\n");
hash_iter_free( survey_iter );
exit(1);
}
}
}

View File

@ -915,17 +915,17 @@ ecl_sum_tstep_type * ecl_sum_data_add_new_tstep( ecl_sum_data_type * data , int
static void ecl_sum_data_add_ecl_file(ecl_sum_data_type * data ,
time_t load_end ,
int report_step ,
const ecl_file_type * ecl_file ,
const ecl_file_view_type * summary_view,
const ecl_smspec_type * smspec) {
int num_ministep = ecl_file_get_num_named_kw( ecl_file , PARAMS_KW);
int num_ministep = ecl_file_view_get_num_named_kw( summary_view , PARAMS_KW);
if (num_ministep > 0) {
int ikw;
for (ikw = 0; ikw < num_ministep; ikw++) {
ecl_kw_type * ministep_kw = ecl_file_iget_named_kw( ecl_file , MINISTEP_KW , ikw);
ecl_kw_type * params_kw = ecl_file_iget_named_kw( ecl_file , PARAMS_KW , ikw);
ecl_kw_type * ministep_kw = ecl_file_view_iget_named_kw( summary_view , MINISTEP_KW , ikw);
ecl_kw_type * params_kw = ecl_file_view_iget_named_kw( summary_view , PARAMS_KW , ikw);
{
ecl_sum_tstep_type * tstep;
@ -933,7 +933,7 @@ static void ecl_sum_data_add_ecl_file(ecl_sum_data_type * data ,
tstep = ecl_sum_tstep_alloc_from_file( report_step ,
ministep_nr ,
params_kw ,
ecl_file_get_src_file( ecl_file ),
ecl_file_view_get_src_file( summary_view ),
smspec );
if (tstep != NULL) {
@ -992,7 +992,7 @@ static bool ecl_sum_data_fread__( ecl_sum_data_type * data , time_t load_end , c
{
ecl_file_type * ecl_file = ecl_file_open( data_file , 0);
if (ecl_file && ecl_sum_data_check_file( ecl_file )) {
ecl_sum_data_add_ecl_file( data , load_end , report_step , ecl_file , data->smspec);
ecl_sum_data_add_ecl_file( data , load_end , report_step , ecl_file_get_global_view( ecl_file ) , data->smspec);
ecl_file_close( ecl_file );
}
}
@ -1009,8 +1009,9 @@ static bool ecl_sum_data_fread__( ecl_sum_data_type * data , time_t load_end , c
SEQHDR block in the unified summary file is block zero (in
ert counting).
*/
if (ecl_file_select_smryblock( ecl_file , report_step - 1)) {
ecl_sum_data_add_ecl_file( data , load_end , report_step , ecl_file , data->smspec);
ecl_file_view_type * summary_view = ecl_file_get_summary_view(ecl_file , report_step - 1 );
if (summary_view) {
ecl_sum_data_add_ecl_file( data , load_end , report_step , summary_view , data->smspec);
report_step++;
} else break;
}

View File

@ -79,6 +79,7 @@ struct smspec_node_struct {
ecl_sum combined key like 'WWCT:OPX' as input.
*/
#define ECL_SUM_KEYFMT_AQUIFER "%s%s%d"
#define ECL_SUM_KEYFMT_BLOCK_IJK "%s%s%d,%d,%d"
#define ECL_SUM_KEYFMT_BLOCK_NUM "%s%s%d"
#define ECL_SUM_KEYFMT_LOCAL_BLOCK "%s%s%s%s%d,%d,%d"
@ -103,6 +104,14 @@ char * smspec_alloc_block_num_key( const char * join_string , const char * keywo
num );
}
char * smspec_alloc_aquifer_key( const char * join_string , const char * keyword , int num) {
return util_alloc_sprintf(ECL_SUM_KEYFMT_AQUIFER,
keyword ,
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 ,
@ -508,6 +517,9 @@ static void smspec_node_set_gen_keys( smspec_node_type * smspec_node , const cha
smspec_node->lgr_ijk[1],
smspec_node->lgr_ijk[2]);
break;
case(ECL_SMSPEC_AQUIFER_VAR):
smspec_node->gen_key1 = smspec_alloc_aquifer_key( key_join_string , smspec_node->keyword , smspec_node->num);
break;
default:
util_abort("%s: internal error - should not be here? \n" , __func__);
@ -612,6 +624,9 @@ bool smspec_node_init( smspec_node_type * smspec_node,
if (util_string_equal( keyword ,SMSPEC_YEARS_KEYWORD))
smspec_node_set_num( smspec_node , grid_dims , SMSPEC_YEARS_NUMS_VALUE );
break;
case(ECL_SMSPEC_AQUIFER_VAR):
smspec_node_set_num( smspec_node , grid_dims , num );
break;
default:
/* Lots of legitimate alternatives which are not internalized. */

View File

@ -26,6 +26,7 @@
#include <ert/ecl/ecl_util.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/ecl_endian_flip.h>

View File

@ -26,6 +26,7 @@
#include <ert/ecl/ecl_util.h>
#include <ert/ecl/ecl_nnc_export.h>
#include <ert/ecl/ecl_kw_magic.h>
#include <ert/ecl/ecl_file_view.h>
@ -118,13 +119,12 @@ void test_export(const char * name, bool have_tran_data) {
int nnc_offset = 0;
int block_nr = 0;
for (block_nr = 0; block_nr < ecl_file_get_num_named_kw( grid_file , NNCHEAD_KW); block_nr++) {
ecl_file_push_block( grid_file );
ecl_file_select_block( grid_file , NNCHEAD_KW , block_nr );
ecl_file_view_type * nnc_view = ecl_file_alloc_global_blockview(grid_file, NNCHEAD_KW, block_nr);
if (ecl_file_has_kw( grid_file , NNC1_KW )) {
ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw( grid_file , NNC1_KW , 0 );
ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw( grid_file , NNC2_KW , 0 );
ecl_kw_type * nnchead = ecl_file_iget_named_kw( grid_file , NNCHEAD_KW , 0);
if (ecl_file_view_has_kw( nnc_view , NNC1_KW )) {
ecl_kw_type * nnc1_kw = ecl_file_view_iget_named_kw( nnc_view , NNC1_KW , 0 );
ecl_kw_type * nnc2_kw = ecl_file_view_iget_named_kw( nnc_view , NNC2_KW , 0 );
ecl_kw_type * nnchead = ecl_file_view_iget_named_kw( nnc_view , NNCHEAD_KW , 0);
int lgr_nr1 = ecl_kw_iget_int( nnchead , NNCHEAD_LGR_INDEX);
int lgr_nr2 = ecl_kw_iget_int( nnchead , NNCHEAD_LGR_INDEX);
ecl_kw_type * nnc_tran = ecl_nnc_export_get_tranx_kw( grid , init_file , lgr_nr1 , lgr_nr2);
@ -163,10 +163,10 @@ void test_export(const char * name, bool have_tran_data) {
}
if (ecl_file_has_kw( grid_file, NNCL_KW)) {
ecl_kw_type * nncl_kw = ecl_file_iget_named_kw( grid_file , NNCL_KW , 0 );
ecl_kw_type * nncg_kw = ecl_file_iget_named_kw( grid_file , NNCG_KW , 0 );
ecl_kw_type * nnchead = ecl_file_iget_named_kw( grid_file , NNCHEAD_KW , 0);
if (ecl_file_view_has_kw( nnc_view , NNCL_KW)) {
ecl_kw_type * nncl_kw = ecl_file_view_iget_named_kw( nnc_view , NNCL_KW , 0 );
ecl_kw_type * nncg_kw = ecl_file_view_iget_named_kw( nnc_view , NNCG_KW , 0 );
ecl_kw_type * nnchead = ecl_file_view_iget_named_kw( nnc_view , NNCHEAD_KW , 0);
int lgr_nr1 = 0;
int lgr_nr2 = ecl_kw_iget_int( nnchead , NNCHEAD_LGR_INDEX);
ecl_kw_type * nnc_tran = ecl_nnc_export_get_tranx_kw( grid , init_file , 0 , lgr_nr2);
@ -183,7 +183,8 @@ void test_export(const char * name, bool have_tran_data) {
}
nnc_offset += ecl_kw_get_size( nncl_kw );
}
ecl_file_pop_block( grid_file );
ecl_file_view_free( nnc_view );
}
{

View File

@ -25,6 +25,7 @@
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/nnc_info.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_kw_magic.h>
@ -36,9 +37,7 @@ void test_scan( const char * grid_filename) {
for (block_nr = 0; block_nr < ecl_file_get_num_named_kw( grid_file , NNCHEAD_KW ); block_nr++) {
ecl_grid_type * lgr = ecl_grid;
int lgr_nr;
ecl_file_push_block( grid_file );
ecl_file_select_block(grid_file , NNCHEAD_KW , block_nr );
ecl_file_view_type * nnc_view = ecl_file_alloc_global_blockview(grid_file, NNCHEAD_KW, block_nr);
{
if (block_nr > 0)
lgr = ecl_grid_iget_lgr( ecl_grid , block_nr - 1);
@ -46,9 +45,9 @@ void test_scan( const char * grid_filename) {
/* Internal nnc */
{
if (ecl_file_has_kw( grid_file , NNC1_KW)) {
ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw(grid_file , NNC1_KW , 0 );
ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw(grid_file , NNC2_KW , 0 );
if (ecl_file_view_has_kw( nnc_view , NNC1_KW)) {
ecl_kw_type * nnc1_kw = ecl_file_view_iget_named_kw(nnc_view , NNC1_KW , 0 );
ecl_kw_type * nnc2_kw = ecl_file_view_iget_named_kw(nnc_view , NNC2_KW , 0 );
int i;
for (i=0; i < ecl_kw_get_size(nnc1_kw); i++) {
const int g1 = ecl_kw_iget_int( nnc1_kw , i ) - 1;
@ -67,10 +66,10 @@ void test_scan( const char * grid_filename) {
/* Global -> lgr */
{
if (ecl_file_has_kw( grid_file , NNCG_KW)) {
ecl_kw_type * nnchead_kw = ecl_file_iget_named_kw( grid_file , NNCHEAD_KW , 0);
ecl_kw_type * nncg_kw = ecl_file_iget_named_kw(grid_file , NNCG_KW , 0 );
ecl_kw_type * nncl_kw = ecl_file_iget_named_kw(grid_file , NNCL_KW , 0 );
if (ecl_file_view_has_kw( nnc_view , NNCG_KW)) {
ecl_kw_type * nnchead_kw = ecl_file_view_iget_named_kw( nnc_view , NNCHEAD_KW , 0);
ecl_kw_type * nncg_kw = ecl_file_view_iget_named_kw(nnc_view , NNCG_KW , 0 );
ecl_kw_type * nncl_kw = ecl_file_view_iget_named_kw(nnc_view , NNCL_KW , 0 );
int i;
int lgr_nr = ecl_kw_iget_int( nnchead_kw , NNCHEAD_LGR_INDEX);
for (i=0; i < ecl_kw_get_size(nncg_kw); i++) {
@ -90,10 +89,10 @@ void test_scan( const char * grid_filename) {
/* Amalgamated: LGR -> LGR */
{
if (ecl_file_has_kw( grid_file , NNCHEADA_KW)) {
ecl_kw_type * nncheada_kw = ecl_file_iget_named_kw( grid_file , NNCHEADA_KW , 0);
ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw(grid_file , NNA1_KW , 0 );
ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw(grid_file , NNA2_KW , 0 );
if (ecl_file_view_has_kw( nnc_view , NNCHEADA_KW)) {
ecl_kw_type * nncheada_kw = ecl_file_view_iget_named_kw(nnc_view , NNCHEADA_KW , 0);
ecl_kw_type * nnc1_kw = ecl_file_view_iget_named_kw(nnc_view , NNA1_KW , 0 );
ecl_kw_type * nnc2_kw = ecl_file_view_iget_named_kw(nnc_view , NNA2_KW , 0 );
int lgr_nr1 = ecl_kw_iget_int( nncheada_kw , NNCHEADA_ILOC1_INDEX);
int lgr_nr2 = ecl_kw_iget_int( nncheada_kw , NNCHEADA_ILOC2_INDEX);
@ -109,7 +108,8 @@ void test_scan( const char * grid_filename) {
}
}
}
ecl_file_pop_block( grid_file );
ecl_file_view_free( nnc_view );
}
}

View File

@ -28,14 +28,24 @@
void test_file( const char * filename , int occurence , bool exists , const ecl_rsthead_type * true_header) {
int report_step = ecl_util_filename_report_nr( filename );
ecl_file_type * rst_file = ecl_file_open( filename , 0);
ecl_rsthead_type * rst_head = ecl_rsthead_ialloc( rst_file , occurence);
ecl_file_enum file_type = ecl_util_get_file_type( filename , NULL , NULL );
ecl_file_view_type * rst_view;
ecl_rsthead_type * rst_head;
if (file_type == ECL_RESTART_FILE)
rst_view = ecl_file_get_global_view( rst_file );
else
rst_view = ecl_file_get_restart_view( rst_file , occurence , -1 , -1 , -1 );
if (exists) {
test_assert_not_NULL( rst_view );
rst_head = ecl_rsthead_alloc( rst_view , report_step);
test_assert_not_NULL( rst_head );
if (occurence == 0) {
ecl_rsthead_type * rst_head0 = ecl_rsthead_alloc( rst_file );
ecl_rsthead_type * rst_head0 = ecl_rsthead_alloc( rst_view , report_step );
test_assert_true( ecl_rsthead_equal( rst_head , rst_head0 ));
ecl_rsthead_free( rst_head0 );
@ -44,7 +54,7 @@ void test_file( const char * filename , int occurence , bool exists , const ecl_
ecl_rsthead_free( rst_head );
} else
test_assert_NULL( rst_head );
test_assert_NULL( rst_view );
}
@ -101,8 +111,8 @@ int main(int argc , char ** argv) {
const char * unified_file = argv[1];
const char * Xfile = argv[2];
// test_file( unified_file , 0 , true , &true1 );
//test_file( unified_file , 100 , false , NULL );
test_file( unified_file , 0 , true , &true1 );
test_file( unified_file , 100 , false , NULL );
test_file( Xfile , 0 , true , &true2 );
exit(0);

View File

@ -37,10 +37,10 @@
int main(int argc , char ** argv) {
const char * Xfile = argv[1];
ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( ecl_file_get_global_view(rst_file) , ecl_util_filename_report_nr(Xfile));
const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 );
const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 );
well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(rst_file);
well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(ecl_file_get_global_view(rst_file));
const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );
const ecl_kw_type * scon_kw = ecl_file_iget_named_kw( rst_file , SCON_KW , 0 );
const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( rst_file , ZWEL_KW , 0 );

View File

@ -32,8 +32,10 @@ extern "C" {
typedef struct well_info_struct well_info_type;
well_info_type * well_info_alloc(const ecl_grid_type * grid);
void well_info_add_UNRST_wells2( well_info_type * well_info , ecl_file_view_type * rst_view, bool load_segment_information);
void well_info_add_UNRST_wells( well_info_type * well_info , ecl_file_type * rst_file, bool load_segment_information);
void well_info_add_wells( well_info_type * well_info , ecl_file_type * rst_file , int report_nr , bool load_segment_information);
void well_info_add_wells2( well_info_type * well_info , ecl_file_view_type * rst_view , int report_nr, bool load_segment_information);
void well_info_load_rstfile( well_info_type * well_info , const char * filename, bool load_segment_information);
void well_info_load_rst_eclfile( well_info_type * well_info , ecl_file_type * rst_file , bool load_segment_information);
void well_info_free( well_info_type * well_info );

View File

@ -24,12 +24,12 @@
extern "C" {
#endif
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
typedef struct well_rseg_loader_struct well_rseg_loader_type;
well_rseg_loader_type * well_rseg_loader_alloc(ecl_file_type * rst_file);
well_rseg_loader_type * well_rseg_loader_alloc(ecl_file_view_type * rst_view);
void well_rseg_loader_free(well_rseg_loader_type * well_rseg_loader);
int well_rseg_loader_element_count(const well_rseg_loader_type * well_rseg_loader);

View File

@ -42,6 +42,12 @@ extern "C" {
well_state_type * well_state_alloc(const char * well_name , int global_well_nr , bool open, well_type_enum type , int report_nr, time_t valid_from);
well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_step , int well_nr , bool load_segment_information);
well_state_type * well_state_alloc_from_file2( ecl_file_view_type * file_view , const ecl_grid_type * grid , int report_nr , int global_well_nr ,bool load_segment_information);
void well_state_add_connections2( well_state_type * well_state ,
const ecl_grid_type * grid ,
ecl_file_view_type * rst_view ,
int well_nr);
void well_state_add_connections( well_state_type * well_state ,
const ecl_grid_type * grid ,
@ -54,6 +60,12 @@ extern "C" {
bool load_segment_information);
bool well_state_add_MSW2( well_state_type * well_state ,
ecl_file_view_type * rst_view,
int well_nr,
bool load_segment_information);
bool well_state_is_MSW( const well_state_type * well_state);
bool well_state_has_segment_data(const well_state_type * well_state);

View File

@ -26,6 +26,7 @@
#include <ert/ecl/ecl_rsthead.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_kw.h>
#include <ert/ecl/ecl_kw_magic.h>
#include <ert/ecl/ecl_util.h>
@ -273,25 +274,24 @@ static void well_info_add_state( well_info_type * well_info , well_state_type *
determine the number of wells.
*/
void well_info_add_wells( well_info_type * well_info , ecl_file_type * rst_file , int report_nr, bool load_segment_information) {
int flags = ecl_file_get_flags(rst_file);
if (ecl_file_flags_set(rst_file, ECL_FILE_CLOSE_STREAM)) {
int new_flags = flags & ~ECL_FILE_CLOSE_STREAM;
ecl_file_set_flags(rst_file, new_flags);
}
{
ecl_rsthead_type * global_header = ecl_rsthead_alloc( rst_file );
void well_info_add_wells2( well_info_type * well_info , ecl_file_view_type * rst_view , int report_nr, bool load_segment_information) {
bool close_stream = ecl_file_view_drop_flag( rst_view , ECL_FILE_CLOSE_STREAM );
ecl_rsthead_type * global_header = ecl_rsthead_alloc( rst_view , report_nr );
int well_nr;
for (well_nr = 0; well_nr < global_header->nwells; well_nr++) {
well_state_type * well_state = well_state_alloc_from_file( rst_file , well_info->grid , report_nr , well_nr , load_segment_information );
well_state_type * well_state = well_state_alloc_from_file2( rst_view , well_info->grid , report_nr , well_nr , load_segment_information );
if (well_state != NULL)
well_info_add_state( well_info , well_state );
}
ecl_rsthead_free( global_header );
if (close_stream)
ecl_file_view_add_flag(rst_view, ECL_FILE_CLOSE_STREAM);
}
ecl_file_set_flags(rst_file, flags);
void well_info_add_wells( well_info_type * well_info , ecl_file_type * rst_file , int report_nr, bool load_segment_information) {
well_info_add_wells2( well_info , ecl_file_get_active_view( rst_file ) , report_nr , load_segment_information );
}
/**
@ -300,23 +300,21 @@ void well_info_add_wells( well_info_type * well_info , ecl_file_type * rst_file
not have the SEQNUM keyword.
*/
void well_info_add_UNRST_wells( well_info_type * well_info , ecl_file_type * rst_file, bool load_segment_information) {
{
int num_blocks = ecl_file_get_num_named_kw( rst_file , SEQNUM_KW );
void well_info_add_UNRST_wells2( well_info_type * well_info , ecl_file_view_type * rst_view, bool load_segment_information) {
int num_blocks = ecl_file_view_get_num_named_kw( rst_view , SEQNUM_KW );
int block_nr;
for (block_nr = 0; block_nr < num_blocks; block_nr++) {
ecl_file_push_block( rst_file ); // <-------------------------------------------------------
{ //
ecl_file_subselect_block( rst_file , SEQNUM_KW , block_nr ); // Ensure that the status
{ // is not changed as a side
const ecl_kw_type * seqnum_kw = ecl_file_iget_named_kw( rst_file , SEQNUM_KW , 0); // effect.
int report_nr = ecl_kw_iget_int( seqnum_kw , 0 ); //
well_info_add_wells( well_info , rst_file , report_nr , load_segment_information ); //
} //
} //
ecl_file_pop_block( rst_file ); // <-------------------------------------------------------
ecl_file_view_type * step_view = ecl_file_view_add_restart_view(rst_view, block_nr , -1 , -1 , -1 );
const ecl_kw_type * seqnum_kw = ecl_file_view_iget_named_kw( step_view , SEQNUM_KW , 0);
int report_nr = ecl_kw_iget_int( seqnum_kw , 0 );
well_info_add_wells2( well_info , step_view , report_nr , load_segment_information );
}
}
void well_info_add_UNRST_wells( well_info_type * well_info , ecl_file_type * rst_file, bool load_segment_information) {
well_info_add_UNRST_wells2( well_info , ecl_file_get_global_view( rst_file ) , load_segment_information);
}

View File

@ -22,6 +22,7 @@
#include <ert/util/int_vector.h>
#include <ert/ecl/ecl_file.h>
#include <ert/ecl/ecl_file_view.h>
#include <ert/ecl/ecl_kw_magic.h>
#include <ert/ecl_well/well_const.h>
@ -31,7 +32,7 @@
struct well_rseg_loader_struct {
ecl_file_type * rst_file;
ecl_file_view_type * rst_view;
int_vector_type * relative_index_map;
int_vector_type * absolute_index_map;
char * buffer;
@ -39,12 +40,12 @@ struct well_rseg_loader_struct {
};
well_rseg_loader_type * well_rseg_loader_alloc(ecl_file_type * rst_file) {
well_rseg_loader_type * well_rseg_loader_alloc(ecl_file_view_type * rst_view) {
well_rseg_loader_type * loader = util_malloc(sizeof * loader);
int element_count = 4;
loader->rst_file = rst_file;
loader->rst_view = rst_view;
loader->relative_index_map = int_vector_alloc(0, 0);
loader->absolute_index_map = int_vector_alloc(0, 0);
loader->buffer = util_malloc(element_count * sizeof(double));
@ -64,9 +65,9 @@ int well_rseg_loader_element_count(const well_rseg_loader_type * well_rseg_loade
void well_rseg_loader_free(well_rseg_loader_type * loader) {
if(ecl_file_flags_set(loader->rst_file, ECL_FILE_CLOSE_STREAM)) {
ecl_file_close_fortio_stream(loader->rst_file);
}
if(ecl_file_view_flags_set(loader->rst_view, ECL_FILE_CLOSE_STREAM))
ecl_file_view_fclose_stream(loader->rst_view);
int_vector_free(loader->relative_index_map);
int_vector_free(loader->absolute_index_map);
@ -83,7 +84,7 @@ double * well_rseg_loader_load_values(const well_rseg_loader_type * loader, int
int_vector_iset(index_map, index, relative_index + rseg_offset);
}
ecl_file_indexed_read(loader->rst_file, loader->kw, 0, index_map, loader->buffer);
ecl_file_view_index_fload_kw(loader->rst_view, loader->kw, 0, index_map, loader->buffer);
return (double*) loader->buffer;
}

View File

@ -233,12 +233,12 @@ void well_state_add_wellhead( well_state_type * well_state , const ecl_rsthead_t
all.
*/
static int well_state_get_lgr_well_nr( const well_state_type * well_state , const ecl_file_type * ecl_file) {
static int well_state_get_lgr_well_nr( const well_state_type * well_state , const ecl_file_view_type * file_view) {
int well_nr = -1;
if (ecl_file_has_kw( ecl_file , ZWEL_KW)) {
ecl_rsthead_type * header = ecl_rsthead_alloc( ecl_file );
const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW , 0 );
if (ecl_file_view_has_kw( file_view , ZWEL_KW)) {
ecl_rsthead_type * header = ecl_rsthead_alloc( file_view , -1);
const ecl_kw_type * zwel_kw = ecl_file_view_iget_named_kw( file_view , ZWEL_KW , 0 );
int num_wells = header->nwells;
well_nr = 0;
while (true) {
@ -304,14 +304,14 @@ well_type_enum well_state_translate_ecl_type_int(int int_type) {
*/
static void well_state_add_connections__( well_state_type * well_state ,
const ecl_file_type * rst_file ,
const ecl_file_view_type * rst_view ,
const char * grid_name ,
int grid_nr,
int well_nr ) {
ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file );
const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0);
const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0);
ecl_rsthead_type * header = ecl_rsthead_alloc( rst_view , -1);
const ecl_kw_type * icon_kw = ecl_file_view_iget_named_kw( rst_view , ICON_KW , 0);
const ecl_kw_type * iwel_kw = ecl_file_view_iget_named_kw( rst_view , IWEL_KW , 0);
well_state_add_wellhead( well_state , header , iwel_kw , well_nr , grid_name , grid_nr );
@ -322,8 +322,8 @@ static void well_state_add_connections__( well_state_type * well_state ,
{
ecl_kw_type * scon_kw = NULL;
well_conn_collection_type * wellcc = hash_get( well_state->connections , grid_name );
if (ecl_file_has_kw( rst_file , SCON_KW))
scon_kw = ecl_file_iget_named_kw( rst_file , SCON_KW , 0);
if (ecl_file_view_has_kw( rst_view , SCON_KW))
scon_kw = ecl_file_view_iget_named_kw( rst_view , SCON_KW , 0);
well_conn_collection_load_from_kw( wellcc , iwel_kw , icon_kw , scon_kw , well_nr , header );
}
@ -332,28 +332,23 @@ static void well_state_add_connections__( well_state_type * well_state ,
static void well_state_add_global_connections( well_state_type * well_state ,
const ecl_file_type * rst_file ,
const ecl_file_view_type * rst_view ,
int well_nr ) {
well_state_add_connections__( well_state , rst_file , ECL_GRID_GLOBAL_GRID , 0 , well_nr );
well_state_add_connections__( well_state , rst_view , ECL_GRID_GLOBAL_GRID , 0 , well_nr );
}
static void well_state_add_LGR_connections( well_state_type * well_state , const ecl_grid_type * grid , ecl_file_type * ecl_file, int global_well_nr ) {
static void well_state_add_LGR_connections( well_state_type * well_state , const ecl_grid_type * grid , ecl_file_view_type * file_view , int global_well_nr ) {
// Go through all the LGRs and add connections; both in the bulk
// grid and as wellhead.
int num_lgr = ecl_grid_get_num_lgr( grid );
int lgr_index;
for (lgr_index = 0; lgr_index < num_lgr; lgr_index++) {
ecl_file_push_block( ecl_file ); // <-------------------------//
{ //
ecl_file_subselect_block( ecl_file , LGR_KW , lgr_index ); //
{ // Restrict the file view
const char * grid_name = ecl_grid_iget_lgr_name( grid , lgr_index ); //
int well_nr = well_state_get_lgr_well_nr( well_state , ecl_file ); // to one LGR block.
if (well_nr >= 0) //
well_state_add_connections__( well_state , ecl_file , grid_name , lgr_index + 1, well_nr ); //
} //
} //
ecl_file_pop_block( ecl_file ); // <-------------------------//
ecl_file_view_type * lgr_view = ecl_file_view_add_blockview(file_view , LGR_KW , lgr_index);
const char * grid_name = ecl_grid_iget_lgr_name( grid , lgr_index );
int well_nr = well_state_get_lgr_well_nr( well_state , lgr_view );
if (well_nr >= 0)
well_state_add_connections__( well_state , lgr_view , grid_name , lgr_index + 1, well_nr );
}
}
@ -364,8 +359,18 @@ void well_state_add_connections( well_state_type * well_state ,
ecl_file_type * rst_file , // Either an open .Xnnnn file or UNRST file restricted to one report step
int well_nr) {
well_state_add_global_connections( well_state , rst_file , well_nr );
well_state_add_LGR_connections( well_state , grid , rst_file , well_nr );
well_state_add_connections2(well_state , grid , ecl_file_get_active_view( rst_file ) , well_nr );
}
void well_state_add_connections2( well_state_type * well_state ,
const ecl_grid_type * grid ,
ecl_file_view_type * rst_view ,
int well_nr) {
well_state_add_global_connections( well_state , rst_view , well_nr );
well_state_add_LGR_connections( well_state , grid , rst_view , well_nr );
}
@ -375,17 +380,26 @@ bool well_state_add_MSW( well_state_type * well_state ,
int well_nr,
bool load_segment_information) {
if (ecl_file_has_kw( rst_file , ISEG_KW)) {
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file );
const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0);
const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0);
return well_state_add_MSW2( well_state , ecl_file_get_active_view(rst_file) , well_nr , load_segment_information );
}
bool well_state_add_MSW2( well_state_type * well_state ,
ecl_file_view_type * rst_view ,
int well_nr,
bool load_segment_information) {
if (ecl_file_view_has_kw( rst_view , ISEG_KW)) {
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_view , -1);
const ecl_kw_type * iwel_kw = ecl_file_view_iget_named_kw( rst_view , IWEL_KW , 0);
const ecl_kw_type * iseg_kw = ecl_file_view_iget_named_kw( rst_view , ISEG_KW , 0);
well_rseg_loader_type * rseg_loader = NULL;
int segment_count;
if (ecl_file_has_kw( rst_file , RSEG_KW )) {
if (ecl_file_view_has_kw( rst_view , RSEG_KW )) {
if (load_segment_information)
rseg_loader = well_rseg_loader_alloc(rst_file);
rseg_loader = well_rseg_loader_alloc(rst_view);
segment_count = well_segment_collection_load_from_kw( well_state->segments ,
well_nr ,
@ -433,13 +447,16 @@ bool well_state_has_segment_data(const well_state_type * well_state){
return false;
}
well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_nr , int global_well_nr ,bool load_segment_information) {
if (ecl_file_has_kw( ecl_file , IWEL_KW)) {
return well_state_alloc_from_file2( ecl_file_get_active_view( ecl_file ) , grid , report_nr , global_well_nr , load_segment_information);
}
well_state_type * well_state_alloc_from_file2( ecl_file_view_type * file_view , const ecl_grid_type * grid , int report_nr , int global_well_nr ,bool load_segment_information) {
if (ecl_file_view_has_kw( file_view , IWEL_KW)) {
well_state_type * well_state = NULL;
ecl_rsthead_type * global_header = ecl_rsthead_alloc( ecl_file );
const ecl_kw_type * global_iwel_kw = ecl_file_iget_named_kw( ecl_file , IWEL_KW , 0);
const ecl_kw_type * global_zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW , 0);
ecl_rsthead_type * global_header = ecl_rsthead_alloc( file_view , -1);
const ecl_kw_type * global_iwel_kw = ecl_file_view_iget_named_kw( file_view , IWEL_KW , 0);
const ecl_kw_type * global_zwel_kw = ecl_file_view_iget_named_kw( file_view , ZWEL_KW , 0);
const int iwel_offset = global_header->niwelz * global_well_nr;
{
@ -467,9 +484,9 @@ well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const e
well_state = well_state_alloc(name , global_well_nr , open , type , report_nr , global_header->sim_time);
free( name );
well_state_add_connections( well_state , grid , ecl_file , global_well_nr);
if (ecl_file_has_kw( ecl_file , ISEG_KW))
well_state_add_MSW( well_state , ecl_file , global_well_nr , load_segment_information);
well_state_add_connections2( well_state , grid , file_view , global_well_nr);
if (ecl_file_view_has_kw( file_view , ISEG_KW))
well_state_add_MSW2( well_state , file_view , global_well_nr , load_segment_information);
}

View File

@ -45,7 +45,7 @@ void well_conn_test_CF( const ecl_kw_type * iwel_kw , const ecl_kw_type * icon_k
int main(int argc , char ** argv) {
const char * Xfile = argv[1];
ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( ecl_file_get_global_view( rst_file ) , ecl_util_filename_report_nr(Xfile));
const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 );
const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );
const ecl_kw_type * scon_kw = ecl_file_iget_named_kw( rst_file , SCON_KW , 0 );

View File

@ -37,7 +37,7 @@ int main(int argc , char ** argv) {
const char * Xfile = argv[1];
bool MSW;
ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( ecl_file_get_global_view(rst_file) , ecl_util_filename_report_nr( Xfile ));
test_install_SIGNALS();
test_assert_true( util_sscanf_bool( argv[2] , &MSW ));

View File

@ -34,7 +34,7 @@
void test_rstfile( const char * filename , bool fracture_connection) {
ecl_file_type * rst_file = ecl_file_open( filename , 0);
const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0);
ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file );
ecl_rsthead_type * header = ecl_rsthead_alloc( ecl_file_get_global_view( rst_file ), ecl_util_filename_report_nr(filename));
well_conn_type * wellhead = well_conn_alloc_wellhead( iwel_kw , header , 0 );

View File

@ -39,10 +39,11 @@
int main(int argc , char ** argv) {
const char * Xfile = argv[1];
ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file );
ecl_file_view_type * rst_view = ecl_file_get_active_view( rst_file );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_view , ecl_util_filename_report_nr(Xfile));
const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 );
const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 );
well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(rst_file);
well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(rst_view);
const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );
const ecl_kw_type * scon_kw = NULL;

View File

@ -36,10 +36,11 @@
int main(int argc , char ** argv) {
const char * Xfile = argv[1];
ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file );
ecl_file_view_type * rst_view = ecl_file_get_active_view(rst_file);
ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_view , ecl_util_filename_report_nr(Xfile));
const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 );
const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 );
well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(rst_file);
well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(rst_view);
test_install_SIGNALS();
test_assert_not_NULL( rst_file );

View File

@ -38,7 +38,7 @@ int main(int argc , char ** argv) {
ecl_grid_type * grid = ecl_grid_alloc( grid_file );
ecl_file_type * rst_file = ecl_file_open( rst_file_name , 0);
ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file );
ecl_rsthead_type * header = ecl_rsthead_alloc( ecl_file_get_global_view( rst_file ) , ecl_util_filename_report_nr(rst_file_name) );
const char * well_name = "WELL";
int report_nr = 100;
time_t valid_from = -1;
@ -46,17 +46,18 @@ int main(int argc , char ** argv) {
well_type_enum type = ERT_GAS_INJECTOR;
int global_well_nr = 0;
bool load_segment_information = true;
ecl_file_view_type * rst_view = ecl_file_get_global_view( rst_file );
for (global_well_nr = 0; global_well_nr < header->nwells; global_well_nr++) {
well_state_type * well_state = well_state_alloc(well_name , global_well_nr , open , type , report_nr , valid_from);
test_assert_true( well_state_is_instance( well_state) );
well_state_add_connections( well_state , grid , rst_file , 0 );
well_state_add_connections2( well_state , grid , rst_view , 0 );
test_assert_true( well_state_has_grid_connections( well_state , ECL_GRID_GLOBAL_GRID ));
test_assert_false( well_state_has_grid_connections( well_state , "???" ));
test_assert_true( well_state_has_global_connections( well_state ));
well_state_add_MSW( well_state , rst_file , global_well_nr , load_segment_information );
well_state_add_MSW2( well_state , rst_view , global_well_nr , load_segment_information );
{
const well_segment_collection_type * segments = well_state_get_segments( well_state );
const well_branch_collection_type * branches = well_state_get_branches( well_state );

View File

@ -38,7 +38,8 @@ int main(int argc , char ** argv) {
ecl_grid_type * grid = ecl_grid_alloc( grid_file );
ecl_file_type * rst_file = ecl_file_open( rst_file_name , 0);
ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file );
ecl_file_view_type * rst_view = ecl_file_get_active_view(rst_file);
ecl_rsthead_type * header = ecl_rsthead_alloc( rst_view , ecl_util_filename_report_nr(rst_file_name) );
const char * well_name = "WELL";
int report_nr = 100;
time_t valid_from = -1;
@ -50,13 +51,13 @@ int main(int argc , char ** argv) {
for (global_well_nr = 0; global_well_nr < header->nwells; global_well_nr++) {
well_state_type * well_state = well_state_alloc(well_name , global_well_nr , open , type , report_nr , valid_from);
test_assert_true( well_state_is_instance( well_state) );
well_state_add_connections( well_state , grid , rst_file , 0 );
well_state_add_MSW( well_state , rst_file , global_well_nr , load_segment_information );
well_state_add_connections2( well_state , grid , rst_view , 0 );
well_state_add_MSW2( well_state , rst_view , global_well_nr , load_segment_information );
{
const well_segment_collection_type * segments = well_state_get_segments( well_state );
if (!ecl_file_has_kw( rst_file , RSEG_KW ))
if (!ecl_file_view_has_kw( rst_view , RSEG_KW ))
test_assert_int_equal( 0 , well_segment_collection_get_size( segments ));
}

View File

@ -978,7 +978,7 @@ static void assert_matrix_size(const matrix_type * m , const char * name , int r
static void assert_size_equal(int ens_size , const bool_vector_type * ens_mask) {
if (bool_vector_size( ens_mask ) != ens_size)
util_abort("%s: fundamental inconsisentcy detected. Total ens_size:%d mask_size:%d \n",__func__ , ens_size , bool_vector_size( ens_mask ));
util_abort("%s: fundamental inconsistency detected. Total ens_size:%d mask_size:%d \n",__func__ , ens_size , bool_vector_size( ens_mask ));
}
@ -1131,34 +1131,29 @@ static void enkf_main_analysis_update( enkf_main_type * enkf_main ,
// Opens and returns a log file. A subroutine of enkf_main_UPDATE.
static FILE * enkf_main_log_step_list(enkf_main_type * enkf_main, const int_vector_type * step_list) {
const char * log_path = analysis_config_get_log_path(enkf_main->analysis_config);
char * log_file;
if (int_vector_size(step_list) == 1)
log_file = util_alloc_sprintf("%s%c%04d", log_path, UTIL_PATH_SEP_CHAR, int_vector_iget(step_list, 0));
else
log_file = util_alloc_sprintf("%s%c%04d-%04d", log_path, UTIL_PATH_SEP_CHAR, int_vector_iget(step_list, 0),
int_vector_get_last(step_list));
FILE * log_stream = util_fopen(log_file, "w");
free(log_file);
return log_stream;
}
/**
This is T H E EnKF update routine.
**/
bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_list, enkf_fs_type * source_fs , enkf_fs_type * target_fs , int target_step , run_mode_type run_mode) {
/*
If merge_observations is true all observations in the time
interval [step1+1,step2] will be used, otherwise only the last
observation at step2 will be used.
* This is THE ENKF update function. It should only be called from enkf_main_UPDATE.
*/
state_map_type * source_state_map = enkf_fs_get_state_map( source_fs );
const analysis_config_type * analysis_config = enkf_main_get_analysis_config( enkf_main );
const int active_ens_size = state_map_count_matching( source_state_map , STATE_HAS_DATA );
const int total_ens_size = enkf_main_get_ensemble_size(enkf_main);
if (analysis_config_have_enough_realisations(analysis_config , active_ens_size, total_ens_size)) {
double alpha = analysis_config_get_alpha( enkf_main->analysis_config );
double std_cutoff = analysis_config_get_std_cutoff( enkf_main->analysis_config );
int current_step = int_vector_get_last( step_list );
state_map_type * target_state_map = enkf_fs_get_state_map( target_fs );
bool_vector_type * ens_mask = bool_vector_alloc(total_ens_size , false);
int_vector_type * ens_active_list = int_vector_alloc(0,0);
state_map_select_matching( source_state_map , ens_mask , STATE_HAS_DATA );
ens_active_list = bool_vector_alloc_active_list( ens_mask );
static void enkf_main_update__(enkf_main_type * enkf_main, const int_vector_type * step_list, enkf_fs_type * source_fs,
enkf_fs_type * target_fs, int target_step, run_mode_type run_mode, state_map_type * source_state_map,
const analysis_config_type * analysis_config, const local_updatestep_type * updatestep,
const int total_ens_size)
{
/*
Observations and measurements are collected in these temporary
@ -1169,23 +1164,21 @@ bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_
deactivating observations which should not be used in the update
process.
*/
bool_vector_type * ens_mask = bool_vector_alloc(total_ens_size, false);
state_map_select_matching(source_state_map, ens_mask, STATE_HAS_DATA);
double global_std_scaling = analysis_config_get_global_std_scaling(analysis_config);
obs_data_type * obs_data = obs_data_alloc(global_std_scaling);
meas_data_type * meas_data = meas_data_alloc(ens_mask);
local_config_type * local_config = enkf_main->local_config;
const local_updatestep_type * updatestep = local_config_get_updatestep( local_config );
hash_type * use_count = hash_alloc();
const char * log_path = analysis_config_get_log_path( enkf_main->analysis_config );
FILE * log_stream;
int_vector_type * ens_active_list = bool_vector_alloc_active_list(ens_mask);
/* Copy all the parameter nodes from source case to target case;
nodes which are updated will be fetched from the new target
case, and nodes which are not updated will be manually copied
over there.
*/
if (target_fs != source_fs) {
stringlist_type * param_keys = ensemble_config_alloc_keylist_from_var_type(enkf_main->ensemble_config, PARAMETER);
for (int i = 0; i < stringlist_get_size(param_keys); i++) {
@ -1193,8 +1186,7 @@ bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_
enkf_config_node_type * config_node = ensemble_config_get_node(enkf_main->ensemble_config, key);
enkf_node_type * data_node = enkf_node_alloc(config_node);
for (int j = 0; j < int_vector_size(ens_active_list); j++) {
node_id_type node_id = {.iens = int_vector_iget( ens_active_list , j ),
.report_step = 0 };
node_id_type node_id = { .iens = int_vector_iget(ens_active_list, j), .report_step = 0 };
enkf_node_load(data_node, source_fs, node_id);
enkf_node_store(data_node, target_fs, false, node_id);
}
@ -1203,25 +1195,13 @@ bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_
stringlist_free(param_keys);
}
FILE * log_stream = enkf_main_log_step_list(enkf_main, step_list);
if ((local_updatestep_get_num_ministep( updatestep ) > 1) &&
(analysis_config_get_module_option( analysis_config , ANALYSIS_ITERABLE))) {
util_exit("** ERROR: Can not combine iterable modules with multi step updates - sorry\n");
}
int current_step = int_vector_get_last(step_list);
hash_type * use_count = hash_alloc();
{
char * log_file;
if (int_vector_size( step_list ) == 1)
log_file = util_alloc_sprintf("%s%c%04d" , log_path , UTIL_PATH_SEP_CHAR , int_vector_iget( step_list , 0));
else
log_file = util_alloc_sprintf("%s%c%04d-%04d" , log_path , UTIL_PATH_SEP_CHAR , int_vector_iget( step_list , 0) , int_vector_get_last( step_list ));
log_stream = util_fopen( log_file , "w" );
free( log_file );
}
for (int ministep_nr = 0; ministep_nr < local_updatestep_get_num_ministep( updatestep ); ministep_nr++) { /* Looping over local analysis ministep */
/* Looping over local analysis ministep */
for (int ministep_nr = 0; ministep_nr < local_updatestep_get_num_ministep(updatestep); ministep_nr++) {
local_ministep_type * ministep = local_updatestep_iget_ministep(updatestep, ministep_nr);
local_obsdata_type * obsdata = local_ministep_get_obsdata(ministep);
@ -1237,18 +1217,16 @@ bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_
if (analysis_config_get_std_scale_correlated_obs(enkf_main->analysis_config)) {
double scale_factor = enkf_obs_scale_correlated_std(enkf_main->obs, source_fs, ens_active_list, obsdata);
ert_log_add_fmt_message(1, NULL, "Scaling standard deviation in obdsata set:%s with %g", local_obsdata_get_name(obsdata) , scale_factor);
ert_log_add_fmt_message(1, NULL, "Scaling standard deviation in obdsata set:%s with %g",
local_obsdata_get_name(obsdata), scale_factor);
}
enkf_obs_get_obs_and_measure_data( enkf_main->obs,
source_fs ,
obsdata,
ens_active_list ,
meas_data,
obs_data);
enkf_obs_get_obs_and_measure_data(enkf_main->obs, source_fs, obsdata, ens_active_list, meas_data, obs_data);
int_vector_free(ens_active_list);
double alpha = analysis_config_get_alpha(enkf_main->analysis_config);
double std_cutoff = analysis_config_get_std_cutoff(enkf_main->analysis_config);
enkf_analysis_deactivate_outliers(obs_data, meas_data, std_cutoff, alpha, enkf_main->verbose);
if (enkf_main->verbose)
@ -1268,7 +1246,8 @@ bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_
meas_data,
obs_data);
else if (target_fs != source_fs)
ert_log_add_fmt_message( 1 , stderr , "No active observations/parameters for MINISTEP: %s." , local_ministep_get_name(ministep));
ert_log_add_fmt_message(1, stderr, "No active observations/parameters for MINISTEP: %s.",
local_ministep_get_name(ministep));
}
fclose(log_stream);
@ -1278,23 +1257,67 @@ bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_
enkf_main_inflate(enkf_main, source_fs, target_fs, current_step, use_count);
hash_free(use_count);
state_map_type * target_state_map = enkf_fs_get_state_map(target_fs);
if (target_state_map != source_state_map) {
state_map_set_from_inverted_mask(target_state_map, ens_mask, STATE_PARENT_FAILURE);
state_map_set_from_mask(target_state_map, ens_mask, STATE_INITIALIZED);
enkf_fs_fsync(target_fs);
}
}
bool_vector_free( ens_mask);
int_vector_free( ens_active_list );
return true;
} else {
}
/**
* This is T H E EnKF update routine.
*/
bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_list, enkf_fs_type * source_fs , enkf_fs_type * target_fs , int target_step , run_mode_type run_mode) {
/*
If merge_observations is true all observations in the time
interval [step1+1,step2] will be used, otherwise only the last
observation at step2 will be used.
*/
state_map_type * source_state_map = enkf_fs_get_state_map( source_fs );
const analysis_config_type * analysis_config = enkf_main_get_analysis_config( enkf_main );
const int active_ens_size = state_map_count_matching( source_state_map , STATE_HAS_DATA );
const int total_ens_size = enkf_main_get_ensemble_size(enkf_main);
// exit if not enough realisations
if (!analysis_config_have_enough_realisations(analysis_config , active_ens_size, total_ens_size)) {
fprintf(stderr,"** ERROR ** There are %d active realisations left, which is less than the minimum specified - stopping assimilation.\n" ,
active_ens_size );
return false;
}
local_config_type * local_config = enkf_main->local_config;
const local_updatestep_type * updatestep = local_config_get_updatestep( local_config );
// exit if multi step update
if ((local_updatestep_get_num_ministep( updatestep ) > 1) &&
(analysis_config_get_module_option( analysis_config , ANALYSIS_ITERABLE))) {
util_exit("** ERROR: Can not combine iterable modules with multi step updates - sorry\n");
}
enkf_main_update__(enkf_main,
step_list,
source_fs,
target_fs,
target_step,
run_mode,
source_state_map,
analysis_config,
updatestep,
total_ens_size);
return true;
}
static bool enkf_main_smoother_update__(enkf_main_type * enkf_main , const int_vector_type * step_list , enkf_fs_type * source_fs, enkf_fs_type * target_fs) {
return enkf_main_UPDATE( enkf_main , step_list , source_fs , target_fs , 0 , SMOOTHER_UPDATE );

View File

@ -559,7 +559,7 @@ bool stringlist_equal(const stringlist_type * s1 , const stringlist_type *s2) {
char * stringlist_alloc_joined_substring( const stringlist_type * s , int start_index , int end_index , const char * sep ) {
if (start_index >= stringlist_get_size( s ))
return NULL;
return util_alloc_string_copy("");
{
char * string = NULL;
int i;

View File

@ -56,6 +56,14 @@ void test_join() {
const char * elt5 = "FFF";
stringlist_type * s = stringlist_alloc_new();
{
// empty join
const char* empty_join = stringlist_alloc_joined_string(s, "!!!");
test_assert_not_NULL(empty_join);
test_assert_string_equal("", empty_join);
}
stringlist_append_ref( s , elt0 );
stringlist_append_ref( s , elt1 );
stringlist_append_ref( s , elt2 );

View File

@ -347,35 +347,46 @@ stringlist_type * lsf_driver_alloc_cmd(lsf_driver_type * driver ,
*/
{
stringlist_type * excludes = stringlist_alloc_new();
char * select = NULL;
if (driver->exclude_hosts != NULL) {
stringlist_type * select_list = stringlist_alloc_new();
if (stringlist_get_size(driver->exclude_hosts) > 0) {
for (int i = 0; i < stringlist_get_size(driver->exclude_hosts); i++) {
char * exclude_host = util_alloc_sprintf("hname!='%s'", stringlist_iget(driver->exclude_hosts, i));
stringlist_append_owned_ref(excludes, exclude_host);
stringlist_append_owned_ref(select_list, exclude_host);
}
const char * excludes_string = stringlist_alloc_joined_string(excludes, " && ");
select = util_alloc_sprintf("select[%s]", excludes_string);
}
stringlist_type * qrr = stringlist_alloc_new();
if (select) {
stringlist_append_copy(qrr, select);
util_free(select);
char * excludes_string = NULL;
char * req = "";
char * resreq = NULL;
if (stringlist_get_size(select_list) > 0) {
excludes_string = stringlist_alloc_joined_string(select_list, " && ");
if (driver->resource_request != NULL) {
resreq = util_alloc_string_copy(driver->resource_request);
util_string_tr(resreq, ']', ' '); // remove "]" from "select[A && B]
excludes_string = stringlist_alloc_joined_string(select_list, " && ");
req = util_alloc_sprintf("%s && %s]", resreq, excludes_string);
} else {
req = util_alloc_sprintf("select[%s]", excludes_string);
}
if (driver->resource_request != NULL)
stringlist_append_copy(qrr, driver->resource_request);
const char* req = stringlist_alloc_joined_string(qrr, " ");
} else {
if (driver->resource_request != NULL) {
resreq = util_alloc_string_copy(driver->resource_request);
req = util_alloc_sprintf("%s", resreq);
}
}
if (resreq)
free(resreq);
if (driver->submit_method == LSF_SUBMIT_REMOTE_SHELL)
quoted_resource_request = util_alloc_sprintf("\"%s\"", req);
else
quoted_resource_request = util_alloc_string_copy(req);
stringlist_free( qrr );
stringlist_free( excludes );
free(req);
if (excludes_string)
free(excludes_string);
stringlist_free(select_list);
}
if (driver->submit_method == LSF_SUBMIT_REMOTE_SHELL)

View File

@ -5,6 +5,7 @@ set(PYTHON_SOURCES
ecl_3dkw.py
ecl_case.py
ecl_file.py
ecl_file_view.py
ecl_grav.py
ecl_grav_calc.py
ecl_grid.py

View File

@ -90,6 +90,7 @@ from .ecl_rft import EclRFT, EclRFTFile
from .fortio import FortIO, openFortIO
from .ecl_kw import EclKW
from .ecl_3dkw import Ecl3DKW
from .ecl_file_view import EclFileView
from .ecl_file import EclFile , openEclFile
from .ecl_3d_file import Ecl3DFile
from .ecl_init_file import EclInitFile

View File

@ -41,38 +41,26 @@ import datetime
import ctypes
import warnings
from cwrap import BaseCClass
from ert.ecl import EclPrototype, EclKW, EclFileEnum
from ert.ecl import EclPrototype, EclKW, EclFileEnum, EclFileView
from ert.util import CTime
class EclFile(BaseCClass):
TYPE_NAME = "ecl_file"
_open = EclPrototype("void* ecl_file_open( char* , int )" , bind = False)
_new = EclPrototype("void* ecl_file_alloc_empty( )" , bind = False)
_get_file_type = EclPrototype("ecl_file_enum ecl_util_get_file_type( char* , bool* , int*)" , bind = False)
_writable = EclPrototype("bool ecl_file_writable( ecl_file )")
_save_kw = EclPrototype("void ecl_file_save_kw( ecl_file , ecl_kw )")
_select_block = EclPrototype("bool ecl_file_select_block( ecl_file , char* , int )")
_restart_block_time = EclPrototype("bool ecl_file_select_rstblock_sim_time( ecl_file , time_t )")
_restart_block_step = EclPrototype("bool ecl_file_select_rstblock_report_step( ecl_file , int )")
_restart_block_iselect = EclPrototype("bool ecl_file_iselect_rstblock( ecl_file , int )")
_select_global = EclPrototype("void ecl_file_select_global( ecl_file )")
_iget_kw = EclPrototype("ecl_kw_ref ecl_file_iget_kw( ecl_file , int)")
_iget_named_kw = EclPrototype("ecl_kw_ref ecl_file_iget_named_kw( ecl_file , char* , int)")
_close = EclPrototype("void ecl_file_close( ecl_file )")
_get_size = EclPrototype("int ecl_file_get_size( ecl_file )")
_get_unique_size = EclPrototype("int ecl_file_get_num_distinct_kw( ecl_file )")
_get_num_named_kw = EclPrototype("int ecl_file_get_num_named_kw( ecl_file , char* )")
_iget_restart_time = EclPrototype("time_t ecl_file_iget_restart_sim_date( ecl_file , int )")
_iget_restart_days = EclPrototype("double ecl_file_iget_restart_sim_days( ecl_file , int )")
_get_restart_index = EclPrototype("int ecl_file_get_restart_index( ecl_file , time_t)")
_get_src_file = EclPrototype("char* ecl_file_get_src_file( ecl_file )")
_replace_kw = EclPrototype("void ecl_file_replace_kw( ecl_file , ecl_kw , ecl_kw , bool)")
_fwrite = EclPrototype("void ecl_file_fwrite_fortio( ecl_file , fortio , int)")
_has_instance = EclPrototype("bool ecl_file_has_kw_ptr(ecl_file , ecl_kw)")
_has_report_step = EclPrototype("bool ecl_file_has_report_step( ecl_file , int)")
_has_sim_time = EclPrototype("bool ecl_file_has_sim_time( ecl_file , time_t )")
_get_global_view = EclPrototype("ecl_file_view_ref ecl_file_get_global_view( ecl_file )")
@staticmethod
@ -98,39 +86,8 @@ class EclFile(BaseCClass):
@classmethod
def restart_block( cls , filename , dtime = None , report_step = None):
"""
Load one report step from unified restart file.
raise NotImplementedError("The restart_block implementation has been removed - open file normally and use EclFileView.")
Unified restart files can be prohibitively large; with this
class method it is possible to load only one report
step. Which report step you are interested in must be
specified with either one of the optional arguments
@report_step or @dtime. If present @dtime should be a normal
python datetime instance:
block1 = EclFile.restart_block( "ECLIPSE.UNRST" , dtime = datetime.datetime( year , month , day ))
block2 = EclFile.restart_block( "ECLIPSE.UNRST" , report_step = 67 )
If the block you are asking for can not be found the method
will return None.
"""
obj = EclFile( filename )
if dtime:
OK = obj._restart_block_time( CTime( dtime ))
elif not report_step is None:
OK = obj._restart_block_step( report_step )
else:
raise TypeError("restart_block() requires either dtime or report_step argument - none given.")
if not OK:
if dtime:
raise ValueError('Could not locate date:%02d/%02d/%4d in restart file "%s".' % (dtime.day , dtime.month , dtime.year , filename))
else:
raise ValueError('Could not locate report step:%d in restart file: "%s".' % (report_step , filename))
return obj
@classmethod
@ -247,7 +204,8 @@ class EclFile(BaseCClass):
raise IOError('Failed to open file "%s"' % filename)
else:
super(EclFile , self).__init__(c_ptr)
self.global_view = self._get_global_view( )
self.global_view.setParent( self )
def save_kw( self , kw ):
@ -280,7 +238,7 @@ class EclFile(BaseCClass):
def __len__(self):
return self._get_size( )
return len(self.global_view)
def close(self):
@ -293,17 +251,29 @@ class EclFile(BaseCClass):
self.close()
def blockView(self, kw , kw_index):
return self.global_view.blockView( kw , kw_index )
def blockView2(self, start_kw , stop_kw , start_index):
return self.global_view.blockView2( start_kw , stop_kw, start_index )
def restartView( self, seqnum_index = None, report_step = None , sim_time = None , sim_days = None):
return self.global_view.restartView( seqnum_index, report_step , sim_time, sim_days )
def select_block( self, kw , kw_index):
OK = self._select_block( kw , kw_index )
if not OK:
raise ValueError('Could not find block "%s" (%d)' % (kw , kw_index))
raise NotImplementedError("The select_block implementation has been removed - use EclFileView")
def select_global( self ):
self._select_global( )
raise NotImplementedError("The select_global implementation has been removed - use EclFileView")
def select_restart_section( self, index = None , report_step = None , sim_time = None):
raise NotImplementedError("The select_restart_section implementation has been removed - use EclFileView")
"""
Will select a restart section as the active section.
@ -326,23 +296,10 @@ class EclFile(BaseCClass):
readability.
"""
OK = False
if not report_step is None:
OK = self._restart_block_step( report_step )
elif not sim_time is None:
OK = self._restart_block_time( CTime( sim_time ) )
elif not index is None:
OK = self._restart_block_iselect( index )
else:
raise TypeError("select_restart_section() requires either dtime or report_step argument - none given")
if not OK:
raise TypeError("select_restart_section() Could not locate report_step/dtime")
return self
def select_last_restart( self ):
raise NotImplementedError("The select_restart_section implementation has been removed - use EclFileView")
"""
Will select the last SEQNUM block in restart file.
@ -351,19 +308,8 @@ class EclFile(BaseCClass):
is a non-unified restart file (or not a restart file at all),
the method will do nothing and return False.
"""
if "SEQNUM" in self:
self.select_restart_section( index = self.num_report_steps() - 1)
return True
else:
return False
def __iget(self , index):
return self._iget_kw( index ).setParent( parent = self )
def __iget_named(self, kw_name , index):
return self._iget_named_kw( kw_name , index ).setParent( parent = self )
@ -394,32 +340,7 @@ class EclFile(BaseCClass):
for swat in restart_file["SWAT"]:
....
"""
if isinstance( index , types.IntType):
if index < 0 or index >= len(self):
raise IndexError
else:
kw = self.__iget( index )
return kw
if isinstance( index , slice ):
indices = index.indices( len(self) )
kw_list = []
for i in range(*indices):
kw_list.append( self[i] )
return kw_list
else:
if isinstance( index , types.StringType):
if self.has_kw( index ):
kw_index = index
kw_list = []
for index in range( self.num_named_kw( kw_index )):
kw_list.append( self.iget_named_kw( kw_index , index))
return kw_list
else:
raise KeyError('Unrecognized keyword "%s".' % index)
else:
raise TypeError("Index must be integer or string (keyword)")
return self.global_view[index]
@ -468,53 +389,8 @@ class EclFile(BaseCClass):
def iget_named_kw( self , kw_name , index , copy = False):
"""
Will return EclKW nr @index reference with header @kw_name.
return self.global_view.iget_named_kw( kw_name , index )
The keywords in a an ECLIPSE file are organized in a long
linear array; keywords with the same name can occur many
times. For instance a summary data[1] file might look like
this:
SEQHDR
MINISTEP
PARAMS
MINISTEP
PARAMS
MINISTEP
PARAMS
....
To get the third 'PARAMS' keyword you can use the method call:
params_kw = file.iget_named_kw( "PARAMS" , 2 )
The functionality of the iget_named_kw() method is also
available through the __getitem__() method as:
params_kw = file["PARAMS"][2]
Observe that the returned EclKW instance is only a reference
to the data owned by the EclFile instance.
Observe that syntactically this is equivalent to
file[kw_name][index], however the latter form will imply that
all the keywords of this type are loaded from the file. If you
know that only a few will actually be used it will be faster
to use this method.
[1]: For working with summary data you are probably better off
using the EclSum class.
"""
if index < self.num_named_kw( kw_name ):
kw = self.__iget_named( kw_name , index )
if copy:
return EclKW.copy( kw )
else:
return kw
else:
raise KeyError('Asked for occurence:%d of %d of keyword "%s".'
% (index , self.num_named_kw( kw_name ), kw_name))
def restart_get_kw( self , kw_name , dtime , copy = False):
@ -603,7 +479,8 @@ class EclFile(BaseCClass):
"""
The number of unique keyword (names) in the current EclFile object.
"""
return self._get_unique_size( )
return self.global_view.uniqueSize( )
def keys(self):
@ -682,7 +559,8 @@ class EclFile(BaseCClass):
"""
The number of keywords with name == @kw in the current EclFile object.
"""
return self._get_num_named_kw( kw )
return self.global_view.numKeywords( kw )
def has_kw( self , kw , num = 0):
"""

View File

@ -0,0 +1,163 @@
import types
from cwrap import BaseCClass
from ert.ecl import EclPrototype, EclKW
from ert.util import CTime
class EclFileView(BaseCClass):
TYPE_NAME = "ecl_file_view"
_iget_kw = EclPrototype("ecl_kw_ref ecl_file_view_iget_kw( ecl_file_view , int)")
_iget_named_kw = EclPrototype("ecl_kw_ref ecl_file_view_iget_named_kw( ecl_file_view , char* , int)")
_get_size = EclPrototype("int ecl_file_view_get_size( ecl_file_view )")
_get_num_named_kw = EclPrototype("int ecl_file_view_get_num_named_kw( ecl_file_view , char* )")
_get_unique_size = EclPrototype("int ecl_file_view_get_num_distinct_kw( ecl_file_view )")
_create_block_view = EclPrototype("ecl_file_view_ref ecl_file_view_add_blockview( ecl_file_view , char*, int )")
_create_block_view2 = EclPrototype("ecl_file_view_ref ecl_file_view_add_blockview2( ecl_file_view , char*, char*, int )")
_restart_view = EclPrototype("ecl_file_view_ref ecl_file_view_add_restart_view( ecl_file_view , int, int, time_t, double )")
def __init__(self):
raise NotImplementedError("Can not instantiate directly")
def __iget(self , index):
return self._iget_kw( index ).setParent( parent = self )
def iget_named_kw(self, kw_name , index):
if not kw_name in self:
raise KeyError("No such keyword: %s" % kw_name)
if index >= self.numKeywords( kw_name ):
raise IndexError("Too large index: %d" % index)
return self._iget_named_kw( kw_name , index ).setParent( parent = self )
def __getitem__(self , index):
"""
Implements [] operator; index can be integer or key.
Will look up EclKW instances from the current EclFile
instance. The @index argument can either be an integer, in
which case the method will return EclKW number @index, or
alternatively a keyword string, in which case the method will
return a list of EclKW instances with that keyword:
restart_file = ecl_file.EclFile("ECLIPSE.UNRST")
kw9 = restart_file[9]
swat_list = restart_file["SWAT"]
The keyword based lookup can be combined with an extra [] to
get EclKW instance nr:
swat9 = restart_file["SWAT"][9]
Will return the 10'th SWAT keyword from the restart file. The
following example will iterate over all the SWAT keywords in a
restart file:
restart_file = ecl_file.EclFile("ECLIPSE.UNRST")
for swat in restart_file["SWAT"]:
....
"""
if isinstance( index , types.IntType):
if index < 0 or index >= len(self):
raise IndexError
else:
kw = self.__iget( index )
return kw
if isinstance( index , slice ):
indices = index.indices( len(self) )
kw_list = []
for i in range(*indices):
kw_list.append( self[i] )
return kw_list
else:
if isinstance( index , types.StringType):
if index in self:
kw_index = index
kw_list = []
for index in range( self.numKeywords( kw_index )):
kw_list.append( self.iget_named_kw( kw_index , index))
return kw_list
else:
raise KeyError("Unrecognized keyword:\'%s\'" % index)
else:
raise TypeError("Index must be integer or string (keyword)")
def __len__(self):
return self._get_size( )
def __contains__(self , kw):
if self.numKeywords(kw) > 0:
return True
else:
return False
def numKeywords(self , kw):
return self._get_num_named_kw( kw )
def uniqueSize(self):
return self._get_unique_size( )
def blockView2(self , start_kw , stop_kw, start_index):
if start_kw:
if not start_kw in self:
raise KeyError("The keyword:%s is not in file" % start_kw)
if start_index >= self.numKeywords( start_kw ):
raise IndexError("Index too high")
if stop_kw:
if not stop_kw in self:
raise KeyError("The keyword:%s is not in file" % stop_kw)
view = self._create_block_view2( start_kw , stop_kw , start_index )
view.setParent( parent = self )
return view
def blockView(self , kw , kw_index):
num = self.numKeywords( kw )
if num == 0:
raise KeyError("Unknown keyword: %s" % kw)
if kw_index >= num:
raise IndexError("Index too high")
view = self._create_block_view( kw , kw_index )
view.setParent( parent = self )
return view
def restartView(self , seqnum_index = None, report_step = None , sim_time = None , sim_days = None):
if report_step is None:
report_step = -1
if sim_time is None:
sim_time = -1
if sim_days is None:
sim_days = -1
if seqnum_index is None:
seqnum_index = -1
view = self._restart_view( seqnum_index , report_step , CTime( sim_time ) , sim_days )
if view is None:
raise ValueError("No such restart block could be identiefied")
view.setParent( parent = self )
return view

View File

@ -44,17 +44,16 @@ class EclGrav(BaseCClass):
TYPE_NAME = "ecl_grav"
_grav_alloc = EclPrototype("void* ecl_grav_alloc( ecl_grid , ecl_file )" , bind = False)
_free = EclPrototype("void ecl_grav_free( ecl_grav )")
_add_survey_RPORV = EclPrototype("void* ecl_grav_add_survey_RPORV( ecl_grav , char* , ecl_file )")
_add_survey_PORMOD = EclPrototype("void* ecl_grav_add_survey_PORMOD( ecl_grav , char* , ecl_file )")
_add_survey_FIP = EclPrototype("void* ecl_grav_add_survey_FIP( ecl_grav , char* , ecl_file )")
_add_survey_RFIP = EclPrototype("void* ecl_grav_add_survey_RFIP( ecl_grav , char* , ecl_file )")
_add_survey_RPORV = EclPrototype("void* ecl_grav_add_survey_RPORV( ecl_grav , char* , ecl_file_view )")
_add_survey_PORMOD = EclPrototype("void* ecl_grav_add_survey_PORMOD( ecl_grav , char* , ecl_file_view )")
_add_survey_FIP = EclPrototype("void* ecl_grav_add_survey_FIP( ecl_grav , char* , ecl_file_view )")
_add_survey_RFIP = EclPrototype("void* ecl_grav_add_survey_RFIP( ecl_grav , char* , ecl_file_view )")
_new_std_density = EclPrototype("void ecl_grav_new_std_density( ecl_grav , int , double)")
_add_std_density = EclPrototype("void ecl_grav_add_std_density( ecl_grav , int , int , double)")
_eval = EclPrototype("double ecl_grav_eval( ecl_grav , char* , char* , ecl_region , double , double , double, int)")
def __init__( self, grid, init_file ):
"""
Creates a new EclGrav instance.
@ -67,35 +66,40 @@ class EclGrav(BaseCClass):
c_ptr = self._grav_alloc( grid , init_file )
super(EclGrav , self).__init__( c_ptr )
self.dispatch = {"FIP" : self.add_survey_FIP,
"RFIP" : self.add_survey_RFIP,
"PORMOD" : self.add_survey_PORMOD,
"RPORV" : self.add_survey_RPORV}
def add_survey_RPORV( self, survey_name, restart_file ):
def add_survey_RPORV( self, survey_name, restart_view ):
"""
Add new survey based on RPORV keyword.
Add a new survey; in this context a survey is the state of
reservoir, i.e. an ECLIPSE restart file. The @survey_name
input argument will be used when refering to this survey at a
later stage. The @restart_file input argument should be an
later stage. The @restart_view input argument should be an
EclFile instance with data from one report step. A typical way
to load the @restart_file argument is:
to load the @restart_view argument is:
import datetime
import ert.ecl.ecl as ecl
from ert.ecl import EclRestartFile
...
...
date = datetime.datetime( year , month , day )
restart_file1 = ecl.EclFile.restart_block( "ECLIPSE.UNRST" , dtime = date)
restart_file2 = ecl.EclFile.restart_block( "ECLIPSE.UNRST" , report_step = 67 )
rst_file = EclRestartFile( "ECLIPSE.UNRST" )
restart_view1 = rst_file.restartView( sim_time = date)
restart_view2 = rst_file.restartView( report_step = 67 )
The pore volume of each cell will be calculated based on the
RPORV keyword from the restart files. The methods
add_survey_PORMOD() and add_survey_FIP() are alternatives
which are based on other keywords.
"""
self._add_survey_RPORV(survey_name, restart_file)
self._add_survey_RPORV(survey_name, restart_view)
def add_survey_PORMOD( self, survey_name, restart_file ):
def add_survey_PORMOD( self, survey_name, restart_view ):
"""
Add new survey based on PORMOD keyword.
@ -103,9 +107,9 @@ class EclGrav(BaseCClass):
the PORV_MOD keyword from the restart file; see
add_survey_RPORV() for further details.
"""
self._add_survey_PORMOD(survey_name, restart_file)
self._add_survey_PORMOD(survey_name, restart_view)
def add_survey_FIP( self, survey_name, restart_file ):
def add_survey_FIP( self, survey_name, restart_view ):
"""
Add new survey based on FIP keywords.
@ -118,9 +122,9 @@ class EclGrav(BaseCClass):
the new_std_density() (and possibly also add_std_density())
method before calling the add_survey_FIP() method.
"""
self._add_survey_FIP(survey_name, restart_file)
self._add_survey_FIP(survey_name, restart_view)
def add_survey_RFIP( self, survey_name, restart_file ):
def add_survey_RFIP( self, survey_name, restart_view ):
"""
Add new survey based on RFIP keywords.
@ -129,8 +133,11 @@ class EclGrav(BaseCClass):
calculated based on the RFIPxxx keyword along with the
per-cell mass density of the respective phases.
"""
self._add_survey_RFIP( survey_name, restart_file)
self._add_survey_RFIP( survey_name, restart_view)
def addSurvey(self, name , restart_view, method):
method = self.dispatch[ method ]
return method( name , restart_view )
def eval(self, base_survey, monitor_survey, pos, region=None,
phase_mask=EclPhaseEnum.ECL_OIL_PHASE + EclPhaseEnum.ECL_GAS_PHASE + EclPhaseEnum.ECL_WATER_PHASE):

View File

@ -19,16 +19,15 @@ from ert.ecl import ECL_LIB , EclFile, Ecl3DKW , Ecl3DFile, EclFileEnum
from cwrap import CWrapper, BaseCClass
class EclRestartHead(BaseCClass):
def __init__(self , kw_arg = None , rst_arg = None):
if kw_arg is None and rst_arg is None:
def __init__(self , kw_arg = None , rst_view = None):
if kw_arg is None and rst_view is None:
raise Exception("Invalid arguments")
if not kw_arg is None:
report_step , intehead_kw , doubhead_kw , logihead_kw = kw_arg
c_ptr = EclRestartHead.cNamespace().alloc_from_kw( report_step , intehead_kw , doubhead_kw , logihead_kw )
else:
rst_file , occurence = rst_arg
c_ptr = EclRestartHead.cNamespace().alloc( rst_file , occurence )
c_ptr = EclRestartHead.cNamespace().alloc( rst_view , -1 )
super(EclRestartHead, self).__init__(c_ptr)
@ -90,7 +89,7 @@ class EclRestartFile(Ecl3DFile):
self.rst_headers = []
if self.unified():
for index in range(self.num_named_kw("SEQNUM")):
self.rst_headers.append( EclRestartHead( rst_arg = (self , index )))
self.rst_headers.append( EclRestartHead( rst_view = self.restartView( seqnum_index = index )))
else:
intehead_kw = self["INTEHEAD"][0]
doubhead_kw = self["DOUBHEAD"][0]
@ -127,7 +126,7 @@ class EclRestartFile(Ecl3DFile):
CWrapper.registerObjectType("ecl_rsthead", EclRestartHead)
cwrapper = CWrapper(ECL_LIB)
EclRestartHead.cNamespace().alloc = cwrapper.prototype("c_void_p ecl_rsthead_ialloc(ecl_file , int )")
EclRestartHead.cNamespace().alloc = cwrapper.prototype("c_void_p ecl_rsthead_alloc(ecl_file_view , int )")
EclRestartHead.cNamespace().alloc_from_kw = cwrapper.prototype("c_void_p ecl_rsthead_alloc_from_kw(int , ecl_kw , ecl_kw , ecl_kw )")
EclRestartHead.cNamespace().free = cwrapper.prototype("void ecl_rsthead_free(ecl_rsthead)")
EclRestartHead.cNamespace().get_report_step = cwrapper.prototype("int ecl_rsthead_get_report_step(ecl_rsthead)")

View File

@ -100,22 +100,7 @@ class EclSMSPECNode(BaseCClass):
@property
def num(self):
"""
Returns the NUMS value for this keyword; or None.
Many of the summary keywords have an integer stored in the
vector NUMS as an attribute, i.e. the block properties have
the global index of the cell in the nums vector. If the
variable in question makes use of the NUMS value this property
will return the value, otherwise it will return None:
sum.smspec_node("FOPT").num => None
sum.smspec_node("BPR:1000").num => 1000
"""
if self._node_need_num( ):
return self._node_num( )
else:
return None
return self.getNum( )
def getKey1(self):
"""
@ -143,3 +128,23 @@ class EclSMSPECNode(BaseCClass):
def varType(self):
return self._var_type( )
def getNum(self):
"""
Returns the NUMS value for this keyword; or None.
Many of the summary keywords have an integer stored in the
vector NUMS as an attribute, i.e. the block properties have
the global index of the cell in the nums vector. If the
variable in question makes use of the NUMS value this property
will return the value, otherwise it will return None:
sum.smspec_node("FOPT").num => None
sum.smspec_node("BPR:1000").num => 1000
"""
if self._node_need_num( ):
return self._node_num( )
else:
return None

View File

@ -45,9 +45,9 @@ class EclSubsidence(BaseCClass):
TYPE_NAME = "ecl_subsidence"
_alloc = EclPrototype("void* ecl_subsidence_alloc( ecl_grid , ecl_file )" , bind = False)
_free = EclPrototype("void ecl_subsidence_free( ecl_subsidence )")
_add_survey_PRESSURE = EclPrototype("void* ecl_subsidence_add_survey_PRESSURE( ecl_subsidence , char* , ecl_file )")
_add_survey_PRESSURE = EclPrototype("void* ecl_subsidence_add_survey_PRESSURE( ecl_subsidence , char* , ecl_file_view )")
_eval = EclPrototype("double ecl_subsidence_eval( ecl_subsidence , char* , char* , ecl_region , double , double , double, double, double)")
_has_survey = EclPrototype("bool ecl_subsidence_has_survey( ecl_subsidence , char*)")
def __init__( self, grid, init_file ):
"""
@ -61,6 +61,10 @@ class EclSubsidence(BaseCClass):
super( EclSubsidence , self ).__init__( c_ptr )
def __contains__(self , survey_name):
return self._has_survey( survey_name )
def add_survey_PRESSURE( self, survey_name, restart_file ):
"""
@ -111,6 +115,15 @@ class EclSubsidence(BaseCClass):
The argument @compressibility is the total reservoir compressibility.
"""
return self._eval(self, base_survey, monitor_survey, region, pos[0], pos[1], pos[2], compressibility,
poisson_ratio)
if not base_survey in self:
raise KeyError("No such survey: %s" % base_survey)
if not monitor_survey in self:
raise KeyError("No such survey: %s" % monitor_survey)
return self._eval(base_survey, monitor_survey, region, pos[0], pos[1], pos[2], compressibility,poisson_ratio)
def free(self):
self._free( )

View File

@ -18,7 +18,7 @@ class MeasData(BaseCClass):
if isinstance(index , str):
return MeasData.cNamespace().has_block( self , index)
else:
raise TypeError("The in operator expects a string argument")
raise TypeError('The in operator expects a string argument, got "%s".' % str(index))
def __getitem__(self , index):
@ -26,7 +26,7 @@ class MeasData(BaseCClass):
if index in self:
return MeasData.cNamespace().get_block( self , index)
else:
raise KeyError("The obs block:%s is not recognized" % index)
raise KeyError('The obs block "%s" is not recognized' % index)
elif isinstance(index,int):
if index < 0:
index += len(self)
@ -34,17 +34,13 @@ class MeasData(BaseCClass):
if 0 <= index < len(self):
return MeasData.cNamespace().iget_block( self , index)
else:
raise IndexError("Index out of range")
raise IndexError("Index out of range, should have 0 <= %d < %d." % (index, len(self)))
else:
raise TypeError("The index variable must string or integer")
def __str__(self):
s = ""
for block in self:
s += "%s" % block
s += "\n"
return s
return '\n'.join([str(block) for block in self])
def createS(self):
@ -55,7 +51,6 @@ class MeasData(BaseCClass):
return S
def deactivateZeroStdSamples(self, obs_data):
assert isinstance(obs_data, ObsData)
self.cNamespace().deactivate_outliers(obs_data, self)
@ -98,5 +93,3 @@ MeasData.cNamespace().get_block = cwrapper.prototype("meas_block_ref meas_data_g
MeasData.cNamespace().iget_block = cwrapper.prototype("meas_block_ref meas_data_iget_block( meas_data , int)")
MeasData.cNamespace().deactivate_outliers = cwrapper.prototype("void enkf_analysis_deactivate_std_zero(obs_data, meas_data)")

View File

@ -39,6 +39,9 @@ class TempArea(TestArea):
super(TempArea, self).__init__(name , c_ptr = c_ptr , store_area = store_area)
def __str__(self):
return self.getPath()
def get_cwd(self):
"""

View File

@ -84,20 +84,20 @@ class TestArea(BaseCClass):
if os.path.exists( self.orgPath(path) ):
self._copy_parent_directory( path)
else:
raise IOError("No such file or directeory: %s" % path)
raise IOError("No such file or directory: %s" % path)
def copy_parent_content( self , path):
if os.path.exists( self.orgPath(path) ):
self._copy_parent_content(path)
else:
raise IOError("No such file or directeory: %s" % path)
raise IOError("No such file or directory: %s" % path)
def copy_directory_content( self, directory):
if os.path.isdir( self.orgPath(directory) ):
self._copy_directory_content(directory)
else:
raise IOError("No such directeory: %s" % path)
raise IOError("No such directory: %s" % directory )
def copy_file( self, filename):

View File

@ -33,9 +33,15 @@ class Simulations(ErtShellCollection):
simulation_runner = EnkfSimulationRunner(self.ert())
now = time.time()
print("Ensemble Experiment started at: %s" % datetime.now().isoformat(sep=" "))
iteration_count = 0
active_realization_mask = BoolVector(default_value = True, initial_size = self.ert().getEnsembleSize())
simulation_runner.createRunPath(active_realization_mask, iteration_count)
simulation_runner.runWorkflows(HookRuntime.PRE_SIMULATION)
print("Start simulations!")
num_successful_realizations = simulation_runner.runEnsembleExperiment()
success = self.ert().analysisConfig().haveEnoughRealisations(num_successful_realizations, self.ert().getEnsembleSize())

View File

@ -4,6 +4,7 @@ set(RSH_SERVERS "" CACHE STRING "List of nodes which will be used to test the R
set(TEST_SOURCES
__init__.py
test_deprecation.py
test_removed.py
test_ecl_3dkw.py
test_ecl_file_statoil.py
test_ecl_file.py
@ -54,6 +55,7 @@ addPythonTest(ecl.faults ecl.test_faults.FaultTest )
addPythonTest(ecl.fault_blocks ecl.test_fault_blocks.FaultBlockTest )
addPythonTest(ecl.ecl_deprecation1.9 ecl.test_deprecation.Deprecation_1_9_Test )
addPythonTest(ecl.ecl_deprecation2.0 ecl.test_deprecation.Deprecation_2_0_Test )
addPythonTest(ecl.ecl_removed2.1 ecl.test_removed.Removed_2_1_Test )
addPythonTest(ecl.ecl_util ecl.test_ecl_util.EclUtilTest )
addPythonTest(ecl.fortio ecl.test_fortio.FortIOTest)
addPythonTest(ecl.ecl_file ecl.test_ecl_file.EclFileTest)

View File

@ -99,3 +99,64 @@ class EclFileTest(ExtendedTestCase):
for kw1,kw2 in zip(kw_list,kw_list2):
self.assertEqual( kw1, kw2 )
def test_block_view(self):
with TestAreaContext("python/ecl_file/view"):
with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
for i in range(5):
header = EclKW("HEADER" , 1 , EclTypeEnum.ECL_INT_TYPE )
header[0] = i
data1 = EclKW("DATA1" , 100 , EclTypeEnum.ECL_INT_TYPE )
data1.assign( i )
data2 = EclKW("DATA2" , 100 , EclTypeEnum.ECL_INT_TYPE )
data2.assign( i*10 )
header.fwrite( f )
data1.fwrite( f )
data2.fwrite( f )
ecl_file = EclFile("TEST")
with self.assertRaises(KeyError):
ecl_file.blockView("NO" , 1)
with self.assertRaises(IndexError):
ecl_file.blockView("HEADER" , 100)
for i in range(5):
view = ecl_file.blockView("HEADER" , i)
self.assertEqual( len(view) , 3)
header = view["HEADER"][0]
data1 = view["DATA1"][0]
data2 = view["DATA2"][0]
self.assertEqual( header[0] , i )
self.assertEqual( data1[99] , i )
self.assertEqual( data2[99] , i*10 )
for i in range(5):
view = ecl_file.blockView2("HEADER" , "DATA2", i )
self.assertEqual( len(view) , 2)
header = view["HEADER"][0]
data1 = view["DATA1"][0]
self.assertEqual( header[0] , i )
self.assertEqual( data1[99] , i )
self.assertFalse( "DATA2" in view )
view = ecl_file.blockView2("HEADER" , None, 0 )
self.assertEqual( len(view) , len(ecl_file))
view = ecl_file.blockView2(None , "DATA2", 0 )
#self.assertEqual( len(view) , 2)
#self.assertTrue( "HEADER" in view )
#self.assertTrue( "DATA1" in view )
#self.assertFalse( "DATA2" in view )

View File

@ -56,7 +56,7 @@ class EclFileStatoilTest(ExtendedTestCase):
def test_iget_named(self):
f = EclFile(self.test_file)
N = f.num_named_kw( "SWAT" )
with self.assertRaises(KeyError):
with self.assertRaises(IndexError):
s = f.iget_named_kw( "SWAT" , N + 1)
@ -144,6 +144,12 @@ class EclFileStatoilTest(ExtendedTestCase):
with self.assertRaises(IOError):
rst_file = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
def test_restart_view(self):
f = EclFile( self.test_file )
with self.assertRaises(ValueError):
v = f.restartView( )
v = f.restartView( sim_days = 274 )
v = f.restartView( sim_time = datetime.date( 2004,1,1) )
v = f.restartView( report_step = 30 )
v = f.restartView( seqnum_index = 30 )

View File

@ -0,0 +1,35 @@
import warnings
import time
import datetime
from ert.test import ExtendedTestCase, TestAreaContext
from ert.ecl import EclFile,EclKW,EclTypeEnum,openFortIO, FortIO
class Removed_2_1_Test(ExtendedTestCase):
def test_ecl_file_block(self):
with TestAreaContext("name") as t:
kw = EclKW("TEST", 3, EclTypeEnum.ECL_INT_TYPE)
with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
kw.fwrite( f )
t.sync()
f = EclFile( "TEST" )
with self.assertRaises(NotImplementedError):
f.select_block( "KW" , 100 )
with self.assertRaises(NotImplementedError):
f.select_global( )
with self.assertRaises(NotImplementedError):
f.select_restart_section( index = None , report_step = None , sim_time = None)
with self.assertRaises(NotImplementedError):
f.select_restart_section( )
with self.assertRaises(NotImplementedError):
EclFile.restart_block( "TEST" )

View File

@ -44,7 +44,6 @@ class SumTest(ExtendedTestCase):
self.assertTrue("FOPT" in case)
self.assertFalse("WWCT:OPX" in case)
def test_TIME_special_case(self):
case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)])
keys = case.keys()
@ -64,11 +63,17 @@ class SumTest(ExtendedTestCase):
self.assertEqual( EclSum.varType( "WWCT:OP_X") , EclSumVarType.ECL_SMSPEC_WELL_VAR )
self.assertEqual( EclSum.varType( "RPR") , EclSumVarType.ECL_SMSPEC_REGION_VAR )
self.assertEqual( EclSum.varType( "WNEWTON") , EclSumVarType.ECL_SMSPEC_MISC_VAR )
case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0)])
node = case.smspec_node( "FOPT" )
self.assertEqual( EclSum.varType( "AARQ:4") , EclSumVarType.ECL_SMSPEC_AQUIFER_VAR )
case = createEclSum("CSV" , [("FOPT", None , 0) , ("FOPR" , None , 0), ("AARQ" , None , 10)])
node = case.smspec_node( "FOPT" )
self.assertEqual( node.varType( ) , EclSumVarType.ECL_SMSPEC_FIELD_VAR )
node = case.smspec_node( "AARQ:10" )
self.assertEqual( node.varType( ) , EclSumVarType.ECL_SMSPEC_AQUIFER_VAR )
self.assertEqual( node.getNum( ) , 10 )
def test_csv_export(self):

View File

@ -424,3 +424,8 @@ class SumTest(ExtendedTestCase):
writer.addTStep( 1 , 100 )
def test_aquifer(self):
case = EclSum( self.createTestPath( "Statoil/ECLIPSE/Aquifer/06_PRESSURE_R009-0"))
self.assertTrue( "AAQR:2" in case )

View File

@ -2,10 +2,10 @@
# spec file for package ert.ecl
#
%define tag final2
%define tag final
Name: ert.ecl
Version: 2015.10
Version: 2016.10
Release: 0
Summary: ERT - Ensemble based Reservoir Tool - ECL library
License: GPL-3+

View File

@ -1,3 +1,17 @@
Versjon 2.1.0, October 2016
* Made ecl_file_view 1st class citizen, exposed to API
* Added EXCLUDE_HOSTS to LSF driver with dynamic blacklisting
* Fixed MAX_RUNTIME is respected by WPRO
* Added functionality to open restart files in RW mode with seek
* Improved date handling (all is UTC now)
* As a result of this the filesystem version has been upgraded to 107, to use an old case you must upgrade it: "ert_upgradefs_107 config_file".
* Bug fixes (EclKW and EclGrid)
* Improved jobs and plugin loading
* The entire source tree was changed with the removal of devel
* ecl_sum can load aquifer variables.
Version 2.0.5, August 2016
* rel_eps & abs_eps