Updated to ERT version fix for amalgamated-nnc-bug

e47dfe0ee4
p4#: 22363
This commit is contained in:
Magne Sjaastad
2013-09-09 12:13:33 +02:00
parent 303f832fac
commit d3ef53285a
186 changed files with 6376 additions and 3838 deletions

View File

@@ -74,13 +74,16 @@ if (HAVE_SETENV)
add_definitions( -DPOSIX_SETENV )
endif()
check_function_exists( opendir HAVE_OPENDIR )
if (HAVE_OPENDIR)
add_definitions( -DHAVE_OPENDIR )
endif()
check_function_exists( getpwuid HAVE_GETPWUID )
if (HAVE_GETPWUID)
add_definitions( -DHAVE_GETPWUID )
endif()
# The usleep() check uses the symbol HAVE__USLEEP with double
# underscore to avoid conflict with plplot which defines the
# HAVE_USLEEP symbol.

View File

@@ -1,9 +1,14 @@
include(cmake/ert_module.cmake)
add_subdirectory( script )
add_subdirectory( src )
add_subdirectory( modules )
#if (BUILD_APPLICATONS)
# add_subdirectory( applications )
#endif()
#if (BUILD_TESTS)
# add_subdirectory( tests )
#endif()
if (BUILD_APPLICATIONS)
add_subdirectory( applications )
endif()
if (BUILD_TESTS)
add_subdirectory( tests )
endif()

View File

@@ -0,0 +1,8 @@
add_executable( ert_module_test ert_module_test.c )
target_link_libraries( ert_module_test analysis ert_util )
if (USE_RUNPATH)
add_runpath( ert_module_test )
endif()
install(TARGETS ert_module_test DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

View File

@@ -15,20 +15,22 @@
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <dlfcn.h>
#include <analysis_module.h>
#include <stdlib.h>
#include <stdbool.h>
#include <rng.h>
#include <dlfcn.h>
#include <ert/util/rng.h>
#include <ert/analysis/analysis_module.h>
void check_module( rng_type * rng , const char * lib_name ) {
int check_module( rng_type * rng , const char * lib_name ) {
analysis_module_load_status_enum load_status;
analysis_module_type * module = analysis_module_alloc_external__( rng , "MODULE" , lib_name , false , &load_status);
if (module != NULL) {
printf("Module loaded successfully\n");
analysis_module_free( module );
return 0;
} else {
if (load_status == DLOPEN_FAILURE) {
printf("\ndlerror(): %s\n\n",dlerror());
@@ -46,13 +48,11 @@ void check_module( rng_type * rng , const char * lib_name ) {
printf("See documentation of \'symbol_table\' in modules.txt.\n\n");
}
}
return 1;
}
int main( int argc , char ** argv) {
int iarg;
for (iarg = 1; iarg < argc; iarg++) {
check_module( NULL , argv[iarg] );
}
exit( check_module( NULL , argv[1] ) );
}

View File

@@ -0,0 +1,21 @@
function( ert_module module args source_files )
set( build_file ${CMAKE_CURRENT_BINARY_DIR}/${module}.so )
set( depends analysis )
set( arg_string "${module} ${args}")
separate_arguments( arg_list UNIX_COMMAND "${arg_string}")
foreach (src_file ${source_files} )
list(APPEND arg_list ${CMAKE_CURRENT_SOURCE_DIR}/${src_file} )
list(APPEND depends ${CMAKE_CURRENT_SOURCE_DIR}/${src_file} )
endforeach()
add_custom_command(
OUTPUT ${build_file}
COMMAND ${PROJECT_SOURCE_DIR}/libanalysis/script/ert_module
ARGS ${arg_list}
DEPENDS ${depends})
install(FILES ${build_file} DESTINATION ${CMAKE_INSTALL_LIBDIR})
add_custom_target( ${module} ALL DEPENDS ${build_file} )
endfunction()

View File

@@ -42,7 +42,7 @@ extern "C" {
#define ANALYSIS_USE_A 4 // The module will read the content of A - but not modify it.
#define ANALYSIS_UPDATE_A 8 // The update will be based on modifying A directly, and not on an X matrix.
#define ANALYSIS_SCALE_DATA 16
#define ANALYSIS_ITERABLE 32 // The module can bu uused as an iterative smoother.
#define EXTERNAL_MODULE_NAME "analysis_table"
#define EXTERNAL_MODULE_SYMBOL analysis_table

View File

@@ -0,0 +1,7 @@
set( args "--silent --exclude-ert -I${PROJECT_SOURCE_DIR}/libanalysis/include -I${PROJECT_SOURCE_DIR}/libert_util/include -I${CMAKE_CURRENT_SOURCE_DIR} -I${PROJECT_BINARY_DIR}/libert_util/include")
set( RML_SOURCE_FILES
rml_enkf.c
rml_enkf_common.c )
ert_module( rml_enkf ${args} "${RML_SOURCE_FILES}")

View File

@@ -13,11 +13,11 @@
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
for more details.
*/
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
@@ -30,9 +30,10 @@
#include <ert/analysis/analysis_module.h>
#include <ert/analysis/analysis_table.h>
#include <ert/analysis/enkf_linalg.h>
#include <ert/analysis/rml_enkf_common.h>
#include <ert/analysis/std_enkf.h>
#include <rml_enkf_common.h>
/*
A random 'magic' integer id which is used for run-time type checking
of the input data.
@@ -128,6 +129,9 @@ void rml_enkf_set_subspace_dimension( rml_enkf_data_type * data , int subspace_d
data->truncation = INVALID_TRUNCATION;
}
void rml_enkf_set_iteration_number( rml_enkf_data_type *data , int iteration_number ) {
data->iteration_nr = iteration_number;
}
void * rml_enkf_data_alloc( rng_type * rng) {
@@ -136,7 +140,7 @@ void * rml_enkf_data_alloc( rng_type * rng) {
rml_enkf_set_truncation( data , DEFAULT_ENKF_TRUNCATION_ );
rml_enkf_set_subspace_dimension( data , DEFAULT_SUBSPACE_DIMENSION );
data->option_flags = ANALYSIS_NEED_ED + ANALYSIS_UPDATE_A;
data->option_flags = ANALYSIS_NEED_ED + ANALYSIS_UPDATE_A + ANALYSIS_ITERABLE;
data->iteration_nr = 0;
data->Std = 0;
data->Cd = NULL;
@@ -296,6 +300,8 @@ bool rml_enkf_set_int( void * arg , const char * var_name , int value) {
if (strcmp( var_name , ENKF_NCOMP_KEY_) == 0)
rml_enkf_set_subspace_dimension( module_data , value );
else if(strcmp( var_name , "NUM_ITER") == 0)
rml_enkf_set_iteration_number( module_data , value );
else
name_recognized = false;

View File

@@ -31,10 +31,8 @@
#include <ert/analysis/analysis_module.h>
#include <ert/analysis/analysis_table.h>
#include <ert/analysis/enkf_linalg.h>
#include <ert/analysis/rml_enkf_common.h>
#include <rml_enkf_common.h>
/* This program contains common functions to both rml_enkf & rml_enkf_imodel*/

View File

@@ -0,0 +1 @@
install(PROGRAMS ert_module DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

View File

@@ -0,0 +1,246 @@
#!/usr/bin/env python
import sys
import os
import os.path
from optparse import OptionParser
ert_root = os.path.realpath( os.path.join(os.path.dirname( os.path.abspath( __file__)) , "../") )
#-----------------------------------------------------------------
default_lib_list = ["analysis" , "ert_util"]
default_define_list = ["HAVE_PTHREAD"]
CFLAGS = "-std=gnu99 -O2 -Wall -fpic -g"
LDFLAGS_list = ["-shared"]
CC = "gcc"
LD = CC
#-----------------------------------------------------------------
c_file = 0
header_file = 1
object_file = 2
other = 3
file_types = {".o" : object_file ,
".h" : header_file ,
".c" : c_file }
def base_name(file):
(name,ext) = os.path.split( file )
return name
def file_type( file ):
name,ext = os.path.splitext( file )
return file_types.get( ext , other )
def object_file_name( file ):
(name,ext) = os.path.splitext( file )
return "%s.o" % name
def make_LDFLAGS( use_rpath , lib_path_list):
if use_rpath:
LDFLAGS_list.append("-Wl,--enable-new-dtags")
for path in lib_path_list:
LDFLAGS_list.append("-Wl,-rpath,%s" % path)
LDFLAGS_list.append("-Wl,-soname,")
return " ".join(LDFLAGS_list)
def make_XFLAG( X , def_list ):
FLAG = ""
for d in def_list:
FLAG += "-%s%s " % (X , d)
return FLAG
def compile_file( file , IFLAG , DFLAG , verbose):
target = object_file_name( file )
if os.path.exists( target ):
os.unlink( target )
cmd = "%s %s %s %s -c %s -o %s" % (CC , CFLAGS , IFLAG , DFLAG , file , target)
if verbose:
print "Compiling: %s" % cmd
os.system( cmd )
if os.path.exists( target ):
return target
else:
sys.exit("Compile cmd:%s failed" % cmd)
def link( soname , filename , object_list , LDFLAGS , LFLAG , lFLAG , verbose):
object_string = ""
for obj in object_list:
object_string += "%s " % obj
cmd = "%s %s%s -o %s %s %s %s" % ( LD , LDFLAGS , soname , filename , object_string , LFLAG , lFLAG)
if verbose:
print "Linking : %s" % cmd
if os.path.exists( filename ):
os.unlink( filename )
os.system(cmd)
if os.path.exists( filename ):
return True
else:
return False
usage = """
The ert_module script is a small convenience script to
compile C source code into an analysis module which can
be loaded by ert. The script is controlled by commandline
arguments:
1. The first argument should be the name of the module
you are creating, an extension .so will be appended.
2. List the source files you want to include, the
files should have extension .c. In addition you can
include object files which have been compiled by
other means, the object files should have
extension .o
3. Optionally you can pass -I and -D options which are
passed to the compiler; and -l and -L options which
are passed to the linker.
Example:
ert_module my_module my_src1.c my_src2.c f90_object1.o f90_object2.o -I/path -DFAST=Yes -L/path/to/lib -lfm -lz
Will create a module 'my_module' based on the src files my_src1.c
and my_src2.c; in addition the object files f90_object1.o and
f90_object2.o will be included in the final module.
-----------------------------------------------------------------
To compile the module code you will typically need the include files
and libraries from an existing ert installation. By default the
ert_module script will locate the ert installation based on the
location of the script, but you can pass the option:
--ert-root=/path/where/ert/is/installed
The --ert-root option should point to a directory containing the
lib64/ and include/ directories of a binary etr distribution. In
addition to --ert-root you can use the normal -L/path/to/lib option to
send in additional link path arguments.
By default the path to shared libraries will not be embedded in the
resulting module, but by passing the option --use-rpath you can tell
the script to embed these paths in the final shared object.
-----------------------------------------------------------------
Options summary:
-L/path/to/lib: Include the path /path/to/lib in the linker path
-llib1 : Link with the library lib1
-I/include : Include the path /include in the compiler include path.
--ert-root=/path/to/ert : Use this is as root for ert headers
and libraries. [Default: inferred from location of script]
--use-rpath : Embed library paths in shared objects. Default off.
--exclude-ert: Do not use any ert default libraries or headers
Default flags:
Compile: %s %s %s
Link: %s %s %s
""" % (CC,
make_XFLAG( "I" , ["./" , "%s/include" % ert_root]) ,
make_XFLAG( "D" , default_define_list) ,
LD ,
make_XFLAG("L" , ["%s/lib64" % ert_root]) ,
make_XFLAG("l" , default_lib_list))
parser = OptionParser( usage )
parser.add_option("--ert-root" , dest="ert_root" , action="store")
parser.add_option("-I" , dest = "include_path_list", action = "append")
parser.add_option("-D" , dest = "define_list" , action = "append")
parser.add_option("-L" , dest = "lib_path_list" , action = "append")
parser.add_option("-l" , dest = "lib_list" , action = "append")
parser.add_option("--exclude-ert" , dest = "exclude_ert" , action="store_true" , default = False)
parser.add_option("--use-rpath" , dest="use_rpath" , action="store_true" , default = False)
parser.add_option("--silent" , dest="silent" , action="store_true" , default = False)
(options , args) = parser.parse_args()
if len(args) == 0:
sys.exit( usage )
if options.ert_root:
ert_root = options.ert_root
if options.exclude_ert:
include_path_list = ["./"]
lib_path_list = []
define_list = []
lib_list = []
else:
include_path_list = ["./" , "%s/include" % ert_root]
lib_path_list = ["%s/lib64" % ert_root]
define_list = default_define_list
lib_list = default_lib_list
if options.include_path_list:
include_path_list += options.include_path_list
if options.define_list:
define_list += options.define_list
if options.lib_list:
lib_list += options.lib_list
if options.lib_path_list:
lib_path_list += options.lib_path_list
verbose = not options.silent
LDFLAGS = make_LDFLAGS( options.use_rpath , lib_path_list)
input_name = args[0]
(path , tmp ) = os.path.split( input_name )
(module , ext) = os.path.splitext( tmp )
soname = "%s.so" % module
if path:
filename = "%s/%s.so" % (path , module)
if not os.path.exists( path ):
os.makedirs( path )
else:
filename = "%s.so" % module
#-----------------------------------------------------------------
IFLAG = make_XFLAG( "I" , include_path_list )
DFLAG = make_XFLAG( "D" , define_list )
LFLAG = make_XFLAG( "L" , lib_path_list )
lFLAG = make_XFLAG( "l" , lib_list )
object_list = []
for arg in args[1:]:
if file_type( arg ) == c_file:
object_list.append( compile_file( arg , IFLAG , DFLAG , verbose) )
elif file_type( arg ) == object_file:
object_list.append( arg )
else:
print "** Warning: ignoring file:%s" % arg
if link( soname , filename , object_list , LDFLAGS , LFLAG , lFLAG , verbose):
sys.exit()
else:
sys.exit("Creating library failed")

View File

@@ -1,6 +1,6 @@
# Common libanalysis library
set( source_files analysis_module.c enkf_linalg.c std_enkf.c sqrt_enkf.c cv_enkf.c bootstrap_enkf.c null_enkf.c fwd_step_enkf.c )
set( header_files analysis_module.h enkf_linalg.h analysis_table.h)
set( header_files analysis_module.h enkf_linalg.h analysis_table.h std_enkf.h)
add_library( analysis SHARED ${source_files} )
set_target_properties( analysis PROPERTIES COMPILE_DEFINITIONS INTERNAL_LINK)
set_target_properties( analysis PROPERTIES VERSION 1.0 SOVERSION 1.0 )
@@ -14,17 +14,22 @@ if (USE_RUNPATH)
add_runpath( analysis )
endif()
# List of modules
set( CMAKE_SHARED_MODULE_PREFIX "" )
add_library( std_enkf MODULE std_enkf.c )
add_library( sqrt_enkf MODULE sqrt_enkf.c )
add_library( rml_enkf MODULE rml_enkf.c rml_enkf_common.c )
## List of modules
#set( CMAKE_SHARED_MODULE_PREFIX "" )
##add_library( std_enkf MODULE std_enkf.c )
#add_library( sqrt_enkf MODULE sqrt_enkf.c )
#add_library( rml_enkf MODULE rml_enkf.c rml_enkf_common.c )
#
#ert_module( std_enkf std_enkf.c )
#-----------------------------------------------------------------
if (INSTALL_ERT)
install(TARGETS analysis DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS rml_enkf DESTINATION ${CMAKE_INSTALL_LIBDIR})
#install(TARGETS rml_enkf DESTINATION ${CMAKE_INSTALL_LIBDIR})
foreach(header ${header_files})
install(FILES ../include/ert/analysis/${header} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/ert/analysis)
endforeach()

View File

@@ -1,167 +0,0 @@
#!/usr/bin/env python
import sys
import os
from optparse import OptionParser
#-----------------------------------------------------------------
lib_list = ["analysis" , "ert_util"]
lib_path_list = ["./" , "../../libutil/slib"]
include_path_list = ["../include" , "../../libutil/src"]
define_list = ["HAVE_PTHREAD"]
CFLAGS = "-std=gnu99 -O2 -Wall -fpic -g"
LDFLAGS = "-shared -Wl,-soname,"
CC = "gcc"
LD = CC
#-----------------------------------------------------------------
c_file = 0
header_file = 1
object_file = 2
other = 3
file_types = {".o" : object_file ,
".h" : header_file ,
".c" : c_file }
def base_name(file):
(name,ext) = os.path.split( file )
return name
def file_type( file ):
name,ext = os.path.splitext( file )
return file_types.get( ext , other )
def object_file_name( file ):
(name,ext) = os.path.splitext( file )
return "%s.o" % name
def make_XFLAG( X , def_list ):
FLAG = ""
for d in def_list:
FLAG += "-%s%s " % (X , d)
return FLAG
def compile_file( file , IFLAG , DFLAG ):
target = object_file_name( file )
if os.path.exists( target ):
os.unlink( target )
cmd = "%s %s %s %s -c %s -o %s" % (CC , CFLAGS , IFLAG , DFLAG , file , target)
print "Compiling: %s" % cmd
os.system( cmd )
if os.path.exists( target ):
return target
else:
sys.exit("Compile cmd:%s failed" % cmd)
def link( libname , object_list , LFLAG , lFLAG):
(tmp,ext) = os.path.splitext( libname )
if not ext:
libname += ".so"
object_string = ""
for obj in object_list:
object_string += "%s " % obj
soname = libname
cmd = "%s %s%s -o %s %s %s %s" % ( LD , LDFLAGS , soname , libname , object_string , LFLAG , lFLAG)
print "Linking : %s" % cmd
if os.path.exists( libname ):
os.unlink( libname )
os.system(cmd)
if os.path.exists( libname ):
return True
else:
return False
usage = """
The ert_module script is a small convenience script to
compile C source code into an analysis module which can
be loaded by ert. The script is controlled by commandline
arguments:
1. The first argument should be the name of the module
you are creating, an extension .so will be appended.
2. List the source files you want to include, the
files should have extension .c. In addition you can
include object files which have been compiled by
other means, the object files should have
extension .o
3. Optionally you can pass -I and -D options which are
passed to the compiler; and -l and -L options which
are passed to the linker.
Example:
ert_module my_module my_src1.c my_src2.c f90_object1.o f90_object2.o -I/path -DFAST=Yes -L/path/to/lib -lfm -lz
Will create a module 'my_module' based on the src files my_src1.c
and my_src2.c; in addition the object files f90_object1.o and
f90_object2.o will be included in the final module.
By default the ert_module script will include some libraries from the
core ert distribution; if you are not interested in referencing these
you can issue the option --exclude-ert. Default flags:
Compile: %s %s
Link: %s %s
""" % (make_XFLAG( "I" , include_path_list) , make_XFLAG( "D" , define_list) , make_XFLAG("L" , lib_path_list) , make_XFLAG("l" , lib_list))
parser = OptionParser( usage )
parser.add_option("-I" , dest = "include_path_list", action = "append")
parser.add_option("-D" , dest = "define_list" , action = "append")
parser.add_option("-L" , dest = "lib_path_list" , action = "append")
parser.add_option("-l" , dest = "lib_list" , action = "append")
parser.add_option("--exclude-ert" , dest = "exclude_ert" , action="store_true" , default = False)
(options , args) = parser.parse_args()
if len(args) == 0:
sys.exit( usage )
if options.exclude_ert:
include_path_list = []
define_list = []
lib_list = []
lib_path_list = []
if options.include_path_list:
include_path_list += options.include_path_list
if options.define_list:
define_list += options.define_list
if options.lib_list:
lib_list += options.lib_list
if options.lib_path_list:
lib_path_list += options.lib_path_list
IFLAG = make_XFLAG( "I" , include_path_list )
DFLAG = make_XFLAG( "D" , define_list )
LFLAG = make_XFLAG( "L" , lib_path_list )
lFLAG = make_XFLAG( "l" , lib_list )
object_list = []
for arg in args[1:]:
if file_type( arg ) == c_file:
object_list.append( compile_file( arg ,IFLAG , DFLAG) )
elif file_type( arg ) == object_file:
object_list.append( arg )
else:
print "** Warning: ignoring file:%s" % arg
link( args[0] , object_list , LFLAG , lFLAG)

View File

@@ -0,0 +1 @@
add_test( analysis_rml_enkf_module ${EXECUTABLE_OUTPUT_PATH}/ert_module_test ${PROJECT_BINARY_DIR}/libanalysis/modules/rml_enkf.so )

View File

@@ -33,7 +33,7 @@ extern "C" {
nnc_vector_type * nnc_vector_alloc(int lgr_nr);
void nnc_vector_free( nnc_vector_type * nnc_vector );
void nnc_vector_add_nnc(nnc_vector_type * nnc_vector, int global_cell_number);
const int_vector_type * nnc_vector_get_index_list(const nnc_vector_type * nnc_vector);
const int_vector_type * nnc_vector_get_index_list(nnc_vector_type * nnc_vector);
int nnc_vector_get_lgr_nr(const nnc_vector_type * nnc_vector );
void nnc_vector_free__(void * arg);

View File

@@ -2133,7 +2133,7 @@ static void ecl_grid_init_nnc_cells( ecl_grid_type * grid1, ecl_grid_type * grid
ecl_cell_type * grid1_cell = ecl_grid_get_cell(grid1, grid1_cell_index);
ecl_cell_type * grid2_cell = ecl_grid_get_cell(grid2, grid2_cell_index);
//Add the non-neighbour connection in both directions
//Add the non-neighbour connection in both directions
nnc_info_add_nnc(grid1_cell->nnc_info, grid2->lgr_nr, grid2_cell_index);
nnc_info_add_nnc(grid2_cell->nnc_info, grid1->lgr_nr, grid1_cell_index);
@@ -2149,28 +2149,35 @@ static void ecl_grid_init_nnc_cells( ecl_grid_type * grid1, ecl_grid_type * grid
*/
static void ecl_grid_init_nnc(ecl_grid_type * main_grid, ecl_file_type * ecl_file) {
int num_nnchead_kw = ecl_file_get_num_named_kw( ecl_file , NNCHEAD_KW );
int num_nncg_kw = ecl_file_get_num_named_kw( ecl_file , NNCG_KW );
int i;
for (i = 0; i < num_nnchead_kw; i++) {
ecl_kw_type * nnchead_kw = ecl_file_iget_named_kw( ecl_file , NNCHEAD_KW , i);
int lgr_nr = ecl_kw_iget_int(nnchead_kw, NNCHEAD_LGR_INDEX);
ecl_kw_type * keyword1 = NULL;
ecl_kw_type * keyword2 = NULL;
if (ECL_GRID_MAINGRID_LGR_NR == lgr_nr) {
keyword1 = ecl_file_iget_named_kw( ecl_file , NNC1_KW , i);
keyword2 = ecl_file_iget_named_kw( ecl_file , NNC2_KW , i);
} else {
int nnc_lgr_index = (num_nnchead_kw == num_nncg_kw) ? i : i-1; //Subtract 1 if no nnc data for main grid
keyword1 = ecl_file_iget_named_kw( ecl_file , NNCL_KW , nnc_lgr_index);
keyword2 = ecl_file_iget_named_kw( ecl_file , NNCG_KW , nnc_lgr_index);
}
ecl_file_push_block(ecl_file); /* <---------------------------------------------------------------- */
ecl_file_select_block(ecl_file , NNCHEAD_KW , i);
{
ecl_grid_type * grid = (lgr_nr > 0) ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid;
ecl_grid_init_nnc_cells(grid, main_grid, keyword1, keyword2);
ecl_kw_type * nnchead_kw = ecl_file_iget_named_kw(ecl_file, 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);
{
ecl_grid_type * grid = (lgr_nr > 0) ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid;
ecl_grid_init_nnc_cells(grid, grid, nnc1, nnc2);
}
}
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);
{
ecl_grid_type * grid = (lgr_nr > 0) ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid;
ecl_grid_init_nnc_cells(grid, main_grid, nncl, nncg);
}
}
}
ecl_file_pop_block( ecl_file ); /* <------------------------------------------------------------------ */
}
}

View File

@@ -422,7 +422,6 @@ void fortio_fclose(fortio_type *fortio) {
bool fortio_is_fortio_file(fortio_type * fortio) {
FILE * stream = fortio->stream;
offset_type init_pos = fortio_ftell(fortio);
int elm_read;
bool is_fortio_file = false;

View File

@@ -24,6 +24,7 @@
#include <ert/util/type_macros.h>
#include <ert/ecl/nnc_vector.h>
#include <ert/ecl/nnc_index_list.h>
#define NNC_VECTOR_TYPE_ID 875615078
@@ -31,8 +32,8 @@
struct nnc_vector_struct {
UTIL_TYPE_ID_DECLARATION;
int_vector_type *nnc_index_list;
int lgr_nr;
nnc_index_list_type * index_list;
int lgr_nr;
};
@@ -44,13 +45,13 @@ static UTIL_SAFE_CAST_FUNCTION(nnc_vector , NNC_VECTOR_TYPE_ID)
nnc_vector_type * nnc_vector_alloc(int lgr_nr) {
nnc_vector_type * nnc_vector = util_malloc( sizeof * nnc_vector );
UTIL_TYPE_ID_INIT(nnc_vector , NNC_VECTOR_TYPE_ID);
nnc_vector->nnc_index_list = int_vector_alloc(0, 0);
nnc_vector->index_list = nnc_index_list_alloc();
nnc_vector->lgr_nr = lgr_nr;
return nnc_vector;
}
void nnc_vector_free( nnc_vector_type * nnc_vector ) {
int_vector_free( nnc_vector->nnc_index_list );
nnc_index_list_free( nnc_vector->index_list );
free( nnc_vector );
}
@@ -62,12 +63,12 @@ void nnc_vector_free__(void * arg) {
void nnc_vector_add_nnc(nnc_vector_type * nnc_vector, int global_cell_number) {
int_vector_append( nnc_vector->nnc_index_list , global_cell_number );
nnc_index_list_add_index( nnc_vector->index_list , global_cell_number );
}
const int_vector_type * nnc_vector_get_index_list(const nnc_vector_type * nnc_vector) {
return nnc_vector->nnc_index_list;
const int_vector_type * nnc_vector_get_index_list(nnc_vector_type * nnc_vector) {
return nnc_index_list_get_list(nnc_vector->index_list);
}

View File

@@ -0,0 +1,34 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'ecl_nnc_index_list_grid.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
#include <ert/util/test_util.h>
#include <ert/util/util.h>
#include <ert/util/int_vector.h>
#include <ert/ecl/nnc_index_list.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/ecl_file.h>
int main( int argc , char ** argv) {
ecl_grid_type * ecl_grid = ecl_grid_alloc( argv[1] );
exit(0);
}

View File

@@ -65,11 +65,13 @@ void test_nnc_lgr( const char * grid_filename ) {
const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0);
test_assert_not_NULL(nnc_cell_number_vec);
int_vector_fprintf(nnc_cell_number_vec , stdout , "nnc_cell_number" , "%6d");
test_assert_int_equal(int_vector_size(nnc_cell_number_vec), 1);
test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, 0), 151053);
//LGR
const int data[] = {126394, 126305};
const int data[] = {126305, 126394};
ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0);
test_assert_not_NULL( lgr_grid );
@@ -85,7 +87,7 @@ void test_nnc_lgr( const char * grid_filename ) {
int i;
for (i = 0; i < int_vector_size(lgr_nnc_cell_number_vec); i++)
test_assert_int_equal(int_vector_iget(lgr_nnc_cell_number_vec, i), data[i]);
test_assert_int_equal(data[i], int_vector_iget(lgr_nnc_cell_number_vec, i));
ecl_grid_free(ecl_grid);
}
@@ -98,7 +100,7 @@ void test_nnc_multiple_lgr( const char * grid_filename) {
{
//Global grid, check NNC for cell with global index 736
int data[] = {11957, 20336, 3528, 6321, 9114, 11907, 20286};
int data[] = {3528, 6321, 9114, 11907, 11957, 20286 , 20336};
const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 736);
test_assert_not_NULL(nnc_info);
@@ -120,7 +122,7 @@ void test_nnc_multiple_lgr( const char * grid_filename) {
{
//Global grid, check NNC for cell with global index 138291
int data[] = {141035, 143828, 141085, 143878};
int data[] = {141035, 141085, 143828, 143878};
const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 138291);
test_assert_not_NULL(nnc_info);
@@ -138,7 +140,7 @@ void test_nnc_multiple_lgr( const char * grid_filename) {
{
//LGR nr 1, cell global index 0: check NNCs to main grid
int data[] = {29012, 26220};
int data[] = {26220 , 29012};
ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0);
test_assert_not_NULL(lgr_grid);
@@ -211,7 +213,7 @@ void test_nnc_multiple_lgr( const char * grid_filename) {
{
//LGR nr 99, check NNC for cell with global index 736
int data[] = {126671, 79142};
int data[] = {79142 ,126671};
ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 98-1); //Subtract 1: LGR nr 98 is not present in the test file. LGRs are numbered 1-97 and 99-110 in test file.
test_assert_not_NULL(lgr_grid);
@@ -333,7 +335,7 @@ int main(int argc , char ** argv) {
test_nnc_global_grid( EGRID_file1 );
test_nnc_lgr( EGRID_file2 );
test_nnc_multiple_lgr( EGRID_file3 );
test_nnc_multiple_lgr( EGRID_file3 );
test_nnc_amalgamated_lgrs(EGRID_file3);
test_nnc_dual_poro( EGRID_file4 );

View File

@@ -35,6 +35,11 @@ int main(int argc , char ** argv) {
nnc_vector_add_nnc( vector , 200 );
nnc_vector_add_nnc( vector , 300 );
nnc_vector_add_nnc( vector , 100 );
nnc_vector_add_nnc( vector , 200 );
nnc_vector_add_nnc( vector , 300 );
{
const int_vector_type * index_list = nnc_vector_get_index_list( vector );

View File

@@ -2,6 +2,9 @@ add_executable( ecl_coarse_test ecl_coarse_test.c )
target_link_libraries( ecl_coarse_test ecl test_util )
add_test( ecl_coarse_test ${EXECUTABLE_OUTPUT_PATH}/ecl_coarse_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 )
add_executable( ecl_nnc_amalgamated ecl_nnc_amalgamated.c )
target_link_libraries( ecl_nnc_amalgamated ecl test_util )
add_test( ecl_nnc_amalgamated ${EXECUTABLE_OUTPUT_PATH}/ecl_nnc_amalgamated ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/nestedLGRcase/TESTCASE_NESTEDLGR.EGRID )
add_executable( ecl_restart_test ecl_restart_test.c )
target_link_libraries( ecl_restart_test ecl test_util )
@@ -61,6 +64,14 @@ target_link_libraries( ecl_nnc_info_test ecl test_util )
add_test (ecl_nnc_info_test ${EXECUTABLE_OUTPUT_PATH}/ecl_nnc_info_test )
add_executable( ecl_nnc_vector ecl_nnc_vector.c )
target_link_libraries( ecl_nnc_vector ecl test_util )
add_test(ecl_nnc_vector ${EXECUTABLE_OUTPUT_PATH}/ecl_nnc_vector )
add_executable( ecl_nnc_index_list ecl_nnc_index_list.c )
target_link_libraries( ecl_nnc_index_list ecl test_util )
add_test (ecl_nnc_index_list ${EXECUTABLE_OUTPUT_PATH}/ecl_nnc_index_list )
add_executable( ecl_kw_grdecl ecl_kw_grdecl.c )
target_link_libraries( ecl_kw_grdecl ecl test_util )
add_test( ecl_kw_grdecl ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_grdecl )
@@ -173,3 +184,4 @@ set_property( TEST ecl_region2region PROPERTY LABELS StatoilData)
set_property( TEST ecl_grid_case PROPERTY LABELS StatoilData)
set_property( TEST ecl_rft_rft PROPERTY LABELS StatoilData)
set_property( TEST ecl_rft_plt PROPERTY LABELS StatoilData)
set_property( TEST ecl_nnc_amalgamated PROPERTY LABELS StatoilData)

View File

@@ -24,6 +24,7 @@
#include <time.h>
#include <ert/util/double_vector.h>
#include <ert/util/int_vector.h>
#include <ert/util/util.h>
#include <ert/util/menu.h>
#include <ert/util/arg_pack.h>
@@ -31,6 +32,7 @@
#include <ert/util/bool_vector.h>
#include <ert/util/msg.h>
#include <ert/util/vector.h>
#include <ert/util/type_vector_functions.h>
#include <ert/plot/plot.h>
#include <ert/plot/plot_dataset.h>
@@ -62,12 +64,18 @@ void enkf_tui_QC_plot_get_PC( enkf_main_type * enkf_main , int step1 , int step2
double truncation , int ncomp ,
matrix_type * PC , matrix_type * PC_obs) {
int ens_size = enkf_main_get_ensemble_size( enkf_main );
bool_vector_type * ens_mask = bool_vector_alloc(0 , false);
obs_data_type * obs_data = obs_data_alloc();
meas_data_type * meas_data = meas_data_alloc( ens_size );
analysis_config_type * analysis_config = enkf_main_get_analysis_config( enkf_main );
int_vector_type * step_list = int_vector_alloc(0,0);
enkf_fs_type * source_fs = enkf_main_get_fs( enkf_main);
state_map_type * state_map = enkf_fs_get_state_map(source_fs);
int_vector_type * ens_active_list;
meas_data_type * meas_data;
state_map_select_matching(state_map , ens_mask , STATE_HAS_DATA);
ens_active_list = bool_vector_alloc_active_list(ens_mask);
meas_data = meas_data_alloc(ens_active_list);
{
for (int step =step1; step <= step2; step++)
int_vector_append( step_list , step );
@@ -81,10 +89,10 @@ void enkf_tui_QC_plot_get_PC( enkf_main_type * enkf_main , int step1 , int step2
double alpha = analysis_config_get_alpha( analysis_config );
enkf_obs_get_obs_and_measure(enkf_main_get_obs( enkf_main ),
enkf_main_get_fs( enkf_main ),
source_fs ,
step_list ,
state,
ens_size,
ens_active_list ,
(const enkf_state_type **) enkf_main_get_ensemble( enkf_main ),
meas_data ,
obs_data ,
@@ -105,6 +113,7 @@ void enkf_tui_QC_plot_get_PC( enkf_main_type * enkf_main , int step1 , int step2
matrix_free( dObs );
}
bool_vector_free(ens_mask);
int_vector_free( step_list );
obs_data_free( obs_data );
meas_data_free( meas_data );

View File

@@ -35,8 +35,6 @@
#include <ert/enkf/ensemble_config.h>
#include <ert/enkf/enkf_analysis.h>
#include <ert/enkf/ecl_config.h>
#include <ert/enkf/analysis_config.h>
#include <ert/enkf/analysis_iter_config.h>
#include <enkf_tui_util.h>
#include <enkf_tui_fs.h>
@@ -116,76 +114,29 @@ void enkf_tui_run_smoother(void * arg) {
void enkf_tui_run_iterated_ES(void * enkf_main) {
const int ens_size = enkf_main_get_ensemble_size( enkf_main );
void enkf_tui_run_iterated_ES(void * arg) {
enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
const ecl_config_type * ecl_config = enkf_main_get_ecl_config( enkf_main );
const int last_report = enkf_main_get_history_length( enkf_main );
{
model_config_type * model_config = enkf_main_get_model_config( enkf_main );
const ecl_config_type * ecl_config = enkf_main_get_ecl_config( enkf_main );
const analysis_config_type * analysis_config = enkf_main_get_analysis_config( enkf_main );
analysis_iter_config_type * iter_config = analysis_config_get_iter_config( analysis_config );
int step1 = 0;
int step2 ;
int_vector_type * step_list = int_vector_alloc(0,0);
bool_vector_type * iactive = bool_vector_alloc(0 , true);
int iter = 0;
int num_iter = analysis_iter_config_get_num_iterations( iter_config );
stringlist_type * node_list = ensemble_config_alloc_keylist_from_var_type( enkf_main_get_ensemble_config(enkf_main) , PARAMETER );
if (ecl_config_has_schedule( ecl_config ))
step2 = util_scanf_int_with_limits("Last report",PROMPT_LEN , 0 , last_report);
else
step2 = last_report;
{
for (int step=step1; step <= step2; step++)
int_vector_append( step_list , step );
}
bool_vector_iset( iactive , ens_size - 1 , true );
while (true) {
{
const char * runpath_fmt = analysis_iter_config_iget_runpath_fmt( iter_config , iter);
if (runpath_fmt != NULL) {
char * runpath_key = util_alloc_sprintf( "runpath-%d" , iter);
model_config_add_runpath( model_config , runpath_key , runpath_fmt);
model_config_select_runpath( model_config , runpath_key );
free( runpath_key );
}
}
enkf_main_run_exp(enkf_main , iactive , true , step1 , step1 , FORECAST);
{
const char * target_fs_name = analysis_iter_config_iget_case( iter_config , iter );
enkf_fs_type * target_fs = enkf_main_get_alt_fs(enkf_main , target_fs_name , false , true );
enkf_main_smoother_update(enkf_main , step_list , target_fs);
enkf_main_copy_ensemble( enkf_main ,
enkf_main_get_current_fs( enkf_main ),
0 , // Smoother update will write on step 0
ANALYZED ,
target_fs_name ,
step1 ,
FORECAST ,
iactive ,
NULL ,
node_list );
enkf_main_set_fs(enkf_main , target_fs , enkf_fs_get_case_name( target_fs ));
}
//iter = analysis_module_get_int(module, "ITER");
iter++;
if (iter == num_iter)
break;
}
int_vector_free( step_list );
bool_vector_free( iactive );
}
int step2;
if (ecl_config_has_schedule( ecl_config ))
step2 = util_scanf_int_with_limits("Last report",PROMPT_LEN , 0 , last_report);
else
step2 = last_report;
enkf_main_run_iterated_ES(enkf_main, step2);
}
void enkf_tui_run_one_more_iteration(void * arg){
enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
const ecl_config_type * ecl_config = enkf_main_get_ecl_config( enkf_main );
const int last_report = enkf_main_get_history_length( enkf_main );
int step2;
if (ecl_config_has_schedule( ecl_config ))
step2 = util_scanf_int_with_limits("Last report",PROMPT_LEN , 0 , last_report);
else
step2 = last_report;
enkf_main_run_one_more_iteration(enkf_main, step2);
}
@@ -221,7 +172,7 @@ void enkf_tui_run_exp(void * enkf_main) {
free( prompt );
}
if (bool_vector_count_equal(iactive , true))
enkf_main_run_exp(enkf_main , iactive , true , init_step_parameters , start_report , init_state);
enkf_main_run_exp(enkf_main , iactive , true , init_step_parameters , start_report , init_state, true);
bool_vector_free(iactive);
}
@@ -247,7 +198,7 @@ void enkf_tui_run_create_runpath__(void * __enkf_main) {
util_safe_free( select_string );
free( prompt );
}
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state);
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state, true);
bool_vector_free(iactive);
}
@@ -372,11 +323,15 @@ void enkf_tui_run_menu(void * arg) {
menu_item_type * restart_enkf_item = menu_add_item(menu , "Restart EnKF run from arbitrary state" , "rR" , enkf_tui_run_restart__ , enkf_main , NULL);
menu_item_type * ES_item = menu_add_item(menu , "Integrated smoother update" , "iI" , enkf_tui_run_smoother , enkf_main , NULL);
menu_item_type * it_ES_item = menu_add_item(menu , "Iterated smoother [RML-EnKF]" , "tT" , enkf_tui_run_iterated_ES , enkf_main , NULL);
menu_item_type * one_more_item = menu_add_item(menu , "One more iteration" , "mM" , enkf_tui_run_one_more_iteration , enkf_main , NULL);
if (!ecl_config_has_schedule( ecl_config )) {
menu_item_disable( enkf_item );
menu_item_disable( restart_enkf_item );
}
if (!ecl_config_has_init_section( ecl_config ))
menu_item_disable( enkf_item );
if (!model_config_has_history( model_config )) {
menu_item_disable( it_ES_item );

View File

@@ -49,7 +49,7 @@ void analysis_config_reload_module( analysis_config_type * con
stringlist_type * analysis_config_alloc_module_names( analysis_config_type * config );
const char * analysis_config_get_log_path( const analysis_config_type * config );
void analysis_config_init( analysis_config_type * analysis , const config_type * config);
analysis_config_type * analysis_config_alloc_default( rng_type * rng );
analysis_config_type * analysis_config_alloc( rng_type * rng );
void analysis_config_free( analysis_config_type * );
bool analysis_config_get_merge_observations(const analysis_config_type * );
double analysis_config_get_alpha(const analysis_config_type * config);
@@ -96,6 +96,12 @@ void analysis_config_set_PC_filename( analysis_config_type * c
const char * analysis_config_get_PC_filename( const analysis_config_type * config );
void analysis_config_set_PC_path( analysis_config_type * config , const char * path );
const char * analysis_config_get_PC_path( const analysis_config_type * config );
void analysis_config_set_min_realisations( analysis_config_type * config , int min_realisations);
int analysis_config_get_min_realisations( const analysis_config_type * config );
bool analysis_config_have_enough_realisations( const analysis_config_type * config , int realisations);
UTIL_IS_INSTANCE_HEADER( analysis_config );
#ifdef __cplusplus
}

View File

@@ -28,6 +28,8 @@ typedef struct analysis_iter_config_struct analysis_iter_config_type;
void analysis_iter_config_set_num_iterations( analysis_iter_config_type * config , int num_iterations);
int analysis_iter_config_get_num_iterations( const analysis_iter_config_type * config );
void analysis_iter_config_set_case_fmt( analysis_iter_config_type * config, const char * case_fmt);
char * analysis_iter_config_get_case_fmt( analysis_iter_config_type * config);
analysis_iter_config_type * analysis_iter_config_alloc();
void analysis_iter_config_free( analysis_iter_config_type * config );
const char * analysis_iter_config_iget_case( analysis_iter_config_type * config , int iter);

View File

@@ -0,0 +1,39 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'cases_config.h' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#ifndef __CASES_CONFIG_H__
#define __CASES_CONFIG_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct cases_config_struct cases_config_type;
bool cases_config_set_int( cases_config_type * config , const char * var_name, int num_iterations);
int cases_config_get_iteration_number( const cases_config_type * config );
void cases_config_fwrite( cases_config_type * config , const char * filename );
void cases_config_fread( cases_config_type * config , const char * filename);
cases_config_type * cases_config_alloc();
void cases_config_free( cases_config_type * config );
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -112,6 +112,7 @@ extern "C" {
#define MAX_RUNNING_RSH_KEY "MAX_RUNNING_RSH"
#define MAX_SUBMIT_KEY "MAX_SUBMIT"
#define NUM_REALIZATIONS_KEY "NUM_REALIZATIONS"
#define MIN_REALIZATIONS_KEY "MIN_REALIZATIONS"
#define OBS_CONFIG_KEY "OBS_CONFIG"
#define OBS_CONFIG_KEY "OBS_CONFIG"
#define PLOT_DRIVER_KEY "PLOT_DRIVER"

View File

@@ -83,6 +83,7 @@ extern "C" {
void ecl_config_fprintf_config( const ecl_config_type * ecl_config , FILE * stream );
ecl_config_type * ecl_config_alloc_empty( );
void ecl_config_add_config_items( config_type * config );
bool ecl_config_has_init_section( const ecl_config_type * ecl_config );
#ifdef __cplusplus
}

View File

@@ -116,7 +116,10 @@
#define DEFAULT_UPDATE_RESULTS false
#define DEFAULT_SINGLE_NODE_UPDATE true
#define DEFAULT_ANALYSIS_MODULE "STD_ENKF"
#define DEFAULT_ANALYSIS_NUM_ITERATIONS 1
#define DEFAULT_ANALYSIS_NUM_ITERATIONS 4
#define DEFAULT_ANALYSIS_ITER_CASE "ITERATED_ENSEMBLE_SMOOTHER%d"
#define DEFAULT_ANALYSIS_ITER_RUNPATH "Simulations/Real%d"
#define DEFAULT_ANALYSIS_MIN_REALISATIONS 0 // 0: No lower limit
/* Default directories. */
#define DEFAULT_QC_PATH "QC"

View File

@@ -34,6 +34,8 @@ extern "C" {
#include <ert/enkf/fs_types.h>
#include <ert/enkf/enkf_fs_type.h>
#include <ert/enkf/time_map.h>
#include <ert/enkf/cases_config.h>
#include <ert/enkf/state_map.h>
#include <ert/enkf/misfit_ensemble_typedef.h>
const char * enkf_fs_get_mount_point( const enkf_fs_type * fs );
@@ -92,8 +94,10 @@ extern "C" {
FILE * enkf_fs_open_excase_file( const enkf_fs_type * fs , const char * input_name);
FILE * enkf_fs_open_excase_tstep_file( const enkf_fs_type * fs , const char * input_name , int tstep );
FILE * enkf_fs_open_excase_member_file( const enkf_fs_type * fs , const char * input_name , int iens );
state_map_type * enkf_fs_get_state_map( const enkf_fs_type * fs );
time_map_type * enkf_fs_get_time_map( const enkf_fs_type * fs );
cases_config_type * enkf_fs_get_cases_config( const enkf_fs_type * fs);
misfit_ensemble_type * enkf_fs_get_misfit_ensemble( const enkf_fs_type * fs );
UTIL_SAFE_CAST_HEADER( enkf_fs );

View File

@@ -110,24 +110,26 @@ extern "C" {
void enkf_main_iload_ecl_mt(enkf_main_type *enkf_main , int );
void enkf_main_assimilation_update(enkf_main_type * enkf_main , const int_vector_type * step_list);
void enkf_main_smoother_update(enkf_main_type * enkf_main , const int_vector_type * step_list , enkf_fs_type * target_fs);
bool enkf_main_smoother_update(enkf_main_type * enkf_main , const int_vector_type * step_list , enkf_fs_type * target_fs);
void enkf_main_run_exp(enkf_main_type * enkf_main ,
const bool_vector_type * iactive ,
bool_vector_type * iactive ,
bool simulate ,
int init_step_parameters ,
int start_report ,
state_enum start_state);
state_enum start_state ,
bool initialize);
void enkf_main_run_assimilation(enkf_main_type * enkf_main ,
const bool_vector_type * iactive ,
bool_vector_type * iactive ,
int init_step_parameters ,
int start_report ,
state_enum start_state);
void enkf_main_run_smoother(enkf_main_type * enkf_main , const char * target_fs_name , bool rerun);
void enkf_main_run_smoother(enkf_main_type * enkf_main , const char * target_fs_name , bool rerun);
void enkf_main_run_iterated_ES(enkf_main_type * enkf_main, int last_report);
void enkf_main_run_one_more_iteration(enkf_main_type * enkf_main, int step2);
void enkf_main_set_data_kw(enkf_main_type * , const char * , const char *);
void enkf_main_set_state_run_path(const enkf_main_type * , int );
void enkf_main_set_state_eclbase(const enkf_main_type * , int );

View File

@@ -25,6 +25,7 @@ extern "C" {
#include <ert/util/hash.h>
#include <ert/util/stringlist.h>
#include <ert/util/int_vector.h>
#include <ert/sched/history.h>
@@ -63,7 +64,7 @@ extern "C" {
enkf_fs_type * fs,
const int_vector_type * step_list ,
state_enum state,
int ens_size,
const int_vector_type * ens_active_list,
const enkf_state_type ** ensemble ,
meas_data_type * meas_data,
obs_data_type * obs_data,

View File

@@ -80,15 +80,15 @@ typedef struct enkf_state_struct enkf_state_type;
void * enkf_state_run_eclipse__(void * );
void * enkf_state_start_forward_model__(void * );
void enkf_state_load_from_forward_model(enkf_state_type * enkf_state ,
void enkf_state_load_from_forward_model(enkf_state_type * enkf_state ,
enkf_fs_type * fs ,
bool * loadOK ,
int * result ,
bool interactive ,
stringlist_type * msg_list);
void enkf_state_forward_init(enkf_state_type * enkf_state ,
enkf_fs_type * fs ,
bool * loadOK );
int * result );
enkf_state_type * enkf_state_alloc(int ,
rng_type * main_rng ,
@@ -125,7 +125,7 @@ typedef struct enkf_state_struct enkf_state_type;
rng_type * enkf_state_get_rng( const enkf_state_type * enkf_state );
unsigned int enkf_state_get_random( enkf_state_type * enkf_state );
/*****************************************************************/
void enkf_state_set_inactive(enkf_state_type * state);

View File

@@ -21,7 +21,7 @@
#ifdef __cplusplus
extern "C" {
#endif
#include <ert/util/arg_pack.h>
@@ -125,6 +125,13 @@ typedef enum {UNDEFINED = 0 ,
{.value = 6 , .name = "BOTH"}
#define ENKF_STATE_ENUM_SIZE 4
typedef enum { REPORT_STEP_INCOMPATIBLE = 1,
LOAD_FAILURE = 2 } enkf_fw_load_result_enum;
@@ -228,6 +235,15 @@ typedef enum {
/*****************************************************************/
/* Possible transitions: */
typedef enum {
STATE_UNDEFINED = 1,
STATE_INITIALIZED = 2,
STATE_HAS_DATA = 4,
STATE_LOAD_FAILURE = 8,
STATE_PARENT_FAILURE = 16
} realisation_state_enum;
typedef struct enkf_obs_struct enkf_obs_type;

View File

@@ -27,10 +27,14 @@ extern "C" {
#include <ert/util/matrix.h>
#include <ert/util/hash.h>
#include <ert/util/int_vector.h>
#include <ert/util/type_macros.h>
typedef struct meas_data_struct meas_data_type;
typedef struct meas_block_struct meas_block_type;
UTIL_IS_INSTANCE_HEADER( meas_data );
void meas_block_iset( meas_block_type * meas_block , int iens , int iobs , double value);
double meas_block_iget_ens_mean( const meas_block_type * meas_block , int iobs );
double meas_block_iget_ens_std( const meas_block_type * meas_block , int iobs);
@@ -38,8 +42,8 @@ void meas_block_deactivate( meas_block_type * meas_block , int iob
void meas_data_fprintf( const meas_data_type * matrix , FILE * stream);
void meas_data_reset(meas_data_type * );
meas_data_type * meas_data_alloc( int );
void meas_data_reset(meas_data_type * );
meas_data_type * meas_data_alloc( const int_vector_type * ens_active_list );
void meas_data_free(meas_data_type * );
void meas_data_add(meas_data_type * , int , double );
matrix_type * meas_data_allocS(const meas_data_type * matrix , int active_size);
@@ -56,7 +60,6 @@ void meas_block_calculate_ens_stats( meas_block_type * meas_block
int meas_block_get_total_size( const meas_block_type * meas_block );
bool meas_block_iget_active( const meas_block_type * meas_block , int iobs);
void meas_data_assign_vector(meas_data_type * target_matrix, const meas_data_type * src_matrix , int target_index , int src_index);
meas_data_type * meas_data_alloc_copy( const meas_data_type * src );
#ifdef __cplusplus
}

View File

@@ -26,6 +26,7 @@ extern "C" {
#include <time.h>
#include <ert/util/path_fmt.h>
#include <ert/util/type_macros.h>
#include <ert/config/config.h>
@@ -55,6 +56,7 @@ extern "C" {
const char * model_config_get_enspath( const model_config_type * model_config);
const char * model_config_get_rftpath( const model_config_type * model_config);
fs_driver_impl model_config_get_dbase_type(const model_config_type * model_config );
const ecl_sum_type * model_config_get_refcase( const model_config_type * model_config );
void model_config_init_internalization( model_config_type * );
void model_config_set_internalize_state( model_config_type * , int );
void model_config_set_load_state( model_config_type * , int );
@@ -82,8 +84,11 @@ extern "C" {
history_source_type model_config_get_history_source( const model_config_type * model_config );
void model_config_set_refcase( model_config_type * model_config , const ecl_sum_type * refcase );
void model_config_fprintf_config( const model_config_type * model_config , int ens_size ,FILE * stream );
model_config_type * model_config_alloc_empty();
model_config_type * model_config_alloc();
bool model_config_select_history( model_config_type * model_config , history_source_type source_type, const sched_file_type * sched_file , const ecl_sum_type * refcase);
void model_config_set_runpath(model_config_type * model_config , const char * fmt);
UTIL_IS_INSTANCE_HEADER( model_config);
#ifdef __cplusplus
}

View File

@@ -63,7 +63,7 @@ extern "C" {
int obs_vector_get_num_active(const obs_vector_type * );
bool obs_vector_iget_active(const obs_vector_type * , int );
void obs_vector_iget_observations(const obs_vector_type * , int , obs_data_type * , const active_list_type * active_list);
void obs_vector_measure(const obs_vector_type * , enkf_fs_type * fs, state_enum state , int report_step , const enkf_state_type * , meas_data_type * , const active_list_type * active_list);
void obs_vector_measure(const obs_vector_type * , enkf_fs_type * fs, state_enum state , int report_step , int active_iens_index , const enkf_state_type * , meas_data_type * , const active_list_type * active_list);
const char * obs_vector_get_state_kw(const obs_vector_type * );
obs_impl_type obs_vector_get_impl_type(const obs_vector_type * );
int obs_vector_get_active_report_step(const obs_vector_type * );

View File

@@ -0,0 +1,56 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'state_map.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.
*/
#ifndef __STATE_MAP_H__
#define __STATE_MAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <ert/util/type_macros.h>
#include <ert/util/bool_vector.h>
#include <ert/enkf/enkf_types.h>
typedef struct state_map_struct state_map_type;
state_map_type * state_map_alloc( );
state_map_type * state_map_fread_alloc( const char * filename );
state_map_type * state_map_alloc_copy( state_map_type * map );
void state_map_free( state_map_type * map );
int state_map_get_size( state_map_type * map);
realisation_state_enum state_map_iget( state_map_type * map , int index);
void state_map_update_undefined( state_map_type * map , int index , realisation_state_enum new_state);
void state_map_iset( state_map_type * map ,int index , realisation_state_enum state);
bool state_map_equal( state_map_type * map1 , state_map_type * map2);
void state_map_fwrite( state_map_type * map , const char * filename);
void state_map_fread( state_map_type * map , const char * filename);
void state_map_select_matching( state_map_type * map , bool_vector_type * select_target , int select_mask);
void state_map_deselect_matching( state_map_type * map , bool_vector_type * select_target , int select_mask);
void state_map_set_from_inverted_mask(state_map_type * map, const bool_vector_type *mask , realisation_state_enum state);
void state_map_set_from_mask(state_map_type * map, const bool_vector_type *mask , realisation_state_enum state);
int state_map_count_matching( state_map_type * state_map , int mask);
UTIL_IS_INSTANCE_HEADER( state_map );
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,6 +1,6 @@
set( source_files ert_report.c time_map.c rng_config.c trans_func.c enkf_types.c enkf_obs.c obs_data.c block_obs.c enkf_config_node.c field_config.c field.c ecl_static_kw.c enkf_state.c enkf_util.c enkf_node.c gen_kw_config.c gen_kw.c enkf_fs.c fs_driver.c meas_data.c summary_obs.c summary.c summary_config.c gen_data_config.c gen_data.c gen_common.c gen_obs.c enkf_sched.c enkf_serialize.c ecl_config.c enkf_defaults.c ensemble_config.c model_config.c site_config.c active_list.c obs_vector.c field_trans.c plain_driver.c local_ministep.c local_updatestep.c container_config.c container.c local_context.c local_config.c analysis_config.c misfit_ensemble.c misfit_member.c misfit_ts.c data_ranking.c misfit_ranking.c ranking_table.c fs_types.c block_fs_driver.c plot_config.c ert_template.c member_config.c enkf_analysis.c enkf_main.c local_dataset.c local_obsset.c surface.c surface_config.c enkf_plot_data.c enkf_plot_member.c qc_module.c ert_report_list.c enkf_plot_arg.c runpath_list.c ert_workflow_list.c analysis_iter_config.c enkf_main_jobs.c ecl_refcase_list.c)
set( source_files ert_report.c time_map.c rng_config.c trans_func.c enkf_types.c enkf_obs.c obs_data.c block_obs.c enkf_config_node.c field_config.c field.c ecl_static_kw.c enkf_state.c enkf_util.c enkf_node.c gen_kw_config.c gen_kw.c enkf_fs.c fs_driver.c meas_data.c summary_obs.c summary.c summary_config.c gen_data_config.c gen_data.c gen_common.c gen_obs.c enkf_sched.c enkf_serialize.c ecl_config.c enkf_defaults.c ensemble_config.c model_config.c site_config.c active_list.c obs_vector.c field_trans.c plain_driver.c local_ministep.c local_updatestep.c container_config.c container.c local_context.c local_config.c analysis_config.c misfit_ensemble.c misfit_member.c misfit_ts.c data_ranking.c misfit_ranking.c ranking_table.c fs_types.c block_fs_driver.c plot_config.c ert_template.c member_config.c enkf_analysis.c enkf_main.c local_dataset.c local_obsset.c surface.c surface_config.c enkf_plot_data.c enkf_plot_member.c qc_module.c ert_report_list.c enkf_plot_arg.c runpath_list.c ert_workflow_list.c analysis_iter_config.c enkf_main_jobs.c ecl_refcase_list.c cases_config.c state_map.c)
set( header_files ert_report.h time_map.h rng_config.h enkf_analysis.h enkf_fs_type.h trans_func.h enkf_obs.h obs_data.h enkf_config_node.h block_obs.h field_config.h field.h enkf_macros.h ecl_static_kw.h enkf_state.h enkf_util.h enkf_main.h enkf_node.h enkf_fs.h gen_kw_config.h gen_kw.h enkf_types.h fs_driver.h meas_data.h summary_obs.h summary_config.h summary_config.h gen_data_config.h gen_data.h gen_common.h gen_obs.h enkf_sched.h fs_types.h enkf_serialize.h plain_driver.h ecl_config.h ensemble_config.h model_config.h site_config.h active_list.h obs_vector.h field_trans.h plain_driver.h local_ministep.h container.h local_updatestep.h local_config.h analysis_config.h misfit_ensemble.h misfit_ensemble_typedef.h misfit_ts.h misfit_member.h data_ranking.h ranking_table.h ranking_common.h misfit_ranking.h block_fs_driver.h field_common.h gen_kw_common.h gen_data_common.h plot_config.h ert_template.h member_config.h enkf_defaults.h container_config.h local_dataset.h local_obsset.h surface.h surface_config.h local_context.h enkf_plot_data.h enkf_plot_member.h qc_module.h ert_report_list.h enkf_plot_arg.h runpath_list.h ert_workflow_list.h analysis_iter_config.h ecl_refcase_list.h)
set( header_files ert_report.h time_map.h rng_config.h enkf_analysis.h enkf_fs_type.h trans_func.h enkf_obs.h obs_data.h enkf_config_node.h block_obs.h field_config.h field.h enkf_macros.h ecl_static_kw.h enkf_state.h enkf_util.h enkf_main.h enkf_node.h enkf_fs.h gen_kw_config.h gen_kw.h enkf_types.h fs_driver.h meas_data.h summary_obs.h summary_config.h summary_config.h gen_data_config.h gen_data.h gen_common.h gen_obs.h enkf_sched.h fs_types.h enkf_serialize.h plain_driver.h ecl_config.h ensemble_config.h model_config.h site_config.h active_list.h obs_vector.h field_trans.h plain_driver.h local_ministep.h container.h local_updatestep.h local_config.h analysis_config.h misfit_ensemble.h misfit_ensemble_typedef.h misfit_ts.h misfit_member.h data_ranking.h ranking_table.h ranking_common.h misfit_ranking.h block_fs_driver.h field_common.h gen_kw_common.h gen_data_common.h plot_config.h ert_template.h member_config.h enkf_defaults.h container_config.h local_dataset.h local_obsset.h surface.h surface_config.h local_context.h enkf_plot_data.h enkf_plot_member.h qc_module.h ert_report_list.h enkf_plot_arg.h runpath_list.h ert_workflow_list.h analysis_iter_config.h ecl_refcase_list.h cases_config.h state_map.h)
add_library( enkf ${LIBRARY_TYPE} ${source_files} )
set_target_properties( enkf PROPERTIES VERSION 1.0 SOVERSION 1.0 )

View File

@@ -24,6 +24,7 @@
#include <ert/util/util.h>
#include <ert/util/stringlist.h>
#include <ert/util/rng.h>
#include <ert/util/type_macros.h>
#include <ert/config/config.h>
@@ -36,7 +37,10 @@
#include <ert/enkf/analysis_iter_config.h>
#define ANALYSIS_CONFIG_TYPE_ID 64431306
struct analysis_config_struct {
UTIL_TYPE_ID_DECLARATION;
hash_type * analysis_modules;
analysis_module_type * analysis_module;
char * log_path; /* Points to directory with update logs. */
@@ -54,12 +58,13 @@ struct analysis_config_struct {
bool single_node_update; /* When creating the default ALL_ACTIVE local configuration. */
rng_type * rng;
analysis_iter_config_type * iter_config;
int min_realisations;
};
UTIL_IS_INSTANCE_FUNCTION( analysis_config , ANALYSIS_CONFIG_TYPE_ID )
/*****************************************************************/
/*
@@ -116,7 +121,29 @@ ANALYSIS_SELECT ModuleName
/*****************************************************************/
bool analysis_config_have_enough_realisations( const analysis_config_type * config , int realisations) {
if (config->min_realisations > 0) {
/* A value > 0 has been set in the config; compare with this value. */
if (realisations >= config->min_realisations)
return true;
else
return false;
} else {
/* No value has been set in the config; just compare the input with zero. */
if (realisations > 0)
return true;
else
return false;
}
}
void analysis_config_set_min_realisations( analysis_config_type * config , int min_realisations) {
config->min_realisations = min_realisations;
}
int analysis_config_get_min_realisations( const analysis_config_type * config ) {
return config->min_realisations;
}
void analysis_config_set_alpha( analysis_config_type * config , double alpha) {
config->overlap_alpha = alpha;
@@ -371,6 +398,9 @@ void analysis_config_init( analysis_config_type * analysis , const config_type *
if (config_item_set( config , RERUN_START_KEY ))
analysis_config_set_rerun_start( analysis , config_get_value_as_int( config , RERUN_START_KEY ));
if (config_item_set( config , MIN_REALIZATIONS_KEY ))
analysis_config_set_min_realisations( analysis , config_get_value_as_int( config , MIN_REALIZATIONS_KEY ));
/* Loading external modules */
{
@@ -458,8 +488,9 @@ void analysis_config_free(analysis_config_type * config) {
analysis_config_type * analysis_config_alloc_default( rng_type * rng ) {
analysis_config_type * analysis_config_alloc( rng_type * rng ) {
analysis_config_type * config = util_malloc( sizeof * config );
UTIL_TYPE_ID_INIT( config , ANALYSIS_CONFIG_TYPE_ID );
config->log_path = NULL;
config->PC_filename = NULL;
@@ -477,6 +508,7 @@ analysis_config_type * analysis_config_alloc_default( rng_type * rng ) {
analysis_config_set_store_PC( config , DEFAULT_STORE_PC );
analysis_config_set_PC_filename( config , DEFAULT_PC_FILENAME );
analysis_config_set_PC_path( config , DEFAULT_PC_PATH );
analysis_config_set_min_realisations( config , DEFAULT_ANALYSIS_MIN_REALISATIONS );
config->analysis_module = NULL;
config->analysis_modules = hash_alloc();
@@ -514,6 +546,7 @@ void analysis_config_add_config_items( config_type * config ) {
config_add_key_value( config , ENKF_RERUN_KEY , false , CONFIG_BOOL);
config_add_key_value( config , RERUN_START_KEY , false , CONFIG_INT);
config_add_key_value( config , UPDATE_LOG_PATH_KEY , false , CONFIG_STRING);
config_add_key_value( config , MIN_REALIZATIONS_KEY , false , CONFIG_INT );
config_add_key_value( config , ANALYSIS_SELECT_KEY , false , CONFIG_STRING);
@@ -553,7 +586,7 @@ void analysis_config_fprintf_config( analysis_config_type * config , FILE * stre
}
if (config->overlap_alpha != DEFAULT_ENKF_ALPHA ) {
fprintf( stream , CONFIG_KEY_FORMAT , ENKF_TRUNCATION_KEY );
fprintf( stream , CONFIG_KEY_FORMAT , ENKF_ALPHA_KEY );
fprintf( stream , CONFIG_FLOAT_FORMAT , config->overlap_alpha );
fprintf( stream , "\n");
}

View File

@@ -47,24 +47,6 @@ int analysis_iter_config_get_num_iterations( const analysis_iter_config_type * c
return config->num_iterations;
}
analysis_iter_config_type * analysis_iter_config_alloc() {
analysis_iter_config_type * config = util_malloc( sizeof * config );
config->runpath_fmt = NULL;
config->case_fmt = NULL;
config->storage = stringlist_alloc_new();
analysis_iter_config_set_num_iterations( config , DEFAULT_ANALYSIS_NUM_ITERATIONS );
return config;
}
void analysis_iter_config_free( analysis_iter_config_type * config ) {
util_safe_free( config->runpath_fmt );
util_safe_free( config->case_fmt );
stringlist_free( config->storage );
}
/**
This should contain a format string with two %d modifiers, the
first will be replaced with the iteration number, and the second
@@ -86,10 +68,36 @@ static void analysis_iter_config_set_runpath_fmt( analysis_iter_config_type * co
}
}
static void analysis_iter_config_set_case_fmt( analysis_iter_config_type * config , const char * case_fmt) {
void analysis_iter_config_set_case_fmt( analysis_iter_config_type * config , const char * case_fmt) {
config->case_fmt = util_realloc_string_copy( config->case_fmt , case_fmt );
}
char * analysis_iter_config_get_case_fmt( analysis_iter_config_type * config) {
return config->case_fmt;
}
analysis_iter_config_type * analysis_iter_config_alloc() {
analysis_iter_config_type * config = util_malloc( sizeof * config );
config->runpath_fmt = NULL;
analysis_iter_config_set_runpath_fmt( config, DEFAULT_ANALYSIS_ITER_RUNPATH);
config->case_fmt = NULL;
analysis_iter_config_set_case_fmt( config, DEFAULT_ANALYSIS_ITER_CASE);
config->storage = stringlist_alloc_new();
analysis_iter_config_set_num_iterations( config , DEFAULT_ANALYSIS_NUM_ITERATIONS );
return config;
}
void analysis_iter_config_free( analysis_iter_config_type * config ) {
util_safe_free( config->runpath_fmt );
util_safe_free( config->case_fmt );
stringlist_free( config->storage );
}
const char * analysis_iter_config_iget_runpath_fmt( analysis_iter_config_type * config , int iter) {
if (config->runpath_fmt != NULL) {
char * runpath_fmt = util_alloc_sprintf( config->runpath_fmt , iter );

View File

@@ -0,0 +1,86 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'cases_config.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <ert/util/util.h>
#include <ert/util/stringlist.h>
#include <ert/config/config.h>
#include <ert/enkf/enkf_defaults.h>
#include <ert/enkf/config_keys.h>
#include <ert/enkf/cases_config.h>
struct cases_config_struct {
int iteration_number;
};
cases_config_type * cases_config_alloc( ) {
cases_config_type * config = util_malloc( sizeof * config );
config->iteration_number = 0;
return config;
}
static void cases_config_set_iteration_number( cases_config_type * config , int num_iterations) {
config->iteration_number = num_iterations;
}
int cases_config_get_iteration_number( const cases_config_type * config ) {
return config->iteration_number;
}
bool cases_config_set_int( cases_config_type * cases_config , const char * var_name , int value) {
bool name_recognized = true;
if (strcmp( var_name , "iteration_number") == 0)
cases_config_set_iteration_number(cases_config, value);
else
name_recognized = false;
return name_recognized;
}
void cases_config_fwrite( cases_config_type * config , const char * filename ) {
FILE * stream = util_mkdir_fopen(filename , "w");
int iteration_no = cases_config_get_iteration_number(config);
util_fwrite_int( iteration_no , stream );
fclose( stream );
}
void cases_config_fread( cases_config_type * config , const char * filename) {
if (util_file_exists( filename )) {
FILE * stream = util_fopen( filename , "r");
int iteration_number = util_fread_int( stream );
cases_config_set_iteration_number(config,iteration_number);
fclose( stream );
}
}
void cases_config_free( cases_config_type * config ) {
free( config );
}

View File

@@ -193,6 +193,13 @@ bool ecl_config_has_schedule( const ecl_config_type * ecl_config ) {
return true;
}
bool ecl_config_has_init_section( const ecl_config_type * ecl_config ) {
if (ecl_config->init_section == NULL)
return false;
else
return true;
}
/**
Observe: This function makes a hard assumption that the
@@ -311,7 +318,10 @@ void ecl_config_set_init_section( ecl_config_type * ecl_config , const char * in
2. If the INIT_SECTION points to a not existing file:
a. We assert that INIT_SECTION points to a pure filename,
i.e. /some/path/which/does/not/exist is NOT accepted.
i.e. /some/path/which/does/not/exist is NOT accepted. In
the case the input argument contain a path a error message
will be printed on stderr and the ->init_section will not
be set.
b. The ecl_config->input_init_section is set to point to this
file.
c. WE TRUST THE USER TO SUPPLY CONTENT (THROUGH SOME FUNKY
@@ -351,7 +361,7 @@ void ecl_config_set_init_section( ecl_config_type * ecl_config , const char * in
*/
if (ecl_config->can_restart) { /* The <INIT> tag is set. */
ecl_config->input_init_section = util_realloc_string_copy( ecl_config->input_init_section , input_init_section ); /* input_init_section = path/to/init_section */
ecl_config->input_init_section = util_realloc_string_copy( ecl_config->input_init_section , input_init_section ); /* input_init_section = path/to/init_section */
if (util_file_exists( ecl_config->input_init_section )) { /* init_section = $CWD/path/to/init_section */
util_safe_free( ecl_config->init_section );
ecl_config->init_section = util_alloc_realpath(input_init_section);
@@ -360,10 +370,11 @@ void ecl_config_set_init_section( ecl_config_type * ecl_config , const char * in
util_alloc_file_components( ecl_config->input_init_section , &path , NULL , NULL );
if (path != NULL)
util_abort("%s: When INIT_SECTION:%s is set to a non-existing file - you can not have any path components.\n",__func__ , input_init_section);
fprintf(stderr,"** Warning: %s: When INIT_SECTION:%s points to a non-existing file - you can not have any path components.\n",__func__ , input_init_section);
else
ecl_config->init_section = util_alloc_string_copy(input_init_section);
util_safe_free( path );
ecl_config->init_section = util_alloc_string_copy(input_init_section);
}
} else
/*

View File

@@ -42,8 +42,9 @@
#include <ert/enkf/plain_driver.h>
#include <ert/enkf/gen_data.h>
#include <ert/enkf/time_map.h>
#include <ert/enkf/state_map.h>
#include <ert/enkf/misfit_ensemble.h>
#include <ert/enkf/cases_config.h>
/**
@@ -204,7 +205,9 @@
#define ENKF_FS_TYPE_ID 1089763
#define ENKF_MOUNT_MAP "enkf_mount_info"
#define TIME_MAP_FILE "time-map"
#define STATE_MAP_FILE "state-map"
#define MISFIT_ENSEMBLE_FILE "misfit-ensemble"
#define CASE_CONFIG_FILE "case_config"
struct enkf_fs_struct {
UTIL_TYPE_ID_DECLARATION;
@@ -221,6 +224,8 @@ struct enkf_fs_struct {
bool read_only; /* Whether this filesystem has been mounted read-only. */
time_map_type * time_map;
cases_config_type * cases_config;
state_map_type * state_map;
misfit_ensemble_type * misfit_ensemble;
/*
The variables below here are for storing arbitrary files within
@@ -242,6 +247,8 @@ static enkf_fs_type * enkf_fs_alloc_empty( const char * mount_point , bool read_
enkf_fs_type * fs = util_malloc(sizeof * fs );
UTIL_TYPE_ID_INIT( fs , ENKF_FS_TYPE_ID );
fs->time_map = time_map_alloc();
fs->cases_config = cases_config_alloc();
fs->state_map = state_map_alloc();
fs->misfit_ensemble = misfit_ensemble_alloc();
fs->index = NULL;
fs->eclipse_static = NULL;
@@ -438,6 +445,35 @@ static void enkf_fs_fread_time_map( enkf_fs_type * fs ) {
}
static void enkf_fs_fsync_cases_config( enkf_fs_type * fs ) {
char * filename = enkf_fs_alloc_case_filename( fs , CASE_CONFIG_FILE );
cases_config_fwrite( fs->cases_config , filename );
free( filename );
}
static void enkf_fs_fsync_state_map( enkf_fs_type * fs ) {
char * filename = enkf_fs_alloc_case_filename( fs , STATE_MAP_FILE );
state_map_fwrite( fs->state_map , filename );
free( filename );
}
static void enkf_fs_fread_cases_config( enkf_fs_type * fs ) {
char * filename = enkf_fs_alloc_case_filename( fs , CASE_CONFIG_FILE );
cases_config_fread( fs->cases_config , filename );
free( filename );
}
static void enkf_fs_fread_state_map( enkf_fs_type * fs ) {
char * filename = enkf_fs_alloc_case_filename( fs , STATE_MAP_FILE );
state_map_fread( fs->state_map , filename );
free( filename );
}
static void enkf_fs_fread_misfit( enkf_fs_type * fs ) {
FILE * stream = enkf_fs_open_excase_file( fs , MISFIT_ENSEMBLE_FILE );
if (stream != NULL) {
@@ -480,6 +516,8 @@ enkf_fs_type * enkf_fs_open( const char * mount_point , bool read_only) {
fclose( stream );
enkf_fs_init_path_fmt( fs );
enkf_fs_fread_time_map( fs );
enkf_fs_fread_cases_config( fs );
enkf_fs_fread_state_map( fs );
enkf_fs_fread_misfit( fs );
}
return fs;
@@ -528,7 +566,9 @@ void enkf_fs_close( enkf_fs_type * fs ) {
path_fmt_free( fs->case_tstep_fmt );
path_fmt_free( fs->case_tstep_member_fmt );
state_map_free( fs->state_map );
time_map_free( fs->time_map );
cases_config_free( fs->cases_config );
free( fs );
}
@@ -590,6 +630,8 @@ void enkf_fs_fsync( enkf_fs_type * fs ) {
enkf_fs_fsync_driver( fs->index );
enkf_fs_fsync_time_map( fs );
enkf_fs_fsync_cases_config( fs) ;
enkf_fs_fsync_state_map( fs );
}
@@ -869,6 +911,14 @@ time_map_type * enkf_fs_get_time_map( const enkf_fs_type * fs ) {
return fs->time_map;
}
cases_config_type * enkf_fs_get_cases_config( const enkf_fs_type * fs) {
return fs->cases_config;
}
state_map_type * enkf_fs_get_state_map( const enkf_fs_type * fs ) {
return fs->state_map;
}
misfit_ensemble_type * enkf_fs_get_misfit_ensemble( const enkf_fs_type * fs ) {
return fs->misfit_ensemble;

View File

@@ -47,8 +47,10 @@
#include <ert/util/log.h>
#include <ert/util/node_ctype.h>
#include <ert/util/string_util.h>
#include <ert/util/type_vector_functions.h>
#include <ert/config/config.h>
#include <ert/config/config_schema_item.h>
#include <ert/ecl/ecl_util.h>
#include <ert/ecl/ecl_io_config.h>
@@ -67,6 +69,7 @@
#include <ert/analysis/analysis_table.h>
#include <ert/analysis/enkf_linalg.h>
#include <ert/enkf/enkf_types.h>
#include <ert/enkf/enkf_config_node.h>
#include <ert/enkf/ecl_config.h>
@@ -98,6 +101,8 @@
#include <ert/enkf/enkf_defaults.h>
#include <ert/enkf/config_keys.h>
#include <ert/enkf/runpath_list.h>
#include <ert/enkf/analysis_config.h>
#include <ert/enkf/analysis_iter_config.h>
/**/
@@ -735,6 +740,7 @@ typedef struct {
int row_offset;
const active_list_type * active_list;
matrix_type * A;
const int_vector_type * iens_active_index;
} serialize_info_type;
@@ -746,21 +752,33 @@ static void serialize_node( enkf_fs_type * fs ,
int report_step ,
state_enum load_state ,
int row_offset ,
int column,
const active_list_type * active_list,
matrix_type * A) {
enkf_node_type * node = enkf_state_get_node( ensemble[iens] , key);
node_id_type node_id = {.report_step = report_step, .iens = iens , .state = load_state };
enkf_node_serialize( node , fs , node_id , active_list , A , row_offset , iens);
enkf_node_serialize( node , fs , node_id , active_list , A , row_offset , column);
}
static void * serialize_nodes_mt( void * arg ) {
serialize_info_type * info = (serialize_info_type *) arg;
int iens;
for (iens = info->iens1; iens < info->iens2; iens++)
serialize_node( info->src_fs , info->ensemble , info->key , iens , info->report_step , info->load_state , info->row_offset , info->active_list , info->A );
for (iens = info->iens1; iens < info->iens2; iens++) {
int column = int_vector_iget( info->iens_active_index , iens);
if (column >= 0)
serialize_node( info->src_fs ,
info->ensemble ,
info->key ,
iens ,
info->report_step ,
info->load_state ,
info->row_offset ,
column,
info->active_list ,
info->A );
}
return NULL;
}
@@ -782,7 +800,7 @@ static void enkf_main_serialize_node( const char * node_key ,
serialize_info[icpu].active_list = active_list;
serialize_info[icpu].load_state = load_state;
serialize_info[icpu].row_offset = row_offset;
thread_pool_add_job( work_pool , serialize_nodes_mt , &serialize_info[icpu]);
}
thread_pool_join( work_pool );
@@ -857,12 +875,14 @@ static void deserialize_node( enkf_fs_type * fs,
int iens,
int target_step ,
int row_offset ,
int column,
const active_list_type * active_list,
matrix_type * A) {
enkf_node_type * node = enkf_state_get_node( ensemble[iens] , key);
node_id_type node_id = { .report_step = target_step , .iens = iens , .state = ANALYZED };
enkf_node_deserialize(node , fs , node_id , active_list , A , row_offset , iens);
enkf_node_deserialize(node , fs , node_id , active_list , A , row_offset , column);
state_map_update_undefined(enkf_fs_get_state_map(fs) , iens , STATE_INITIALIZED);
}
@@ -870,9 +890,11 @@ static void deserialize_node( enkf_fs_type * fs,
static void * deserialize_nodes_mt( void * arg ) {
serialize_info_type * info = (serialize_info_type *) arg;
int iens;
for (iens = info->iens1; iens < info->iens2; iens++)
deserialize_node( info->target_fs , info->ensemble , info->key , iens , info->target_step , info->row_offset , info->active_list , info->A );
for (iens = info->iens1; iens < info->iens2; iens++) {
int column = int_vector_iget( info->iens_active_index , iens );
if (column >= 0)
deserialize_node( info->target_fs , info->ensemble , info->key , iens , info->target_step , info->row_offset , column, info->active_list , info->A );
}
return NULL;
}
@@ -924,12 +946,22 @@ static void serialize_info_free( serialize_info_type * serialize_info ) {
free( serialize_info );
}
static serialize_info_type * serialize_info_alloc( enkf_fs_type * src_fs, enkf_fs_type * target_fs , int target_step , enkf_state_type ** ensemble , run_mode_type run_mode , int report_step , matrix_type * A , int num_cpu_threads ) {
static serialize_info_type * serialize_info_alloc( enkf_fs_type * src_fs,
enkf_fs_type * target_fs ,
const int_vector_type * iens_active_index ,
int target_step ,
enkf_state_type ** ensemble ,
run_mode_type run_mode ,
int report_step ,
matrix_type * A ,
int num_cpu_threads ) {
serialize_info_type * serialize_info = util_calloc( num_cpu_threads , sizeof * serialize_info );
int ens_size = matrix_get_columns( A );
int ens_size = int_vector_size(iens_active_index);
int icpu;
int iens_offset = 0;
for (icpu = 0; icpu < num_cpu_threads; icpu++) {
serialize_info[icpu].iens_active_index = iens_active_index;
serialize_info[icpu].run_mode = run_mode;
serialize_info[icpu].src_fs = src_fs;
serialize_info[icpu].target_fs = target_fs;
@@ -988,6 +1020,7 @@ void enkf_main_get_PC( const enkf_main_type * enkf_main ,
static void enkf_main_analysis_update( enkf_main_type * enkf_main ,
enkf_fs_type * target_fs ,
const bool_vector_type * ens_mask ,
int target_step ,
hash_type * use_count,
run_mode_type run_mode ,
@@ -1011,20 +1044,20 @@ static void enkf_main_analysis_update( enkf_main_type * enkf_main ,
matrix_type * E = NULL;
matrix_type * D = NULL;
matrix_type * localA = NULL;
int_vector_type * iens_active_index = bool_vector_alloc_active_index_list(ens_mask , -1);
if (analysis_module_get_option( module , ANALYSIS_NEED_ED)) {
E = obs_data_allocE( obs_data , enkf_main->rng , ens_size , active_size );
D = obs_data_allocD( obs_data , E , S );
}
if (analysis_module_get_option( module , ANALYSIS_SCALE_DATA))
if (analysis_module_get_option( module , ANALYSIS_SCALE_DATA)){
obs_data_scale( obs_data , S , E , D , R , dObs );
}
if (analysis_module_get_option( module , ANALYSIS_USE_A | ANALYSIS_UPDATE_A))
if (analysis_module_get_option( module , ANALYSIS_USE_A | ANALYSIS_UPDATE_A)){
localA = A;
}
/*****************************************************************/
@@ -1032,7 +1065,15 @@ static void enkf_main_analysis_update( enkf_main_type * enkf_main ,
{
hash_iter_type * dataset_iter = local_ministep_alloc_dataset_iter( ministep );
enkf_fs_type * src_fs = enkf_main_get_fs( enkf_main );
serialize_info_type * serialize_info = serialize_info_alloc( src_fs , target_fs , target_step , enkf_main_get_ensemble( enkf_main ) , run_mode , step2 , A , cpu_threads);
serialize_info_type * serialize_info = serialize_info_alloc( src_fs ,
target_fs ,
iens_active_index,
target_step ,
enkf_main_get_ensemble( enkf_main ) ,
run_mode ,
step2 ,
A ,
cpu_threads);
// Store PC:
if (analysis_config_get_store_PC( enkf_main->analysis_config )) {
@@ -1047,8 +1088,10 @@ static void enkf_main_analysis_update( enkf_main_type * enkf_main ,
matrix_free( PC_obs );
}
if (localA == NULL)
if (localA == NULL){
analysis_module_initX( module , X , NULL , S , R , dObs , E , D );
}
while (!hash_iter_is_complete( dataset_iter )) {
const char * dataset_name = hash_iter_get_next_key( dataset_iter );
@@ -1059,11 +1102,21 @@ static void enkf_main_analysis_update( enkf_main_type * enkf_main ,
enkf_main_serialize_dataset( enkf_main , dataset , step2 , use_count , active_size , row_offset , tp , serialize_info);
if (analysis_module_get_option( module , ANALYSIS_UPDATE_A))
analysis_module_updateA( module , localA , S , R , dObs , E , D );
if (analysis_module_get_option( module , ANALYSIS_UPDATE_A)){
if (analysis_module_get_option( module , ANALYSIS_ITERABLE)){
int iteration = cases_config_get_iteration_number(enkf_fs_get_cases_config(src_fs));
char iteration_str[15];
sprintf(iteration_str,"%d",iteration);
analysis_module_set_var( module , "NUM_ITER", iteration_str);
analysis_module_updateA( module , localA , S , R , dObs , E , D );
}
else
analysis_module_updateA( module , localA , S , R , dObs , E , D );
}
else {
if (analysis_module_get_option( module , ANALYSIS_USE_A))
if (analysis_module_get_option( module , ANALYSIS_USE_A)){
analysis_module_initX( module , X , localA , S , R , dObs , E , D );
}
matrix_inplace_matmul_mt2( A , X , tp );
}
@@ -1084,6 +1137,7 @@ static void enkf_main_analysis_update( enkf_main_type * enkf_main ,
/*****************************************************************/
int_vector_free(iens_active_index);
matrix_safe_free( E );
matrix_safe_free( D );
matrix_free( S );
@@ -1100,101 +1154,131 @@ static void enkf_main_analysis_update( enkf_main_type * enkf_main ,
**/
static void enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_list, enkf_fs_type * target_fs , int target_step , run_mode_type run_mode) {
static bool enkf_main_UPDATE(enkf_main_type * enkf_main , const int_vector_type * step_list, 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.
*/
const int ens_size = enkf_main_get_ensemble_size(enkf_main);
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 );
{
/*
Observations and measurements are collected in these temporary
structures. obs_data is a precursor for the 'd' vector, and
meas_forecast is a precursor for the 'S' matrix'.
enkf_fs_type * source_fs = enkf_main_get_fs(enkf_main);
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 );
The reason for going via these temporary structures is to support
deactivating observations which should not be used in the update
process.
*/
obs_data_type * obs_data = obs_data_alloc();
meas_data_type * meas_forecast = meas_data_alloc( ens_size );
meas_data_type * meas_analyzed = meas_data_alloc( ens_size );
local_config_type * local_config = enkf_main->local_config;
const local_updatestep_type * updatestep = local_config_iget_updatestep( local_config , current_step ); /* Only last step considered when forming local update */
hash_type * use_count = hash_alloc();
const char * log_path = analysis_config_get_log_path( enkf_main->analysis_config );
FILE * log_stream;
if (analysis_config_have_enough_realisations(analysis_config , active_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 );
const int total_ens_size = enkf_main_get_ensemble_size(enkf_main);
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 );
{
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 );
}
/*
Observations and measurements are collected in these temporary
structures. obs_data is a precursor for the 'd' vector, and
meas_forecast is a precursor for the 'S' matrix'.
The reason for going via these temporary structures is to support
deactivating observations which should not be used in the update
process.
*/
obs_data_type * obs_data = obs_data_alloc();
meas_data_type * meas_forecast = meas_data_alloc( ens_active_list );
meas_data_type * meas_analyzed = meas_data_alloc( ens_active_list );
local_config_type * local_config = enkf_main->local_config;
const local_updatestep_type * updatestep = local_config_iget_updatestep( local_config , current_step ); /* Only last step considered when forming local update */
hash_type * use_count = hash_alloc();
const char * log_path = analysis_config_get_log_path( enkf_main->analysis_config );
FILE * log_stream;
for (int ministep_nr = 0; ministep_nr < local_updatestep_get_num_ministep( updatestep ); ministep_nr++) { /* Looping over local analysis ministep */
local_ministep_type * ministep = local_updatestep_iget_ministep( updatestep , ministep_nr );
local_obsset_type * obsset = local_ministep_get_obsset( ministep );
obs_data_reset( obs_data );
meas_data_reset( meas_forecast );
{
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" );
enkf_obs_get_obs_and_measure( enkf_main->obs,
enkf_main_get_fs(enkf_main),
step_list ,
FORECAST,
ens_size,
(const enkf_state_type **) enkf_main->ensemble,
meas_forecast,
obs_data ,
obsset );
enkf_analysis_deactivate_outliers( obs_data , meas_forecast , std_cutoff , alpha);
if (enkf_main->verbose)
enkf_analysis_fprintf_obs_summary( obs_data , meas_forecast , step_list , local_ministep_get_name( ministep ) , stdout );
enkf_analysis_fprintf_obs_summary( obs_data , meas_forecast , step_list , local_ministep_get_name( ministep ) , log_stream );
if (obs_data_get_active_size(obs_data) > 0)
enkf_main_analysis_update( enkf_main ,
target_fs ,
target_step ,
use_count ,
run_mode ,
int_vector_get_first( step_list ),
current_step ,
ministep ,
meas_forecast ,
obs_data );
}
fclose( log_stream );
obs_data_free( obs_data );
meas_data_free( meas_forecast );
meas_data_free( meas_analyzed );
free( log_file );
}
enkf_main_inflate( enkf_main , target_fs , current_step , use_count);
hash_free( use_count );
for (int ministep_nr = 0; ministep_nr < local_updatestep_get_num_ministep( updatestep ); ministep_nr++) { /* Looping over local analysis ministep */
local_ministep_type * ministep = local_updatestep_iget_ministep( updatestep , ministep_nr );
local_obsset_type * obsset = local_ministep_get_obsset( ministep );
obs_data_reset( obs_data );
meas_data_reset( meas_forecast );
enkf_obs_get_obs_and_measure( enkf_main->obs,
source_fs ,
step_list ,
FORECAST,
ens_active_list ,
(const enkf_state_type **) enkf_main->ensemble,
meas_forecast,
obs_data ,
obsset );
enkf_analysis_deactivate_outliers( obs_data , meas_forecast , std_cutoff , alpha);
if (enkf_main->verbose)
enkf_analysis_fprintf_obs_summary( obs_data , meas_forecast , step_list , local_ministep_get_name( ministep ) , stdout );
enkf_analysis_fprintf_obs_summary( obs_data , meas_forecast , step_list , local_ministep_get_name( ministep ) , log_stream );
if (obs_data_get_active_size(obs_data) > 0)
enkf_main_analysis_update( enkf_main ,
target_fs ,
ens_mask ,
target_step ,
use_count ,
run_mode ,
int_vector_get_first( step_list ),
current_step ,
ministep ,
meas_forecast ,
obs_data );
}
fclose( log_stream );
obs_data_free( obs_data );
meas_data_free( meas_forecast );
meas_data_free( meas_analyzed );
enkf_main_inflate( enkf_main , target_fs , current_step , use_count);
hash_free( use_count );
if (target_state_map != source_state_map) {
state_map_set_from_inverted_mask( target_state_map , ens_mask , STATE_PARENT_FAILURE);
enkf_fs_fsync( target_fs );
}
}
bool_vector_free( ens_mask );
int_vector_free( ens_active_list );
return true;
} else {
fprintf(stderr,"** ERROR ** There are %d active realisations left, which is less than the minimum specified (%d) - stopping assimilation.\n" ,
active_ens_size ,
analysis_config_get_min_realisations(analysis_config));
return false;
}
}
void enkf_main_assimilation_update(enkf_main_type * enkf_main , const int_vector_type * step_list) {
enkf_main_UPDATE( enkf_main , step_list , enkf_main_get_fs( enkf_main ) , int_vector_get_last( step_list ) , ENKF_ASSIMILATION );
}
void enkf_main_smoother_update(enkf_main_type * enkf_main , const int_vector_type * step_list , enkf_fs_type * target_fs) {
enkf_main_UPDATE( enkf_main , step_list , target_fs , 0 , SMOOTHER_UPDATE );
bool enkf_main_smoother_update(enkf_main_type * enkf_main , const int_vector_type * step_list , enkf_fs_type * target_fs) {
return enkf_main_UPDATE( enkf_main , step_list , target_fs , 0 , SMOOTHER_UPDATE );
}
@@ -1238,9 +1322,9 @@ static void enkf_main_report_load_failure( const enkf_main_type * enkf_main , in
*/
static bool enkf_main_run_step(enkf_main_type * enkf_main ,
static void enkf_main_run_step(enkf_main_type * enkf_main ,
run_mode_type run_mode ,
const bool_vector_type * iactive ,
bool_vector_type * iactive ,
int load_start , /* For internalizing results, and the first step in the update when merging. */
int init_step_parameter ,
state_enum init_state_parameter ,
@@ -1253,14 +1337,19 @@ static bool enkf_main_run_step(enkf_main_type * enkf_main ,
if (step1 > 0)
ecl_config_assert_restart( enkf_main_get_ecl_config( enkf_main ) );
{
enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
bool verbose_queue = enkf_main->verbose;
int max_internal_submit = model_config_get_max_internal_submit(enkf_main->model_config);
const int ens_size = enkf_main_get_ensemble_size( enkf_main );
int job_size;
int iens;
state_map_deselect_matching( enkf_fs_get_state_map( fs ) , iactive , STATE_LOAD_FAILURE | STATE_PARENT_FAILURE);
bool_vector_fprintf( iactive , stdout , "IACTIVE" , "%2d");
if (enkf_main->verbose) {
if (run_mode == ENKF_ASSIMILATION)
printf("Starting forward step: %d -> %d\n",step1 , step2);
@@ -1347,10 +1436,10 @@ static bool enkf_main_run_step(enkf_main_type * enkf_main ,
subset (with offset > 0) of realisations are simulated. */
if (run_mode != INIT_ONLY) {
bool totalOK = true;
for (iens = 0; iens < ens_size; iens++) {
for (iens = 0; iens < ens_size; iens++) {
if (bool_vector_iget(iactive , iens)) {
run_status_type run_status = enkf_state_get_simple_run_status( enkf_main->ensemble[iens] );
switch (run_status) {
case JOB_RUN_FAILURE:
enkf_main_report_run_failure( enkf_main , iens );
@@ -1373,9 +1462,7 @@ static bool enkf_main_run_step(enkf_main_type * enkf_main ,
if (run_mode != ENKF_ASSIMILATION)
qc_module_run_workflow( enkf_main->qc_module , enkf_main );
}
return totalOK;
} else
return true;
}
}
}
@@ -1439,18 +1526,21 @@ void enkf_main_init_run( enkf_main_type * enkf_main, run_mode_type run_mode) {
void enkf_main_run_exp(enkf_main_type * enkf_main ,
const bool_vector_type * iactive ,
bool_vector_type * iactive ,
bool simulate ,
int init_step_parameters ,
int start_report ,
state_enum start_state) {
state_enum start_state ,
bool initialize) {
bool force_init = false;
int ens_size = enkf_main_get_ensemble_size( enkf_main );
run_mode_type run_mode = simulate ? ENSEMBLE_EXPERIMENT : INIT_ONLY;
{
stringlist_type * param_list = ensemble_config_alloc_keylist_from_var_type( enkf_main->ensemble_config , PARAMETER );
enkf_main_initialize_from_scratch( enkf_main , param_list , 0 , ens_size - 1, force_init);
if(initialize)
enkf_main_initialize_from_scratch( enkf_main , param_list , 0 , ens_size - 1, force_init);
stringlist_free( param_list );
}
enkf_main_init_run( enkf_main , run_mode );
@@ -1465,7 +1555,7 @@ void enkf_main_run_exp(enkf_main_type * enkf_main ,
void enkf_main_run_assimilation(enkf_main_type * enkf_main ,
const bool_vector_type * iactive ,
bool_vector_type * iactive ,
int init_step_parameters ,
int start_report ,
state_enum start_state) {
@@ -1534,30 +1624,37 @@ void enkf_main_run_assimilation(enkf_main_type * enkf_main ,
if (load_start > 0)
load_start++;
enkf_main_run_step(enkf_main , ENKF_ASSIMILATION , iactive , load_start , init_step_parameter ,
init_state_parameter , init_state_dynamic , report_step1 , report_step2);
{
bool runOK = enkf_main_run_step(enkf_main , ENKF_ASSIMILATION , iactive , load_start , init_step_parameter ,
init_state_parameter , init_state_dynamic , report_step1 , report_step2);
enkf_fs_type * fs = enkf_main_get_fs(enkf_main);
state_map_type * state_map = enkf_fs_get_state_map(fs);
const analysis_config_type * analysis_config = enkf_main_get_analysis_config(enkf_main);
int active_ens_size = state_map_count_matching(state_map , STATE_HAS_DATA);
if (runOK) {
if (analysis_config_have_enough_realisations(analysis_config , active_ens_size)) {
if (enkf_on) {
bool merge_observations = analysis_config_get_merge_observations( enkf_main->analysis_config );
int_vector_type * step_list;
int stride;
if (merge_observations)
stride = 1;
else
stride = 0;
step_list = enkf_main_update_alloc_step_list( enkf_main , load_start , report_step2 , stride );
enkf_main_assimilation_update(enkf_main , step_list);
int_vector_free( step_list );
enkf_fs_fsync( enkf_main->dbase );
}
} else
util_exit("Problems with the forward model - exiting.\n");
} else {
fprintf(stderr,"** ERROR ** There are %d active realisations left, which is less than the minimum specified (%d) - stopping assimilation.\n" ,
active_ens_size ,
analysis_config_get_min_realisations(analysis_config));
break;
}
prev_enkf_on = enkf_on;
}
}
@@ -1578,17 +1675,18 @@ void enkf_main_run_smoother(enkf_main_type * enkf_main , const char * target_fs_
bool_vector_type * iactive = bool_vector_alloc( 0 , true );
bool_vector_iset( iactive , ens_size - 1 , true );
enkf_main_init_run( enkf_main , ENSEMBLE_EXPERIMENT );
if (enkf_main_run_step(enkf_main , ENSEMBLE_EXPERIMENT , iactive , 0 , 0 , ANALYZED , UNDEFINED , 0 , 0)) {
enkf_main_init_run( enkf_main , ENSEMBLE_EXPERIMENT);
enkf_main_run_step(enkf_main , ENSEMBLE_EXPERIMENT , iactive , 0 , 0 , ANALYZED , UNDEFINED , 0 , 0);
{
bool update_done;
time_map_type * time_map = enkf_fs_get_time_map( enkf_main_get_fs( enkf_main ));
enkf_fs_type * target_fs = enkf_main_get_alt_fs( enkf_main , target_fs_name , false , true );
{
int stride = 1;
int_vector_type * step_list = enkf_main_update_alloc_step_list( enkf_main , 0 , time_map_get_last_step( time_map ) , stride);
enkf_main_smoother_update( enkf_main , step_list , target_fs );
update_done = enkf_main_smoother_update( enkf_main , step_list , target_fs );
int_vector_free( step_list );
}
enkf_main_set_fs( enkf_main , target_fs , target_fs_name);
if (rerun) {
/*
@@ -1602,8 +1700,12 @@ void enkf_main_run_smoother(enkf_main_type * enkf_main , const char * target_fs_
active runpath for the remaining part of this program
invocation.
*/
model_config_select_runpath( enkf_main_get_model_config( enkf_main ) , RERUN_PATH_KEY );
enkf_main_run_step(enkf_main , ENSEMBLE_EXPERIMENT , iactive , 0 , 0 , ANALYZED , UNDEFINED , 0 , 0 );
if (update_done) {
enkf_main_set_fs( enkf_main , target_fs , target_fs_name);
model_config_select_runpath( enkf_main_get_model_config( enkf_main ) , RERUN_PATH_KEY );
enkf_main_run_step(enkf_main , ENSEMBLE_EXPERIMENT , iactive , 0 , 0 , ANALYZED , UNDEFINED , 0 , 0 );
} else
fprintf(stderr,"** Warning: the analysis update failed - no rerun started.\n");
}
}
@@ -1611,6 +1713,87 @@ void enkf_main_run_smoother(enkf_main_type * enkf_main , const char * target_fs_
}
}
void enkf_main_iterate_smoother(enkf_main_type * enkf_main, int step2, int iteration_number, analysis_iter_config_type * iter_config, int_vector_type * step_list, bool_vector_type * iactive, model_config_type * model_config){
const char * target_fs_name = analysis_iter_config_iget_case( iter_config , iteration_number+1 );
const int ens_size = enkf_main_get_ensemble_size( enkf_main );
const int step1 = 0;
if (target_fs_name == NULL){
fprintf(stderr,"Sorry: the updated ensemble will overwrite the current case in the iterated ensemble smoother.");
enkf_main_smoother_update(enkf_main , step_list , enkf_main_get_fs(enkf_main));
}
else{
enkf_fs_type * target_fs = enkf_main_get_alt_fs(enkf_main , target_fs_name , false , true );
enkf_main_smoother_update(enkf_main , step_list , target_fs );
enkf_main_set_fs(enkf_main , target_fs , enkf_fs_get_case_name( target_fs ));
cases_config_set_int(enkf_fs_get_cases_config(target_fs), "iteration_number", iteration_number+1);
}
bool_vector_iset( iactive , ens_size - 1 , true );
const char * runpath_fmt = analysis_iter_config_iget_runpath_fmt( iter_config , iteration_number);
if (runpath_fmt != NULL) {
char * runpath_key = util_alloc_sprintf( "runpath-%d" , 999);
model_config_add_runpath( model_config , runpath_key , runpath_fmt);
model_config_select_runpath( model_config , runpath_key );
free( runpath_key );
}
enkf_main_run_exp(enkf_main , iactive , true , step1 , step1 , FORECAST, false);
}
void enkf_main_run_iterated_ES(enkf_main_type * enkf_main, int step2) {
{
const int ens_size = enkf_main_get_ensemble_size( enkf_main );
model_config_type * model_config = enkf_main_get_model_config( enkf_main );
const analysis_config_type * analysis_config = enkf_main_get_analysis_config( enkf_main );
analysis_iter_config_type * iter_config = analysis_config_get_iter_config( analysis_config );
const int step1 = 0;
int_vector_type * step_list = int_vector_alloc(0,0);
bool_vector_type * iactive = bool_vector_alloc(0 , true);
int iter = 0;
int num_iter = analysis_iter_config_get_num_iterations( iter_config );
{
for (int step=step1; step <= step2; step++)
int_vector_append( step_list , step );
}
bool_vector_iset( iactive , ens_size - 1 , true );
const char * runpath_fmt = analysis_iter_config_iget_runpath_fmt( iter_config , iter);
if (runpath_fmt != NULL) {
char * runpath_key = util_alloc_sprintf( "runpath-%d" , iter);
model_config_add_runpath( model_config , runpath_key , runpath_fmt);
model_config_select_runpath( model_config , runpath_key );
free( runpath_key );
}
enkf_main_run_exp(enkf_main , iactive , true , step1 , step1 , FORECAST, true);
while (true) {
if (iter == num_iter)
break;
enkf_main_iterate_smoother(enkf_main, step2, iter, iter_config, step_list, iactive, model_config);
iter++;
}
int_vector_free( step_list );
bool_vector_free( iactive );
}
}
void enkf_main_run_one_more_iteration(enkf_main_type * enkf_main, int step2) {
model_config_type * model_config = enkf_main_get_model_config( enkf_main );
const analysis_config_type * analysis_config = enkf_main_get_analysis_config( enkf_main );
analysis_iter_config_type * iter_config = analysis_config_get_iter_config( analysis_config );
enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
cases_config_type * case_config = enkf_fs_get_cases_config( fs );
int iteration_number = cases_config_get_iteration_number( case_config );
const int step1 = 0;
int_vector_type * step_list = int_vector_alloc(0,0);
bool_vector_type * iactive = bool_vector_alloc(0 , true);
{
for (int step=step1; step <= step2; step++)
int_vector_append( step_list , step );
}
enkf_main_iterate_smoother(enkf_main, step2, iteration_number, iter_config, step_list, iactive, model_config);
}
/*****************************************************************/
/* Filesystem copy functions */
@@ -1702,9 +1885,15 @@ void enkf_main_initialize_from_existing__(enkf_main_type * enkf_main ,
const char * target_case = NULL;
enkf_main_copy_ensemble(enkf_main ,
source_case , source_report_step , source_state ,
target_case , target_report_step , target_state ,
iens_mask , ranking_key , node_list);
source_case ,
source_report_step ,
source_state ,
target_case ,
target_report_step ,
target_state ,
iens_mask ,
ranking_key ,
node_list);
}
@@ -2131,7 +2320,7 @@ enkf_main_type * enkf_main_alloc_empty( ) {
enkf_main->plot_config = plot_config_alloc_default();
enkf_main->ranking_table = ranking_table_alloc( 0 );
enkf_main->obs = enkf_obs_alloc( );
enkf_main->model_config = model_config_alloc_empty( );
enkf_main->model_config = model_config_alloc( );
enkf_main_rng_init( enkf_main );
enkf_main->subst_func_pool = subst_func_pool_alloc( );
@@ -2139,7 +2328,7 @@ enkf_main_type * enkf_main_alloc_empty( ) {
enkf_main->templates = ert_templates_alloc( enkf_main->subst_list );
enkf_main->workflow_list = ert_workflow_list_alloc( enkf_main->subst_list );
enkf_main->qc_module = qc_module_alloc( enkf_main->workflow_list , DEFAULT_QC_PATH );
enkf_main->analysis_config = analysis_config_alloc_default( enkf_main->rng );
enkf_main->analysis_config = analysis_config_alloc( enkf_main->rng );
enkf_main->report_list = ert_report_list_alloc( DEFAULT_REPORT_PATH , plot_config_get_path( enkf_main->plot_config ) );
enkf_main_init_subst_list( enkf_main );

View File

@@ -48,7 +48,7 @@ void * enkf_main_ensemble_run_JOB( void * self , const stringlist_type * args )
// if (stringlist_get_size( args )
bool_vector_iset( iactive , ens_size - 1 , true );
enkf_main_run_exp( enkf_main , iactive , true , 0 , 0 , ANALYZED );
enkf_main_run_exp( enkf_main , iactive , true , 0 , 0 , ANALYZED , true);
return NULL;
}

View File

@@ -261,19 +261,19 @@ obs_vector_type * enkf_obs_get_vector(const enkf_obs_type * obs, const char * ke
void enkf_obs_get_obs_and_measure_summary(const enkf_obs_type * enkf_obs,
obs_vector_type * obs_vector ,
enkf_fs_type * fs,
const int_vector_type * step_list ,
state_enum state,
int ens_size,
const enkf_state_type ** ensemble ,
meas_data_type * meas_data,
obs_data_type * obs_data,
const local_obsset_type * obsset ,
double_vector_type * obs_value ,
double_vector_type * obs_std) {
static void enkf_obs_get_obs_and_measure_summary(const enkf_obs_type * enkf_obs,
obs_vector_type * obs_vector ,
enkf_fs_type * fs,
const int_vector_type * step_list ,
state_enum state,
const int_vector_type * ens_active_list ,
const enkf_state_type ** ensemble ,
meas_data_type * meas_data,
obs_data_type * obs_data,
const local_obsset_type * obsset ,
double_vector_type * obs_value ,
double_vector_type * obs_std) {
const active_list_type * active_list = local_obsset_get_obs_active_list( obsset , obs_vector_get_obs_key( obs_vector ));
matrix_type * error_covar = NULL;
int active_count = 0;
@@ -353,16 +353,20 @@ void enkf_obs_get_obs_and_measure_summary(const enkf_obs_type * enkf_obs,
int step = int_vector_iget( step_list , i );
if (obs_vector_iget_active( obs_vector , step ) && active_list_iget( active_list , 0 /* Index into the scalar summary observation */)) {
int iens;
for (iens = 0; iens < ens_size; iens++) {
for (int iens_index = 0; iens_index < int_vector_size( ens_active_list ); iens_index++) {
const int iens = int_vector_iget( ens_active_list , iens_index );
const char * state_key = obs_vector_get_state_kw(obs_vector);
enkf_node_type * enkf_node = enkf_state_get_node(ensemble[iens] , state_key);
node_id_type node_id = {.report_step = step,
.iens = iens,
.iens = iens ,
.state = state };
enkf_node_load( enkf_node , fs , node_id );
meas_block_iset(meas_block , iens , active_count , summary_get( enkf_node_value_ptr( enkf_node ) , node_id.report_step , node_id.state ));
meas_block_iset(meas_block ,
iens_index , active_count ,
summary_get( enkf_node_value_ptr( enkf_node ) , node_id.report_step , node_id.state ));
}
active_count++;
}
@@ -385,7 +389,7 @@ void enkf_obs_get_obs_and_measure(const enkf_obs_type * enkf_obs,
enkf_fs_type * fs,
const int_vector_type * step_list ,
state_enum state,
int ens_size,
const int_vector_type * ens_active_list ,
const enkf_state_type ** ensemble ,
meas_data_type * meas_data,
obs_data_type * obs_data,
@@ -406,7 +410,7 @@ void enkf_obs_get_obs_and_measure(const enkf_obs_type * enkf_obs,
fs ,
step_list ,
state ,
ens_size ,
ens_active_list ,
ensemble ,
meas_data ,
obs_data ,
@@ -420,14 +424,10 @@ void enkf_obs_get_obs_and_measure(const enkf_obs_type * enkf_obs,
if (obs_vector_iget_active(obs_vector , report_step)) { /* The observation is active for this report step. */
const active_list_type * active_list = local_obsset_get_obs_active_list( obsset , obs_key );
obs_vector_iget_observations(obs_vector , report_step , obs_data , active_list); /* Collect the observed data in the obs_data instance. */
{
/* Could be multithreaded */
int iens;
for (iens = 0; iens < ens_size; iens++) {
obs_vector_measure(obs_vector , fs , state , report_step , ensemble[iens] , meas_data , active_list);
}
/* Could be multithreaded */
for (int iens_index = 0; iens_index < int_vector_size( ens_active_list ); iens_index++) {
const int iens = int_vector_iget( ens_active_list , iens_index );
obs_vector_measure(obs_vector , fs , state , report_step , iens_index , ensemble[iens] , meas_data , active_list);
}
}
}

View File

@@ -70,6 +70,7 @@
#include <ert/enkf/ert_template.h>
#include <ert/enkf/member_config.h>
#include <ert/enkf/enkf_defaults.h>
#include <ert/enkf/state_map.h>
#define ENKF_STATE_TYPE_ID 78132
@@ -280,16 +281,29 @@ static void shared_info_free(shared_info_type * shared_info) {
/*****************************************************************/
void enkf_state_initialize(enkf_state_type * enkf_state , enkf_fs_type * fs , const stringlist_type * param_list, bool force_init) {
state_enum init_state = ANALYZED;
int ip;
for (ip = 0; ip < stringlist_get_size(param_list); ip++) {
int iens = enkf_state_get_iens( enkf_state );
enkf_node_type * param_node = enkf_state_get_node( enkf_state , stringlist_iget( param_list , ip));
node_id_type node_id = {.report_step = 0, .iens = iens , .state = init_state };
if (force_init || (enkf_node_has_data( param_node , fs , node_id) == false)) {
if (enkf_node_initialize( param_node , iens , enkf_state->rng))
enkf_node_store( param_node , fs , true , node_id);
int iens = enkf_state_get_iens( enkf_state );
state_map_type * state_map = enkf_fs_get_state_map( fs );
realisation_state_enum current_state = state_map_iget(state_map, iens);
if ((current_state == STATE_PARENT_FAILURE) && (force_init == false))
return;
else {
state_enum init_state = ANALYZED;
for (int ip = 0; ip < stringlist_get_size(param_list); ip++)
{
enkf_node_type * param_node = enkf_state_get_node(enkf_state, stringlist_iget(param_list, ip));
node_id_type node_id = { .report_step = 0, .iens = iens, .state = init_state };
bool has_data = enkf_node_has_data(param_node, fs, node_id);
if (force_init || (has_data == false) || (current_state == STATE_LOAD_FAILURE))
{
if (enkf_node_initialize(param_node, iens, enkf_state->rng)) {
enkf_node_store(param_node, fs, true, node_id);
state_map_iset(state_map , iens , STATE_INITIALIZED);
}
}
}
enkf_fs_fsync(fs);
}
}
@@ -588,7 +602,7 @@ const char * enkf_state_get_eclbase( const enkf_state_type * enkf_state ) {
}
static ecl_sum_type * enkf_state_load_ecl_sum(const enkf_state_type * enkf_state , stringlist_type * messages , bool * loadOK) {
static ecl_sum_type * enkf_state_load_ecl_sum(const enkf_state_type * enkf_state , stringlist_type * messages , int * result) {
const run_info_type * run_info = enkf_state->run_info;
const ecl_config_type * ecl_config = enkf_state->shared_info->ecl_config;
const bool fmt_file = ecl_config_get_formatted(ecl_config);
@@ -650,7 +664,7 @@ static ecl_sum_type * enkf_state_load_ecl_sum(const enkf_state_type * enkf_state
}
ecl_sum_free( summary );
summary = NULL;
*loadOK = false;
*result |= LOAD_FAILURE;
}
}
}
@@ -674,8 +688,21 @@ static void enkf_state_log_GEN_DATA_load( const enkf_node_type * enkf_node , int
}
static bool enkf_state_report_step_compatible(const enkf_state_type * enkf_state, const ecl_sum_type * ecl_sum_simulated) {
bool ret = true;
static bool enkf_state_internalize_dynamic_eclipse_results(enkf_state_type * enkf_state , enkf_fs_type * fs , const model_config_type * model_config , bool * loadOK, bool interactive , stringlist_type * msg_list) {
const model_config_type * model_config = enkf_state->shared_info->model_config;
const ecl_sum_type * ecl_sum_reference = model_config_get_refcase(model_config);
if (ecl_sum_reference) //Can be NULL
ret = ecl_sum_report_step_compatible(ecl_sum_reference, ecl_sum_simulated);
return ret;
}
static bool enkf_state_internalize_dynamic_eclipse_results(enkf_state_type * enkf_state , enkf_fs_type * fs , const model_config_type * model_config , int * result, bool interactive , stringlist_type * msg_list) {
const run_info_type * run_info = enkf_state->run_info;
int load_start = run_info->load_start;
@@ -684,10 +711,16 @@ static bool enkf_state_internalize_dynamic_eclipse_results(enkf_state_type * enk
{
/* Looking for summary files on disk, and loading them. */
ecl_sum_type * summary = enkf_state_load_ecl_sum( enkf_state , msg_list , loadOK );
ecl_sum_type * summary = enkf_state_load_ecl_sum( enkf_state , msg_list , result );
/** OK - now we have actually loaded the ecl_sum instance, or ecl_sum == NULL. */
if (summary != NULL) {
/*Check the loaded summary against the reference ecl_sum_type */
if (!enkf_state_report_step_compatible(enkf_state, summary))
*result |= REPORT_STEP_INCOMPATIBLE;
/* The actual loading internalizing - from ecl_sum -> enkf_node. */
const shared_info_type * shared_info = enkf_state->shared_info;
const int iens = member_config_get_iens( enkf_state->my_config );
@@ -708,7 +741,7 @@ static bool enkf_state_internalize_dynamic_eclipse_results(enkf_state_type * enk
if (interactive && enkf_node_get_impl_type(node) == GEN_DATA)
enkf_state_log_GEN_DATA_load( node , 0 , msg_list );
} else {
*loadOK = false;
*result |= LOAD_FAILURE;
log_add_fmt_message(shared_info->logh , 3 , NULL , "[%03d:----] Failed to load data for vector node:%s.",iens , enkf_node_get_key( node ));
if (interactive)
stringlist_append_owned_ref( msg_list , util_alloc_sprintf("Failed to load vector:%s" , enkf_node_get_key( node )));
@@ -723,7 +756,7 @@ static bool enkf_state_internalize_dynamic_eclipse_results(enkf_state_type * enk
if (interactive && enkf_node_get_impl_type(node) == GEN_DATA)
enkf_state_log_GEN_DATA_load( node , report_step , msg_list );
} else {
*loadOK = false;
*result |= LOAD_FAILURE;
log_add_fmt_message(shared_info->logh , 3 , NULL , "[%03d:%04d] Failed to load data for node:%s.",iens , report_step , enkf_node_get_key( node ));
if (interactive)
stringlist_append_owned_ref( msg_list , util_alloc_sprintf("Failed to load node:%s at step:%d" , enkf_node_get_key( node ) , report_step));
@@ -747,11 +780,11 @@ static bool enkf_state_internalize_dynamic_eclipse_results(enkf_state_type * enk
}
static bool enkf_state_internalize_dynamic_results(enkf_state_type * enkf_state , enkf_fs_type * fs , const model_config_type * model_config , bool * loadOK, bool interactive , stringlist_type * msg_list) {
static bool enkf_state_internalize_dynamic_results(enkf_state_type * enkf_state , enkf_fs_type * fs , const model_config_type * model_config , int * result, bool interactive , stringlist_type * msg_list) {
const ecl_config_type * ecl_config = enkf_state->shared_info->ecl_config;
if (ecl_config_active( ecl_config )) {
bool eclipse_load = enkf_state_internalize_dynamic_eclipse_results( enkf_state , fs , model_config , loadOK, interactive , msg_list);
bool eclipse_load = enkf_state_internalize_dynamic_eclipse_results( enkf_state , fs , model_config , result, interactive , msg_list);
if (!eclipse_load)
fprintf(stderr , "** Warning: could not load ECLIPSE summary data from %s - this will probably fail later ...\n" , enkf_state->run_info->run_path);
return eclipse_load;
@@ -795,7 +828,7 @@ static char * __realloc_static_kw(char * kw , int occurence) {
When the state has been loaded it goes straight to disk.
*/
static void enkf_state_internalize_eclipse_state(enkf_state_type * enkf_state , enkf_fs_type * fs , const model_config_type * model_config , int report_step , bool store_vectors , bool * loadOK , bool interactive , stringlist_type * msg_list) {
static void enkf_state_internalize_eclipse_state(enkf_state_type * enkf_state , enkf_fs_type * fs , const model_config_type * model_config , int report_step , bool store_vectors , int * result, bool interactive , stringlist_type * msg_list) {
member_config_type * my_config = enkf_state->my_config;
shared_info_type * shared_info = enkf_state->shared_info;
run_info_type * run_info = enkf_state->run_info;
@@ -964,7 +997,7 @@ static void enkf_state_internalize_eclipse_state(enkf_state_type * enkf_state ,
} else {
if (enkf_node_get_impl_type(enkf_node) != GEN_DATA) {
*loadOK = false;
*result |= LOAD_FAILURE;
log_add_fmt_message(shared_info->logh , 1 , NULL , "[%03d:%04d] Failed load data for node:%s.",iens , report_step , enkf_node_get_key( enkf_node ));
if (interactive)
@@ -989,14 +1022,14 @@ static void enkf_state_internalize_state(enkf_state_type * enkf_state ,
const model_config_type * model_config ,
int report_step ,
bool store_vectors ,
bool * loadOK ,
int * result ,
bool interactive ,
stringlist_type * msg_list) {
const ecl_config_type * ecl_config = enkf_state->shared_info->ecl_config;
if (ecl_config_active( ecl_config ))
enkf_state_internalize_eclipse_state( enkf_state , fs , model_config , report_step , store_vectors , loadOK , interactive , msg_list);
enkf_state_internalize_eclipse_state( enkf_state , fs , model_config , report_step , store_vectors , result , interactive , msg_list);
}
@@ -1011,7 +1044,7 @@ static void enkf_state_internalize_state(enkf_state_type * enkf_state ,
*/
static void enkf_state_internalize_results(enkf_state_type * enkf_state , enkf_fs_type * fs , bool * loadOK , bool interactive , stringlist_type * msg_list) {
static void enkf_state_internalize_results(enkf_state_type * enkf_state , enkf_fs_type * fs ,int * result , bool interactive , stringlist_type * msg_list) {
run_info_type * run_info = enkf_state->run_info;
model_config_type * model_config = enkf_state->shared_info->model_config;
int report_step;
@@ -1022,7 +1055,7 @@ static void enkf_state_internalize_results(enkf_state_type * enkf_state , enkf_f
hence we must load the summary results first.
*/
if (enkf_state_internalize_dynamic_results(enkf_state , fs , model_config , loadOK, interactive , msg_list)) {
if (enkf_state_internalize_dynamic_results(enkf_state , fs , model_config , result, interactive , msg_list)) {
int last_report = time_map_get_last_step( enkf_fs_get_time_map( fs ));
/*
@@ -1038,7 +1071,7 @@ static void enkf_state_internalize_results(enkf_state_type * enkf_state , enkf_f
bool store_vectors = (report_step == last_report) ? true : false;
if (model_config_load_state( model_config , report_step))
enkf_state_internalize_state(enkf_state , fs , model_config , report_step , store_vectors , loadOK , interactive , msg_list);
enkf_state_internalize_state(enkf_state , fs , model_config , report_step , store_vectors , result , interactive , msg_list);
}
}
}
@@ -1046,7 +1079,7 @@ static void enkf_state_internalize_results(enkf_state_type * enkf_state , enkf_f
void enkf_state_forward_init(enkf_state_type * enkf_state ,
enkf_fs_type * fs ,
bool * loadOK ) {
int * result ) {
run_info_type * run_info = enkf_state->run_info;
if (run_info->step1 == 0) {
@@ -1068,7 +1101,7 @@ void enkf_state_forward_init(enkf_state_type * enkf_state ,
if (enkf_node_forward_init(node , run_info->run_path , iens ))
enkf_node_store( node , fs, false , node_id );
else
*loadOK = false;
*result |= LOAD_FAILURE;
}
}
@@ -1082,14 +1115,22 @@ void enkf_state_forward_init(enkf_state_type * enkf_state ,
void enkf_state_load_from_forward_model(enkf_state_type * enkf_state ,
enkf_fs_type * fs ,
bool * loadOK ,
int * result,
bool interactive ,
stringlist_type * msg_list) {
if (ensemble_config_have_forward_init( enkf_state->ensemble_config ))
enkf_state_forward_init( enkf_state , fs , loadOK );
enkf_state_forward_init( enkf_state , fs , result );
enkf_state_internalize_results( enkf_state , fs , loadOK , interactive , msg_list );
enkf_state_internalize_results( enkf_state , fs , result , interactive , msg_list );
{
state_map_type * state_map = enkf_fs_get_state_map( fs );
int iens = member_config_get_iens( enkf_state->my_config );
if (*result & LOAD_FAILURE)
state_map_iset( state_map , iens , STATE_LOAD_FAILURE);
else
state_map_iset( state_map , iens , STATE_HAS_DATA);
}
}
@@ -1107,23 +1148,28 @@ void * enkf_state_load_from_forward_model_mt( void * arg ) {
int step2 = arg_pack_iget_int( arg_pack , 4 );
bool interactive = arg_pack_iget_bool( arg_pack , 5 );
stringlist_type * msg_list = arg_pack_iget_ptr( arg_pack , 6 );
bool loadOK = true;
int iens = member_config_get_iens( enkf_state->my_config );
int result = 0;
run_info_init_for_load( enkf_state->run_info ,
load_start ,
step1 ,
step2 ,
member_config_get_iens( enkf_state->my_config ) ,
iens ,
model_config_get_runpath_fmt( enkf_state->shared_info->model_config ) ,
enkf_state->subst_list );
enkf_state_load_from_forward_model( enkf_state , fs , &loadOK , interactive , msg_list );
enkf_state_load_from_forward_model( enkf_state , fs , &result , interactive , msg_list );
if (result & REPORT_STEP_INCOMPATIBLE) {
// If refcase has been used for observations: crash and burn.
fprintf(stderr,"** Warning the timesteps in refcase and current simulation are not in accordance - something wrong with schedule file?\n");
result -= REPORT_STEP_INCOMPATIBLE;
}
if (interactive) {
printf(".");
fflush(stdout);
}
return NULL;
}
@@ -1305,7 +1351,7 @@ void enkf_state_fread(enkf_state_type * enkf_state , enkf_fs_type * fs , int mas
if (enkf_node_include_type(enkf_node , mask)) {
node_id_type node_id = {.report_step = report_step ,
.iens = member_config_get_iens( my_config ) ,
state = state };
.state = state };
bool forward_init = enkf_node_use_forward_init( enkf_node );
if (forward_init)
enkf_node_try_load(enkf_node , fs , node_id );
@@ -1940,7 +1986,7 @@ static bool enkf_state_complete_forward_modelOK(enkf_state_type * enkf_state , e
run_info_type * run_info = enkf_state->run_info;
const member_config_type * my_config = enkf_state->my_config;
const int iens = member_config_get_iens( my_config );
bool loadOK = true;
int result = 0;
/**
@@ -1950,8 +1996,16 @@ static bool enkf_state_complete_forward_modelOK(enkf_state_type * enkf_state , e
is OK the final status is updated, otherwise: restart.
*/
log_add_fmt_message( shared_info->logh , 2 , NULL , "[%03d:%04d-%04d] Forward model complete - starting to load results." , iens , run_info->step1, run_info->step2);
enkf_state_load_from_forward_model(enkf_state , fs , &loadOK , false , NULL);
if (loadOK) {
enkf_state_load_from_forward_model(enkf_state , fs , &result , false , NULL);
if (result & REPORT_STEP_INCOMPATIBLE) {
// If refcase has been used for observations: crash and burn.
fprintf(stderr,"** Warning the timesteps in refcase and current simulation are not in accordance - something wrong with schedule file?\n");
result -= REPORT_STEP_INCOMPATIBLE;
}
if (0 == result) {
/*
The loading succeded - so this is a howling success! We set
the main status to JOB_QUEUE_ALL_OK and inform the queue layer
@@ -1965,7 +2019,7 @@ static bool enkf_state_complete_forward_modelOK(enkf_state_type * enkf_state , e
run_info->__ready = false; /* Setting it to false - for the next round ??? */
run_info_complete_run(enkf_state->run_info); /* free() on runpath */
}
return loadOK;
return (0 == result) ? true : false;
}
@@ -1992,7 +2046,11 @@ static bool enkf_state_complete_forward_modelEXIT(enkf_state_type * enkf_state ,
log_add_fmt_message( shared_info->logh , 1 , NULL , "[%03d:%04d-%04d] FAILED COMPLETELY." , iens , run_info->step1, run_info->step2);
if (run_info->run_status != JOB_LOAD_FAILURE)
run_info->run_status = JOB_RUN_FAILURE;
{
state_map_type * state_map = enkf_fs_get_state_map( fs );
int iens = member_config_get_iens( enkf_state->my_config );
state_map_iset( state_map , iens , STATE_LOAD_FAILURE );
}
return false;
}
}

View File

@@ -26,18 +26,22 @@
#include <string.h>
#include <pthread.h>
#include <ert/util/type_macros.h>
#include <ert/util/util.h>
#include <ert/util/hash.h>
#include <ert/util/matrix.h>
#include <ert/util/set.h>
#include <ert/util/vector.h>
#include <ert/util/int_vector.h>
#include <ert/enkf/meas_data.h>
#define MEAS_BLOCK_TYPE_ID 661936407
#define MEAS_DATA_TYPE_ID 561000861
struct meas_data_struct {
UTIL_TYPE_ID_DECLARATION;
int ens_size;
vector_type * data;
pthread_mutex_t data_mutex;
@@ -146,15 +150,6 @@ static void meas_data_assign_block( meas_block_type * target_block , const meas_
}
}
static void meas_block_memcpy( meas_block_type * target_block , const meas_block_type * src_block) {
if (target_block->data_size != src_block->data_size)
util_abort("%s: size mismatch. target:%d src:%d \n",__func__ , target_block->data_size , src_block->data_size );
memcpy( target_block->data , src_block->data , src_block->data_size * sizeof * src_block->data );
memcpy( target_block->active , src_block->active , src_block->obs_size * sizeof * src_block->active );
}
void meas_block_calculate_ens_stats( meas_block_type * meas_block ) {
bool include_inactive = true;
@@ -222,18 +217,23 @@ int meas_block_get_total_size( const meas_block_type * meas_block ) {
/*****************************************************************/
UTIL_IS_INSTANCE_FUNCTION( meas_data , MEAS_DATA_TYPE_ID )
meas_data_type * meas_data_alloc(int ens_size) {
meas_data_type * meas = util_malloc(sizeof * meas );
meas_data_type * meas_data_alloc( const int_vector_type * ens_active_list ) {
int ens_size = int_vector_size( ens_active_list );
if (ens_size <= 0)
util_abort("%s: ens_size must be > 0 - aborting \n",__func__);
meas->ens_size = ens_size;
meas->data = vector_alloc_new();
meas->lookup_keys = set_alloc_empty();
pthread_mutex_init( &meas->data_mutex , NULL );
return meas;
{
meas_data_type * meas = util_malloc(sizeof * meas );
UTIL_TYPE_ID_INIT( meas , MEAS_DATA_TYPE_ID );
meas->ens_size = ens_size;
meas->data = vector_alloc_new();
meas->lookup_keys = set_alloc_empty();
pthread_mutex_init( &meas->data_mutex , NULL );
return meas;
}
}
@@ -324,21 +324,6 @@ void meas_data_assign_vector(meas_data_type * target_matrix, const meas_data_typ
}
meas_data_type * meas_data_alloc_copy( const meas_data_type * src_matrix ) {
meas_data_type * copy_matrix = meas_data_alloc( src_matrix->ens_size );
for (int block_nr = 0; block_nr < vector_get_size( src_matrix->data ); block_nr++) {
const meas_block_type * src_block = meas_data_iget_block_const( src_matrix , block_nr );
meas_data_add_block( copy_matrix , src_block->obs_key , src_block->report_step , src_block->obs_size );
{
meas_block_type * copy_block = meas_data_iget_block( copy_matrix , block_nr );
meas_block_memcpy( copy_block , src_block );
}
}
return copy_matrix;
}
void meas_data_fprintf( const meas_data_type * matrix , FILE * stream ) {

View File

@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <ert/util/type_macros.h>
#include <ert/util/util.h>
#include <ert/util/path_fmt.h>
#include <ert/util/hash.h>
@@ -73,12 +74,15 @@
only options visible to the user.
*/
#define MODEL_CONFIG_TYPE_ID 661053
struct model_config_struct {
UTIL_TYPE_ID_DECLARATION;
stringlist_type * case_names; /* A list of "iens -> name" mappings - can be NULL. */
char * case_table_file;
forward_model_type * forward_model; /* The forward_model - as loaded from the config file. Each enkf_state object internalizes its private copy of the forward_model. */
history_type * history; /* The history object. */
path_fmt_type * current_runpath; /* path_fmt instance for runpath - runtime the call gets arguments: (iens, report_step1 , report_step2) - i.e. at least one %d must be present.*/
char * current_path_key;
hash_type * runpath_map;
char * jobname_fmt; /* Format string with one '%d' for the jobname - can be NULL in which case the eclbase name will be used. */
enkf_sched_type * enkf_sched; /* The enkf_sched object controlling when the enkf is ON|OFF, strides in report steps and special forward model - allocated on demand - right before use. */
@@ -170,6 +174,7 @@ void model_config_add_runpath( model_config_type * model_config , const char * p
bool model_config_select_runpath( model_config_type * model_config , const char * path_key) {
if (hash_has_key( model_config->runpath_map , path_key )) {
model_config->current_runpath = hash_get( model_config->runpath_map , path_key );
model_config->current_path_key = util_realloc_string_copy( model_config->current_path_key , path_key);
return true;
} else {
if (model_config->current_runpath != NULL) // OK - we already have a valid selection - stick to that and return False.
@@ -182,6 +187,16 @@ bool model_config_select_runpath( model_config_type * model_config , const char
}
void model_config_set_runpath(model_config_type * model_config , const char * fmt) {
if (model_config->current_path_key) {
model_config_add_runpath(model_config , model_config->current_path_key , fmt);
model_config_select_runpath( model_config , model_config->current_path_key );
} else
util_abort("%s: current path has not been set \n",__func__);
}
/**
This function is not called at bootstrap time, but rather as part
of an initialization just before the run. Can be called maaaanye
@@ -241,6 +256,9 @@ fs_driver_impl model_config_get_dbase_type(const model_config_type * model_confi
return model_config->dbase_type;
}
const ecl_sum_type * model_config_get_refcase( const model_config_type * model_config ) {
return model_config->refcase;
}
void * model_config_get_dbase_args( const model_config_type * model_config ) {
return NULL;
@@ -291,8 +309,9 @@ void model_config_set_max_internal_submit( model_config_type * model_config , in
}
UTIL_IS_INSTANCE_FUNCTION( model_config , MODEL_CONFIG_TYPE_ID)
model_config_type * model_config_alloc_empty() {
model_config_type * model_config_alloc() {
model_config_type * model_config = util_malloc(sizeof * model_config );
/**
There are essentially three levels of initialisation:
@@ -302,11 +321,13 @@ model_config_type * model_config_alloc_empty() {
3. Initialize with user supplied values.
*/
UTIL_TYPE_ID_INIT(model_config , MODEL_CONFIG_TYPE_ID);
model_config->case_names = NULL;
model_config->enspath = NULL;
model_config->rftpath = NULL;
model_config->dbase_type = INVALID_DRIVER_ID;
model_config->current_runpath = NULL;
model_config->current_path_key = NULL;
model_config->enkf_sched = NULL;
model_config->enkf_sched_file = NULL;
model_config->case_table_file = NULL;
@@ -476,6 +497,7 @@ void model_config_free(model_config_type * model_config) {
util_safe_free( model_config->enkf_sched_file );
util_safe_free( model_config->select_case );
util_safe_free( model_config->case_table_file );
util_safe_free( model_config->current_path_key);
if (model_config->history != NULL)
history_free(model_config->history);

View File

@@ -756,7 +756,14 @@ void obs_vector_iget_observations(const obs_vector_type * obs_vector , int repor
}
void obs_vector_measure(const obs_vector_type * obs_vector , enkf_fs_type * fs , state_enum state , int report_step , const enkf_state_type * enkf_state , meas_data_type * meas_data , const active_list_type * active_list) {
void obs_vector_measure(const obs_vector_type * obs_vector ,
enkf_fs_type * fs ,
state_enum state ,
int report_step ,
int active_iens_index ,
const enkf_state_type * enkf_state ,
meas_data_type * meas_data ,
const active_list_type * active_list) {
void * obs_node = vector_iget( obs_vector->nodes , report_step );
if ( obs_node != NULL ) {
@@ -766,6 +773,7 @@ void obs_vector_measure(const obs_vector_type * obs_vector , enkf_fs_type * fs ,
.iens = enkf_state_get_iens( enkf_state ) };
enkf_node_load(enkf_node , fs , node_id);
node_id.iens = active_iens_index;
obs_vector->measure(obs_node , enkf_node_value_ptr(enkf_node) , node_id , meas_data , active_list);
}
}

View File

@@ -0,0 +1,245 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'state_map.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.
*/
#define _GNU_SOURCE /* Must define this to get access to pthread_rwlock_t */
#include <stdlib.h>
#include <pthread.h>
#include <stdbool.h>
#include <ert/util/util.h>
#include <ert/util/int_vector.h>
#include <ert/util/bool_vector.h>
#include <ert/util/type_macros.h>
#include <ert/enkf/enkf_types.h>
#include <ert/enkf/state_map.h>
#define STATE_MAP_TYPE_ID 500672132
struct state_map_struct {
UTIL_TYPE_ID_DECLARATION;
int_vector_type * state;
pthread_rwlock_t rw_lock;
};
UTIL_IS_INSTANCE_FUNCTION( state_map , STATE_MAP_TYPE_ID )
state_map_type * state_map_alloc( ) {
state_map_type * map = util_malloc( sizeof * map );
UTIL_TYPE_ID_INIT( map , STATE_MAP_TYPE_ID );
map->state = int_vector_alloc( 0 , STATE_UNDEFINED );
pthread_rwlock_init( &map->rw_lock , NULL);
return map;
}
state_map_type * state_map_fread_alloc( const char * filename ) {
state_map_type * map = state_map_alloc();
if (util_file_exists( filename )) {
FILE * stream = util_fopen( filename , "r");
int_vector_fread( map->state , stream );
fclose( stream );
}
return map;
}
state_map_type * state_map_alloc_copy( state_map_type * map ) {
state_map_type * copy = state_map_alloc();
pthread_rwlock_rdlock( &map->rw_lock );
{
int_vector_memcpy( copy->state , map->state );
}
pthread_rwlock_unlock( &map->rw_lock );
return copy;
}
void state_map_free( state_map_type * map ) {
free( map );
}
int state_map_get_size( state_map_type * map) {
int size;
pthread_rwlock_rdlock( &map->rw_lock );
{
size = int_vector_size( map->state );
}
pthread_rwlock_unlock( &map->rw_lock );
return size;
}
bool state_map_equal( state_map_type * map1 , state_map_type * map2) {
bool equal = true;
pthread_rwlock_rdlock( &map1->rw_lock );
pthread_rwlock_rdlock( &map2->rw_lock );
{
if (int_vector_size( map1->state) != int_vector_size( map2->state))
equal = false;
if (equal)
equal = int_vector_equal( map1->state , map2->state );
}
pthread_rwlock_unlock( &map1->rw_lock );
pthread_rwlock_unlock( &map2->rw_lock );
return equal;
}
realisation_state_enum state_map_iget( state_map_type * map , int index) {
realisation_state_enum state;
pthread_rwlock_rdlock( &map->rw_lock );
{
state = int_vector_safe_iget( map->state , index );
}
pthread_rwlock_unlock( &map->rw_lock );
return state;
}
static void state_map_iset__( state_map_type * map , int index , realisation_state_enum new_state) {
realisation_state_enum current_state = int_vector_safe_iget( map->state , index );
int target_mask = 0;
if (current_state == STATE_UNDEFINED)
target_mask = STATE_INITIALIZED | STATE_PARENT_FAILURE;
else if (current_state == STATE_INITIALIZED)
target_mask = STATE_LOAD_FAILURE | STATE_HAS_DATA | STATE_INITIALIZED | STATE_PARENT_FAILURE;
else if (current_state == STATE_HAS_DATA)
target_mask = STATE_LOAD_FAILURE | STATE_HAS_DATA | STATE_PARENT_FAILURE;
else if (current_state == STATE_LOAD_FAILURE)
target_mask = STATE_HAS_DATA | STATE_INITIALIZED;
else if (current_state == STATE_PARENT_FAILURE)
target_mask = STATE_INITIALIZED;
if (new_state & target_mask)
int_vector_iset( map->state , index , new_state);
else
util_abort("%s: illegal state transition for realisation:%d %d -> %d \n" , __func__ , index , current_state , new_state );
}
void state_map_iset( state_map_type * map ,int index , realisation_state_enum state) {
pthread_rwlock_wrlock( &map->rw_lock );
{
state_map_iset__( map , index , state );
}
pthread_rwlock_unlock( &map->rw_lock );
}
void state_map_update_undefined( state_map_type * map , int index , realisation_state_enum new_state) {
realisation_state_enum current_state = state_map_iget( map , index );
if (current_state == STATE_UNDEFINED)
state_map_iset( map , index , new_state );
}
void state_map_fwrite( state_map_type * map , const char * filename) {
pthread_rwlock_rdlock( &map->rw_lock );
{
FILE * stream = util_mkdir_fopen( filename , "w");
if (stream) {
int_vector_fwrite( map->state , stream );
fclose( stream );
} else
util_abort("%s: failed to open:%s for writing \n",__func__ , filename );
}
pthread_rwlock_unlock( &map->rw_lock );
}
void state_map_fread( state_map_type * map , const char * filename) {
pthread_rwlock_wrlock( &map->rw_lock );
{
if (util_file_exists( filename )) {
FILE * stream = util_fopen( filename , "r");
if (stream) {
int_vector_fread( map->state , stream );
fclose( stream );
} else
util_abort("%s: failed to open:%s for reading \n",__func__ , filename );
} else
int_vector_reset( map->state );
}
pthread_rwlock_unlock( &map->rw_lock );
}
static void state_map_select_matching__( state_map_type * map , bool_vector_type * select_target , int select_mask , bool select) {
pthread_rwlock_rdlock( &map->rw_lock );
{
{
const int * map_ptr = int_vector_get_ptr( map->state );
for (int i=0; i < int_vector_size( map->state ); i++) {
int state_value = map_ptr[i];
if (state_value & select_mask)
bool_vector_iset( select_target , i , select);
}
}
pthread_rwlock_unlock( &map->rw_lock );
}
}
void state_map_select_matching( state_map_type * map , bool_vector_type * select_target , int select_mask) {
state_map_select_matching__(map , select_target , select_mask , true );
}
void state_map_deselect_matching( state_map_type * map , bool_vector_type * select_target , int select_mask) {
state_map_select_matching__(map , select_target , select_mask , false );
}
static void state_map_set_from_mask__( state_map_type * map , const bool_vector_type * mask , realisation_state_enum state, bool invert) {
const bool * mask_ptr = bool_vector_get_ptr(mask);
for (int i=0; i < bool_vector_size( mask); i++) {
if (mask_ptr[i] != invert)
state_map_iset(map , i , state);
}
}
void state_map_set_from_inverted_mask( state_map_type * state_map , const bool_vector_type * mask , realisation_state_enum state) {
state_map_set_from_mask__(state_map , mask , state , true);
}
void state_map_set_from_mask( state_map_type * state_map , const bool_vector_type * mask , realisation_state_enum state) {
state_map_set_from_mask__(state_map , mask , state , false);
}
int state_map_count_matching( state_map_type * state_map , int mask) {
int count = 0;
pthread_rwlock_rdlock( &state_map->rw_lock );
{
const int * map_ptr = int_vector_get_ptr( state_map->state );
for (int i=0; i < int_vector_size( state_map->state ); i++) {
int state_value = map_ptr[i];
if (state_value & mask)
count++;
}
}
pthread_rwlock_unlock(&state_map->rw_lock);
return count;
}

View File

@@ -7,6 +7,21 @@ target_link_libraries( enkf_site_config enkf test_util )
add_executable( enkf_time_map enkf_time_map.c )
target_link_libraries( enkf_time_map enkf test_util )
add_executable( enkf_cases_config enkf_cases_config.c )
target_link_libraries( enkf_cases_config enkf test_util )
add_test( enkf_cases_config ${EXECUTABLE_OUTPUT_PATH}/enkf_cases_config )
add_executable( enkf_analysis_config enkf_analysis_config.c )
target_link_libraries( enkf_analysis_config enkf test_util )
add_test( enkf_analysis ${EXECUTABLE_OUTPUT_PATH}/enkf_analysis_config )
add_executable( enkf_state_map enkf_state_map.c )
target_link_libraries( enkf_state_map enkf test_util )
add_executable( enkf_meas_data enkf_meas_data.c )
target_link_libraries( enkf_meas_data enkf test_util )
add_executable( enkf_ensemble_GEN_PARAM enkf_ensemble_GEN_PARAM.c )
target_link_libraries( enkf_ensemble_GEN_PARAM enkf test_util )
@@ -31,6 +46,18 @@ add_test( enkf_forward_init_GEN_KW_FALSE
${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_KW_false FALSE)
#-----------------------------------------------------------------
add_executable( enkf_state_report_step_compatible enkf_state_report_step_compatible.c )
target_link_libraries( enkf_state_report_step_compatible enkf test_util )
add_test( enkf_state_report_step_compatible_TRUE
${EXECUTABLE_OUTPUT_PATH}/enkf_state_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/ecl_sum_compatible_true config_ecl_sum_compatible_true TRUE)
add_test( enkf_state_report_step_compatible_FALSE
${EXECUTABLE_OUTPUT_PATH}/enkf_state_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/ecl_sum_compatible_false config_ecl_sum_compatible_false FALSE)
#-----------------------------------------------------------------
add_executable( enkf_forward_init_GEN_PARAM enkf_forward_init_GEN_PARAM.c )
@@ -133,10 +160,13 @@ add_test( enkf_time_map1 ${EXECUTABLE_OUTPUT_PATH}/enkf_time_map )
add_test( enkf_time_map2 ${EXECUTABLE_OUTPUT_PATH}/enkf_time_map ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST )
add_test( enkf_ensemble_GEN_PARAM ${EXECUTABLE_OUTPUT_PATH}/enkf_ensemble_GEN_PARAM ${CMAKE_CURRENT_SOURCE_DIR}/data/ensemble/GEN_PARAM )
add_test( enkf_ensemble ${EXECUTABLE_OUTPUT_PATH}/enkf_ensemble )
add_test( enkf_state_map ${EXECUTABLE_OUTPUT_PATH}/enkf_state_map )
add_test( enkf_meas_data ${EXECUTABLE_OUTPUT_PATH}/enkf_meas_data )
set_property( TEST enkf_time_map2 PROPERTY LABELS StatoilData )
set_property( TEST enkf_site_config PROPERTY LABELS StatoilData )
set_property( TEST enkf_state_report_step_compatible_TRUE PROPERTY LABELS StatoilData )
set_property( TEST enkf_state_report_step_compatible_FALSE PROPERTY LABELS StatoilData )
set_property( TEST enkf_forward_init_SURFACE_FALSE PROPERTY LABELS StatoilData )
set_property( TEST enkf_forward_init_SURFACE_TRUE PROPERTY LABELS StatoilData )
set_property( TEST enkf_forward_init_FIELD_FALSE PROPERTY LABELS StatoilData )

View File

@@ -0,0 +1,83 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'enkf_analysis_config.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <ert/util/test_util.h>
#include <ert/util/util.h>
#include <ert/util/rng.h>
#include <ert/enkf/analysis_config.h>
analysis_config_type * create_analysis_config() {
rng_type * rng = rng_alloc( MZRAN , INIT_DEFAULT );
analysis_config_type * ac = analysis_config_alloc( rng );
return ac;
}
void test_create() {
analysis_config_type * ac = create_analysis_config( );
test_assert_true( analysis_config_is_instance( ac ) );
analysis_config_free( ac );
}
void test_min_realisations( ) {
analysis_config_type * ac = create_analysis_config( );
test_assert_int_equal( 0 , analysis_config_get_min_realisations( ac ) );
analysis_config_set_min_realisations( ac , 26 );
test_assert_int_equal( 26 , analysis_config_get_min_realisations( ac ) );
analysis_config_free( ac );
}
void test_continue( ) {
analysis_config_type * ac = create_analysis_config( );
test_assert_true( analysis_config_have_enough_realisations( ac , 10 ));
test_assert_false( analysis_config_have_enough_realisations( ac , 0 ));
analysis_config_set_min_realisations( ac , 5 );
test_assert_true( analysis_config_have_enough_realisations( ac , 10 ));
analysis_config_set_min_realisations( ac , 15 );
test_assert_false( analysis_config_have_enough_realisations( ac , 10 ));
analysis_config_set_min_realisations( ac , 10 );
test_assert_true( analysis_config_have_enough_realisations( ac , 10 ));
analysis_config_set_min_realisations( ac , 0 );
test_assert_true( analysis_config_have_enough_realisations( ac , 10 ));
analysis_config_free( ac );
}
int main(int argc , char ** argv) {
test_create();
test_min_realisations();
test_continue();
exit(0);
}

View File

@@ -0,0 +1,44 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'enkf_cases_config.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <ert/util/test_util.h>
#include <ert/util/util.h>
#include <ert/util/rng.h>
#include <ert/enkf/cases_config.h>
void test_create_get_set_and_get() {
cases_config_type * cases_config = cases_config_alloc( );
test_assert_int_equal( 0, cases_config_get_iteration_number( cases_config ) );
cases_config_set_int( cases_config , "iteration_number" , 12);
test_assert_int_equal( 12, cases_config_get_iteration_number( cases_config ) );
cases_config_fwrite( cases_config , "TEST_CASES_CONFIG" );
cases_config_fread( cases_config , "TEST_CASES_CONFIG" );
cases_config_free( cases_config );
}
int main(int argc , char ** argv) {
test_create_get_set_and_get();
exit(0);
}

View File

@@ -37,7 +37,7 @@ void create_runpath(enkf_main_type * enkf_main ) {
int start_report = 0;
int init_step_parameters = 0;
bool_vector_iset( iactive , ens_size - 1 , true );
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state);
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state, true);
bool_vector_free(iactive);
}
@@ -96,7 +96,7 @@ int main(int argc , char ** argv) {
test_assert_true( util_is_directory( "simulations/run0" ));
{
bool loadOK = true;
int error = 0;
stringlist_type * msg_list = stringlist_alloc_new();
{
@@ -108,21 +108,26 @@ int main(int argc , char ** argv) {
test_assert_false( enkf_node_has_data( field_node , fs, node_id ));
util_unlink_existing( "simulations/run0/petro.grdecl" );
test_assert_false( enkf_node_forward_init( field_node , "simulations/run0" , 0 ));
enkf_state_forward_init( state , fs , &loadOK );
test_assert_false( loadOK );
loadOK = true;
enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
stringlist_free( msg_list );
test_assert_false( loadOK );
test_assert_false(enkf_node_forward_init(field_node, "simulations/run0", 0));
enkf_state_forward_init(state, fs, &error);
test_assert_true(LOAD_FAILURE & error);
error = 0;
{
enkf_fs_type * fs = enkf_main_get_fs(enkf_main);
state_map_type * state_map = enkf_fs_get_state_map(fs);
state_map_iset(state_map, 0, STATE_INITIALIZED);
}
enkf_state_load_from_forward_model(state, fs, &error, false, msg_list);
stringlist_free(msg_list);
test_assert_true(LOAD_FAILURE & error);
}
util_copy_file( init_file , "simulations/run0/petro.grdecl");
{
bool loadOK = true;
int error = 0;
stringlist_type * msg_list = stringlist_alloc_new();
{
@@ -130,12 +135,14 @@ int main(int argc , char ** argv) {
enkf_main_init_run(enkf_main , run_mode); /* This is ugly */
}
test_assert_true( enkf_node_forward_init( field_node , "simulations/run0" , 0));
enkf_state_forward_init( state , fs , &loadOK );
test_assert_true( loadOK );
enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
enkf_state_forward_init( state , fs , &error );
test_assert_int_equal( error, 0 );
enkf_state_load_from_forward_model( state , fs , &error , false , msg_list );
stringlist_free( msg_list );
test_assert_true( loadOK );
test_assert_int_equal(error, 0);
{
double value;

View File

@@ -37,7 +37,7 @@ void create_runpath(enkf_main_type * enkf_main ) {
int start_report = 0;
int init_step_parameters = 0;
bool_vector_iset( iactive , ens_size - 1 , true );
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state);
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state, true);
bool_vector_free(iactive);
}
@@ -94,7 +94,7 @@ int main(int argc , char ** argv) {
test_assert_true( util_is_directory( "simulations/run0" ));
{
bool loadOK = true;
int error = 0;
stringlist_type * msg_list = stringlist_alloc_new();
{
@@ -106,14 +106,20 @@ int main(int argc , char ** argv) {
test_assert_false( enkf_node_has_data( gen_kw_node , fs, node_id ));
util_unlink_existing( "simulations/run0/MULTFLT_INIT" );
test_assert_false( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 ));
enkf_state_forward_init( state , fs , &loadOK );
test_assert_false( loadOK );
enkf_state_forward_init( state , fs , &error );
test_assert_true(LOAD_FAILURE & error);
loadOK = true;
enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
error = 0;
{
enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
state_map_type * state_map = enkf_fs_get_state_map(fs);
state_map_iset(state_map , 0 , STATE_INITIALIZED);
}
enkf_state_load_from_forward_model( state , fs , &error , false , msg_list );
stringlist_free( msg_list );
test_assert_false( loadOK );
test_assert_true(LOAD_FAILURE & error);
}
@@ -125,7 +131,7 @@ int main(int argc , char ** argv) {
}
{
bool loadOK = true;
int error = 0;
stringlist_type * msg_list = stringlist_alloc_new();
{
@@ -133,12 +139,14 @@ int main(int argc , char ** argv) {
enkf_main_init_run(enkf_main , run_mode); /* This is ugly */
}
test_assert_true( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 ));
enkf_state_forward_init( state , fs , &loadOK );
test_assert_true( loadOK );
enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
enkf_state_forward_init( state , fs , &error );
test_assert_int_equal(0, error);
enkf_state_load_from_forward_model( state , fs , &error , false , msg_list );
stringlist_free( msg_list );
test_assert_true( loadOK );
test_assert_int_equal(0, error);
{
double value;

View File

@@ -37,7 +37,7 @@ void create_runpath(enkf_main_type * enkf_main ) {
int start_report = 0;
int init_step_parameters = 0;
bool_vector_iset( iactive , ens_size - 1 , true );
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state);
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state, true);
bool_vector_free(iactive);
}
@@ -111,7 +111,7 @@ int main(int argc , char ** argv) {
}
{
bool loadOK = true;
int error = 0;
stringlist_type * msg_list = stringlist_alloc_new();
{
@@ -120,11 +120,18 @@ int main(int argc , char ** argv) {
}
test_assert_true( enkf_node_forward_init( gen_param_node , "simulations/run0" , 0 ));
enkf_state_forward_init( state , fs , &loadOK );
test_assert_true( loadOK );
enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
enkf_state_forward_init( state , fs , &error );
test_assert_int_equal(0, error);
{
enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
state_map_type * state_map = enkf_fs_get_state_map(fs);
state_map_iset(state_map , 0 , STATE_INITIALIZED);
}
enkf_state_load_from_forward_model( state , fs , &error , false , msg_list );
stringlist_free( msg_list );
test_assert_true( loadOK );
test_assert_int_equal(0, error);
{
double value;

View File

@@ -37,7 +37,7 @@ void create_runpath(enkf_main_type * enkf_main ) {
int start_report = 0;
int init_step_parameters = 0;
bool_vector_iset( iactive , ens_size - 1 , true );
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state);
enkf_main_run_exp(enkf_main , iactive , false , init_step_parameters , start_report , init_state, true);
bool_vector_free(iactive);
}
@@ -98,7 +98,7 @@ int main(int argc , char ** argv) {
test_assert_true( util_is_directory( "simulations/run0" ));
{
bool loadOK = true;
int error = 0;
stringlist_type * msg_list = stringlist_alloc_new();
{
@@ -112,19 +112,25 @@ int main(int argc , char ** argv) {
util_unlink_existing( "simulations/run0/Surface.irap" );
test_assert_false( enkf_node_forward_init( surface_node , "simulations/run0" , 0 ));
enkf_state_forward_init( state , fs , &loadOK );
test_assert_false( loadOK );
enkf_state_forward_init( state , fs , &error );
test_assert_true(LOAD_FAILURE & error);
error = 0;
{
enkf_fs_type * fs = enkf_main_get_fs(enkf_main);
state_map_type * state_map = enkf_fs_get_state_map(fs);
state_map_iset(state_map, 0, STATE_INITIALIZED);
}
enkf_state_load_from_forward_model(state, fs, &error, false, msg_list);
loadOK = true;
enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
stringlist_free( msg_list );
test_assert_false( loadOK );
test_assert_true(LOAD_FAILURE & error);
}
util_copy_file( init_file , "simulations/run0/Surface.irap");
{
bool loadOK = true;
int error = 0;
stringlist_type * msg_list = stringlist_alloc_new();
{
@@ -133,11 +139,11 @@ int main(int argc , char ** argv) {
}
test_assert_true( enkf_node_forward_init( surface_node , "simulations/run0" , 0 ));
enkf_state_forward_init( state , fs , &loadOK );
test_assert_true( loadOK );
enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
enkf_state_forward_init( state , fs , &error );
test_assert_int_equal(0, error);
enkf_state_load_from_forward_model( state , fs , &error , false , msg_list );
stringlist_free( msg_list );
test_assert_true( loadOK );
test_assert_int_equal(0, error);
{
double value;

View File

@@ -27,6 +27,7 @@
#include <ert/util/thread_pool.h>
#include <ert/util/arg_pack.h>
#include <ert/enkf/enkf_defaults.h>
#include <ert/enkf/analysis_iter_config.h>
#include <ert/enkf/config_keys.h>
@@ -61,8 +62,10 @@ int main(int argc , char ** argv) {
{
analysis_iter_config_type * iter_config = analysis_iter_config_alloc();
test_assert_string_equal( analysis_iter_config_iget_case( iter_config , 5) , NULL );
test_assert_string_equal( analysis_iter_config_iget_runpath_fmt( iter_config , 5) , NULL );
char itercase[50];
sprintf(itercase,DEFAULT_ANALYSIS_ITER_CASE,5);
test_assert_string_equal( analysis_iter_config_iget_case( iter_config , 5) , itercase );
test_assert_string_equal( analysis_iter_config_iget_runpath_fmt( iter_config , 5) , DEFAULT_ANALYSIS_ITER_RUNPATH );
analysis_iter_config_init( iter_config , config );
@@ -71,7 +74,7 @@ int main(int argc , char ** argv) {
test_assert_string_equal( analysis_iter_config_iget_runpath_fmt( iter_config , 5) , "run/iter5/real%d" );
analysis_iter_config_free( iter_config );
}
}
remove( config_file );
free( config_file );
config_free( config );

View File

@@ -0,0 +1,52 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'enkf_meas_data.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <ert/util/test_util.h>
#include <ert/util/int_vector.h>
#include <ert/enkf/meas_data.h>
void create_test() {
int_vector_type * ens_active_list = int_vector_alloc(0 , false);
int_vector_append( ens_active_list , 10 );
int_vector_append( ens_active_list , 20 );
int_vector_append( ens_active_list , 30 );
{
meas_data_type * meas_data = meas_data_alloc( ens_active_list );
test_assert_int_equal( 3 , meas_data_get_ens_size( meas_data ));
meas_data_free( meas_data );
}
int_vector_free( ens_active_list );
}
int main(int argc , char ** argv) {
create_test();
exit(0);
}

View File

@@ -20,12 +20,39 @@
#include <stdio.h>
#include <unistd.h>
#include <ert/util/test_util.h>
#include <ert/enkf/model_config.h>
int main(int argc , char ** argv) {
model_config_type * model_config = model_config_alloc_empty();
void test_create() {
model_config_type * model_config = model_config_alloc();
test_assert_true( model_config_is_instance( model_config));
model_config_free( model_config );
}
void test_runpath() {
model_config_type * model_config = model_config_alloc();
model_config_add_runpath(model_config , "KEY" , "RunPath%d");
model_config_add_runpath(model_config , "KEY2" , "2-RunPath%d");
test_assert_true( model_config_select_runpath(model_config , "KEY"));
test_assert_false( model_config_select_runpath(model_config , "KEYX"));
test_assert_string_equal("RunPath%d" , model_config_get_runpath_as_char(model_config));
model_config_set_runpath( model_config , "PATH%d");
test_assert_string_equal("PATH%d" , model_config_get_runpath_as_char(model_config));
test_assert_true( model_config_select_runpath(model_config , "KEY2"));
test_assert_string_equal("2-RunPath%d" , model_config_get_runpath_as_char(model_config));
test_assert_true( model_config_select_runpath(model_config , "KEY"));
test_assert_string_equal("PATH%d" , model_config_get_runpath_as_char(model_config));
model_config_free( model_config );
}
int main(int argc , char ** argv) {
test_create();
exit(0);
}

View File

@@ -0,0 +1,274 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'enkf_state_map.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <ert/util/test_work_area.h>
#include <ert/util/test_util.h>
#include <ert/util/util.h>
#include <ert/util/thread_pool.h>
#include <ert/util/bool_vector.h>
#include <ert/util/arg_pack.h>
#include <ert/enkf/state_map.h>
#include <ert/enkf/enkf_types.h>
void create_test() {
state_map_type * state_map = state_map_alloc();
test_assert_true( state_map_is_instance( state_map ));
test_assert_int_equal( 0 , state_map_get_size( state_map ));
state_map_free( state_map );
}
void get_test( ) {
state_map_type * state_map = state_map_alloc();
test_assert_int_equal( STATE_UNDEFINED , state_map_iget( state_map , 0 ));
test_assert_int_equal( STATE_UNDEFINED , state_map_iget( state_map , 100 ));
state_map_free( state_map );
}
void set_test( ) {
state_map_type * state_map = state_map_alloc();
state_map_iset( state_map , 0 , STATE_INITIALIZED );
test_assert_int_equal( STATE_INITIALIZED , state_map_iget( state_map , 0 ));
state_map_iset( state_map , 100 , STATE_INITIALIZED );
test_assert_int_equal( STATE_INITIALIZED , state_map_iget( state_map , 100 ));
test_assert_int_equal( STATE_UNDEFINED , state_map_iget( state_map , 50 ));
test_assert_int_equal( 101 , state_map_get_size( state_map ));
state_map_free( state_map );
}
void load_empty_test() {
state_map_type * state_map = state_map_fread_alloc( "File/does/not/exists" );
test_assert_true( state_map_is_instance( state_map ));
test_assert_int_equal( 0 , state_map_get_size( state_map ));
state_map_free( state_map );
}
void test_equal() {
state_map_type * state_map1 = state_map_alloc();
state_map_type * state_map2 = state_map_alloc();
test_assert_true( state_map_equal( state_map1 , state_map2 ));
for (int i =0; i < 25; i++) {
state_map_iset( state_map1 , i , STATE_INITIALIZED );
state_map_iset( state_map2 , i , STATE_INITIALIZED );
}
test_assert_true( state_map_equal( state_map1 , state_map2 ));
state_map_iset( state_map2 , 15 , STATE_HAS_DATA );
test_assert_false( state_map_equal( state_map1 , state_map2 ));
state_map_iset( state_map2 , 15 , STATE_LOAD_FAILURE );
state_map_iset( state_map2 , 15 , STATE_INITIALIZED );
test_assert_true( state_map_equal( state_map1 , state_map2 ));
state_map_iset( state_map2 , 150 , STATE_INITIALIZED );
test_assert_false( state_map_equal( state_map1 , state_map2 ));
}
void test_copy() {
state_map_type * state_map = state_map_alloc();
state_map_iset( state_map , 0 , STATE_INITIALIZED );
state_map_iset( state_map , 100 , STATE_INITIALIZED );
{
state_map_type * copy = state_map_alloc_copy( state_map );
test_assert_true( state_map_equal( copy , state_map ));
state_map_iset( state_map , 10 , STATE_INITIALIZED );
test_assert_false( state_map_equal( copy , state_map ));
state_map_free( copy );
}
state_map_free( state_map );
}
void test_io( ) {
test_work_area_type * work_area = test_work_area_alloc( "enkf-state-map" , false );
{
state_map_type * state_map = state_map_alloc();
state_map_type * copy1 , *copy2;
state_map_iset( state_map , 0 , STATE_INITIALIZED );
state_map_iset( state_map , 100 , STATE_INITIALIZED );
state_map_fwrite( state_map , "map");
copy1 = state_map_fread_alloc( "map" );
test_assert_true( state_map_equal( state_map , copy1 ));
copy2 = state_map_alloc();
state_map_fread( copy2 , "map" );
test_assert_true( state_map_equal( state_map , copy2 ));
state_map_iset( copy2 , 67 , STATE_INITIALIZED );
test_assert_false(state_map_equal( state_map , copy2 ));
state_map_fread( copy2 , "map");
test_assert_true( state_map_equal( state_map , copy2 ));
state_map_fread( copy2 , "DoesNotExis");
test_assert_int_equal( 0 , state_map_get_size( copy2 ));
}
test_work_area_free( work_area );
}
void test_update_undefined( ) {
state_map_type * map = state_map_alloc( );
state_map_iset( map , 10 , STATE_INITIALIZED );
test_assert_int_equal( STATE_UNDEFINED , state_map_iget( map , 5 ) );
test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );
state_map_update_undefined( map , 5 , STATE_INITIALIZED );
test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 5 ) );
state_map_update_undefined( map , 10 , STATE_INITIALIZED );
test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );
state_map_free( map );
}
void test_select_matching( ) {
state_map_type * map = state_map_alloc( );
bool_vector_type * mask1 = bool_vector_alloc(0 , false);
bool_vector_type * mask2 = bool_vector_alloc(1000 , true);
state_map_iset( map , 10 , STATE_INITIALIZED );
state_map_iset( map , 10 , STATE_HAS_DATA );
state_map_iset( map , 20 , STATE_INITIALIZED );
state_map_select_matching( map , mask1 , STATE_HAS_DATA | STATE_INITIALIZED );
state_map_select_matching( map , mask2 , STATE_HAS_DATA | STATE_INITIALIZED );
test_assert_int_equal( state_map_get_size( map ) , bool_vector_size( mask1 ));
for (int i=0; i < bool_vector_size( mask1 ); i++) {
if (i==10)
test_assert_true( bool_vector_iget( mask1 , i ));
else if (i== 20)
test_assert_true( bool_vector_iget( mask1 , i ));
else {
test_assert_false( bool_vector_iget( mask1 , i ));
test_assert_true( bool_vector_iget( mask2 , i ));
}
}
bool_vector_free( mask1 );
bool_vector_free( mask2 );
state_map_free( map );
}
void test_deselect_matching( ) {
state_map_type * map = state_map_alloc( );
bool_vector_type * mask1 = bool_vector_alloc(0 , false);
bool_vector_type * mask2 = bool_vector_alloc(1000 , true);
state_map_iset( map , 10 , STATE_INITIALIZED );
state_map_iset( map , 10 , STATE_HAS_DATA );
state_map_iset( map , 20 , STATE_INITIALIZED );
state_map_deselect_matching( map , mask1 , STATE_HAS_DATA | STATE_INITIALIZED );
state_map_deselect_matching( map , mask2 , STATE_HAS_DATA | STATE_INITIALIZED );
test_assert_int_equal( state_map_get_size( map ) , bool_vector_size( mask1 ));
for (int i=0; i < bool_vector_size( mask1 ); i++) {
if (i==10)
test_assert_false( bool_vector_iget( mask1 , i ));
else if (i== 20)
test_assert_false( bool_vector_iget( mask2 , i ));
else {
test_assert_false( bool_vector_iget( mask1 , i ));
test_assert_true( bool_vector_iget( mask2 , i ));
}
}
bool_vector_free( mask1 );
bool_vector_free( mask2 );
state_map_free( map );
}
void test_set_from_mask() {
int i;
state_map_type * map1 = state_map_alloc();
state_map_type * map2 = state_map_alloc();
bool_vector_type * mask = bool_vector_alloc(0, false);
bool_vector_iset(mask , 10 , true);
bool_vector_iset(mask , 20 , true);
state_map_set_from_mask(map1 , mask , STATE_INITIALIZED);
state_map_set_from_inverted_mask(map2 , mask , STATE_INITIALIZED);
test_assert_int_equal(21 , state_map_get_size(map1));
test_assert_int_equal(21 , state_map_get_size(map2));
for (i = 0; i < state_map_get_size(map1); i++) {
if (i == 10 || i== 20) {
test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map1 , i) );
test_assert_int_equal( STATE_UNDEFINED , state_map_iget(map2 , i));
}
else {
test_assert_int_equal(STATE_UNDEFINED , state_map_iget(map1 , i ));
test_assert_int_equal( STATE_INITIALIZED , state_map_iget(map2 , i));
}
}
}
void test_count_matching() {
state_map_type * map1 = state_map_alloc();
state_map_iset(map1 , 10 , STATE_INITIALIZED );
state_map_iset(map1 , 15 , STATE_INITIALIZED );
state_map_iset(map1 , 15 , STATE_HAS_DATA );
state_map_iset(map1 , 16 , STATE_INITIALIZED );
state_map_iset(map1 , 16 , STATE_HAS_DATA );
state_map_iset(map1 , 16 , STATE_LOAD_FAILURE );
test_assert_int_equal( 1 , state_map_count_matching( map1 , STATE_HAS_DATA));
test_assert_int_equal( 2 , state_map_count_matching( map1 , STATE_HAS_DATA | STATE_LOAD_FAILURE));
test_assert_int_equal( 3 , state_map_count_matching( map1 , STATE_HAS_DATA | STATE_LOAD_FAILURE | STATE_INITIALIZED));
state_map_free( map1 );
}
int main(int argc , char ** argv) {
create_test();
get_test();
set_test();
load_empty_test();
test_equal();
test_copy();
test_io();
test_update_undefined( );
test_select_matching();
test_count_matching();
exit(0);
}

View File

@@ -0,0 +1,85 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'enkf_state_report_step_compatible.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <ert/util/test_util.h>
#include <ert/util/test_work_area.h>
#include <ert/util/util.h>
#include <ert/enkf/enkf_main.h>
bool check_ecl_sum_compatible(const enkf_main_type * enkf_main)
{
stringlist_type * msg_list = stringlist_alloc_new();
enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 );
enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
state_map_type * state_map = enkf_fs_get_state_map(fs);
state_map_iset(state_map, 0, STATE_INITIALIZED);
int error = 0;
enkf_state_load_from_forward_model( state , fs , &error , false , msg_list );
stringlist_free( msg_list );
return (REPORT_STEP_INCOMPATIBLE & error) ? false : true;
}
int main(int argc , char ** argv) {
enkf_main_install_SIGNALS();
const char * root_path = argv[1];
const char * config_file = argv[2];
const char * compatible_str = argv[3];
bool check_compatible;
test_assert_true( util_sscanf_bool( compatible_str , &check_compatible));
test_work_area_type * work_area = test_work_area_alloc(config_file , false);
test_work_area_copy_directory_content( work_area , root_path );
bool strict = true;
enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true );
{
run_mode_type run_mode = ENSEMBLE_EXPERIMENT;
enkf_main_init_run(enkf_main , run_mode); /* This is ugly */
enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 );
bool active = true;
int max_internal_sumbit = 1;
int init_step_parameter = 1;
state_enum init_state_parameter = FORECAST;
state_enum init_state_dynamic = FORECAST;
int load_start = 1;
int step1 = 1;
int step2 = 1;
enkf_state_init_run(state, run_mode, active, max_internal_sumbit, init_step_parameter, init_state_parameter, init_state_dynamic, load_start, step1, step2);
}
test_assert_bool_equal(check_compatible, check_ecl_sum_compatible(enkf_main));
enkf_main_free( enkf_main );
test_work_area_free(work_area);
}

View File

@@ -20,7 +20,7 @@
#ifdef WITH_PTHREAD
#define WITH_THREAD_POOL
#include "thread_pool_posix.h"
#include <ert/util/thread_pool_posix.h>
#endif
#endif

View File

@@ -0,0 +1,34 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'type_vector_functions.h' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#ifndef __TYPE_VECTOR_FUNCTIONS_H__
#define __TYPE_VECTOR_FUNCTIONS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <ert/util/int_vector.h>
#include <ert/util/bool_vector.h>
int_vector_type * bool_vector_alloc_active_list( const bool_vector_type * mask );
bool_vector_type * int_vector_alloc_mask( const int_vector_type * active_list );
int_vector_type * bool_vector_alloc_active_index_list(const bool_vector_type * mask , int default_value);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -22,9 +22,14 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <stdarg.h>
#include <sys/types.h>
#include <time.h>
#ifdef HAVE_GETPWUID
#include <pwd.h>
#endif
#ifdef HAVE_GETUID
#include <sys/stat.h>
@@ -278,6 +283,7 @@ typedef enum {left_pad = 0,
void util_fread_dev_urandom(int , char * );
bool util_string_isspace(const char * s);
char * util_alloc_dump_filename();
void util_exit(const char * fmt , ...);
void util_abort(const char * fmt , ...);
void util_abort_signal(int );

View File

@@ -1,6 +1,6 @@
set(source_files rng.c lookup_table.c statistics.c mzran.c set.c hash_node.c hash_sll.c hash.c node_data.c node_ctype.c util.c thread_pool.c msg.c arg_pack.c path_fmt.c menu.c subst_list.c subst_func.c vector.c parser.c stringlist.c matrix.c buffer.c log.c template.c timer.c time_interval.c string_util.c)
set(source_files rng.c lookup_table.c statistics.c mzran.c set.c hash_node.c hash_sll.c hash.c node_data.c node_ctype.c util.c thread_pool.c msg.c arg_pack.c path_fmt.c menu.c subst_list.c subst_func.c vector.c parser.c stringlist.c matrix.c buffer.c log.c template.c timer.c time_interval.c string_util.c type_vector_functions.c)
set(header_files ssize_t.h type_macros.h rng.h lookup_table.h statistics.h mzran.h set.h hash.h hash_node.h hash_sll.h node_data.h node_ctype.h util.h thread_pool.h msg.h arg_pack.h path_fmt.h stringlist.h menu.h subst_list.h subst_func.h vector.h parser.h matrix.h buffer.h log.h template.h timer.h time_interval.h string_util.h)
set(header_files ssize_t.h type_macros.h rng.h lookup_table.h statistics.h mzran.h set.h hash.h hash_node.h hash_sll.h node_data.h node_ctype.h util.h thread_pool.h msg.h arg_pack.h path_fmt.h stringlist.h menu.h subst_list.h subst_func.h vector.h parser.h matrix.h buffer.h log.h template.h timer.h time_interval.h string_util.h type_vector_functions.h)
set( test_source test_util.c test_work_area.c )

View File

@@ -23,7 +23,7 @@
#include <ert/util/int_vector.h>
#include <ert/util/bool_vector.h>
#include <ert/util/string_util.h>
#include <ert/util/type_vector_functions.h>
/*****************************************************************/
@@ -127,21 +127,13 @@ static int_vector_type * string_util_sscanf_alloc_active_list(const char * range
/*****************************************************************/
static bool_vector_type * alloc_mask( const int_vector_type * active_list ) {
bool_vector_type * mask = bool_vector_alloc( 0 , false );
int i;
for (i=0; i < int_vector_size( active_list ); i++)
bool_vector_iset( mask , int_vector_iget( active_list , i) , true );
return mask;
}
bool string_util_update_active_list( const char * range_string , int_vector_type * active_list ) {
int_vector_sort( active_list );
{
bool_vector_type * mask = alloc_mask( active_list );
bool_vector_type * mask = int_vector_alloc_mask( active_list );
bool valid = false;
if (string_util_update_active_mask( range_string , mask )) {

View File

@@ -106,7 +106,7 @@ test_work_area_type * test_work_area_alloc(const char * test_name, bool retain)
if (test_name) {
uid_t uid = getuid();
struct passwd * pw = getpwuid( uid );
rng_type * rng = rng_alloc(MZRAN , INIT_CLOCK );
rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM );
char * path = util_alloc_sprintf( PATH_FMT , pw->pw_name , test_name , rng_get_int( rng , 100000000 ));
test_work_area_type * work_area = test_work_area_alloc__( path , retain );
free( path );

View File

@@ -0,0 +1,61 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'ert_util_vector_function.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/int_vector.h>
#include <ert/util/bool_vector.h>
int_vector_type * bool_vector_alloc_active_list( const bool_vector_type * mask ) {
int_vector_type * active_list = int_vector_alloc(0,0);
int i;
for (i =0; i < bool_vector_size( mask ); i++)
if (bool_vector_iget( mask , i ))
int_vector_append( active_list , i );
return active_list;
}
int_vector_type * bool_vector_alloc_active_index_list(const bool_vector_type * mask , int default_value) {
int_vector_type * index_list = int_vector_alloc(bool_vector_size( mask) , default_value);
int active_index = 0;
int i;
for (i=0; i < bool_vector_size(mask); i++) {
if (bool_vector_iget( mask , i)) {
int_vector_iset(index_list , i , active_index);
active_index++;
}
}
return index_list;
}
bool_vector_type * int_vector_alloc_mask( const int_vector_type * active_list ) {
bool_vector_type * mask = bool_vector_alloc( 0 , false );
int i;
for (i=0; i < int_vector_size( active_list ); i++)
bool_vector_iset( mask , int_vector_iget( active_list , i) , true );
return mask;
}

View File

@@ -38,10 +38,12 @@
#ifdef HAVE_FORK
#ifdef WITH_PTHREAD
#ifdef HAVE_EXECINFO
#ifdef HAVE_GETPWUID
#define HAVE_UTIL_ABORT
#endif
#endif
#endif
#endif
#ifdef HAVE_UTIL_ABORT
#define __USE_GNU // Must be defined to get access to the dladdr() function; Man page says the symbol should be: _GNU_SOURCE but that does not seem to work?

View File

@@ -1,18 +1,16 @@
/*
This file implements the fully fledged util<69>abort() function which
This file implements the fully fledged util<69>abort() function which
assumes that the current build has the following features:
fork() : To support calling external program addr2line().
pthread : To serialize the use of util<69>abort() - not very important.
execinfo.h : The backtrace functions backtrace() and backtrace<63>symbols().
pthread : To serialize the use of util<69>abort() - not very important.
execinfo.h : The backtrace functions backtrace() and backtrace<63>symbols().
_GNU_SOURCE : To get the dladdr() function.
If not all these features are availbale the simpler version in
util<69>abort_simple.c is built instead.
util<69>abort_simple.c is built instead.
*/
/**
This function uses the external program addr2line to convert the
hexadecimal adress given by the libc function backtrace() into a
@@ -175,15 +173,36 @@ static void util_fprintf_backtrace(FILE * stream) {
fprintf(stream , "--------------------------------------------------------------------------------\n");
}
char * util_alloc_dump_filename() {
time_t timestamp = time(NULL);
struct tm *converted = localtime(&timestamp);
char day[32];
size_t last = strftime(day, 32, "%Y%m%d-%H%M%S", converted);
day[last] = '\0';
struct passwd *pwd = getpwuid(getuid());
char * filename = util_alloc_sprintf("/tmp/ert_abort_dump.%s.%s.log", pwd->pw_name, day);
return filename;
}
void util_abort(const char * fmt , ...) {
pthread_mutex_lock( &__abort_mutex ); /* Abort before unlock() */
{
char * filename = util_alloc_dump_filename();
bool dump_to_file = true;
FILE * abort_dump = fopen(filename, "w");
if (abort_dump == NULL) {
abort_dump = stderr;
dump_to_file = false;
}
va_list ap;
va_start(ap , fmt);
fprintf(stderr , "\n\n");
fprintf(stderr , "\n\n");
vfprintf(stderr , fmt , ap);
fprintf(abort_dump , "\n\n");
vfprintf(abort_dump , fmt , ap);
fprintf(abort_dump , "\n\n");
va_end(ap);
/*
@@ -191,37 +210,29 @@ void util_abort(const char * fmt , ...) {
addr2line; the call is based on util_fork_exec() which is
currently only available on POSIX.
*/
const bool include_backtrace = true;
if (include_backtrace) {
if (__abort_program_message != NULL) {
fprintf(stderr,"--------------------------------------------------------------------------------\n");
fprintf(stderr,"%s",__abort_program_message);
fprintf(stderr, "Current executable ..: %s\n" , program_invocation_name);
fprintf(stderr,"--------------------------------------------------------------------------------\n");
fprintf(abort_dump,"--------------------------------------------------------------------------------\n");
fprintf(abort_dump,"%s",__abort_program_message);
fprintf(abort_dump, "Current executable ..: %s\n" , program_invocation_name);
fprintf(abort_dump,"--------------------------------------------------------------------------------\n");
}
fprintf(stderr,"\n");
fprintf(stderr,"****************************************************************************\n");
fprintf(stderr,"** **\n");
fprintf(stderr,"** A fatal error occured, and we have to abort. **\n");
fprintf(stderr,"** **\n");
fprintf(stderr,"** We now *try* to provide a backtrace, which would be very useful **\n");
fprintf(stderr,"** when debugging. The process of making a (human readable) backtrace **\n");
fprintf(stderr,"** is quite complex, among other things it involves several calls to the **\n");
fprintf(stderr,"** external program addr2line. We have arrived here because the program **\n");
fprintf(stderr,"** state is already quite broken, so the backtrace might be (seriously) **\n");
fprintf(stderr,"** broken as well. **\n");
fprintf(stderr,"** **\n");
fprintf(stderr,"****************************************************************************\n");
util_fprintf_backtrace( stderr );
fprintf(abort_dump,"\n");
util_fprintf_backtrace( abort_dump );
}
}
pthread_mutex_unlock( &__abort_mutex );
signal(SIGABRT , SIG_DFL);
fprintf(stderr , "Aborting ... \n");
if (dump_to_file) {
util_fclose(abort_dump);
fprintf(stderr, "\n\nA fatal error occured, see file %s for details \n", filename);
}
free(filename);
}
pthread_mutex_unlock(&__abort_mutex);
signal(SIGABRT, SIG_DFL);
abort();
}

View File

@@ -95,6 +95,10 @@ add_executable( ert_util_file_readable ert_util_file_readable.c )
target_link_libraries( ert_util_file_readable ert_util test_util )
add_test( ert_util_file_readable ${EXECUTABLE_OUTPUT_PATH}/ert_util_file_readable ${FILE_READABLE_SERVERS})
add_executable( ert_util_type_vector_functions ert_util_type_vector_functions.c )
target_link_libraries( ert_util_type_vector_functions ert_util test_util )
add_test( ert_util_type_vector_functions ${EXECUTABLE_OUTPUT_PATH}/ert_util_type_vector_functions)
add_executable( ert_util_addr2line ert_util_addr2line.c )
target_link_libraries( ert_util_addr2line ert_util test_util )
add_test( ert_util_addr2line ${EXECUTABLE_OUTPUT_PATH}/ert_util_addr2line)
@@ -118,3 +122,7 @@ add_executable( ert_util_arg_pack ert_util_arg_pack.c)
set_target_properties( ert_util_arg_pack PROPERTIES COMPILE_FLAGS "-Werror")
target_link_libraries( ert_util_arg_pack ert_util test_util )
add_test( ert_util_arg_pack ${EXECUTABLE_OUTPUT_PATH}/ert_util_arg_pack)
add_executable( ert_util_abort_gnu_tests ert_util_abort_gnu_tests.c)
target_link_libraries( ert_util_abort_gnu_tests ert_util test_util)
add_test( ert_util_abort_gnu_tests ${EXECUTABLE_OUTPUT_PATH}/ert_util_abort_gnu_tests)

View File

@@ -0,0 +1,44 @@
/*
* File: ert_util_abort_gnu_tests.c
* Author: kflik
*
* Created on August 16, 2013, 9:41 AM
*/
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <sys/types.h>
#include <pwd.h>
#include <sys/wait.h>
#include <ert/util/util.h>
#include <ert/util/test_util.h>
/*
*
*/
int main(int argc, char** argv) {
char * filename = util_alloc_dump_filename();
if (util_file_exists(filename)) {
remove(filename);
}
test_assert_false(util_file_exists(filename));
pid_t child_pid = fork();
if (child_pid == 0) {
util_abort("I was terminated with the util_abort function");
} else {
waitpid(child_pid, NULL, 0);
test_assert_true(util_file_exists(filename));
free(filename);
}
return (EXIT_SUCCESS);
}

View File

@@ -0,0 +1,106 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'ert_util_type_vector_functions.c' is part of ERT -
Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
#include <ert/util/int_vector.h>
#include <ert/util/bool_vector.h>
#include <ert/util/type_vector_functions.h>
#include <ert/util/test_util.h>
void test_index_list() {
int_vector_type * index_list = int_vector_alloc( 0 , 0 );
int_vector_append( index_list , 10 );
int_vector_append( index_list , 20 );
int_vector_append( index_list , 30 );
{
bool_vector_type * mask = int_vector_alloc_mask( index_list );
test_assert_false( bool_vector_get_default( mask ));
test_assert_int_equal( 31 , bool_vector_size( mask ));
test_assert_true( bool_vector_iget( mask , 10 ));
test_assert_true( bool_vector_iget( mask , 20 ));
test_assert_true( bool_vector_iget( mask , 30 ));
test_assert_int_equal( 3 , bool_vector_count_equal( mask , true ));
bool_vector_free( mask );
}
int_vector_free( index_list );
}
void test_mask() {
bool_vector_type * mask = bool_vector_alloc(0 , false);
bool_vector_iset(mask , 10, true);
bool_vector_iset(mask , 15, true);
bool_vector_iset(mask , 20, true);
{
int_vector_type * index_list = bool_vector_alloc_active_list( mask );
test_assert_int_equal( 3 , int_vector_size( index_list ));
test_assert_int_equal( 10 , int_vector_iget( index_list , 0 ));
test_assert_int_equal( 15 , int_vector_iget( index_list , 1 ));
test_assert_int_equal( 20 , int_vector_iget( index_list , 2 ));
int_vector_free( index_list );
}
bool_vector_free( mask );
}
void test_active_index_list() {
int default_value = -1;
bool_vector_type * mask = bool_vector_alloc(0 , false);
bool_vector_iset(mask , 10, true);
bool_vector_iset(mask , 15, true);
bool_vector_iset(mask , 20, true);
{
int_vector_type * active_index_list = bool_vector_alloc_active_index_list(mask , default_value);
test_assert_int_equal( default_value , int_vector_get_default(active_index_list));
test_assert_int_equal( 21 , int_vector_size( active_index_list ));
test_assert_int_equal( default_value , int_vector_iget( active_index_list , 0));
test_assert_int_equal( default_value , int_vector_iget( active_index_list , 1));
test_assert_int_equal( default_value , int_vector_iget( active_index_list , 12));
test_assert_int_equal( default_value , int_vector_iget( active_index_list , 19));
test_assert_int_equal( 0 , int_vector_iget( active_index_list , 10));
test_assert_int_equal( 1 , int_vector_iget( active_index_list , 15));
test_assert_int_equal( 2 , int_vector_iget( active_index_list , 20));
int_vector_free( active_index_list);
}
bool_vector_free(mask);
}
int main( int argc , char ** argv) {
test_index_list();
test_mask();
test_active_index_list();
exit(0);
}

View File

@@ -39,6 +39,20 @@ void test_div() {
}
void test_alloc() {
const int size = 100;
const int default_value = 77;
int_vector_type * v = int_vector_alloc(size , default_value);
test_assert_int_equal(size , int_vector_size(v));
for (int i=0; i < size; i++)
test_assert_int_equal( default_value , int_vector_iget( v , i));
int_vector_free( v);
}
int main(int argc , char ** argv) {
@@ -112,7 +126,7 @@ int main(int argc , char ** argv) {
int_vector_free( v1 );
int_vector_free( v2 );
}
test_alloc();
test_div();
exit(0);
}

View File

@@ -0,0 +1,74 @@
include global_config
SDP_ROOT = $(shell get_sdp_root.py)
#################################################################
COMPILE_INCLUDE = -I$(LIBRMS_HOME)/src -I$(LIBECL_HOME)/include -I$(LIBUTIL_HOME)/include
INSTALL_INC_PATH = $(LIBRMS_HOME)/include
INSTALL_LIB_PATH = $(LIBRMS_HOME)/lib
#################################################################
OBJECTS = rms_file.o rms_util.o rms_tag.o rms_type.o rms_tagkey.o rms_stats.o rms_export.o
INC_FILES = rms_file.h rms_util.h rms_tag.h rms_type.h rms_tagkey.h rms_stats.h rms_export.h
LIB = librms.a
LOCAL: LIB
install -d $(INSTALL_INC_PATH)
install -d $(INSTALL_LIB_PATH)
install $(INC_FILES) $(INSTALL_INC_PATH)
install $(LIB) $(INSTALL_LIB_PATH)
SDP_INSTALL: LIB BIN
install $(LIB) $(SDP_ROOT)/lib/lib$(LIB_ROOT).a
install $(INC_FILES) $(SDP_ROOT)/include
LIB: $(LIB)
clean:
rm -f *.o *~
rm -f $(LIB)
rm -f $(INSTALL_LIB_PATH)/$(LIB)
rm -f $(INSTALL_INC_PATH)/*.h
rebuild: clean LOCAL
$(LIB): $(OBJECTS)
$(AR) $(ARFLAGS) $(LIB) $(OBJECTS)
%.o : %.c
$(CC) -c $(CFLAGS) $(COMPILE_INCLUDE) $(CPPFLAGS) $< -o $@
new:
../../Scripts/cdep.py all_include.h 0
include dependencies
##################################################################
## Binaries
#
#BIN_FILES = rms.x rms_stat.x roff_tags.x rms_extract.x rms_setname.x
#BIN: $(BIN_FILES)
#BIN_FILES_SDP_INSTALL = roff_tags.x
#
#rms_test.o : rms_test.c
#rms_stat.o : rms_stat.c
#tag_list.o : tag_list.c
#rms_extract.o : rms_extract.c
#rms_setname.o : rms_setname.c
#
#roff_tags.x: tag_list.o $(LIB)
# $(CC) -$(MFLAG) $(LDFLAGS) tag_list.o -o roff_tags.x $(LIB_PATH) $(LIB_LINK)
#
#rms.x: rms_test.o $(LIB)
# $(CC) -$(MFLAG) $(LDFLAGS) rms_test.o -o rms.x $(LIB_PATH) $(LIB_LINK)
#
#rms_stat.x: rms_stat.o $(LIB)
# $(CC) -$(MFLAG) $(LDFLAGS) rms_stat.o -o rms_stat.x $(LIB_PATH) $(LIB_LINK)
#
#rms_extract.x: rms_extract.o $(LIB)
# $(CC) -$(MFLAG) $(LDFLAGS) rms_extract.o -o rms_extract.x $(LIB_PATH) $(LIB_LINK)
#
#rms_setname.x: rms_setname.o $(LIB)
# $(CC) -$(MFLAG) $(LDFLAGS) rms_setname.o -o rms_setname.x $(LIB_PATH) $(LIB_LINK)

View File

@@ -1,7 +1,8 @@
set(PYTHON_SOURCES
__init__.py
config_enums.py
content_type_enum.py
config_parser.py
unrecognized_enum.py
)
add_python_package("Python ert.config" ${PYTHON_INSTALL_PREFIX}/ert/config "${PYTHON_SOURCES}" True)

View File

@@ -18,6 +18,6 @@ import ert.util
CONFIG_LIB = clib.ert_load("libconfig.so")
from .config_enums import ContentTypeEnum, UnrecognizedEnum
from .config_parser import ConfigParser , SchemaItem , ContentItem , ContentNode
from .unrecognized_enum import UnrecognizedEnum
from .content_type_enum import ContentTypeEnum
from .config_parser import ConfigParser, SchemaItem, ContentItem, ContentNode

View File

@@ -16,145 +16,141 @@
import os.path
from ert.config import UnrecognizedEnum, CONFIG_LIB
from ert.cwrap import CClass, CWrapper, CWrapperNameSpace
from ert.config import UnrecognizedEnum, CONFIG_LIB, ContentTypeEnum
from ert.cwrap import BaseCClass, CWrapper
class SchemaItem(CClass):
class SchemaItem(BaseCClass):
def __init__(self, keyword, required=False):
c_ptr = cfunc.schema_alloc(keyword, required)
self.init_cref(c_ptr, cfunc.schema_free)
c_ptr = SchemaItem.cNamespace().alloc(keyword, required)
super(SchemaItem, self).__init__(c_ptr)
@classmethod
def wrap(cls, c_ptr, parent):
obj = object.__new__(cls)
obj.init_cref(c_ptr, parent)
return obj
def iget_type( self, index ):
return cfunc.schema_iget_type(self, index)
def iget_type( self, index):
""" @rtype: ContentTypeEnum """
return SchemaItem.cNamespace().iget_type(self, index)
def iset_type( self, index, schema_type ):
cfunc.schema_iset_type(self, index, schema_type)
"""
@type schema_type: ContentTypeEnum
"""
assert isinstance(schema_type, ContentTypeEnum)
SchemaItem.cNamespace().iset_type(self, index, schema_type)
def set_argc_minmax(self, minimum, maximum):
cfunc.schema_set_argc_minmax(self, minimum, maximum)
SchemaItem.cNamespace().set_argc_minmax(self, minimum, maximum)
#-----------------------------------------------------------------
def free(self):
SchemaItem.cNamespace().free(self)
class ContentItem(CClass):
class ContentItem(BaseCClass):
# Not possible to create new python instances of this class
def __init__(self):
raise NotImplementedError("Class can not be instantiated directly!")
@classmethod
def wrap(cls, c_ptr, parent):
obj = object.__new__(cls)
obj.init_cref(c_ptr, parent)
return obj
def __len__(self):
return cfunc.content_size(self)
return ContentItem.cNamespace().size(self)
def __getitem__(self, index):
if isinstance(index, int):
if (index >= 0) and (index < self.__len__()):
c_ptr = cfunc.iget_content_node(self, index)
return ContentNode.wrap(c_ptr, self)
return ContentItem.cNamespace().iget_content_node(self, index).setParent(self)
else:
raise IndexError
else:
raise ValueError("[] operator must have integer index")
#-----------------------------------------------------------------
class ContentNode(CClass):
class ContentNode(BaseCClass):
# Not possible to create new python instances of this class
@classmethod
def wrap(cls, c_ptr, parent):
obj = object.__new__(cls)
obj.init_cref(c_ptr, parent)
return obj
def __init__(self):
raise NotImplementedError("Class can not be instantiated directly!")
def __len__(self):
return cfunc.content_node_size(self)
return ContentNode.cNamespace().size(self)
def __getitem__(self, index):
if isinstance(index, int):
if (index >= 0) and (index < self.__len__()):
return cfunc.content_node_iget(self, index)
return ContentNode.cNamespace().iget(self, index)
else:
raise IndexError
else:
raise ValueError("[] operator must have integer index")
def content(self, sep=" "):
return cfunc.content_full_string(self, sep)
return ContentNode.cNamespace().get_full_string(self, sep)
#-----------------------------------------------------------------
class ConfigParser(CClass):
class ConfigParser(BaseCClass):
def __init__(self):
c_ptr = cfunc.config_alloc()
self.init_cobj(c_ptr, cfunc.config_free)
c_ptr = ConfigParser.cNamespace().alloc()
super(ConfigParser, self).__init__(c_ptr)
def add(self, keyword, required=False):
c_ptr = cfunc.add(self, keyword, required)
schema_item = SchemaItem.wrap(c_ptr, self)
return schema_item
return ConfigParser.cNamespace().add(self, keyword, required).setParent()
def parse( self, config_file, comment_string="--", include_kw="INCLUDE", define_kw="DEFINE",
def parse(self, config_file, comment_string="--", include_kw="INCLUDE", define_kw="DEFINE",
unrecognized=UnrecognizedEnum.CONFIG_UNRECOGNIZED_WARN, validate=True):
assert isinstance(unrecognized, UnrecognizedEnum)
if os.path.exists(config_file):
return cfunc.parse(self, config_file, comment_string, include_kw, define_kw, unrecognized, validate)
return ConfigParser.cNamespace().parse(self, config_file, comment_string, include_kw, define_kw, unrecognized, validate)
else:
raise IOError("File: %s does not exists")
def __getitem__(self, keyword):
if cfunc.has_content(self, keyword):
c_ptr = cfunc.get_content(self, keyword)
return ContentItem.wrap(c_ptr, self)
if ConfigParser.cNamespace().has_content(self, keyword):
return ConfigParser.cNamespace().get_content(self, keyword).setParent(self)
else:
return None
#-----------------------------------------------------------------
def free(self):
ConfigParser.cNamespace().free(self)
cwrapper = CWrapper(CONFIG_LIB)
cwrapper.registerType("config_parser", ConfigParser)
cwrapper.registerType("config_parser_obj", ConfigParser.createPythonObject)
cwrapper.registerType("config_parser_ref", ConfigParser.createCReference)
cwrapper.registerType("schema_item", SchemaItem)
cwrapper.registerType("schema_item_obj", SchemaItem.createPythonObject)
cwrapper.registerType("schema_item_ref", SchemaItem.createCReference)
cwrapper.registerType("content_item", ContentItem)
cwrapper.registerType("content_item_obj", ContentItem.createPythonObject)
cwrapper.registerType("content_item_ref", ContentItem.createCReference)
cwrapper.registerType("content_node", ContentNode)
cwrapper.registerType("content_node_obj", ContentNode.createPythonObject)
cwrapper.registerType("content_node_ref", ContentNode.createCReference)
cfunc = CWrapperNameSpace("config")
ConfigParser.cNamespace().alloc = cwrapper.prototype("c_void_p config_alloc( )")
ConfigParser.cNamespace().add = cwrapper.prototype("schema_item_ref config_add_schema_item( config_parser , char* , bool)")
ConfigParser.cNamespace().free = cwrapper.prototype("void config_free( config_parser )")
ConfigParser.cNamespace().parse = cwrapper.prototype("bool config_parse( config_parser , char* , char* , char* , char* , config_unrecognized_enum , bool )")
ConfigParser.cNamespace().has_content = cwrapper.prototype("bool config_has_content_item( config_parser , char*) ")
ConfigParser.cNamespace().get_content = cwrapper.prototype("content_item_ref config_get_content_item( config_parser , char*) ")
cfunc.add = cwrapper.prototype("c_void_p config_add_schema_item( config_parser , char* , bool)")
cfunc.config_alloc = cwrapper.prototype("c_void_p config_alloc( )")
cfunc.config_free = cwrapper.prototype("void config_free( config_parser )")
cfunc.parse = cwrapper.prototype("bool config_parse( config_parser , char* , char* , char* , char* , int , bool )")
cfunc.has_content = cwrapper.prototype("bool config_has_content_item( config_parser , char*) ")
cfunc.get_content = cwrapper.prototype("c_void_p config_get_content_item( config_parser , char*) ")
SchemaItem.cNamespace().alloc = cwrapper.prototype("c_void_p config_schema_item_alloc( char* , bool )")
SchemaItem.cNamespace().free = cwrapper.prototype("void config_schema_item_free( schema_item )")
SchemaItem.cNamespace().iget_type = cwrapper.prototype("config_content_type_enum config_schema_item_iget_type( schema_item, int)")
SchemaItem.cNamespace().iset_type = cwrapper.prototype("void config_schema_item_iset_type( schema_item , int , config_content_type_enum)")
SchemaItem.cNamespace().set_argc_minmax = cwrapper.prototype("void config_schema_item_set_argc_minmax( schema_item , int , int)")
cfunc.schema_alloc = cwrapper.prototype("c_void_p config_schema_item_alloc( char* , bool )")
cfunc.schema_free = cwrapper.prototype("void config_schema_item_free( schema_item )")
cfunc.schema_iget_type = cwrapper.prototype("int config_schema_item_iget_type( schema_item ,int)")
cfunc.schema_iset_type = cwrapper.prototype("void config_schema_item_iset_type( schema_item , int , int)")
cfunc.schema_set_argc_minmax = cwrapper.prototype("void config_schema_item_set_argc_minmax( schema_item , int , int)")
ContentItem.cNamespace().size = cwrapper.prototype("int config_content_item_get_size( content_item )")
ContentItem.cNamespace().iget_content_node = cwrapper.prototype("content_node_ref config_content_item_iget_node( content_item , int)")
cfunc.content_size = cwrapper.prototype("int config_content_item_get_size( content_item )")
cfunc.iget_content_node = cwrapper.prototype("int config_content_item_iget_node( content_item , int)")
cfunc.content_node_iget = cwrapper.prototype("char* config_content_node_iget( content_node , int)")
cfunc.content_node_size = cwrapper.prototype("int config_content_node_get_size( content_node )")
cfunc.content_full_string = cwrapper.prototype("char* config_content_node_get_full_string( content_node , char* )")
ContentNode.cNamespace().iget = cwrapper.prototype("char* config_content_node_iget( content_node , int)")
ContentNode.cNamespace().size = cwrapper.prototype("int config_content_node_get_size( content_node )")
ContentNode.cNamespace().get_full_string = cwrapper.prototype("char* config_content_node_get_full_string( content_node , char* )")

View File

@@ -0,0 +1,29 @@
# Copyright (C) 2013 Statoil ASA, Norway.
#
# The file 'content_type_enum.py' is part of ERT - Ensemble based Reservoir Tool.
#
# ERT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ERT is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.
#
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.cwrap import BaseCEnum
from ert.config import CONFIG_LIB
class ContentTypeEnum(BaseCEnum):
pass
ContentTypeEnum.populateEnum(CONFIG_LIB, "config_schema_item_type_enum_iget")
ContentTypeEnum.registerEnum(CONFIG_LIB, "config_content_type_enum")

View File

@@ -0,0 +1,24 @@
# Copyright (C) 2013 Statoil ASA, Norway.
#
# The file 'unrecognized_enum.py' is part of ERT - Ensemble based Reservoir Tool.
#
# ERT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ERT is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.
#
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.cwrap import BaseCEnum
from ert.config import CONFIG_LIB
class UnrecognizedEnum(BaseCEnum):
pass
UnrecognizedEnum.populateEnum(CONFIG_LIB, "config_schema_item_unrecognized_enum_iget")
UnrecognizedEnum.registerEnum(CONFIG_LIB, "config_unrecognized_enum")

View File

@@ -1,9 +1,12 @@
set(PYTHON_SOURCES
__init__.py
basecclass.py
basecenum.py
cclass.py
cenum.py
cfile.py
clib.py
cnamespace.py
cwrap.py
)

View File

@@ -43,4 +43,9 @@ from .cclass import CClass
from .cenum import create_enum
from .cfile import CFILE
from .clib import load, ert_lib_path, ert_load
from .cwrap import CWrapper, CWrapperNameSpace
from .cwrap import CWrapper, CWrapperNameSpace
from .cnamespace import CNamespace
from .basecclass import BaseCClass
from .basecenum import BaseCEnum

View File

@@ -0,0 +1,78 @@
import ctypes
from ert.cwrap import CNamespace
class BaseCClass(object):
namespaces = {}
def __init__(self, c_pointer, parent=None, is_reference=False):
self._c_pointer = None
self._parent = None
self._is_reference = False
if not c_pointer > 0:
raise ValueError("Must have a valid pointer value!")
self._c_pointer = c_pointer
self._parent = parent
self._is_reference = is_reference
@classmethod
def cNamespace(cls):
""" @rtype: CNamespace """
if not BaseCClass.namespaces.has_key(cls):
BaseCClass.namespaces[cls] = CNamespace(cls.__name__)
return BaseCClass.namespaces[cls]
@classmethod
def from_param(cls, c_class_object):
if not isinstance(c_class_object, BaseCClass):
raise ValueError("c_class_object must be an BaseCClass instance!")
if c_class_object is None or not hasattr(c_class_object, "_c_pointer"):
return ctypes.c_void_p()
else:
return ctypes.c_void_p(c_class_object._c_pointer)
@classmethod
def createPythonObject(cls, c_pointer):
if not c_pointer == 0:
new_obj = cls.__new__(cls)
BaseCClass.__init__(new_obj, c_pointer=c_pointer, parent=None, is_reference=False)
return new_obj
return None
@classmethod
def createCReference(cls, c_pointer, parent=None):
if not c_pointer == 0:
new_obj = cls.__new__(cls)
BaseCClass.__init__(new_obj, c_pointer=c_pointer, parent=parent, is_reference=True)
return new_obj
return None
def setParent(self, parent=None):
if self._is_reference:
self._parent = parent
else:
raise UserWarning("Can only set parent on reference types!")
return self
def isReference(self):
""" @rtype: bool """
return self._is_reference
def parent(self):
return self._parent
def free(self):
raise NotImplementedError("A CClass requires a free method implementation!")
def __del__(self):
if self.free is not None:
if hasattr(self, "_is_reference") and not self._is_reference:
# Important to check the c_pointer; in the case of failed object creation
# we can have a Python object with c_pointer == None.
if self._c_pointer > 0:
self.free()

View File

@@ -0,0 +1,141 @@
import ctypes
from ert.cwrap import CWrapper
class BaseCEnum(object):
enum_namespace = {}
def __init__(self, *args, **kwargs):
if not self in self.enum_namespace[self.__class__]:
raise NotImplementedError("Can not be instantiated directly!")
def __new__(cls, *args, **kwargs):
if len(args) == 1:
enum = cls.__resolveEnum(args[0])
if enum is None:
raise ValueError("Unknown enum value: %i" % args[0])
return enum
else:
obj = super(BaseCEnum, cls).__new__(cls, *args)
obj.name = None
obj.value = None
return obj
@classmethod
def from_param(cls, c_class_object):
if not isinstance(c_class_object, BaseCEnum):
raise ValueError("c_class_object must be an BaseCEnum instance!")
return c_class_object.value
@classmethod
def addEnum(cls, name, value):
if not isinstance(value, int):
raise ValueError("Value must be an integer!")
enum = cls.__new__(cls)
enum.name = name
enum.value = value
setattr(cls, name, enum)
if not cls.enum_namespace.has_key(cls):
cls.enum_namespace[cls] = []
cls.enum_namespace[cls].append(enum)
@classmethod
def enums(cls):
return list(cls.enum_namespace[cls])
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.value == other.value
if isinstance(other, int):
return self.value == other
return False
def __str__(self):
return self.name
def __add__(self, other):
self.__assertOtherIsSameType(other)
value = self.value + other.value
return self.__resolveOrCreateEnum(value)
def __or__(self, other):
self.__assertOtherIsSameType(other)
value = self.value | other.value
return self.__resolveOrCreateEnum(value)
def __xor__(self, other):
self.__assertOtherIsSameType(other)
value = self.value ^ other.value
return self.__resolveOrCreateEnum(value)
def __and__(self, other):
self.__assertOtherIsSameType(other)
value = self.value & other.value
return self.__resolveOrCreateEnum(value)
@classmethod
def __createEnum(cls, value):
enum = cls.__new__(cls)
enum.name = "Unnamed '%s' enum with value: %i" % (str(cls.__name__), value)
enum.value = value
return enum
@classmethod
def __resolveOrCreateEnum(cls, value):
enum = cls.__resolveEnum(value)
if enum is not None:
return enum
return cls.__createEnum(value)
@classmethod
def __resolveEnum(cls, value):
for enum in cls.enum_namespace[cls]:
if enum.value == value:
return enum
return None
def __assertOtherIsSameType(self, other):
assert isinstance(other, self.__class__), "Can only operate on enums of same type: %s =! %s" % (
self.__class__.__name__, other.__class__.__name__)
@classmethod
def populateEnum(cls, library, enum_provider_function):
try:
func = getattr(library, enum_provider_function)
except AttributeError:
raise ValueError("Could not find enum description function:%s - can not load enum:%s." % (enum_provider_function, cls.__name__))
func.restype = ctypes.c_char_p
func.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)]
index = 0
while True:
value = ctypes.c_int()
name = func(index, ctypes.byref(value))
if name:
cls.addEnum(name, value.value)
index += 1
else:
break
@classmethod
def registerEnum(cls, library, enum_name):
cwrapper = CWrapper(library)
cwrapper.registerType(enum_name, cls)

View File

@@ -16,6 +16,7 @@
import ctypes
class CClass(object):
"""
Base class used by all the classes wrapping a C 'class'.
@@ -86,38 +87,38 @@ class CClass(object):
C object.
"""
c_ptr = None
cfree = None
c_ptr = None
cfree = None
parent = None
@classmethod
def from_param( cls , obj ):
def from_param( cls, obj ):
if obj is None:
return ctypes.c_void_p()
else:
return ctypes.c_void_p( obj.c_ptr )
return ctypes.c_void_p(obj.c_ptr)
@classmethod
def asPythonObject( cls , c_ptr, cfree):
def asPythonObject( cls, c_ptr, cfree):
assert cfree is not None
obj = cls( )
obj.init_cobj( c_ptr , cfree)
obj = cls()
obj.init_cobj(c_ptr, cfree)
return obj
@classmethod
def asPythonReference( cls , c_ptr , parent ):
obj = cls( )
obj.init_cref( c_ptr , parent )
def asPythonReference( cls, c_ptr, parent ):
obj = cls()
obj.init_cref(c_ptr, parent)
return obj
def init_cref(self , c_ptr , parent):
def init_cref(self, c_ptr, parent):
self.c_ptr = c_ptr
self.parent = parent
self.cfree = None
def init_cobj( self , c_ptr , cfree):
def init_cobj( self, c_ptr, cfree):
self.c_ptr = c_ptr
self.parent = None
self.cfree = cfree
@@ -128,5 +129,5 @@ class CClass(object):
# Important to check the c_ptr; in the case of failed object creation
# we can have a Python object with c_ptr == None.
if self.c_ptr:
self.cfree( self )
self.cfree(self)

View File

@@ -0,0 +1,25 @@
class CNamespace(object):
def __init__(self, name):
object.__setattr__(self, "_name", name)
object.__setattr__(self, "_functions", {})
def __str__(self):
return "%s wrapper" % self._name
def __setitem__(self, key, value):
self.__setValue(key, value)
def __getitem__(self, item):
return self._functions[item]
def __setattr__(self, key, value):
self.__setValue(key, value)
def __setValue(self, key, value):
assert not hasattr(self, key), "The namespace %s already contains a function named %s!" % (self._name, key)
self._functions[key] = value
object.__setattr__(self, key, value)

View File

@@ -25,57 +25,56 @@ import re
import sys
prototype_pattern = "(?P<return>[a-zA-Z][a-zA-Z0-9_*]*) +(?P<function>[a-zA-Z]\w*) *[(](?P<arguments>[a-zA-Z0-9_*, ]*)[)]"
prototype_pattern = "(?P<return>[a-zA-Z][a-zA-Z0-9_*]*) +(?P<function>[a-zA-Z]\w*) *[(](?P<arguments>[a-zA-Z0-9_*, ]*)[)]"
class CWrapper:
# Observe that registered_types is a class attribute, shared
# between all CWrapper instances.
registered_types = {}
pattern = re.compile( prototype_pattern )
pattern = re.compile(prototype_pattern)
def __init__( self , lib ):
def __init__( self, lib ):
self.lib = lib
@classmethod
def registerType(cls, type, value ):
def registerType(cls, type_name, value):
"""Register a type against a legal ctypes type"""
cls.registered_types[type] = value
cls.registered_types[type_name] = value
@classmethod
def registerDefaultTypes(cls):
"""Registers the default available types for prototyping."""
cls.registerType("void" , None)
cls.registerType("c_ptr" , ctypes.c_void_p)
cls.registerType("int" , ctypes.c_int)
cls.registerType("int*" , ctypes.POINTER(ctypes.c_int))
cls.registerType("size_t" , ctypes.c_size_t)
cls.registerType("size_t*" , ctypes.POINTER(ctypes.c_size_t))
cls.registerType("bool" , ctypes.c_int)
cls.registerType("bool*" , ctypes.POINTER(ctypes.c_int))
cls.registerType("long" , ctypes.c_long)
cls.registerType("long*" , ctypes.POINTER(ctypes.c_long))
cls.registerType("char" , ctypes.c_char)
cls.registerType("char*" , ctypes.c_char_p)
cls.registerType("char**" , ctypes.POINTER(ctypes.c_char_p))
cls.registerType("float" , ctypes.c_float)
cls.registerType("float*" , ctypes.POINTER(ctypes.c_float))
cls.registerType("double" , ctypes.c_double)
cls.registerType("double*" , ctypes.POINTER(ctypes.c_double))
cls.registerType("void", None)
cls.registerType("c_ptr", ctypes.c_void_p)
cls.registerType("int", ctypes.c_int)
cls.registerType("int*", ctypes.POINTER(ctypes.c_int))
cls.registerType("size_t", ctypes.c_size_t)
cls.registerType("size_t*", ctypes.POINTER(ctypes.c_size_t))
cls.registerType("bool", ctypes.c_int)
cls.registerType("bool*", ctypes.POINTER(ctypes.c_int))
cls.registerType("long", ctypes.c_long)
cls.registerType("long*", ctypes.POINTER(ctypes.c_long))
cls.registerType("char", ctypes.c_char)
cls.registerType("char*", ctypes.c_char_p)
cls.registerType("char**", ctypes.POINTER(ctypes.c_char_p))
cls.registerType("float", ctypes.c_float)
cls.registerType("float*", ctypes.POINTER(ctypes.c_float))
cls.registerType("double", ctypes.c_double)
cls.registerType("double*", ctypes.POINTER(ctypes.c_double))
def __parseType(self, type):
def __parseType(self, type_name):
"""Convert a prototype definition type from string to a ctypes legal type."""
type = type.strip()
type_name = type_name.strip()
if CWrapper.registered_types.has_key(type):
return CWrapper.registered_types[type]
if CWrapper.registered_types.has_key(type_name):
return CWrapper.registered_types[type_name]
else:
return getattr(ctypes , type)
return getattr(ctypes, type_name)
def prototype(self, prototype , lib = None):
def prototype(self, prototype, lib=None):
"""
Defines the return type and arguments for a C-function
@@ -110,7 +109,7 @@ class CWrapper:
functioname = match.groupdict()["function"]
arguments = match.groupdict()["arguments"].split(",")
func = getattr(self.lib , functioname)
func = getattr(self.lib, functioname)
func.restype = self.__parseType(restype)
if len(arguments) == 1 and arguments[0].strip() == "":
@@ -123,26 +122,26 @@ class CWrapper:
return func
def safe_prototype(self,pattern , lib = None):
def safe_prototype(self, pattern, lib=None):
try:
func = self.prototype(pattern, lib)
except AttributeError:
func = None
sys.stderr.write("****Defunct function call: %s\n" % pattern)
return func
def print_types(self):
for ctype in self.registered_types.keys():
print "%16s -> %s" % (ctype , self.registered_types[ ctype ])
print "%16s -> %s" % (ctype, self.registered_types[ctype])
class CWrapperNameSpace:
def __init__( self , name ):
def __init__( self, name ):
self.name = name
def __str__(self):
return "%s wrapper" % self.name
CWrapper.registerDefaultTypes()

View File

@@ -12,8 +12,11 @@ SET(PYTHON_SOURCES
ecl_region.py
ecl_rft.py
ecl_rft_cell.py
ecl_smspec_node.py
ecl_subsidence.py
ecl_sum.py
ecl_sum_node.py
ecl_sum_vector.py
ecl_util.py
fortio.py

View File

@@ -21,7 +21,7 @@ C based functions.
"""
import os
import warnings
from ert.ecl import EclRFTFile, EclGrid, EclSum, EclUtil
from ert.ecl import EclRFTFile, EclGrid, EclSum, EclUtil, EclDefault, EclQueue
@@ -192,17 +192,17 @@ class EclCase:
argv = [ecl_version , self.datafile , num_cpu]
if ecl_cmd is None:
ecl_cmd = ecl_default.default.ecl_cmd
ecl_cmd = EclDefault.ecl_cmd()
if driver_type is None:
driver_type = ECL_DEFAULT.driver_type
driver_type = EclDefault.driver_type()
if ecl_version is None:
ecl_version = ECL_DEFAULT.ecl_version
ecl_version = EclDefault.ecl_version()
if driver is None:
if driver_options is None:
driver_options = ECL_DEFAULT.driver_options[ driver_type ]
driver_options = EclDefault.driver_options()[ driver_type ]
driver = queue_driver.Driver( driver_type , max_running = 0 , options = driver_options )
job = driver.submit( self.base , ecl_cmd , self.path , argv , blocking = blocking)
return job
@@ -222,5 +222,7 @@ class EclCase:
The @queue argument should be an existing EclQueue() instance
which will collect the jobs, and pass them on to a driver when
there is free capacity.
@type queue: EclQueue
"""
queue.submit( self.datafile )
queue.submitDatafile( self.datafile )

View File

@@ -157,10 +157,10 @@ class EclQueue(JobQueue):
driver_options = EclDefault.driver_options()[driver_type]
driver = Driver(driver_type, max_running=max_running, options=driver_options)
JobQueue.__init__(self, driver, size=size)
super(EclQueue, self).__init__(driver, size=size)
def submit( self, data_file):
def submitDataFile(self, data_file):
"""
Will submit a new simulation of case given by @data_file.
@@ -173,5 +173,5 @@ class EclQueue(JobQueue):
num_cpu = EclUtil.get_num_cpu(data_file)
argv = [self.ecl_version, path_base, "%s" % num_cpu]
return JobQueue.submit(self, self.ecl_cmd, run_path, base, argv, num_cpu=num_cpu)
return super(EclQueue, self).submit(self.ecl_cmd, run_path, base, argv, num_cpu=num_cpu)

View File

@@ -818,8 +818,10 @@ class EclRegion(CClass):
"""
IntVector instance with global indices in the region.
"""
c_ptr = cfunc.get_global_list( self )
global_list = IntVector.asPythonReference( c_ptr , self )
# c_ptr = cfunc.get_global_list( self )
# global_list = IntVector.asPythonReference( c_ptr , self )
global_list = cfunc.get_global_list(self)
global_list.setParent(self)
return global_list
@property
@@ -930,7 +932,7 @@ cfunc.xor = cwrapper.prototype("void ecl_region_xor( ecl_
cfunc.get_kw_index_list = cwrapper.prototype("c_void_p ecl_region_get_kw_index_list( ecl_region , ecl_kw , bool )")
cfunc.get_active_list = cwrapper.prototype("c_void_p ecl_region_get_active_list( ecl_region )")
cfunc.get_global_list = cwrapper.prototype("c_void_p ecl_region_get_global_list( ecl_region )")
cfunc.get_global_list = cwrapper.prototype("int_vector_ref ecl_region_get_global_list( ecl_region )")
cfunc.get_active_global = cwrapper.prototype("c_void_p ecl_region_get_global_active_list( ecl_region )")
cfunc.select_cmp_less = cwrapper.prototype("void ecl_region_cmp_select_less( ecl_region , ecl_kw , ecl_kw)")

View File

@@ -0,0 +1,122 @@
from ert.cwrap import BaseCClass, CWrapper
from ert.ecl import ECL_LIB
class EclSMSPECNode(BaseCClass):
"""
Small class with some meta information about a summary variable.
The summary variables have different attributes, like if they
represent a total quantity, a rate or a historical quantity. These
quantities, in addition to the underlying values like WGNAMES,
KEYWORD and NUMS taken from the the SMSPEC file are stored in this
structure.
"""
def __init__(self):
super(EclSMSPECNode, self).__init__(0) # null pointer
raise NotImplementedError("Class can not be instantiated directly!")
@property
def is_total(self):
"""
Will check if the node corresponds to a total quantity.
The question of whether a variable corresponds to a 'total'
quantity or not can be interesting for e.g. interpolation
purposes. The actual question whether a quantity is total or
not is based on a hardcoded list in smspec_node_set_flags() in
smspec_node.c; this list again is based on the tables 2.7 -
2.11 in the ECLIPSE fileformat documentation.
"""
return EclSMSPECNode.cNamespace().node_is_total(self)
@property
def is_rate(self):
"""
Will check if the variable in question is a rate variable.
The conecpt of rate variabel is important (internally) when
interpolation values to arbitrary times.
"""
return EclSMSPECNode.cNamespace().node_is_rate(self)
@property
def is_historical(self):
"""
Checks if the key corresponds to a historical variable.
The check is only based on the last character; all variables
ending with 'H' are considered historical.
"""
return EclSMSPECNode.cNamespace().node_is_historical(self)
@property
def unit(self):
"""
Returns the unit of this node as a string.
"""
return EclSMSPECNode.cNamespace().node_unit(self)
@property
def wgname(self):
"""
Returns the WGNAME property for this node.
Many variables do not have the WGNAME property, i.e. the field
related variables like FOPT and the block properties like
BPR:10,10,10. For these variables the function will return
None, and not the ECLIPSE dummy value: ":+:+:+:+".
"""
return EclSMSPECNode.cNamespace().node_wgname(self)
@property
def keyword(self):
"""
Returns the KEYWORD property for this node.
The KEYWORD property is the main classification property in
the ECLIPSE SMSPEC file. The properties of a variable can be
read from the KEWYORD value; see table 3.4 in the ECLIPSE file
format reference manual.
"""
return EclSMSPECNode.cNamespace().node_keyword(self)
@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 EclSMSPECNode.cNamespace().node_need_num(self):
return EclSMSPECNode.cNamespace().node_num(self)
else:
return None
cwrapper = CWrapper(ECL_LIB)
cwrapper.registerType("smspec_node", EclSMSPECNode)
cwrapper.registerType("smspec_node_obj", EclSMSPECNode.createPythonObject)
cwrapper.registerType("smspec_node_ref", EclSMSPECNode.createCReference)
EclSMSPECNode.cNamespace().node_is_total = cwrapper.prototype("bool smspec_node_is_total( smspec_node )")
EclSMSPECNode.cNamespace().node_is_historical = cwrapper.prototype("bool smspec_node_is_historical( smspec_node )")
EclSMSPECNode.cNamespace().node_is_rate = cwrapper.prototype("bool smspec_node_is_rate( smspec_node )")
EclSMSPECNode.cNamespace().node_unit = cwrapper.prototype("char* smspec_node_get_unit( smspec_node )")
EclSMSPECNode.cNamespace().node_wgname = cwrapper.prototype("char* smspec_node_get_wgname( smspec_node )")
EclSMSPECNode.cNamespace().node_keyword = cwrapper.prototype("char* smspec_node_get_keyword( smspec_node )")
EclSMSPECNode.cNamespace().node_num = cwrapper.prototype("int smspec_node_get_num( smspec_node )")
EclSMSPECNode.cNamespace().node_need_num = cwrapper.prototype("bool smspec_node_need_nums( smspec_node )")

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,27 @@
class EclSumNode:
def __init__(self, mini_step, report_step, days, date, mpl_date, value):
"""
EclSumNode is a 'struct' with a summary value and time.
EclSumNode - a small 'struct' with a summary value and time in
several formats. When iterating over a EclSumVector instance
you will get EclSumNode instances. The content of the
EclSumNode type is stored as plain attributes:
value : The actual value
report_step : The report step
mini_step : The ministep
days : Days since simulation start
date : The simulation date
mpl_date : A date format suitable for matplotlib
"""
self.value = value
self.report_step = report_step
self.mini_step = mini_step
self.days = days
self.date = date
self.mpl_date = mpl_date
def __str__(self):
return "<EclSumNode: days:%g value:%g>" % ( self.days, self.value )

View File

@@ -0,0 +1,281 @@
from ert.ecl.ecl_sum_node import EclSumNode
class EclSumVector:
def __init__(self, parent, key, report_only):
"""
A summary vector with a vector of values and time.
A summary vector contains the the full time history of one
key, along with the corresponding time vectors in several
different time formats. Depending on the report_only argument
the data vectors in the EclSumVector can either contain all
the time values, or only those corresponding to report_steps.
The EclSumVector contains a reference to the parent EclSum
structure and this is used to implement several of the
properties and methods of the object; the EclSum vector
instances should therefor only be instantiated through the
EclSum.get_vector() method, and not manually with the
EclSumVector() constructor.
"""
self.parent = parent
self.key = key
self.report_only = report_only
self.__dates = parent.get_dates(report_only)
self.__days = parent.get_days(report_only)
self.__mpl_dates = parent.get_mpl_dates(report_only)
self.__mini_step = parent.get_mini_step(report_only)
self.__report_step = parent.get_report_step(report_only)
self.__values = None
def __str__(self):
return "<Summary vector: %s>" % self.key
@property
def unit( self ):
"""
The unit of this vector.
"""
return self.parent.get_unit(self.key)
def assert_values( self ):
"""
This function will load and internalize all the values.
"""
if self.__values is None:
self.__values = self.parent.get_values(self.key, self.report_only)
@property
def values( self ):
"""
All the summary values of the vector, as a numpy vector.
"""
self.assert_values()
return self.__values
@property
def dates( self ):
"""
All the dates of the vector, list of datetime() instances.
"""
return self.__dates
@property
def days( self ):
"""
The time in days as a numpy vector.
In the case of lab unit this will be hours.
"""
return self.__days
@property
def mpl_dates( self ):
"""
All the dates as numpy vector of dates in matplotlib format.
"""
return self.__mpl_dates
@property
def mini_step( self ):
"""
All the ministeps of the vector.
Ministeps is the ECLIPSE notion of timesteps. The ministeps
are numbered sequentially starting at zero; if you have loaded
the entire simulation the ministep number will correspond to
the natural indexing. The length of each ministep is
determined by the convergence properties of the ECLIPSE
simulation.
"""
return self.__mini_step
@property
def report_step( self ):
"""
All the report_step of the vector.
"""
return self.__report_step
def __iget__( self, index ):
"""
Will return an EclSumNode for element @index; should be called
through the [] operator, otherwise you can come across
unitialized data.
"""
return EclSumNode(self.__mini_step[index],
self.__report_step[index],
self.__days[index],
self.__dates[index],
self.__mpl_dates[index],
self.__values[index])
def __len__(self):
"""
The length of the vector - used for the len() builtin.
"""
return len(self.__days)
def __getitem__(self, index):
"""
Implements the [] operator.
Will return EclSumNode instance according to @index. The index
value will be interpreted as in a normal python [] lookup,
i.e. negative values will be interpreted as starting from the
right and also slice notation is allowed[*].
[*] Observe that in the case of slices the return value will
not be a proper EclSumVector instance, but rather a normal
Python list of EclSumNode instances.
"""
self.assert_values()
length = len(self.values)
if isinstance(index, int):
if index < 0:
index += len(self.__values)
if index < 0 or index > length:
raise KeyError("Invalid index:%d out of range [0:%d)" % ( index, length))
else:
return self.__iget__(index)
elif isinstance(index, slice):
# Observe that the slice based lookup does __not__ return
# a proper EclSumVector instance; it will merely return
# a simple Python list with EclSumNode instances.
(start, stop, step) = index.indices(length)
index = start
sub_vector = []
while index < stop:
sub_vector.append(self.__iget__(index))
index += step
return sub_vector
raise KeyError("Invalid index:%s - must have integer or slice." % index)
@property
def first( self ):
"""
Will return the first EclSumNode in this vector.
"""
self.assert_values()
return self.__iget__(0)
@property
def last( self ):
"""
Will return the last EclSumNode in this vector.
"""
self.assert_values()
index = len(self.__values) - 1
return self.__iget__(index)
@property
def last_value( self ):
"""
Will return the last value in this vector.
"""
self.assert_values()
index = len(self.__values) - 1
return self.__iget__(index).value
def get_interp( self, days=None, date=None):
"""
Will lookup value interpolated to @days or @date.
The function requires one, and only one, time indicator in
terms of @days or @date. If the @date variable is given that
should be Python datetime instance.
vec = sum["WWCT:A-3"]
vec.get_interp( days = 100 )
vec.get_interp( date = datetime.date( year , month , day ))
This function will crash and burn if the time arguments are
invalid; if in doubt you should check first.
"""
return self.parent.get_interp(self.key, days, date)
def get_interp_vector( self, days_list=None, date_list=None):
"""
Will return Python list of interpolated values.
See get_interp() for further details.
"""
return self.parent.get_interp_vector(self.key, days_list, date_list)
def get_from_report( self, report_step ):
"""
Will lookup the value based on @report_step.
"""
return self.parent.get_from_report(self.key, report_step)
#################################################################
def first_gt_index( self, limit ):
"""
Locates first index where the value is above @limit.
Observe that this method will raise an exception if it is
called from a vector instance with report_only = True.
"""
if not self.report_only:
key_index = self.parent.cNamespace().get_general_var_index(self.parent, self.key)
time_index = self.parent.cNamespace().get_first_gt(self.parent, key_index, limit)
return time_index
else:
raise Exception("Sorry - first_gt_index() can not be called for vectors with report_only=True")
def first_gt( self, limit ):
"""
Locate the first EclSumNode where value is above @limit.
vec = sum["WWCT:A-3"]
w = vec.first_gt( 0.50 )
print "Water cut above 0.50 in well A-3 at: %s" % w.date
Uses first_gt_index() internally and can not be called for
vectors with report_only = True.
"""
time_index = self.first_gt_index(limit)
print time_index
if time_index >= 0:
return self.__iget__(time_index)
else:
return None
def first_lt_index( self, limit ):
"""
Locates first index where the value is below @limit.
See first_gt_index() for further details.
"""
if not self.report_only:
key_index = self.parent.cNamespace().get_general_var_index(self.parent, self.key)
time_index = self.parent.cNamespace().get_first_lt(self.parent, key_index, limit)
return time_index
else:
raise Exception("Sorry - first_lt_index() can not be called for vectors with report_only=True")
def first_lt( self, limit ):
"""
Locates first element where the value is below @limit.
See first_gt() for further details.
"""
time_index = self.first_lt_index(limit)
if time_index >= 0:
return self.__iget__(time_index)
else:
return None

Some files were not shown because too many files have changed in this diff Show More