Skip to content

Commit

Permalink
#811, #812 WIP, Formation names coloring of cells. First shot. Works …
Browse files Browse the repository at this point in the history
…but needs refinment.
  • Loading branch information
JacobStoren committed Sep 6, 2016
1 parent ca6e650 commit c903e87
Show file tree
Hide file tree
Showing 28 changed files with 373 additions and 50 deletions.
Expand Up @@ -28,6 +28,7 @@
#include "RigStatisticsDataCache.h"
#include "RigFemPartResults.h"
#include "RigFemPartCollection.h"
#include "RigFormationNames.h"

#include "cafProgressInfo.h"
#include "cvfBoundingBox.h"
Expand All @@ -38,6 +39,7 @@
#include "RigFemNativeStatCalc.h"
#include "cafTensor3.h"
#include "cafProgressInfo.h"
#include "RigFemPartGrid.h"


//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -66,6 +68,21 @@ RigFemPartResultsCollection::~RigFemPartResultsCollection()

}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemPartResultsCollection::setActiveFormationNames(RigFormationNames* activeFormationNames)
{
m_activeFormationNamesData = activeFormationNames;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFormationNames* RigFemPartResultsCollection::activeFormationNames()
{
return m_activeFormationNamesData.p();
}

//--------------------------------------------------------------------------------------------------
/// Will always return a valid object, but it can be empty
Expand Down Expand Up @@ -151,6 +168,11 @@ std::map<std::string, std::vector<std::string> > RigFemPartResultsCollection::sc
{
std::map<std::string, std::vector<std::string> > fieldCompNames;

if (resPos == RIG_FORMATION_NAMES)
{
if (activeFormationNames()) fieldCompNames["Active Formation Names"];
}

if (m_readerInterface.notNull())
{
if (resPos == RIG_NODAL)
Expand Down Expand Up @@ -619,6 +641,38 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::calculateDerivedResult(in
return m_femPartResults[partIndex]->createScalarResult(resVarAddr);
}

if (resVarAddr.resultPosType == RIG_FORMATION_NAMES)
{
RigFemScalarResultFrames* resFrames = m_femPartResults[partIndex]->createScalarResult(resVarAddr);

const RigFemPart * femPart = m_femParts->part(partIndex);
std::vector<float>& dstFrameData = resFrames->frameData(0);

size_t valCount = femPart->elementNodeResultCount();
float inf = std::numeric_limits<float>::infinity();
dstFrameData.resize(valCount, inf);

RigFormationNames* activeFormNames = m_activeFormationNamesData.p();

int elementCount = femPart->elementCount();
for(int elmIdx = 0; elmIdx < elementCount; ++elmIdx)
{
RigElementType elmType = femPart->elementType(elmIdx);
int elmNodeCount = RigFemTypes::elmentNodeCount(elmType);

size_t i, j, k;
femPart->structGrid()->ijkFromCellIndex(elmIdx, &i, &j, &k);
int formNameIdx = activeFormNames->formationIndexFromKLayerIdx(k);

for(int elmNodIdx = 0; elmNodIdx < elmNodeCount; ++elmNodIdx)
{
size_t elmNodResIdx = femPart->elementNodeResultIdx(elmIdx, elmNodIdx);
dstFrameData[elmNodResIdx] = formNameIdx;
}
}

return resFrames;
}
return NULL;
}

Expand Down
Expand Up @@ -32,13 +32,17 @@ class RigFemPartResultsCollection;
class RigFemPartResults;
class RigStatisticsDataCache;
class RigFemPartCollection;
class RigFormationNames;

class RigFemPartResultsCollection: public cvf::Object
{
public:
RigFemPartResultsCollection(RifGeoMechReaderInterface* readerInterface, const RigFemPartCollection * femPartCollection);
~RigFemPartResultsCollection();

void setActiveFormationNames(RigFormationNames* activeFormationNames);
RigFormationNames* activeFormationNames();

std::map<std::string, std::vector<std::string> > scalarFieldAndComponentNames(RigFemResultPosEnum resPos);
std::vector<std::string> stepNames();
bool assertResultsLoaded(const RigFemResultAddress& resVarAddr);
Expand Down Expand Up @@ -72,6 +76,7 @@ class RigFemPartResultsCollection: public cvf::Object
cvf::Collection<RigFemPartResults> m_femPartResults;
cvf::ref<RifGeoMechReaderInterface> m_readerInterface;
cvf::cref<RigFemPartCollection> m_femParts;
cvf::ref<RigFormationNames> m_activeFormationNamesData;

RigStatisticsDataCache* statistics(const RigFemResultAddress& resVarAddr);
std::vector< RigFemResultAddress> getResAddrToComponentsToRead(const RigFemResultAddress& resVarAddr);
Expand Down
Expand Up @@ -43,7 +43,8 @@ RigFemResultAddress(RigFemResultPosEnum resPosType,
{
bool isTypeValid = resultPosType == RIG_NODAL
|| resultPosType == RIG_ELEMENT_NODAL
|| resultPosType == RIG_INTEGRATION_POINT;
|| resultPosType == RIG_INTEGRATION_POINT
|| resultPosType == RIG_FORMATION_NAMES;
bool isFieldValid = fieldName != "";
return isTypeValid && isFieldValid;
}
Expand Down
Expand Up @@ -3,5 +3,6 @@
enum RigFemResultPosEnum {
RIG_NODAL,
RIG_ELEMENT_NODAL,
RIG_INTEGRATION_POINT
RIG_INTEGRATION_POINT,
RIG_FORMATION_NAMES
};
Expand Up @@ -244,7 +244,8 @@ void RivFemPartPartMgr::updateCellResultColor(size_t timeStepIndex, RimGeoMechCe
vxToResultMapping = &(m_surfaceGenerator.quadVerticesToNodeIdxMapping());
}
else if ( resVarAddress.resultPosType == RIG_ELEMENT_NODAL
|| resVarAddress.resultPosType == RIG_INTEGRATION_POINT)
|| resVarAddress.resultPosType == RIG_INTEGRATION_POINT
|| resVarAddress.resultPosType == RIG_FORMATION_NAMES)
{
vxToResultMapping = &(m_surfaceGenerator.quadVerticesToGlobalElmNodeIdx());
}
Expand Down
2 changes: 2 additions & 0 deletions ApplicationCode/ProjectDataModel/RimCase.h
Expand Up @@ -59,6 +59,8 @@ class RimCase : public caf::PdmObject

virtual cvf::Vec3d displayModelOffset() const;

virtual void updateFormationNamesData() = 0;

private:
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override;
virtual caf::PdmFieldHandle* userDescriptionField() override { return &caseUserDescription; }
Expand Down
2 changes: 1 addition & 1 deletion ApplicationCode/ProjectDataModel/RimDefines.cpp
Expand Up @@ -31,7 +31,7 @@ namespace caf
addItem(RimDefines::STATIC_NATIVE, "STATIC_NATIVE", "Static");
addItem(RimDefines::GENERATED, "GENERATED", "Generated");
addItem(RimDefines::INPUT_PROPERTY, "INPUT_PROPERTY", "Input Property");

addItem(RimDefines::FORMATION_NAMES, "FORMATION_NAMES", "Formation Names");
setDefault(RimDefines::DYNAMIC_NATIVE);
}

Expand Down
1 change: 1 addition & 0 deletions ApplicationCode/ProjectDataModel/RimDefines.h
Expand Up @@ -32,6 +32,7 @@ class RimDefines
STATIC_NATIVE,
GENERATED,
INPUT_PROPERTY,
FORMATION_NAMES,
REMOVED
};

Expand Down
30 changes: 30 additions & 0 deletions ApplicationCode/ProjectDataModel/RimEclipseCase.cpp
Expand Up @@ -33,6 +33,7 @@
#include "RimEclipsePropertyFilter.h"
#include "RimEclipsePropertyFilterCollection.h"
#include "RimEclipseView.h"
#include "RimFormationNames.h"
#include "RimReservoirCellResultsStorage.h"
#include "RimProject.h"
#include "RimMainPlotCollection.h"
Expand Down Expand Up @@ -283,6 +284,30 @@ void RimEclipseCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c
}
}
}
else if(changedField == &activeFormationNames)
{
updateFormationNamesData();
}
}


//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCase::updateFormationNamesData()
{
RigCaseData* rigEclipseCase = reservoirData();
if(rigEclipseCase)
{
if(activeFormationNames())
{
rigEclipseCase->setActiveFormationNames(activeFormationNames()->formationNamesData());
}
else
{
rigEclipseCase->setActiveFormationNames(nullptr);
}
}
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -303,9 +328,14 @@ void RimEclipseCase::computeCachedData()
rigEclipseCase->mainGrid()->computeCachedData();
pInf.incrementProgress();

pInf.setNextProgressIncrement(17);
pInf.setProgressDescription("Calculating faults");
rigEclipseCase->mainGrid()->calculateFaults(rigEclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS));
pInf.incrementProgress();

pInf.setProgressDescription("Calculating Formation Names Result");
this->updateFormationNamesData();
pInf.incrementProgress();
}
}

Expand Down
2 changes: 2 additions & 0 deletions ApplicationCode/ProjectDataModel/RimEclipseCase.h
Expand Up @@ -98,6 +98,8 @@ class RimEclipseCase : public RimCase
virtual void initAfterRead();
virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue );

virtual void updateFormationNamesData() override;

// Internal methods
protected:
void computeCachedData();
Expand Down
Expand Up @@ -453,6 +453,11 @@ bool RimEclipseResultDefinition::isTernarySaturationSelected() const
//--------------------------------------------------------------------------------------------------
bool RimEclipseResultDefinition::hasCategoryResult() const
{
if (this->m_resultType() == RimDefines::FORMATION_NAMES
&& m_eclipseCase
&& m_eclipseCase->reservoirData()
&& m_eclipseCase->reservoirData()->activeFormationNames() ) return true;

if (!this->hasStaticResult()) return false;

return this->resultVariable().contains("NUM", Qt::CaseInsensitive);
Expand Down
16 changes: 15 additions & 1 deletion ApplicationCode/ProjectDataModel/RimEclipseView.cpp
Expand Up @@ -74,6 +74,7 @@
#include <QMessageBox>

#include <limits.h>
#include "RigFormationNames.h"



Expand Down Expand Up @@ -990,7 +991,20 @@ void RimEclipseView::updateMinMaxValuesAndAddLegendToView(QString legendLabel, R
{
size_t adjustedTimeStep = m_currentTimeStep;
if (resultColors->hasStaticResult()) adjustedTimeStep = 0;
resultColors->legendConfig()->setCategories(cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex()), cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex(), adjustedTimeStep));

if(resultColors->resultType() != RimDefines::FORMATION_NAMES)
{
resultColors->legendConfig()->setCategories(cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex()),
cellResultsData->uniqueCellScalarValues(resultColors->scalarResultIndex(), adjustedTimeStep));
}
else
{
const std::vector<QString>& fnVector =
eclipseCase()->reservoirData()->activeFormationNames()->formationNames();
std::set<int> nameIndices;
for(int i = 0; i < fnVector.size(); ++i) nameIndices.insert(i);
resultColors->legendConfig()->setCategories(nameIndices, nameIndices);
}
}

m_viewer->addColorLegendToBottomLeftCorner(resultColors->legendConfig()->legend());
Expand Down
2 changes: 2 additions & 0 deletions ApplicationCode/ProjectDataModel/RimFormationNames.cpp
Expand Up @@ -18,6 +18,8 @@

#include "RimFormationNames.h"

#include "RigFormationNames.h"

#include "RimTools.h"

#include "cafPdmUiFilePathEditor.h"
Expand Down
37 changes: 0 additions & 37 deletions ApplicationCode/ProjectDataModel/RimFormationNames.h
Expand Up @@ -50,40 +50,3 @@ class RimFormationNames : public caf::PdmObject

cvf::ref<RigFormationNames> m_formationNamesData;
};

class RigFormationNames: public cvf::Object
{
public:
int formationIndexFromKLayerIdx(size_t Kidx)
{
if(Kidx >= m_nameIndexPrKLayer.size()) return -1;
return m_nameIndexPrKLayer[Kidx];
}

QString formationNameFromKLayerIdx(size_t Kidx)
{
int idx = formationIndexFromKLayerIdx(Kidx);
if (idx >= m_formationNames.size()) return "";
if (idx == -1) return "";

return m_formationNames[idx];
}

void appendFormationRange(const QString& name, int kStartIdx, int kEndIdx)
{
CVF_ASSERT(kStartIdx <= kEndIdx);
int nameIdx = static_cast<int>(m_formationNames.size());
m_formationNames.push_back(name);
if (kEndIdx >= static_cast<int>(m_nameIndexPrKLayer.size())) m_nameIndexPrKLayer.resize(kEndIdx + 1, -1);

for (int kIdx = kStartIdx; kIdx <= kEndIdx; ++kIdx)
{
m_nameIndexPrKLayer[kIdx] = nameIdx;
}
}

private:

std::vector<int> m_nameIndexPrKLayer;
std::vector<QString> m_formationNames;
};
37 changes: 36 additions & 1 deletion ApplicationCode/ProjectDataModel/RimGeoMechCase.cpp
Expand Up @@ -27,12 +27,14 @@
#include "RigFemPartCollection.h"
#include "RigFemPartResultsCollection.h"
#include "RigGeoMechCaseData.h"
#include "RigFormationNames.h"

#include "RimGeoMechView.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RimTools.h"
#include "RimWellLogPlotCollection.h"
#include "RimFormationNames.h"

#include <QFile>

Expand Down Expand Up @@ -114,7 +116,10 @@ bool RimGeoMechCase::openGeoMechCase(std::string* errorMessage)
// Also, several places is checked for this data to validate availability of data
m_geoMechCaseData = NULL;
}

else
{
this->updateFormationNamesData();
}
return fileOpenSuccess;
}

Expand Down Expand Up @@ -240,6 +245,36 @@ std::vector<QDateTime> RimGeoMechCase::dateTimeVectorFromTimeStepStrings(const Q
return dates;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if(changedField == &activeFormationNames)
{
updateFormationNamesData();
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechCase::updateFormationNamesData()
{
RigGeoMechCaseData* rigCaseData = geoMechData();
if(rigCaseData && rigCaseData->femPartResults())
{
if(activeFormationNames())
{
rigCaseData->femPartResults()->setActiveFormationNames(activeFormationNames()->formationNamesData());
}
else
{
rigCaseData->femPartResults()->setActiveFormationNames(nullptr);
}
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit c903e87

Please sign in to comment.