Skip to content

Commit

Permalink
WIP: Well rates (#1403)
Browse files Browse the repository at this point in the history
Well and connection rates
  • Loading branch information
Kjell Kongsvik committed Feb 6, 2017
1 parent 10f8bcb commit 361b2c9
Show file tree
Hide file tree
Showing 25 changed files with 394 additions and 82 deletions.
5 changes: 4 additions & 1 deletion libecl/include/ert/ecl/ecl_kw_magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ values (2e20) are denoted with '*'.
#define STARTSOL_KW "STARTSOL"
#define ENDSOL_KW "ENDSOL"

#define XWEL_KW "XWEL"
#define IWEL_KW "IWEL"
#define ZWEL_KW "ZWEL"
#define ICON_KW "ICON"
#define SCON_KW "SCON"
#define XCON_KW "XCON"
#define ISEG_KW "ISEG"
#define RSEG_KW "RSEG"

Expand All @@ -381,6 +383,7 @@ values (2e20) are denoted with '*'.

#define INTEHEAD_NWELLS_INDEX 16 // Number of wells
#define INTEHEAD_NIWELZ_INDEX 24 // Number of elements pr. well in the IWEL array.
#define INTEHEAD_NXWELZ_INDEX 26 // Number of elements pr. well in the XWEL array.
#define INTEHEAD_NZWELZ_INDEX 27 // Number of 8 character words pr. well

#define INTEHEAD_NCWMAX_INDEX 17 // Maximum number of completions per well
Expand All @@ -390,7 +393,7 @@ values (2e20) are denoted with '*'.
#define INTEHEAD_NXWELZ_INDEX 26
#define INTEHEAD_NICONZ_INDEX 32 // Number of elements pr completion in the ICON array.
#define INTEHEAD_NSCONZ_INDEX 33 // Number of elements pr completion in the SCON array
#define INTEHEAD_NXCONZ_INDEX 34
#define INTEHEAD_NXCONZ_INDEX 34 // Number of elements pr completion in the XCON array
#define INTEHEAD_NIGRPZ_INDEX 36 // Number of elements pr group in the IGRP array.


Expand Down
2 changes: 2 additions & 0 deletions libecl/include/ert/ecl/ecl_rsthead.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ extern "C" {
int nwells; // Number of wells
int niwelz; // Number of elements pr well in IWEL array
int nzwelz; // Number of 8 character words pr well in ZWEL array
int nxwelz; // Number of elements pr well in XWEL array.

// Connection properties
int niconz; // Number of elements per completion in ICON array
int ncwmax; // Maximum number of completions per well
int nsconz; // Number of elements per completion in SCON array
int nxconz; // Number of elements per completion in XCON array

// Segment properties
int nisegz; // Number of entries pr segment in the ISEG array
Expand Down
3 changes: 2 additions & 1 deletion libecl/src/ecl_rsthead.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ ecl_rsthead_type * ecl_rsthead_alloc_from_kw( int report_step , const ecl_kw_typ

rsthead->nwells = data[INTEHEAD_NWELLS_INDEX];
rsthead->niwelz = data[INTEHEAD_NIWELZ_INDEX];
rsthead->nxwelz = data[INTEHEAD_NXWELZ_INDEX];
rsthead->nzwelz = data[INTEHEAD_NZWELZ_INDEX];

rsthead->nsconz = data[INTEHEAD_NSCONZ_INDEX];
rsthead->nxconz = data[INTEHEAD_NXCONZ_INDEX];
rsthead->niconz = data[INTEHEAD_NICONZ_INDEX];
rsthead->ncwmax = data[INTEHEAD_NCWMAX_INDEX];

Expand Down
3 changes: 2 additions & 1 deletion libecl_well/applications/segment_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int main(int argc , char ** argv) {
well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(ecl_file_get_global_view(rst_file));
const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );
const ecl_kw_type * scon_kw = ecl_file_iget_named_kw( rst_file , SCON_KW , 0 );
const ecl_kw_type * xcon_kw = ecl_file_iget_named_kw( rst_file , XCON_KW , 0 );
const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( rst_file , ZWEL_KW , 0 );

{
Expand All @@ -62,7 +63,7 @@ int main(int argc , char ** argv) {
if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_loader , rst_head , load_segment_information , &is_MSW_well)) {
well_branch_collection_type * branches = well_branch_collection_alloc();

well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , scon_kw , well_nr , rst_head);
well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , scon_kw, xcon_kw , well_nr , rst_head);
well_segment_collection_link( segments );
well_segment_collection_add_branches( segments , branches );
well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections );
Expand Down
15 changes: 13 additions & 2 deletions libecl_well/include/ert/ecl_well/well_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {

bool well_conn_MSW(const well_conn_type * conn);

well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw , const ecl_kw_type * scon_kw , const ecl_rsthead_type * header , int well_nr , int conn_nr);
well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw , const ecl_kw_type * scon_kw , const ecl_kw_type* xcon_kw, const ecl_rsthead_type * header , int well_nr , int conn_nr);
well_conn_type * well_conn_alloc_wellhead( const ecl_kw_type * iwel_kw , const ecl_rsthead_type * header , int well_nr);

int well_conn_get_i(const well_conn_type * conn);
Expand All @@ -67,7 +67,18 @@ extern "C" {
bool well_conn_equal( const well_conn_type *conn1 , const well_conn_type * conn2);
double well_conn_get_connection_factor( const well_conn_type * conn );

UTIL_IS_INSTANCE_HEADER( well_conn );
double well_conn_get_oil_rate(const well_conn_type *conn);
double well_conn_get_gas_rate(const well_conn_type *conn);
double well_conn_get_water_rate(const well_conn_type *conn);
double well_conn_get_volume_rate(const well_conn_type *conn);

double well_conn_get_oil_rate_si(const well_conn_type *conn);
double well_conn_get_gas_rate_si(const well_conn_type *conn);
double well_conn_get_water_rate_si(const well_conn_type *conn);
double well_conn_get_volume_rate_si(const well_conn_type *conn);


UTIL_IS_INSTANCE_HEADER( well_conn );
UTIL_SAFE_CAST_HEADER( well_conn );


Expand Down
2 changes: 1 addition & 1 deletion libecl_well/include/ert/ecl_well/well_conn_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
well_conn_type * well_conn_collection_iget(const well_conn_collection_type * wellcc , int index);
void well_conn_collection_add( well_conn_collection_type * wellcc , well_conn_type * conn);
void well_conn_collection_add_ref( well_conn_collection_type * wellcc , well_conn_type * conn);
int well_conn_collection_load_from_kw( well_conn_collection_type * wellcc , const ecl_kw_type * iwel_kw , const ecl_kw_type * icon_kw , const ecl_kw_type * scon_kw , int iwell , const ecl_rsthead_type * rst_head);
int well_conn_collection_load_from_kw( well_conn_collection_type * wellcc , const ecl_kw_type * iwel_kw , const ecl_kw_type * icon_kw , const ecl_kw_type * scon_kw , const ecl_kw_type * xcon_kw , int iwell , const ecl_rsthead_type * rst_head);

UTIL_IS_INSTANCE_HEADER( well_conn_collection );

Expand Down
29 changes: 24 additions & 5 deletions libecl_well/include/ert/ecl_well/well_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ extern "C" {
#define ISEG_OUTLET_INDEX 1
#define ISEG_BRANCH_INDEX 3

#define XWEL_RES_WRAT_ITEM 1
#define XWEL_RES_GRAT_ITEM 2
#define XWEL_RES_ORAT_ITEM 3
#define XWEL_RESV_ITEM 4


#define ICON_IC_INDEX 0
#define ICON_I_INDEX 1
#define ICON_J_INDEX 2
Expand All @@ -98,6 +104,10 @@ extern "C" {
#define ICON_DEFAULT_DIR_TARGET ICON_DIRZ

#define SCON_CF_INDEX 0

#define XCON_WRAT_INDEX 46
#define XCON_GRAT_INDEX 47
#define XCON_ORAT_INDEX 48
#define XCON_QR_INDEX 49

#define RSEG_LENGTH_INDEX 0
Expand All @@ -121,11 +131,20 @@ extern "C" {
#define IWEL_GAS_INJECTOR 4

typedef enum {
ERT_UNDOCUMENTED_ZERO = 0,
ERT_PRODUCER = 10,
ERT_WATER_INJECTOR = 22,
ERT_GAS_INJECTOR = 21,
ERT_OIL_INJECTOR = 78
ERT_UNDOCUMENTED_ZERO = 0, // Deprecated - retained for Resinsight compatibility
ECL_WELL_ZERO = 0,

ERT_PRODUCER = 1, // Deprecated
ECL_WELL_PRODUCER = 1,

ERT_OIL_INJECTOR = 2, // Deprecated
ECL_WELL_OIL_INJECTOR = 2,

ERT_WATER_INJECTOR = 3, // Deprecated
ECL_WELL_WATER_INJECTOR = 3,

ERT_GAS_INJECTOR = 4, // Deprecated
ECL_WELL_GAS_INJECTOR = 4,
} well_type_enum;

#ifdef __cplusplus
Expand Down
16 changes: 11 additions & 5 deletions libecl_well/include/ert/ecl_well/well_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ extern "C" {
#define GLOBAL_GRID_NAME "GLOBAL" // The name assigned to the global grid for name based lookup.

typedef struct well_state_struct well_state_type;
well_state_type * well_state_alloc(const char * well_name , int global_well_nr , bool open, well_type_enum type , int report_nr, time_t valid_from);
well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_step , int well_nr , bool load_segment_information);
well_state_type * well_state_alloc_from_file2( ecl_file_view_type * file_view , const ecl_grid_type * grid , int report_nr , int global_well_nr ,bool load_segment_information);

well_state_type * well_state_alloc(const char * well_name , int global_well_nr , bool open, well_type_enum type , int report_nr, time_t valid_from);
well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_step , int well_nr , bool load_segment_information);
well_state_type * well_state_alloc_from_file2( ecl_file_view_type * file_view , const ecl_grid_type * grid , int report_nr , int global_well_nr ,bool load_segment_information);

void well_state_add_connections2( well_state_type * well_state ,
const ecl_grid_type * grid ,
ecl_file_view_type * rst_view ,
Expand Down Expand Up @@ -93,6 +93,12 @@ extern "C" {
bool well_state_has_grid_connections( const well_state_type * well_state , const char * grid_name);
bool well_state_has_global_connections( const well_state_type * well_state );

double well_state_get_oil_rate( const well_state_type * well_state );
double well_state_get_gas_rate( const well_state_type * well_state );
double well_state_get_water_rate( const well_state_type * well_state);
double well_state_get_volume_rate( const well_state_type * well_state);


UTIL_IS_INSTANCE_HEADER( well_state );

#ifdef __cplusplus
Expand Down
54 changes: 51 additions & 3 deletions libecl_well/src/well_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ struct well_conn_struct {
int segment_id; // -1: Ordinary well
bool matrix_connection; // k >= nz => fracture (and k -= nz )
double connection_factor;
double oil_rate;
double gas_rate;
double water_rate;
double volume_rate;

};


Expand Down Expand Up @@ -102,6 +107,11 @@ static well_conn_type * well_conn_alloc__( int i , int j , int k , double connec
else
conn->segment_id = segment_id;

conn->water_rate = 0;
conn->gas_rate = 0;
conn->oil_rate = 0;
conn->volume_rate = 0;

return conn;
} else {
printf("assert-direction failed. dir:%d matrix_connection:%d \n",dir , matrix_connection);
Expand Down Expand Up @@ -141,6 +151,7 @@ well_conn_type * well_conn_alloc_fracture_MSW( int i , int j , int k , double co
*/
well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw ,
const ecl_kw_type * scon_kw ,
const ecl_kw_type * xcon_kw ,
const ecl_rsthead_type * header ,
int well_nr ,
int conn_nr ) {
Expand Down Expand Up @@ -211,9 +222,15 @@ well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw ,
connection_factor = ecl_kw_iget_as_double(scon_kw , scon_offset + SCON_CF_INDEX);
}

{
int segment_id = ecl_kw_iget_int( icon_kw , icon_offset + ICON_SEGMENT_INDEX ) - ECLIPSE_WELL_SEGMENT_OFFSET + WELL_SEGMENT_OFFSET;
conn = well_conn_alloc__(i,j,k,connection_factor,dir,open,segment_id,matrix_connection);
int segment_id = ecl_kw_iget_int( icon_kw , icon_offset + ICON_SEGMENT_INDEX ) - ECLIPSE_WELL_SEGMENT_OFFSET + WELL_SEGMENT_OFFSET;
conn = well_conn_alloc__(i,j,k,connection_factor,dir,open,segment_id,matrix_connection);

if (xcon_kw) {
const int xcon_offset = header->nxconz * (header->ncwmax * well_nr + conn_nr);
conn->water_rate = ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_WRAT_INDEX);
conn->gas_rate = ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_GRAT_INDEX);
conn->oil_rate = ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_ORAT_INDEX);
conn->volume_rate = ecl_kw_iget_double(xcon_kw, xcon_offset + XCON_QR_INDEX);
}

/**
Expand Down Expand Up @@ -310,3 +327,34 @@ bool well_conn_matrix_connection( const well_conn_type * conn) {
return conn->matrix_connection;
}

double well_conn_get_oil_rate(const well_conn_type *conn) {
return conn->oil_rate;
}

double well_conn_get_gas_rate(const well_conn_type *conn) {
return conn->gas_rate;
}

double well_conn_get_water_rate(const well_conn_type *conn) {
return conn->water_rate;
}

double well_conn_get_volume_rate(const well_conn_type *conn) {
return conn->volume_rate;
}

double well_conn_get_oil_rate_si(const well_conn_type *conn) {
return conn->oil_rate;
}

double well_conn_get_gas_rate_si(const well_conn_type *conn) {
return conn->gas_rate;
}

double well_conn_get_water_rate_si(const well_conn_type *conn) {
return conn->water_rate;
}

double well_conn_get_volume_rate_si(const well_conn_type *conn) {
return conn->volume_rate;
}
3 changes: 2 additions & 1 deletion libecl_well/src/well_conn_collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ int well_conn_collection_load_from_kw( well_conn_collection_type * wellcc ,
const ecl_kw_type * iwel_kw ,
const ecl_kw_type * icon_kw ,
const ecl_kw_type * scon_kw ,
const ecl_kw_type * xcon_kw ,
int iwell ,
const ecl_rsthead_type * rst_head) {

Expand All @@ -112,7 +113,7 @@ int well_conn_collection_load_from_kw( well_conn_collection_type * wellcc ,
int iconn;

for (iconn = 0; iconn < num_connections; iconn++) {
well_conn_type * conn = well_conn_alloc_from_kw( icon_kw , scon_kw , rst_head , iwell , iconn );
well_conn_type * conn = well_conn_alloc_from_kw( icon_kw , scon_kw, xcon_kw, rst_head , iwell , iconn );
if (conn)
well_conn_collection_add( wellcc , conn );
}
Expand Down
Loading

0 comments on commit 361b2c9

Please sign in to comment.