Skip to content

Commit

Permalink
Merge pull request #525 from stefoss23/well_segment_state_ts_to_cpp
Browse files Browse the repository at this point in the history
WIP: Well segment collection using std::Vector
  • Loading branch information
joakim-hove authored Nov 9, 2018
2 parents 3ac7147 + b867f0e commit 3400ad1
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions lib/ecl/well_segment_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <stdbool.h>

#include <vector>

#include <ert/util/util.h>
#include <ert/util/vector.hpp>

Expand All @@ -33,58 +35,61 @@


struct well_segment_collection_struct {
int_vector_type * segment_index_map;
vector_type * __segment_storage;
std::vector<int> segment_index_map;
std::vector<well_segment_type*> __segment_storage;
};



well_segment_collection_type * well_segment_collection_alloc(void) {
well_segment_collection_type * segment_collection = (well_segment_collection_type*)util_malloc( sizeof * segment_collection );

segment_collection->__segment_storage = vector_alloc_new();
segment_collection->segment_index_map = int_vector_alloc( 0 , -1 );
well_segment_collection_type * segment_collection = new well_segment_collection_type();
return segment_collection;
}



void well_segment_collection_free(well_segment_collection_type * segment_collection ) {
vector_free( segment_collection->__segment_storage );
int_vector_free( segment_collection->segment_index_map );
free( segment_collection );
for (int i = 0; i < static_cast<int>(segment_collection->__segment_storage.size()); i++)
well_segment_free( segment_collection->__segment_storage[i] );
delete segment_collection;
}



int well_segment_collection_get_size( const well_segment_collection_type * segment_collection ) {
return vector_get_size( segment_collection->__segment_storage );
return segment_collection->__segment_storage.size();
}


void well_segment_collection_add( well_segment_collection_type * segment_collection , well_segment_type * segment) {
int segment_id = well_segment_get_id( segment );
int current_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id );
if (current_index >= 0)
vector_iset_owned_ref( segment_collection->__segment_storage , current_index , segment , well_segment_free__);
int current_index = -1;
if (segment_id < static_cast<int>(segment_collection->segment_index_map.size()))
current_index = segment_collection->segment_index_map[segment_id];
if (current_index >= 0) {
well_segment_free( segment_collection->__segment_storage[current_index] );
segment_collection->__segment_storage[current_index] = segment;
}
else {
int new_index = vector_get_size(segment_collection->__segment_storage);
vector_append_owned_ref( segment_collection->__segment_storage , segment , well_segment_free__);
if (segment_id >= int_vector_size(segment_collection->segment_index_map))
int_vector_resize(segment_collection->segment_index_map, segment_id+1, -1);
int_vector_iset( segment_collection->segment_index_map , segment_id , new_index);
int new_index = segment_collection->__segment_storage.size();
segment_collection->__segment_storage.push_back( segment );
if ( segment_id >= static_cast<int>(segment_collection->segment_index_map.size()) )
segment_collection->segment_index_map.resize(segment_id+1, -1);
segment_collection->segment_index_map[segment_id] = new_index;
}
}



well_segment_type * well_segment_collection_iget( const well_segment_collection_type * segment_collection , int index) {
return (well_segment_type*)vector_iget( segment_collection->__segment_storage , index );
return segment_collection->__segment_storage[ index ];
}


well_segment_type * well_segment_collection_get( const well_segment_collection_type * segment_collection , int segment_id) {
int internal_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id );
int internal_index = -1;
if (segment_id < static_cast<int>(segment_collection->segment_index_map.size()))
internal_index = segment_collection->segment_index_map[segment_id];
if (internal_index >= 0)
return well_segment_collection_iget( segment_collection , internal_index );
else
Expand All @@ -93,7 +98,9 @@ well_segment_type * well_segment_collection_get( const well_segment_collection_t


bool well_segment_collection_has_segment( const well_segment_collection_type * segment_collection , int segment_id) {
int internal_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id );
int internal_index = -1;
if (segment_id < static_cast<int>(segment_collection->segment_index_map.size()))
internal_index = segment_collection->segment_index_map[segment_id];
if (internal_index >= 0)
return true;
else
Expand Down Expand Up @@ -135,8 +142,8 @@ int well_segment_collection_load_from_kw( well_segment_collection_type * segment


void well_segment_collection_link(const well_segment_collection_type * segment_collection) {
int index;
for (index = 0; index < vector_get_size( segment_collection->__segment_storage); index++) {
size_t index;
for (index = 0; index < segment_collection->__segment_storage.size(); index++) {
well_segment_type * segment = well_segment_collection_iget( segment_collection , index );
int outlet_segment_id = well_segment_get_outlet_id( segment );
if (!well_segment_nearest_wellhead(segment)) {
Expand Down

0 comments on commit 3400ad1

Please sign in to comment.