Skip to content

Commit

Permalink
Merge pull request #415 from joakim-hove/summary-types
Browse files Browse the repository at this point in the history
Summary types
  • Loading branch information
joakim-hove authored Jun 4, 2018
2 parents 820832a + d969e87 commit f0e5f80
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 81 deletions.
97 changes: 50 additions & 47 deletions lib/ecl/smspec_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,32 +281,25 @@ static char LAST_CHAR(const char * s) {
return s[ strlen(s) - 1];
}

static void smspec_node_set_flags( smspec_node_type * smspec_node) {
/*
Check if this is a rate variabel - that info is used when
interpolating results to true_time between ministeps.
*/
{
const char *rate_vars[] = {"OPR" , "GPR" , "WPR" , "GOR" , "WCT"};
int num_rate_vars = sizeof( rate_vars ) / sizeof( rate_vars[0] );
bool is_rate = false;
int ivar;
for (ivar = 0; ivar < num_rate_vars; ivar++) {
const char * var_substring = &smspec_node->keyword[1];
if (strncmp( rate_vars[ivar] , var_substring , strlen( rate_vars[ivar] )) == 0) {
is_rate = true;
break;
}

bool smspec_node_identify_rate(const char * keyword) {
const char *rate_vars[] = {"OPR" , "GPR" , "WPR" , "LPR", "OIR", "GIR", "WIR", "LIR", "GOR" , "WCT"};
int num_rate_vars = sizeof( rate_vars ) / sizeof( rate_vars[0] );
bool is_rate = false;
int ivar;
for (ivar = 0; ivar < num_rate_vars; ivar++) {
const char * var_substring = &keyword[1];
if (strncmp( rate_vars[ivar] , var_substring , strlen( rate_vars[ivar] )) == 0) {
is_rate = true;
break;
}
smspec_node->rate_variable = is_rate;
}
return is_rate;
}

{
if (LAST_CHAR(smspec_node->keyword) == 'H')
smspec_node->historical = true;
}

/*
bool smspec_node_identify_total(const char * keyword, ecl_smspec_var_type var_type) {
/*
This code checks in a predefined list whether a certain WGNAMES
variable represents a total accumulated quantity. Only the last three
characters in the variable is considered (i.e. the leading 'W', 'G' or
Expand All @@ -316,34 +309,44 @@ static void smspec_node_set_flags( smspec_node_type * smspec_node) {
the tables 2.7 - 2.11 in the ECLIPSE fileformat documentation. Have
skipped some of the most exotic keywords.
*/
{
bool is_total = false;
if (smspec_node->var_type == ECL_SMSPEC_WELL_VAR ||
smspec_node->var_type == ECL_SMSPEC_GROUP_VAR ||
smspec_node->var_type == ECL_SMSPEC_FIELD_VAR ||
smspec_node->var_type == ECL_SMSPEC_REGION_VAR ||
smspec_node->var_type == ECL_SMSPEC_COMPLETION_VAR ) {
const char *total_vars[] = {"OPT" , "GPT" , "WPT" , "GIT", "WIT", "OPTF" , "OPTS" , "OIT" , "OVPT" , "OVIT" , "MWT" ,
"WVPT" , "WVIT" , "GMT" , "GPTF" , "SGT" , "GST" , "FGT" , "GCT" , "GIMT" ,
"WGPT" , "WGIT" , "EGT" , "EXGT" , "GVPT" , "GVIT" , "LPT" , "VPT" , "VIT" , "NPT" , "NIT"};

int num_total_vars = sizeof( total_vars ) / sizeof( total_vars[0] );
int ivar;
for (ivar = 0; ivar < num_total_vars; ivar++) {
const char * var_substring = &smspec_node->keyword[1];
/*
We want to mark both FOPT and FOPTH as historical variables;
we use strncmp() to make certain that the trailing 'H' is
not included in the comparison.
*/
if (strncmp( total_vars[ivar] , var_substring , strlen( total_vars[ivar] )) == 0) {
is_total = true;
break;
}
bool is_total = false;
if (var_type == ECL_SMSPEC_WELL_VAR ||
var_type == ECL_SMSPEC_GROUP_VAR ||
var_type == ECL_SMSPEC_FIELD_VAR ||
var_type == ECL_SMSPEC_REGION_VAR ||
var_type == ECL_SMSPEC_COMPLETION_VAR ) {
const char *total_vars[] = {"OPT" , "GPT" , "WPT" , "GIT", "WIT", "OPTF" , "OPTS" , "OIT" , "OVPT" , "OVIT" , "MWT" ,
"WVPT" , "WVIT" , "GMT" , "GPTF" , "SGT" , "GST" , "FGT" , "GCT" , "GIMT" ,
"WGPT" , "WGIT" , "EGT" , "EXGT" , "GVPT" , "GVIT" , "LPT" , "VPT" , "VIT" , "NPT" , "NIT"};

int num_total_vars = sizeof( total_vars ) / sizeof( total_vars[0] );
int ivar;
for (ivar = 0; ivar < num_total_vars; ivar++) {
const char * var_substring = &keyword[1];
/*
We want to mark both FOPT and FOPTH as total variables;
we use strncmp() to make certain that the trailing 'H' is
not included in the comparison.
*/
if (strncmp( total_vars[ivar] , var_substring , strlen( total_vars[ivar] )) == 0) {
is_total = true;
break;
}
}
smspec_node->total_variable = is_total;
}
return is_total;
}


static void smspec_node_set_flags( smspec_node_type * smspec_node) {
/*
Check if this is a rate variabel - that info is used when
interpolating results to true_time between ministeps.
*/
smspec_node->rate_variable = smspec_node_identify_rate(smspec_node->keyword);
if (LAST_CHAR(smspec_node->keyword) == 'H')
smspec_node->historical = true;
smspec_node->total_variable = smspec_node_identify_total(smspec_node->keyword, smspec_node->var_type);
}

/**
Expand Down
64 changes: 33 additions & 31 deletions lib/include/ert/ecl/smspec_node.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
Copyright (C) 2012 Statoil ASA, Norway.
The file 'smspec_node.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.
Copyright (C) 2012 Statoil ASA, Norway.
The file 'smspec_node.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.
*/


Expand Down Expand Up @@ -44,10 +44,10 @@ typedef enum {ECL_SMSPEC_INVALID_VAR = 0 ,
ECL_SMSPEC_REGION_VAR = 2 , /* X */
ECL_SMSPEC_GROUP_VAR = 3 , /* X */
ECL_SMSPEC_WELL_VAR = 4 , /* X */
ECL_SMSPEC_SEGMENT_VAR = 5 , /* X */
ECL_SMSPEC_SEGMENT_VAR = 5 , /* X */
ECL_SMSPEC_BLOCK_VAR = 6 , /* X */
ECL_SMSPEC_AQUIFER_VAR = 7 ,
ECL_SMSPEC_COMPLETION_VAR = 8 , /* X */
ECL_SMSPEC_COMPLETION_VAR = 8 , /* X */
ECL_SMSPEC_NETWORK_VAR = 9 ,
ECL_SMSPEC_REGION_2_REGION_VAR = 10 ,
ECL_SMSPEC_LOCAL_BLOCK_VAR = 11 , /* X */
Expand Down Expand Up @@ -88,22 +88,22 @@ typedef enum {ECL_SMSPEC_INVALID_VAR = 0 ,
const int grid_dims[3] ,
int num);

smspec_node_type * smspec_node_alloc( ecl_smspec_var_type var_type ,
const char * wgname ,
const char * keyword ,
const char * unit ,
const char * key_join_string ,
const int grid_dims[3] ,
smspec_node_type * smspec_node_alloc( ecl_smspec_var_type var_type ,
const char * wgname ,
const char * keyword ,
const char * unit ,
const char * key_join_string ,
const int grid_dims[3] ,
int num , int param_index, float default_value);

smspec_node_type * smspec_node_alloc_lgr( ecl_smspec_var_type var_type ,
const char * wgname ,
const char * keyword ,
const char * unit ,
const char * lgr ,
const char * key_join_string ,
smspec_node_type * smspec_node_alloc_lgr( ecl_smspec_var_type var_type ,
const char * wgname ,
const char * keyword ,
const char * unit ,
const char * lgr ,
const char * key_join_string ,
int lgr_i, int lgr_j , int lgr_k,
int param_index,
int param_index,
float default_value);

smspec_node_type * smspec_node_alloc_new(int params_index, float default_value);
Expand All @@ -112,7 +112,7 @@ typedef enum {ECL_SMSPEC_INVALID_VAR = 0 ,
void smspec_node_free( smspec_node_type * index );
void smspec_node_free__(void * arg);
void smspec_node_set_params_index( smspec_node_type * smspec_node , int params_index);
int smspec_node_get_params_index( const smspec_node_type * smspec_node );
int smspec_node_get_params_index( const smspec_node_type * smspec_node );
const char * smspec_node_get_gen_key1( const smspec_node_type * smspec_node);
const char * smspec_node_get_gen_key2( const smspec_node_type * smspec_node);
ecl_smspec_var_type smspec_node_get_var_type( const smspec_node_type * smspec_node);
Expand Down Expand Up @@ -141,6 +141,8 @@ typedef enum {ECL_SMSPEC_INVALID_VAR = 0 ,

int smspec_node_cmp( const smspec_node_type * node1, const smspec_node_type * node2);
int smspec_node_cmp__( const void * node1, const void * node2);
bool smspec_node_identify_total(const char * keyword, ecl_smspec_var_type var_type);
bool smspec_node_identify_rate(const char * keyword);

#ifdef __cplusplus
}
Expand Down
15 changes: 12 additions & 3 deletions python/ecl/summary/ecl_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class EclSum(BaseCClass):
_add_tstep = EclPrototype("ecl_sum_tstep_ref ecl_sum_add_tstep(ecl_sum, int, double)")
_export_csv = EclPrototype("void ecl_sum_export_csv(ecl_sum, char*, stringlist, char*, char*)")
_identify_var_type = EclPrototype("ecl_sum_var_type ecl_sum_identify_var_type(char*)", bind = False)
_is_rate = EclPrototype("bool smspec_node_identify_rate(char*)", bind = False)
_is_total = EclPrototype("bool smspec_node_identify_total(char*, ecl_sum_var_type)", bind = False)
_get_last_value = EclPrototype("double ecl_sum_get_last_value_gen_key(ecl_sum, char*)")
_get_first_value = EclPrototype("double ecl_sum_get_first_value_gen_key(ecl_sum, char*)")
_init_numpy_vector = EclPrototype("void ecl_sum_init_double_vector(ecl_sum, char*, double*)")
Expand Down Expand Up @@ -213,10 +215,17 @@ def createPythonObject(cls, c_pointer):
return result


@classmethod
def var_type(cls, keyword):
return cls._identify_var_type(keyword)
@staticmethod
def var_type(keyword):
return EclSum._identify_var_type(keyword)

@staticmethod
def is_rate(keyword):
return EclSum._is_rate(keyword)

@staticmethod
def is_total(keyword):
return EclSum._is_total(keyword, EclSum.var_type(keyword))

@staticmethod
def writer(case,
Expand Down
10 changes: 10 additions & 0 deletions python/tests/ecl_tests/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,13 @@ def test_pandas(self):
rows, columns = frame.shape
self.assertEqual(len(case.keys()), columns)
self.assertEqual(len(case), rows)


def test_total_and_rate(self):
self.assertTrue( EclSum.is_total("FOPT"))
self.assertTrue( EclSum.is_total("WWPT:OP_3"))
self.assertFalse( EclSum.is_total("RPR:2"))

self.assertTrue( EclSum.is_rate("WOPR:OP_4"))
self.assertFalse( EclSum.is_rate("BPR:123"))
self.assertTrue(EclSum.is_rate("FWIR"))

0 comments on commit f0e5f80

Please sign in to comment.