From 050c4b8c2802647effe3298e8c0b96b650cca138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rnar=20Grip=20Fj=C3=A6r?= Date: Wed, 5 Apr 2017 12:04:36 +0200 Subject: [PATCH] #1026 Combine continuous fault cells to one line in export # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Wed Apr 5 12:04:36 2017 +0200 # # On branch dev # Your branch is ahead of 'origin/dev' by 2 commits. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: ApplicationCode/Commands/RicExportFaultsFeature.cpp # modified: ApplicationCode/Commands/RicExportFaultsFeature.h # --- .../Commands/RicExportFaultsFeature.cpp | 137 +++++++++++++++--- .../Commands/RicExportFaultsFeature.h | 5 + 2 files changed, 118 insertions(+), 24 deletions(-) diff --git a/ApplicationCode/Commands/RicExportFaultsFeature.cpp b/ApplicationCode/Commands/RicExportFaultsFeature.cpp index 01ef011273..f4a56c96a8 100644 --- a/ApplicationCode/Commands/RicExportFaultsFeature.cpp +++ b/ApplicationCode/Commands/RicExportFaultsFeature.cpp @@ -111,6 +111,73 @@ void RicExportFaultsFeature::setupActionLook(QAction* actionToSetup) actionToSetup->setIcon(QIcon(":/Save.png")); } +//-------------------------------------------------------------------------------------------------- +/// Order FaultCellAndFace by i, j, face then k. +//-------------------------------------------------------------------------------------------------- +bool RicExportFaultsFeature::faultOrdering(FaultCellAndFace first, FaultCellAndFace second) + { + size_t i1, i2, j1, j2, k1, k2; + cvf::StructGridInterface::FaceType f1, f2; + std::tie(i1, j1, k1, f1) = first; + std::tie(i2, j2, k2, f2) = second; + if (i1 == i2) + { + if (j1 == j2) + { + if (f1 == f2) + { + return k1 < k2; + } + else + { + return f1 < f2; + } + } + else + { + return j1 < j2; + } + } + else + { + return i1 < i2; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicExportFaultsFeature::faceText(cvf::StructGridInterface::FaceType faceType) +{ + switch (faceType) + { + case cvf::StructGridInterface::POS_I: return QString(" I"); + case cvf::StructGridInterface::NEG_I: return QString("-I"); + case cvf::StructGridInterface::POS_J: return QString(" J"); + case cvf::StructGridInterface::NEG_J: return QString("-J"); + case cvf::StructGridInterface::POS_K: return QString(" K"); + case cvf::StructGridInterface::NEG_K: return QString("-K"); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportFaultsFeature::writeLine(QTextStream & stream, QString faultName, size_t i, size_t j, size_t startK, size_t endK, cvf::StructGridInterface::FaceType faceType) +{ + // Convert indices to eclipse format + i++; + j++; + startK++; + endK++; + + stream << "'" << faultName << "'" << " " << i << " " << i + << " " << j << " " << j + << " " << startK << " " << endK + << " " << RicExportFaultsFeature::faceText(faceType) << " / "; + stream << endl; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -131,33 +198,55 @@ void RicExportFaultsFeature::saveFault(QString completeFilename, const RigMainGr stream << "-- Name I1 I2 J1 J2 K1 K2 Face ( I/J/K )" << endl; // 'NAME' 1 1 1 1 1 2 J / - - for (const RigFault::FaultFace& fface: faultFaces) - { - size_t i1, j1, k1, i2, j2, k2; + + std::vector faultCellAndFaces; - bool ok = mainGrid->ijkFromCellIndex(fface.m_nativeReservoirCellIndex, &i1, &j1, &k1); + for (const RigFault::FaultFace& faultCellAndFace : faultFaces) + { + size_t i, j, k; + bool ok = mainGrid->ijkFromCellIndex(faultCellAndFace.m_nativeReservoirCellIndex, &i, &j, &k); if (!ok) continue; - ok = mainGrid->ijkFromCellIndex(fface.m_oppositeReservoirCellIndex, &i2, &j2, &k2); - QString faceText; - switch (fface.m_nativeFace) - { - case cvf::StructGridInterface::POS_I: faceText = " I"; break; - case cvf::StructGridInterface::NEG_I: faceText = "-I"; break; - case cvf::StructGridInterface::POS_J: faceText = " J"; break; - case cvf::StructGridInterface::NEG_J: faceText = "-J"; break; - case cvf::StructGridInterface::POS_K: faceText = " K"; break; - case cvf::StructGridInterface::NEG_K: faceText = "-K"; break; - } - - stream << "'" << faultName << "'" << " " << i1 << " " << i2 - << " " << j1 << " " << j2 - << " " << k1 << " " << k2 - << " " << faceText << " / "; - stream << endl ; + faultCellAndFaces.push_back(std::make_tuple(i, j, k, faultCellAndFace.m_nativeFace)); } - stream << "/" << endl; + // Sort order: i, j, face then k. + std::sort(faultCellAndFaces.begin(), faultCellAndFaces.end(), RicExportFaultsFeature::faultOrdering); -} \ No newline at end of file + size_t lastI = std::numeric_limits::max(); + size_t lastJ = std::numeric_limits::max(); + size_t lastK = std::numeric_limits::max(); + size_t startK = std::numeric_limits::max(); + cvf::StructGridInterface::FaceType lastFaceType = cvf::StructGridInterface::FaceType::NO_FACE; + + for (const FaultCellAndFace &faultCellAndFace : faultCellAndFaces) + { + size_t i, j, k; + cvf::StructGridInterface::FaceType faceType; + std::tie(i, j, k, faceType) = faultCellAndFace; + + if (i != lastI || j != lastJ || lastFaceType != faceType || k != lastK+1) + { + // No fault should have no face + if (lastFaceType != cvf::StructGridInterface::FaceType::NO_FACE) + { + RicExportFaultsFeature::writeLine(stream, faultName, lastI, lastJ, startK, lastK, lastFaceType); + } + lastI = i; + lastJ = j; + lastK = k; + lastFaceType = faceType; + startK = k; + } + else + { + lastK = k; + } + } + // No fault should have no face + if (lastFaceType != cvf::StructGridInterface::FaceType::NO_FACE) + { + RicExportFaultsFeature::writeLine(stream, faultName, lastI, lastJ, startK, lastK, lastFaceType); + } + stream << "/" << endl; +} diff --git a/ApplicationCode/Commands/RicExportFaultsFeature.h b/ApplicationCode/Commands/RicExportFaultsFeature.h index 33f9e5f78b..5633e1b4f1 100644 --- a/ApplicationCode/Commands/RicExportFaultsFeature.h +++ b/ApplicationCode/Commands/RicExportFaultsFeature.h @@ -26,6 +26,8 @@ class RigMainGrid; +typedef std::tuple FaultCellAndFace; + //================================================================================================== /// //================================================================================================== @@ -41,5 +43,8 @@ protected: private: static void saveFault(QString completeFilename, const RigMainGrid* mainGrid, const std::vector& faultFaces, QString faultName); + static bool faultOrdering(FaultCellAndFace first, FaultCellAndFace second); + static QString faceText(cvf::StructGridInterface::FaceType faceType); + static void writeLine(QTextStream &stream, QString faultName, size_t i, size_t j, size_t startK, size_t endK, cvf::StructGridInterface::FaceType faceType); };