Merge pull request #1606 from joakim-hove/wellconnections-output

Changes in WellConnection ordering
This commit is contained in:
Joakim Hove 2020-03-25 18:01:51 +01:00 committed by GitHub
commit 91841a99e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 33 deletions

View File

@ -84,12 +84,13 @@ namespace Opm {
/// \param[in] well_i logical cartesian i-coordinate of well head
/// \param[in] well_j logical cartesian j-coordinate of well head
/// \param[in] grid EclipseGrid object, used for cell depths
void order(size_t well_i, size_t well_j);
void order();
bool operator==( const WellConnections& ) const;
bool operator!=( const WellConnections& ) const;
Connection::Order ordering() const { return this->m_ordering; }
std::vector<const Connection *> output(const EclipseGrid& grid) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
@ -128,6 +129,8 @@ namespace Opm {
const std::vector<double>& ntg);
size_t findClosestConnection(int oi, int oj, double oz, size_t start_pos);
void orderTRACK();
void orderMSW();
Connection::Order m_ordering = Connection::Order::TRACK;
int headI, headJ;

View File

@ -63,36 +63,16 @@ namespace {
wellID < nWell; ++wellID)
{
const auto& well = wells[wellID];
std::vector<const Opm::Connection*> connSI;
for (const auto& conn : well.getConnections()) {
if (grid.cellActive(conn.getI(), conn.getJ(), conn.getK()))
connSI.push_back( &conn );
}
//Branch according to MSW well or not and
//sort active connections according to appropriate seqIndex
if (well.isMultiSegment()) {
//sort connections according to input sequence in COMPSEGS
std::sort(connSI.begin(), connSI.end(), [](const Opm::Connection* conn1, const Opm::Connection* conn2)
{
return conn1->getCompSegSeqIndex() < conn2->getCompSegSeqIndex();
});
} else {
std::sort(connSI.begin(), connSI.end(), [](const Opm::Connection* conn1, const Opm::Connection* conn2)
{
return conn1->getSeqIndex() < conn2->getSeqIndex();
});
}
const auto well_iter = xw.find(well.name());
const Opm::data::Well * well_rates = (well_iter == xw.end()) ? nullptr : &well_iter->second;
for (auto nConn = connSI.size(), connID = 0*nConn; connID < nConn; ++connID)
{
const auto& conn = *(connSI[connID]);
const auto& connections = well.getConnections().output(grid);
std::size_t connID = 0;
for (const auto& conn : connections) {
if (well_rates)
connOp(wellID, conn, connID, well_rates->find_connection(conn.global_index()));
connOp(wellID, *conn, connID, well_rates->find_connection(conn->global_index()));
else
connOp(wellID, conn, connID, nullptr);
connOp(wellID, *conn, connID, nullptr);
connID++;
}
}
}

View File

@ -598,7 +598,7 @@ bool Well::updateAutoShutin(bool auto_shutin) {
bool Well::updateConnections(std::shared_ptr<WellConnections> connections_arg) {
connections_arg->order( this->headI, this->headJ );
connections_arg->order( );
if (*this->connections != *connections_arg) {
this->connections = connections_arg;
//if (this->connections->allConnectionsShut()) {}

View File

@ -163,6 +163,25 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction
}
}
std::vector<const Connection *> WellConnections::output(const EclipseGrid& grid) const {
if (this->m_connections.empty())
return {};
std::vector<const Connection*> out;
for (const auto& conn : this->m_connections)
if (grid.cellActive(conn.getI(), conn.getJ(), conn.getK()))
out.push_back( &conn );
if (!this->m_connections[0].attachedToSegment() && (this->m_ordering != Connection::Order::INPUT)) {
std::sort(out.begin(), out.end(), [](const Opm::Connection* conn1, const Opm::Connection* conn2)
{
return conn1->getSeqIndex() < conn2->getSeqIndex();
});
}
return out;
}
void WellConnections::addConnection(int i, int j , int k ,
std::size_t global_index,
int complnum,
@ -451,17 +470,31 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction
void WellConnections::order(size_t well_i, size_t well_j)
void WellConnections::order()
{
if (m_connections.empty())
return;
if (this->m_ordering != Connection::Order::TRACK)
return;
if (this->m_connections[0].attachedToSegment())
this->orderMSW();
else if (this->m_ordering == Connection::Order::TRACK)
this->orderTRACK();
}
void WellConnections::orderMSW() {
std::sort(this->m_connections.begin(), this->m_connections.end(), [](const Opm::Connection& conn1, const Opm::Connection& conn2)
{
return conn1.getCompSegSeqIndex() < conn2.getCompSegSeqIndex();
});
}
void WellConnections::orderTRACK() {
// Find the first connection and swap it into the 0-position.
const double surface_z = 0.0;
size_t first_index = findClosestConnection(well_i, well_j, surface_z, 0);
size_t first_index = findClosestConnection(this->headI, this->headJ, surface_z, 0);
std::swap(m_connections[first_index], m_connections[0]);
// Repeat for remaining connections.
@ -481,7 +514,6 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction
}
size_t WellConnections::findClosestConnection(int oi, int oj, double oz, size_t start_pos)
{
size_t closest = std::numeric_limits<size_t>::max();

View File

@ -102,6 +102,12 @@ BOOST_AUTO_TEST_CASE(WellCOMPDATtestTRACK) {
for (size_t k = 0; k < completions.size(); ++k) {
BOOST_CHECK_EQUAL(completions.get( k ).getK(), k);
}
// Output / input ordering
const auto& output_connections = completions.output(grid);
std::vector<int> expected = {0,2,3,4,5,6,7,8,1};
for (size_t k = 0; k < completions.size(); ++k)
BOOST_CHECK_EQUAL( expected[k], output_connections[k]->getK());
}