Updated ERT, opm-common and opm-parser

ERT 80650d05d49b419ec74ba316312313dfc6ba0875
opm-common e7db252f3e310a04718f315e6cdb9d6c428c5762
opm-parser 817722b99baa62cc63a5f859cc90b951f0b0636e
This commit is contained in:
Magne Sjaastad
2016-06-13 14:18:50 +02:00
parent 6a8ffb7c6b
commit da76b01611
629 changed files with 10346 additions and 7232 deletions

View File

@@ -16,8 +16,8 @@
for more details.
*/
#ifndef __ANALYSIS_MODULE_H__
#define __ANALYSIS_MODULE_H__
#ifndef ERT_ANALYSIS_MODULE_H
#define ERT_ANALYSIS_MODULE_H
#ifdef __cplusplus
extern "C" {
#endif

View File

@@ -1,5 +1,5 @@
#ifndef __ANALYSIS_TABLE_H__
#define __ANALYSIS_TABLE_H__
#ifndef ERT_ANALYSIS_TABLE_H
#define ERT_ANALYSIS_TABLE_H
#ifdef __cplusplus
extern "C" {

View File

@@ -1,5 +1,5 @@
#ifndef __ENKF_LINALG_H__
#define __ENKF_LINALG_H__
#ifndef ERT_ENKF_LINALG_H
#define ERT_ENKF_LINALG_H
#include <ert/util/matrix_lapack.h>
#include <ert/util/matrix.h>

View File

@@ -1,5 +1,5 @@
#ifndef __STD_ENKF_H__
#define __STD_ENKF_H__
#ifndef ERT_STD_ENKF_H
#define ERT_STD_ENKF_H
#ifdef __cplusplus
extern "C" {

View File

@@ -1,5 +1,5 @@
#ifndef __RML_ENKF_COMMON_H__
#define __RML_ENKF_COMMON_H__
#ifndef ERT_RML_ENKF_COMMON_H
#define ERT_RML_ENKF_COMMON_H
#include <stdbool.h>

View File

@@ -1,26 +1,26 @@
/*
copyright (C) 2011 Statoil ASA, Norway.
The file 'fwd_step_enkf.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.
copyright (C) 2011 Statoil ASA, Norway.
The file 'fwd_step_enkf.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 <string.h>
#include <math.h>
#include <stdio.h>
#include <ert/util/type_macros.h>
#include <ert/util/util.h>
#include <ert/util/rng.h>
@@ -39,15 +39,17 @@
#define DEFAULT_R2_LIMIT 0.99
#define NFOLDS_KEY "CV_NFOLDS"
#define R2_LIMIT_KEY "FWD_STEP_R2_LIMIT"
#define DEFAULT_VERBOSE false
#define VERBOSE_KEY "VERBOSE"
struct fwd_step_enkf_data_struct {
UTIL_TYPE_ID_DECLARATION;
stepwise_type * stepwise_data;
stepwise_type * stepwise_data;
rng_type * rng;
int nfolds;
long option_flags;
double r2_limit;
bool verbose;
};
@@ -63,106 +65,123 @@ void fwd_step_enkf_set_r2_limit( fwd_step_enkf_data_type * data , double limit )
data->r2_limit = limit;
}
void fwd_step_enkf_set_verbose( fwd_step_enkf_data_type * data , bool verbose ) {
data->verbose = verbose;
}
void * fwd_step_enkf_data_alloc( rng_type * rng ) {
fwd_step_enkf_data_type * data = util_malloc( sizeof * data );
UTIL_TYPE_ID_INIT( data , FWD_STEP_ENKF_TYPE_ID );
data->stepwise_data = NULL;
data->rng = rng;
data->nfolds = DEFAULT_NFOLDS;
data->r2_limit = DEFAULT_R2_LIMIT;
data->option_flags = ANALYSIS_NEED_ED + ANALYSIS_UPDATE_A + ANALYSIS_SCALE_DATA;
data->verbose = DEFAULT_VERBOSE;
return data;
}
/*Main function: */
void fwd_step_enkf_updateA(void * module_data ,
matrix_type * A ,
matrix_type * S ,
matrix_type * R ,
matrix_type * dObs ,
void fwd_step_enkf_updateA(void * module_data ,
matrix_type * A ,
matrix_type * S ,
matrix_type * R ,
matrix_type * dObs ,
matrix_type * E ,
matrix_type * D ) {
fwd_step_enkf_data_type * fwd_step_data = fwd_step_enkf_data_safe_cast( module_data );
printf("Running Forward Stepwise regression:\n");
{
int ens_size = matrix_get_columns( S );
int nx = matrix_get_rows( A );
int nd = matrix_get_rows( S );
int ens_size = matrix_get_columns( S );
int nx = matrix_get_rows( A );
int nd = matrix_get_rows( S );
int nfolds = fwd_step_data->nfolds;
double r2_limit = fwd_step_data->r2_limit;
bool verbose = fwd_step_data->verbose;
if ( ens_size <= nfolds)
util_abort("%s: The number of ensembles must be larger than the CV fold - aborting\n", __func__);
{
stepwise_type * stepwise_data = stepwise_alloc1(ens_size, nd , fwd_step_data->rng);
matrix_type * workS = matrix_alloc( ens_size , nd );
matrix_type * workE = matrix_alloc( ens_size , nd );
/*workS = S' */
for (int i = 0; i < nd; i++) {
for (int j = 0; j < ens_size; j++) {
matrix_iset( workS , j , i , matrix_iget( S , i , j ) );
}
}
/*This might be illigal???? */
matrix_subtract_row_mean( S ); /* Shift away the mean */
workS = matrix_alloc_transpose( S );
workE = matrix_alloc_transpose( E );
stepwise_set_X0( stepwise_data , workS );
double xHat;
stepwise_set_E0( stepwise_data , workE );
matrix_type * di = matrix_alloc( 1 , nd );
printf("nx = %d\n",nx);
if (verbose){
printf("===============================================================================================================================\n");
printf("Total number of parameters : %d\n",nx);
printf("Total number of observations: %d\n",nd);
printf("Number of ensembles : %d\n",ens_size);
printf("CV folds : %d\n",nfolds);
printf("Relative R2 tolerance : %f\n",r2_limit);
printf("===============================================================================================================================\n");
printf("%-15s%-15s%-15s%-15s\n", "Parameter", "NumAttached", "FinalR2", "ActiveIndices");
}
for (int i = 0; i < nx; i++) {
/*Update values of y */
/*Start of the actual update */
matrix_type * y = matrix_alloc( ens_size , 1 );
for (int j = 0; j < ens_size; j++) {
matrix_iset(y , j , 0 , matrix_iget( A, i , j ) );
}
/*This might be illigal???? */
stepwise_set_Y0( stepwise_data , y );
stepwise_estimate(stepwise_data , fwd_step_data->r2_limit , fwd_step_data->nfolds );
stepwise_estimate(stepwise_data , r2_limit , nfolds );
/*manipulate A directly*/
for (int j = 0; j < ens_size; j++) {
for (int k = 0; k < nd; k++) {
matrix_iset(di , 0 , k , matrix_iget( D , k , j ) );
}
xHat = stepwise_eval(stepwise_data , di );
matrix_iset(A , i , j , xHat);
double aij = matrix_iget( A , i , j );
double xHat = stepwise_eval(stepwise_data , di );
matrix_iset(A , i , j , aij + xHat);
}
if (verbose)
stepwise_printf(stepwise_data, i);
}
if (verbose)
printf("===============================================================================================================================\n");
printf("Done with stepwise regression enkf\n");
stepwise_free( stepwise_data );
matrix_free( di );
/*workS is freed in stepwise_free() */
/*matrix_free( workS ); */
/*matrix_free( y );*/
}
}
}
@@ -201,13 +220,28 @@ bool fwd_step_enkf_set_int( void * arg , const char * var_name , int value) {
fwd_step_enkf_data_type * module_data = fwd_step_enkf_data_safe_cast( arg );
{
bool name_recognized = true;
/*Set number of CV folds */
if (strcmp( var_name , NFOLDS_KEY) == 0)
fwd_step_enkf_set_nfolds( module_data , value);
else
name_recognized = false;
return name_recognized;
}
}
bool fwd_step_enkf_set_bool( void * arg , const char * var_name , bool value) {
fwd_step_enkf_data_type * module_data = fwd_step_enkf_data_safe_cast( arg );
{
bool name_recognized = true;
/*Set verbose */
if (strcmp( var_name , VERBOSE_KEY) == 0)
fwd_step_enkf_set_verbose( module_data , value);
else
name_recognized = false;
return name_recognized;
}
}
@@ -225,6 +259,8 @@ bool fwd_step_enkf_has_var( const void * arg, const char * var_name) {
return true;
else if (strcmp(var_name , R2_LIMIT_KEY ) == 0)
return true;
else if (strcmp(var_name , VERBOSE_KEY ) == 0)
return true;
else
return false;
}
@@ -250,6 +286,15 @@ int fwd_step_enkf_get_int( const void * arg, const char * var_name) {
}
}
bool fwd_step_enkf_get_bool( const void * arg, const char * var_name) {
const fwd_step_enkf_data_type * module_data = fwd_step_enkf_data_safe_cast_const( arg );
{
if (strcmp(var_name , VERBOSE_KEY) == 0)
return module_data->verbose;
else
return false;
}
}
@@ -263,19 +308,19 @@ int fwd_step_enkf_get_int( const void * arg, const char * var_name) {
analysis_table_type SYMBOL_TABLE = {
.alloc = fwd_step_enkf_data_alloc,
.freef = fwd_step_enkf_data_free,
.set_int = fwd_step_enkf_set_int ,
.set_double = fwd_step_enkf_set_double ,
.set_bool = NULL ,
.set_string = NULL ,
.get_options = fwd_step_enkf_get_options ,
.initX = NULL ,
.set_int = fwd_step_enkf_set_int ,
.set_double = fwd_step_enkf_set_double ,
.set_bool = fwd_step_enkf_set_bool ,
.set_string = NULL ,
.get_options = fwd_step_enkf_get_options ,
.initX = NULL ,
.updateA = fwd_step_enkf_updateA,
.init_update = NULL ,
.complete_update = NULL ,
.has_var = fwd_step_enkf_has_var,
.get_int = fwd_step_enkf_get_int ,
.get_double = fwd_step_enkf_get_double ,
.get_bool = NULL ,
.get_bool = fwd_step_enkf_get_bool ,
.get_ptr = NULL
};