Using shared_ptr to manage connections

This commit is contained in:
Joakim Hove
2018-06-25 10:35:45 +02:00
parent d52d4cc3a6
commit f3d82437fd
6 changed files with 55 additions and 52 deletions

View File

@@ -26,7 +26,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/MSW/WellSegments.hpp>
namespace Opm {
WellConnections updatingConnectionsWithSegments(const DeckKeyword& compsegs, const WellConnections& input_connections, const WellSegments& segments);
WellConnections * updatingConnectionsWithSegments(const DeckKeyword& compsegs, const WellConnections& input_connections, const WellSegments& segments);
}
#endif

View File

@@ -95,10 +95,11 @@ namespace Opm {
void addWELSPECS(const DeckRecord& deckRecord);
void addConnections(size_t time_step, const std::vector< Connection >& );
void addWellConnections(size_t time_step, WellConnections );
const WellConnections& getConnections(size_t timeStep) const;
const WellConnections& getConnections() const;
WellConnections getActiveConnections(size_t timeStep, const EclipseGrid& grid) const;
WellConnections * newWellConnections(size_t time_step);
void updateWellConnections(size_t time_step, WellConnections * new_set );
/* The rate of a given phase under the following assumptions:
* * Returns zero if production is requested for an injector (and vice
@@ -183,7 +184,7 @@ namespace Opm {
DynamicState< double > m_efficiencyFactors;
DynamicState< int > m_isProducer;
DynamicState< WellConnections > m_completions;
DynamicState< std::shared_ptr<WellConnections> > m_completions;
DynamicState< WellProductionProperties > m_productionProperties;
DynamicState< WellInjectionProperties > m_injectionProperties;
DynamicState< WellPolymerProperties > m_polymerProperties;

View File

@@ -23,15 +23,15 @@
namespace Opm {
WellConnections updatingConnectionsWithSegments(const DeckKeyword& compsegs,
const WellConnections& input_connections,
const WellSegments& segment_set)
WellConnections * updatingConnectionsWithSegments(const DeckKeyword& compsegs,
const WellConnections& input_connections,
const WellSegments& segment_set)
{
WellConnections new_connection_set(input_connections);
WellConnections * new_connection_set = new WellConnections(input_connections);
std::vector<Compsegs> compsegs_vector = Compsegs::compsegsFromCOMPSEGSKeyword( compsegs );
Compsegs::processCOMPSEGS(compsegs_vector, segment_set);
Compsegs::updateConnectionsWithSegment(compsegs_vector, new_connection_set);
Compsegs::updateConnectionsWithSegment(compsegs_vector, *new_connection_set);
return new_connection_set;
}
}

View File

@@ -561,7 +561,7 @@ namespace Opm {
for( auto* well : getWells( wellNamePattern ) ) {
const auto& currentWellConnections = well->getConnections(currentStep);
WellConnections newWellConnections;
WellConnections * newWellConnections = well->newWellConnections(currentStep);
Opm::Value<int> I = getValueItem(record.getItem("I"));
Opm::Value<int> J = getValueItem(record.getItem("J"));
@@ -576,13 +576,13 @@ namespace Opm {
if (FIRST.hasValue()) {
if (i < (size_t) FIRST.getValue()) {
newWellConnections.add(currentConnection);
newWellConnections->add(currentConnection);
continue;
}
}
if (LAST.hasValue()) {
if (i > (size_t) LAST.getValue()) {
newWellConnections.add(currentConnection);
newWellConnections->add(currentConnection);
continue;
}
}
@@ -592,24 +592,24 @@ namespace Opm {
int ck = currentConnection.getK();
if (I.hasValue() && (!(I.getValue() == ci) )) {
newWellConnections.add(currentConnection);
newWellConnections->add(currentConnection);
continue;
}
if (J.hasValue() && (!(J.getValue() == cj) )) {
newWellConnections.add(currentConnection);
newWellConnections->add(currentConnection);
continue;
}
if (K.hasValue() && (!(K.getValue() == ck) )) {
newWellConnections.add(currentConnection);
newWellConnections->add(currentConnection);
continue;
}
newWellConnections.add( Connection{ currentConnection, wellPi } );
newWellConnections->add( Connection{ currentConnection, wellPi } );
}
well->addWellConnections(currentStep, newWellConnections);
well->updateWellConnections(currentStep, newWellConnections);
}
}
}
@@ -945,11 +945,11 @@ namespace Opm {
};
for( auto& well : this->getWells( wellname ) ) {
WellConnections new_completions;
WellConnections * new_completions = well->newWellConnections(timestep);
for( const auto& completion : well->getConnections( timestep ) )
new_completions.add( new_completion( completion ) );
new_completions->add( new_completion( completion ) );
well->addWellConnections( timestep, new_completions );
well->updateWellConnections( timestep, new_completions );
}
}
}
@@ -1032,11 +1032,11 @@ namespace Opm {
};
for( auto* well : wells ) {
WellConnections new_completions;
WellConnections * new_completions = well->newWellConnections(currentStep);
for( const auto& c : well->getConnections( currentStep ) )
new_completions.add( new_completion( c ) );
new_completions->add( new_completion( c ) );
well->addWellConnections( currentStep, new_completions );
well->updateWellConnections( currentStep, new_completions );
m_events.addEvent( ScheduleEvents::COMPLETION_CHANGE, currentStep );
}
}
@@ -1452,9 +1452,9 @@ namespace Opm {
const auto& segment_set = well.getWellSegments(currentStep);
const auto& completion_set = well.getConnections( currentStep );
const WellConnections new_completion_set = updatingConnectionsWithSegments(keyword, completion_set, segment_set);
WellConnections * new_completion_set = updatingConnectionsWithSegments(keyword, completion_set, segment_set);
well.addWellConnections(currentStep, new_completion_set);
well.updateWellConnections(currentStep, new_completion_set);
}
void Schedule::handleWGRUPCON( const DeckKeyword& keyword, size_t currentStep) {

View File

@@ -48,7 +48,7 @@ namespace Opm {
m_guideRateScalingFactor( timeMap, 1.0 ),
m_efficiencyFactors (timeMap, 1.0 ),
m_isProducer( timeMap, true ) ,
m_completions( timeMap, WellConnections{} ),
m_completions( timeMap, std::make_shared<WellConnections>(headI, headJ) ),
m_productionProperties( timeMap, WellProductionProperties() ),
m_injectionProperties( timeMap, WellInjectionProperties() ),
m_polymerProperties( timeMap, WellPolymerProperties() ),
@@ -348,7 +348,7 @@ namespace Opm {
}
const WellConnections& Well::getConnections(size_t timeStep) const {
return m_completions.get( timeStep );
return *m_completions.get( timeStep );
}
WellConnections Well::getActiveConnections(size_t timeStep, const EclipseGrid& grid) const {
@@ -356,23 +356,23 @@ namespace Opm {
}
const WellConnections& Well::getConnections() const {
return m_completions.back();
return *m_completions.back();
}
void Well::addConnections(size_t time_step, const std::vector< Connection >& newConnections ) {
auto new_set = this->getConnections( time_step );
int complnum_shift = new_set.size();
WellConnections * new_set = new WellConnections( this->getConnections(time_step));
int complnum_shift = new_set->size();
const auto headI = this->m_headI[ time_step ];
const auto headJ = this->m_headJ[ time_step ];
auto prev_size = new_set.size();
auto prev_size = new_set->size();
for( auto completion : newConnections ) {
completion.fixDefaultIJ( headI , headJ );
completion.shift_complnum( complnum_shift );
new_set.add( completion );
const auto new_size = new_set.size();
new_set->add( completion );
const auto new_size = new_set->size();
/* Connections can be "re-added", i.e. same coordinates but with a
* different set of properties. In this case they also inherit the
@@ -383,18 +383,7 @@ namespace Opm {
else ++prev_size;
}
this->addWellConnections( time_step, new_set );
}
void Well::addWellConnections(size_t time_step, WellConnections new_set ){
if( getWellConnectionOrdering() == WellCompletion::TRACK) {
const auto headI = this->m_headI[ time_step ];
const auto headJ = this->m_headJ[ time_step ];
new_set.orderConnections( headI, headJ );
}
m_completions.update( time_step, std::move( new_set ) );
addEvent( ScheduleEvents::COMPLETION_CHANGE , time_step );
this->updateWellConnections( time_step, new_set );
}
const std::string Well::getGroupName(size_t time_step) const {
@@ -567,7 +556,20 @@ namespace Opm {
m_segmentset.update(time_step, new_segmentset);
}
WellConnections * Well::newWellConnections(size_t time_step) {
return new WellConnections( this->m_headI[time_step], this->m_headJ[time_step]);
}
void Well::updateWellConnections(size_t time_step, WellConnections * new_set ){
if( getWellConnectionOrdering() == WellCompletion::TRACK) {
const auto headI = this->m_headI[ time_step ];
const auto headJ = this->m_headJ[ time_step ];
new_set->orderConnections( headI, headJ );
}
m_completions.update( time_step, std::shared_ptr<WellConnections>( new_set ));
addEvent( ScheduleEvents::COMPLETION_CHANGE , time_step );
}
void Well::addEvent(ScheduleEvents::Events event, size_t reportStep) {
@@ -586,6 +588,6 @@ namespace Opm {
instance, hence this for loop is over all timesteps.
*/
for (auto& completions : m_completions)
completions.filter(grid);
completions->filter(grid);
}
}

View File

@@ -86,35 +86,35 @@ BOOST_AUTO_TEST_CASE(MultisegmentWellTest) {
BOOST_CHECK_EQUAL(6U, segment_set.size());
const Opm::WellConnections new_connection_set = Opm::updatingConnectionsWithSegments(compsegs, connection_set, segment_set);
const Opm::WellConnections * new_connection_set = Opm::updatingConnectionsWithSegments(compsegs, connection_set, segment_set);
BOOST_CHECK_EQUAL(7U, new_connection_set.size());
BOOST_CHECK_EQUAL(7U, new_connection_set->size());
const Opm::Connection& connection1 = new_connection_set.get(0);
const Opm::Connection& connection1 = new_connection_set->get(0);
const int segment_number_connection1 = connection1.getSegmentNumber();
const double center_depth_connection1 = connection1.getCenterDepth();
BOOST_CHECK_EQUAL(segment_number_connection1, 1);
BOOST_CHECK_EQUAL(center_depth_connection1, 2512.5);
const Opm::Connection& connection3 = new_connection_set.get(2);
const Opm::Connection& connection3 = new_connection_set->get(2);
const int segment_number_connection3 = connection3.getSegmentNumber();
const double center_depth_connection3 = connection3.getCenterDepth();
BOOST_CHECK_EQUAL(segment_number_connection3, 3);
BOOST_CHECK_EQUAL(center_depth_connection3, 2562.5);
const Opm::Connection& connection5 = new_connection_set.get(4);
const Opm::Connection& connection5 = new_connection_set->get(4);
const int segment_number_connection5 = connection5.getSegmentNumber();
const double center_depth_connection5 = connection5.getCenterDepth();
BOOST_CHECK_EQUAL(segment_number_connection5, 6);
BOOST_CHECK_CLOSE(center_depth_connection5, 2538.83, 0.001);
const Opm::Connection& connection6 = new_connection_set.get(5);
const Opm::Connection& connection6 = new_connection_set->get(5);
const int segment_number_connection6 = connection6.getSegmentNumber();
const double center_depth_connection6 = connection6.getCenterDepth();
BOOST_CHECK_EQUAL(segment_number_connection6, 6);
BOOST_CHECK_CLOSE(center_depth_connection6, 2537.83, 0.001);
const Opm::Connection& connection7 = new_connection_set.get(6);
const Opm::Connection& connection7 = new_connection_set->get(6);
const int segment_number_connection7 = connection7.getSegmentNumber();
const double center_depth_connection7 = connection7.getCenterDepth();
BOOST_CHECK_EQUAL(segment_number_connection7, 7);