#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
#
This commit is contained in:
Bjørnar Grip Fjær 2017-04-05 12:04:36 +02:00
parent dc1a207313
commit 050c4b8c28
2 changed files with 118 additions and 24 deletions

View File

@ -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<FaultCellAndFace> 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);
}
size_t lastI = std::numeric_limits<size_t>::max();
size_t lastJ = std::numeric_limits<size_t>::max();
size_t lastK = std::numeric_limits<size_t>::max();
size_t startK = std::numeric_limits<size_t>::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;
}

View File

@ -26,6 +26,8 @@
class RigMainGrid;
typedef std::tuple<size_t, size_t, size_t, cvf::StructGridInterface::FaceType> FaultCellAndFace;
//==================================================================================================
///
//==================================================================================================
@ -41,5 +43,8 @@ protected:
private:
static void saveFault(QString completeFilename, const RigMainGrid* mainGrid, const std::vector<RigFault::FaultFace>& 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);
};