Changes in WellConnection ordering
1. If the well is MSW the connections in the WellConnection class is sorted in output order in the ::order() method, and retained that way. 2. Add method WellConnection::output() which return a vector of connection pointers sorted in output order.
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user