2013-08-26 06:56:42 -05:00
|
|
|
/*
|
2019-05-07 00:15:25 -05:00
|
|
|
Copyright (C) 2013 Equinor ASA, Norway.
|
2018-08-13 03:20:34 -05:00
|
|
|
|
|
|
|
The file 'well_branch_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_well/well_const.hpp>
|
|
|
|
#include <ert/ecl_well/well_conn.hpp>
|
|
|
|
#include <ert/ecl_well/well_branch_collection.hpp>
|
2013-08-26 06:56:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
#define WELL_BRANCH_COLLECTION_TYPE_ID 67177087
|
|
|
|
|
|
|
|
struct well_branch_collection_struct {
|
|
|
|
UTIL_TYPE_ID_DECLARATION;
|
|
|
|
|
2019-05-07 00:15:25 -05:00
|
|
|
std::vector<well_segment_type*> __start_segments;
|
|
|
|
std::vector<int> index_map;
|
2013-08-26 06:56:42 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UTIL_IS_INSTANCE_FUNCTION( well_branch_collection , WELL_BRANCH_COLLECTION_TYPE_ID )
|
|
|
|
static UTIL_SAFE_CAST_FUNCTION( well_branch_collection , WELL_BRANCH_COLLECTION_TYPE_ID )
|
|
|
|
|
|
|
|
|
|
|
|
well_branch_collection_type * well_branch_collection_alloc() {
|
2019-05-07 00:15:25 -05:00
|
|
|
well_branch_collection_type * branch_collection = new well_branch_collection_type();
|
2013-08-26 06:56:42 -05:00
|
|
|
UTIL_TYPE_ID_INIT( branch_collection , WELL_BRANCH_COLLECTION_TYPE_ID );
|
|
|
|
return branch_collection;
|
|
|
|
}
|
|
|
|
|
2019-05-07 00:15:25 -05:00
|
|
|
namespace {
|
2013-08-26 06:56:42 -05:00
|
|
|
|
2019-05-07 00:15:25 -05:00
|
|
|
int well_branch_collection_safe_iget_index( const well_branch_collection_type * branches, int index ) {
|
|
|
|
if (index >= (int)branches->index_map.size())
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return branches->index_map[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-08-26 06:56:42 -05:00
|
|
|
|
|
|
|
void well_branch_collection_free( well_branch_collection_type * branches ) {
|
2019-05-07 00:15:25 -05:00
|
|
|
delete branches;
|
2013-08-26 06:56:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void well_branch_collection_free__( void * arg ) {
|
|
|
|
well_branch_collection_type * branches = well_branch_collection_safe_cast( arg );
|
|
|
|
well_branch_collection_free( branches );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int well_branch_collection_get_size( const well_branch_collection_type * branches ) {
|
2019-05-07 00:15:25 -05:00
|
|
|
return branches->__start_segments.size();
|
2013-08-26 06:56:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool well_branch_collection_has_branch( const well_branch_collection_type * branches , int branch_id) {
|
2019-05-07 00:15:25 -05:00
|
|
|
if (well_branch_collection_safe_iget_index( branches , branch_id) >= 0)
|
2013-08-26 06:56:42 -05:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const well_segment_type * well_branch_collection_iget_start_segment( const well_branch_collection_type * branches , int index ) {
|
2019-05-07 00:15:25 -05:00
|
|
|
if (index < static_cast<int>(branches->__start_segments.size()))
|
|
|
|
return branches->__start_segments[index];
|
2013-08-26 06:56:42 -05:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const well_segment_type * well_branch_collection_get_start_segment( const well_branch_collection_type * branches , int branch_id) {
|
2019-05-07 00:15:25 -05:00
|
|
|
int internal_index = well_branch_collection_safe_iget_index( branches , branch_id);
|
2013-08-26 06:56:42 -05:00
|
|
|
if (internal_index >= 0)
|
|
|
|
return well_branch_collection_iget_start_segment( branches , internal_index );
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 00:15:25 -05:00
|
|
|
bool well_branch_collection_add_start_segment( well_branch_collection_type * branches , well_segment_type * start_segment) {
|
2013-08-26 06:56:42 -05:00
|
|
|
if ((well_segment_get_link_count( start_segment ) == 0) && (well_segment_get_outlet(start_segment))) {
|
|
|
|
int branch_id = well_segment_get_branch_id( start_segment );
|
2019-05-07 00:15:25 -05:00
|
|
|
int current_index = well_branch_collection_safe_iget_index( branches , branch_id);
|
2018-08-13 03:20:34 -05:00
|
|
|
if (current_index >= 0)
|
2019-05-07 00:15:25 -05:00
|
|
|
branches->__start_segments[current_index] = start_segment;
|
2013-08-26 06:56:42 -05:00
|
|
|
else {
|
2019-05-07 00:15:25 -05:00
|
|
|
int new_index = branches->__start_segments.size();
|
|
|
|
branches->__start_segments.push_back(start_segment);
|
|
|
|
if (branch_id >= (int)branches->index_map.size())
|
|
|
|
branches->index_map.resize(branch_id+1, -1);
|
|
|
|
branches->index_map[branch_id] = new_index;
|
2013-08-26 06:56:42 -05:00
|
|
|
}
|
2018-08-13 03:20:34 -05:00
|
|
|
|
2013-08-26 06:56:42 -05:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-08 05:31:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-13 03:20:34 -05:00
|
|
|
|