2013-08-26 06:56:42 -05:00
|
|
|
/*
|
2019-05-07 00:15:25 -05:00
|
|
|
Copyright (C) 2013 Equinor ASA, Norway.
|
2015-04-14 08:47:22 -05:00
|
|
|
|
|
|
|
The file 'well_conn_collection.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.
|
2013-08-26 06:56:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2019-05-07 00:15:25 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2018-08-13 03:20:34 -05:00
|
|
|
#include <ert/util/util.h>
|
2018-05-04 07:06:42 -05:00
|
|
|
#include <ert/util/type_macros.hpp>
|
2013-08-26 06:56:42 -05:00
|
|
|
|
2018-05-04 07:06:42 -05:00
|
|
|
#include <ert/ecl/ecl_kw.hpp>
|
|
|
|
#include <ert/ecl/ecl_rsthead.hpp>
|
2013-08-26 06:56:42 -05:00
|
|
|
|
2018-05-04 07:06:42 -05:00
|
|
|
#include <ert/ecl_well/well_const.hpp>
|
|
|
|
#include <ert/ecl_well/well_conn.hpp>
|
|
|
|
#include <ert/ecl_well/well_conn_collection.hpp>
|
2013-08-26 06:56:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
#define WELL_CONN_COLLECTION_TYPE_ID 67150087
|
|
|
|
|
|
|
|
struct well_conn_collection_struct {
|
|
|
|
UTIL_TYPE_ID_DECLARATION;
|
2019-05-07 00:15:25 -05:00
|
|
|
std::vector<well_conn_type*> connection_list;
|
|
|
|
std::vector<bool> connection_list_owned;
|
2013-08-26 06:56:42 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UTIL_IS_INSTANCE_FUNCTION( well_conn_collection , WELL_CONN_COLLECTION_TYPE_ID )
|
|
|
|
static UTIL_SAFE_CAST_FUNCTION( well_conn_collection , WELL_CONN_COLLECTION_TYPE_ID )
|
|
|
|
|
|
|
|
|
|
|
|
well_conn_collection_type * well_conn_collection_alloc() {
|
2019-05-07 00:15:25 -05:00
|
|
|
well_conn_collection_type * wellcc = new well_conn_collection_type();
|
2013-08-26 06:56:42 -05:00
|
|
|
UTIL_TYPE_ID_INIT( wellcc , WELL_CONN_COLLECTION_TYPE_ID );
|
|
|
|
return wellcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
The collection takes ownership of the connection object and frees it
|
2015-04-14 08:47:22 -05:00
|
|
|
when the collection is discarded.
|
2013-08-26 06:56:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
void well_conn_collection_add( well_conn_collection_type * wellcc , well_conn_type * conn) {
|
2019-05-07 00:15:25 -05:00
|
|
|
wellcc->connection_list.push_back(conn);
|
|
|
|
wellcc->connection_list_owned.push_back(true);
|
2013-08-26 06:56:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-04-14 08:47:22 -05:00
|
|
|
The collection only stores a refernce to the object, which will be destroyed by 'someone else'.
|
2013-08-26 06:56:42 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
void well_conn_collection_add_ref( well_conn_collection_type * wellcc , well_conn_type * conn) {
|
2019-05-07 00:15:25 -05:00
|
|
|
wellcc->connection_list.push_back(conn);
|
|
|
|
wellcc->connection_list_owned.push_back(false);
|
2013-08-26 06:56:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void well_conn_collection_free( well_conn_collection_type * wellcc ) {
|
2019-05-07 00:15:25 -05:00
|
|
|
for (size_t i = 0; i < wellcc->connection_list.size(); i++)
|
|
|
|
if (wellcc->connection_list_owned[i])
|
|
|
|
well_conn_free(wellcc->connection_list[i]);
|
|
|
|
delete wellcc;
|
2013-08-26 06:56:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void well_conn_collection_free__( void * arg ) {
|
|
|
|
well_conn_collection_type * wellcc = well_conn_collection_safe_cast( arg );
|
|
|
|
well_conn_collection_free( wellcc );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int well_conn_collection_get_size( const well_conn_collection_type * wellcc ) {
|
2019-05-07 00:15:25 -05:00
|
|
|
return wellcc->connection_list.size();
|
2013-08-26 06:56:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const well_conn_type * well_conn_collection_iget_const(const well_conn_collection_type * wellcc , int index) {
|
|
|
|
int size = well_conn_collection_get_size( wellcc );
|
|
|
|
if (index < size)
|
2019-05-07 00:15:25 -05:00
|
|
|
return wellcc->connection_list[index];
|
2013-08-26 06:56:42 -05:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-05-04 07:06:42 -05:00
|
|
|
|
2013-08-26 06:56:42 -05:00
|
|
|
well_conn_type * well_conn_collection_iget(const well_conn_collection_type * wellcc , int index) {
|
|
|
|
int size = well_conn_collection_get_size( wellcc );
|
|
|
|
if (index < size)
|
2019-05-07 00:15:25 -05:00
|
|
|
return wellcc->connection_list[index];
|
2013-08-26 06:56:42 -05:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-14 08:47:22 -05:00
|
|
|
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 ,
|
2017-02-07 06:44:59 -06:00
|
|
|
const ecl_kw_type * xcon_kw ,
|
2015-04-14 08:47:22 -05:00
|
|
|
int iwell ,
|
2013-12-09 08:19:06 -06:00
|
|
|
const ecl_rsthead_type * rst_head) {
|
2015-04-14 08:47:22 -05:00
|
|
|
|
2013-08-26 06:56:42 -05:00
|
|
|
const int iwel_offset = rst_head->niwelz * iwell;
|
2016-10-13 06:31:31 -05:00
|
|
|
int num_connections = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_CONNECTIONS_INDEX );
|
2013-08-26 06:56:42 -05:00
|
|
|
int iconn;
|
|
|
|
|
|
|
|
for (iconn = 0; iconn < num_connections; iconn++) {
|
2017-02-07 06:44:59 -06:00
|
|
|
well_conn_type * conn = well_conn_alloc_from_kw( icon_kw , scon_kw, xcon_kw, rst_head , iwell , iconn );
|
2013-08-26 06:56:42 -05:00
|
|
|
if (conn)
|
|
|
|
well_conn_collection_add( wellcc , conn );
|
|
|
|
}
|
|
|
|
return num_connections;
|
2015-04-14 08:47:22 -05:00
|
|
|
|
2013-08-26 06:56:42 -05:00
|
|
|
}
|
|
|
|
|