#3979 #3980 Contour Maps: Fix GeoMech crash and make limit to POR-result optional.

This commit is contained in:
Gaute Lindkvist committed 2019-01-22 14:00:09 +01:00
1 parent 8814ae9902
commit 810a991ba4
8 files changed
+93 -43

No files matched your search

@@ -2261,6 +2261,19 @@ void RigFemPartResultsCollection::deleteResult(const RigFemResultAddress& resVar
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemPartResultsCollection::deleteResultFrame(const RigFemResultAddress& resVarAddr, int partIndex, int frameIndex)
{
CVF_ASSERT(resVarAddr.isValid());
RigFemScalarResultFrames* frames = m_femPartResults[partIndex]->findScalarResult(resVarAddr);
if (frames)
{
std::vector<float>().swap(frames->frameData(frameIndex));
}
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -67,7 +67,7 @@ public:
std::vector<std::string> filteredStepNames() const; std::vector<std::string> filteredStepNames() const;
bool assertResultsLoaded(const RigFemResultAddress& resVarAddr); bool assertResultsLoaded(const RigFemResultAddress& resVarAddr);
void deleteResult(const RigFemResultAddress& resVarAddr); void deleteResult(const RigFemResultAddress& resVarAddr);
void deleteResultFrame(const RigFemResultAddress& resVarAddr, int partIndex, int frameIndex);
std::vector<RigFemResultAddress> loadedResults() const; std::vector<RigFemResultAddress> loadedResults() const;
const std::vector<float>& resultValues(const RigFemResultAddress& resVarAddr, int partIndex, int frameIndex); const std::vector<float>& resultValues(const RigFemResultAddress& resVarAddr, int partIndex, int frameIndex);
@@ -677,22 +677,20 @@ double RimContourMapProjection::minValue(const std::vector<double>& aggregatedRe
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::pair<double, double> RimContourMapProjection::minmaxValuesAllTimeSteps() std::pair<double, double> RimContourMapProjection::minmaxValuesAllTimeSteps(int skipSteps /*= 1*/)
{ {
if (timestepRangeNeedsUpdating()) if (timestepRangeNeedsUpdating())
{ {
clearTimeStepRange(); clearTimeStepRange();
for (int i = 0; i < (int)baseView()->ownerCase()->timeStepStrings().size(); ++i) m_minResultAllTimeSteps = std::min(m_minResultAllTimeSteps, minValue(m_aggregatedResults));
m_maxResultAllTimeSteps = std::max(m_maxResultAllTimeSteps, maxValue(m_aggregatedResults));
for (int i = 0; i < (int)baseView()->ownerCase()->timeStepStrings().size() - 1; i += skipSteps)
{ {
if (i == m_currentResultTimestep) std::vector<double> aggregatedResults = generateResults(i);
{ {
m_minResultAllTimeSteps = std::min(m_minResultAllTimeSteps, minValue(m_aggregatedResults)); std::vector<double> aggregatedResults = generateResults(i, true);
m_maxResultAllTimeSteps = std::max(m_maxResultAllTimeSteps, maxValue(m_aggregatedResults));
}
else
{
std::vector<double> aggregatedResults = generateResults(i, 10);
m_minResultAllTimeSteps = std::min(m_minResultAllTimeSteps, minValue(aggregatedResults)); m_minResultAllTimeSteps = std::min(m_minResultAllTimeSteps, minValue(aggregatedResults));
m_maxResultAllTimeSteps = std::max(m_maxResultAllTimeSteps, maxValue(aggregatedResults)); m_maxResultAllTimeSteps = std::max(m_maxResultAllTimeSteps, maxValue(aggregatedResults));
} }
@@ -965,7 +963,7 @@ void RimContourMapProjection::generateTrianglesWithVertexValues()
} }
} }
std::vector<std::vector<cvf::Vec4d>> trianglesPerLevel(std::max((size_t)1, contourLevels.size())); std::vector<std::vector<cvf::Vec4d>> trianglesPerLevel(std::max((size_t)1, m_contourPolygons.size()));
for (size_t c = 0; c < trianglesPerLevel.size(); ++c) for (size_t c = 0; c < trianglesPerLevel.size(); ++c)
{ {
std::vector<cvf::Vec4d> allTrianglesThisLevel; std::vector<cvf::Vec4d> allTrianglesThisLevel;
@@ -979,10 +977,6 @@ void RimContourMapProjection::generateTrianglesWithVertexValues()
{ {
trianglesPerLevel[c] = allTrianglesThisLevel; trianglesPerLevel[c] = allTrianglesThisLevel;
} }
else
{
m_contourPolygons[c].clear();
}
} }
std::vector<cvf::Vec4d> finalTriangles; std::vector<cvf::Vec4d> finalTriangles;
@@ -1026,14 +1020,15 @@ void RimContourMapProjection::generateContourPolygons()
const double areaTreshold = (m_sampleSpacing * m_sampleSpacing) / (sampleSpacingFactor() * sampleSpacingFactor()); const double areaTreshold = (m_sampleSpacing * m_sampleSpacing) / (sampleSpacingFactor() * sampleSpacingFactor());
if (minValue() != std::numeric_limits<double>::infinity() && maxValue() != -std::numeric_limits<double>::infinity() && std::vector<double> contourLevels;
std::fabs(maxValue() - minValue()) > 1.0e-8) if (legendConfig()->mappingMode() != RimRegularLegendConfig::CATEGORY_INTEGER)
{ {
std::vector<double> contourLevels; legendConfig()->scalarMapper()->majorTickValues(&contourLevels);
if (legendConfig()->mappingMode() != RimRegularLegendConfig::CATEGORY_INTEGER) int nContourLevels = static_cast<int>(contourLevels.size());
if (minValue() != std::numeric_limits<double>::infinity() && maxValue() != -std::numeric_limits<double>::infinity() &&
std::fabs(maxValue() - minValue()) > 1.0e-8)
{ {
legendConfig()->scalarMapper()->majorTickValues(&contourLevels);
int nContourLevels = static_cast<int>(contourLevels.size());
if (nContourLevels > 2) if (nContourLevels > 2)
{ {
if (legendConfig()->mappingMode() == RimRegularLegendConfig::LINEAR_DISCRETE || if (legendConfig()->mappingMode() == RimRegularLegendConfig::LINEAR_DISCRETE ||
@@ -1046,30 +1041,34 @@ void RimContourMapProjection::generateContourPolygons()
contourLevels.front() *= 0.5; contourLevels.front() *= 0.5;
} }
std::vector<caf::ContourLines::ListOfLineSegments> unorderedLineSegmentsPerLevel = caf::ContourLines::create( std::vector<caf::ContourLines::ListOfLineSegments> unorderedLineSegmentsPerLevel =
m_aggregatedVertexResults, xVertexPositions(), yVertexPositions(), contourLevels); caf::ContourLines::create(m_aggregatedVertexResults, xVertexPositions(), yVertexPositions(), contourLevels);
std::vector<ContourPolygons>(unorderedLineSegmentsPerLevel.size()).swap(contourPolygons); std::vector<ContourPolygons>(unorderedLineSegmentsPerLevel.size()).swap(contourPolygons);
for (size_t i = 0; i < unorderedLineSegmentsPerLevel.size(); ++i) for (size_t i = 0; i < unorderedLineSegmentsPerLevel.size(); ++i)
{ {
std::vector<std::vector<cvf::Vec3d>> polygonsForThisLevel; std::vector<std::vector<cvf::Vec3d>> polygonsForThisLevel;
RigCellGeometryTools::createPolygonFromLineSegments(unorderedLineSegmentsPerLevel[i], polygonsForThisLevel, 1.0e-8); RigCellGeometryTools::createPolygonFromLineSegments(
unorderedLineSegmentsPerLevel[i], polygonsForThisLevel, 1.0e-8);
for (size_t j = 0; j < polygonsForThisLevel.size(); ++j) for (size_t j = 0; j < polygonsForThisLevel.size(); ++j)
{ {
double signedArea = cvf::GeometryTools::signedAreaPlanarPolygon(cvf::Vec3d::Z_AXIS, polygonsForThisLevel[j]); double signedArea =
cvf::GeometryTools::signedAreaPlanarPolygon(cvf::Vec3d::Z_AXIS, polygonsForThisLevel[j]);
ContourPolygon contourPolygon; ContourPolygon contourPolygon;
contourPolygon.value = contourLevels[i]; contourPolygon.value = contourLevels[i];
if (signedArea < 0.0) if (signedArea < 0.0)
{ {
contourPolygon.vertices.insert(contourPolygon.vertices.end(), polygonsForThisLevel[j].rbegin(), polygonsForThisLevel[j].rend()); contourPolygon.vertices.insert(
contourPolygon.vertices.end(), polygonsForThisLevel[j].rbegin(), polygonsForThisLevel[j].rend());
} }
else else
{ {
contourPolygon.vertices = polygonsForThisLevel[j]; contourPolygon.vertices = polygonsForThisLevel[j];
} }
contourPolygon.area = cvf::GeometryTools::signedAreaPlanarPolygon(cvf::Vec3d::Z_AXIS, contourPolygon.vertices); contourPolygon.area =
cvf::GeometryTools::signedAreaPlanarPolygon(cvf::Vec3d::Z_AXIS, contourPolygon.vertices);
if (contourPolygon.area > areaTreshold) if (contourPolygon.area > areaTreshold)
{ {
for (const cvf::Vec3d& vertex : contourPolygon.vertices) for (const cvf::Vec3d& vertex : contourPolygon.vertices)
@@ -1098,9 +1097,9 @@ void RimContourMapProjection::generateContourPolygons()
} }
} }
m_contourLevelCumulativeAreas.resize(contourPolygons.size(), 0.0); m_contourLevelCumulativeAreas.resize(contourPolygons.size(), 0.0);
for (int64_t i = (int64_t) contourPolygons.size() - 1; i >= 0; --i) for (int64_t i = (int64_t)contourPolygons.size() - 1; i >= 0; --i)
{ {
double levelOuterArea = sumPolygonArea(contourPolygons[i]); double levelOuterArea = sumPolygonArea(contourPolygons[i]);
m_contourLevelCumulativeAreas[i] = levelOuterArea; m_contourLevelCumulativeAreas[i] = levelOuterArea;
} }
} }
@@ -121,7 +121,7 @@ protected:
// Protected virtual methods to be overridden by Eclipse and Geo-mechanical contour map implementations // Protected virtual methods to be overridden by Eclipse and Geo-mechanical contour map implementations
virtual void updateGridInformation() = 0; virtual void updateGridInformation() = 0;
virtual std::vector<double> retrieveParameterWeights() = 0; virtual std::vector<double> retrieveParameterWeights() = 0;
virtual std::vector<double> generateResults(int timeStep, int everyNCells = 1) = 0; virtual std::vector<double> generateResults(int timeStep) = 0;
virtual bool resultVariableChanged() const = 0; virtual bool resultVariableChanged() const = 0;
virtual void clearResultVariable() = 0; virtual void clearResultVariable() = 0;
virtual RimGridView* baseView() const = 0; virtual RimGridView* baseView() const = 0;
@@ -145,7 +145,7 @@ protected:
double maxValue(const std::vector<double>& aggregatedResults) const; double maxValue(const std::vector<double>& aggregatedResults) const;
double minValue(const std::vector<double>& aggregatedResults) const; double minValue(const std::vector<double>& aggregatedResults) const;
std::pair<double, double> minmaxValuesAllTimeSteps(); std::pair<double, double> minmaxValuesAllTimeSteps(int skipSteps = 1);
virtual cvf::ref<cvf::UByteArray> getCellVisibility() const; virtual cvf::ref<cvf::UByteArray> getCellVisibility() const;
void generateGridMapping(); void generateGridMapping();
@@ -172,7 +172,7 @@ void RimEclipseContourMapProjection::updatedWeightingResult()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::vector<double> RimEclipseContourMapProjection::generateResults(int timeStep, int everyNCells) std::vector<double> RimEclipseContourMapProjection::generateResults(int timeStep)
{ {
m_weightingResult->loadResult(); m_weightingResult->loadResult();
@@ -214,8 +214,10 @@ std::vector<double> RimEclipseContourMapProjection::generateResults(int timeStep
} }
} }
int everyNCells = temporaryResult ? 10 : 1;
#pragma omp parallel for #pragma omp parallel for
for (int index = 0; index < static_cast<int>(nCells); index += everyNCells) for (int index = 0; index < static_cast<int>(nCells); ++index)
{ {
cvf::Vec2ui ij = ijFromCellIndex(index); cvf::Vec2ui ij = ijFromCellIndex(index);
aggregatedResults[index] = calculateValueInMapCell(ij.x(), ij.y()); aggregatedResults[index] = calculateValueInMapCell(ij.x(), ij.y());
@@ -63,7 +63,7 @@ protected:
void updateGridInformation() override; void updateGridInformation() override;
std::vector<double> retrieveParameterWeights() override; std::vector<double> retrieveParameterWeights() override;
std::vector<double> generateResults(int timeStep, int everyNCells = 1) override; std::vector<double> generateResults(int timeStep) override;
bool resultVariableChanged() const override; bool resultVariableChanged() const override;
void clearResultVariable() override; void clearResultVariable() override;
RimGridView* baseView() const override; RimGridView* baseView() const override;
@@ -57,7 +57,8 @@ CAF_PDM_SOURCE_INIT(RimGeoMechContourMapProjection, "RimGeoMechContourMapProject
RimGeoMechContourMapProjection::RimGeoMechContourMapProjection() RimGeoMechContourMapProjection::RimGeoMechContourMapProjection()
{ {
CAF_PDM_InitObject("RimContourMapProjection", ":/2DMapProjection16x16.png", "", ""); CAF_PDM_InitObject("RimContourMapProjection", ":/2DMapProjection16x16.png", "", "");
CAF_PDM_InitField(&m_limitToPorePressureRegions, "LimitToPorRegion", true, "Limit to Pore Pressure regions", "", "", "");
CAF_PDM_InitField(&m_includePaddingAroundPorePressureRegion, "PaddingAroundPorRegion", true, "Include Padding around Pore Pressure regions", "", "", "");
setName("Map Projection"); setName("Map Projection");
nameField()->uiCapability()->setUiReadOnly(true); nameField()->uiCapability()->setUiReadOnly(true);
} }
@@ -94,12 +95,16 @@ void RimGeoMechContourMapProjection::updateLegend()
double minVal = minValue(m_aggregatedResults); double minVal = minValue(m_aggregatedResults);
double maxVal = maxValue(m_aggregatedResults); double maxVal = maxValue(m_aggregatedResults);
std::pair<double, double> minmaxValAllTimeSteps = minmaxValuesAllTimeSteps(); std::pair<double, double> minmaxValAllTimeSteps = minmaxValuesAllTimeSteps(2);
legendConfig()->setAutomaticRanges(minmaxValAllTimeSteps.first, minmaxValAllTimeSteps.second, minVal, maxVal); legendConfig()->setAutomaticRanges(minmaxValAllTimeSteps.first, minmaxValAllTimeSteps.second, minVal, maxVal);
QString projectionLegendText = QString("Map Projection\n%1").arg(m_resultAggregation().uiText()); QString projectionLegendText = QString("Map Projection\n%1").arg(m_resultAggregation().uiText());
projectionLegendText += QString("\nResult: %1").arg(cellColors->resultFieldUiName()); projectionLegendText += QString("\nResult: %1").arg(cellColors->resultFieldUiName());
if (!cellColors->resultComponentUiName().isEmpty())
{
projectionLegendText += QString(", %1").arg(cellColors->resultComponentUiName());
}
legendConfig()->setTitle(projectionLegendText); legendConfig()->setTitle(projectionLegendText);
} }
@@ -117,7 +122,10 @@ cvf::ref<cvf::UByteArray> RimGeoMechContourMapProjection::getCellVisibility() co
RivFemElmVisibilityCalculator::computeRangeVisibility(cellGridIdxVisibility.p(), m_femPart.p(), cellRangeFilter); RivFemElmVisibilityCalculator::computeRangeVisibility(cellGridIdxVisibility.p(), m_femPart.p(), cellRangeFilter);
RivFemElmVisibilityCalculator::computePropertyVisibility(cellGridIdxVisibility.p(), m_femPart.p(), view()->currentTimeStep(), cellGridIdxVisibility.p(), view()->geoMechPropertyFilterCollection()); RivFemElmVisibilityCalculator::computePropertyVisibility(cellGridIdxVisibility.p(), m_femPart.p(), view()->currentTimeStep(), cellGridIdxVisibility.p(), view()->geoMechPropertyFilterCollection());
ensureOnlyValidPorBarVisible(cellGridIdxVisibility.p(), view()->currentTimeStep()); if (m_limitToPorePressureRegions)
{
ensureOnlyValidPorBarVisible(cellGridIdxVisibility.p(), view()->currentTimeStep());
}
return cellGridIdxVisibility; return cellGridIdxVisibility;
} }
@@ -136,6 +144,7 @@ void RimGeoMechContourMapProjection::ensureOnlyValidPorBarVisible(cvf::UByteArra
for (int i = 0; i < static_cast<int>(visibility->size()); ++i) for (int i = 0; i < static_cast<int>(visibility->size()); ++i)
{ {
size_t resValueIdx = m_femPart->elementNodeResultIdx((int) i, 0); size_t resValueIdx = m_femPart->elementNodeResultIdx((int) i, 0);
CVF_ASSERT(resValueIdx < resultValues.size());
double scalarValue = resultValues[resValueIdx]; double scalarValue = resultValues[resValueIdx];
(*visibility)[i] &= scalarValue != std::numeric_limits<double>::infinity(); (*visibility)[i] &= scalarValue != std::numeric_limits<double>::infinity();
} }
@@ -178,7 +187,7 @@ std::vector<double> RimGeoMechContourMapProjection::retrieveParameterWeights()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::vector<double> RimGeoMechContourMapProjection::generateResults(int timeStep, int everyNCells) std::vector<double> RimGeoMechContourMapProjection::generateResults(int timeStep)
{ {
RigGeoMechCaseData* caseData = geoMechCase()->geoMechData(); RigGeoMechCaseData* caseData = geoMechCase()->geoMechData();
RigFemPartResultsCollection* resultCollection = caseData->femPartResults(); RigFemPartResultsCollection* resultCollection = caseData->femPartResults();
@@ -198,8 +207,10 @@ std::vector<double> RimGeoMechContourMapProjection::generateResults(int timeStep
m_resultValues = resultCollection->resultValues(resAddr, 0, timeStep); m_resultValues = resultCollection->resultValues(resAddr, 0, timeStep);
int everyNCells = temporaryResult ? 10 : 1;
#pragma omp parallel for #pragma omp parallel for
for (int index = 0; index < static_cast<int>(nCells); index += everyNCells) for (int index = 0; index < static_cast<int>(nCells); ++index)
{ {
cvf::Vec2ui ij = ijFromCellIndex(index); cvf::Vec2ui ij = ijFromCellIndex(index);
aggregatedResults[index] = calculateValueInMapCell(ij.x(), ij.y()); aggregatedResults[index] = calculateValueInMapCell(ij.x(), ij.y());
@@ -207,6 +218,12 @@ std::vector<double> RimGeoMechContourMapProjection::generateResults(int timeStep
m_currentResultAddr = resAddr; m_currentResultAddr = resAddr;
if (temporaryResult)
{
resultCollection->deleteResultFrame(resAddr, 0, timeStep);
}
return aggregatedResults; return aggregatedResults;
} }
@@ -421,6 +438,10 @@ void RimGeoMechContourMapProjection::fieldChangedByUi(const caf::PdmFieldHandle*
const QVariant& newValue) const QVariant& newValue)
{ {
RimContourMapProjection::fieldChangedByUi(changedField, oldValue, newValue); RimContourMapProjection::fieldChangedByUi(changedField, oldValue, newValue);
if (changedField == &m_limitToPorePressureRegions)
{
clearGridMapping();
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -448,3 +469,16 @@ QList<caf::PdmOptionItemInfo>
} }
return options; return options;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechContourMapProjection::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
RimContourMapProjection::defineUiOrdering(uiConfigName, uiOrdering);
caf::PdmUiGroup* group = uiOrdering.addNewGroup("Grid Boundaries");
group->add(&m_limitToPorePressureRegions);
}
}
@@ -63,7 +63,7 @@ protected:
void ensureOnlyValidPorBarVisible(cvf::UByteArray* visibility, int timeStep) const; void ensureOnlyValidPorBarVisible(cvf::UByteArray* visibility, int timeStep) const;
void updateGridInformation() override; void updateGridInformation() override;
std::vector<double> retrieveParameterWeights() override; std::vector<double> retrieveParameterWeights() override;
std::vector<double> generateResults(int timeStep, int everyNCells = 1) override; std::vector<double> generateResults(int timeStep) override;
bool resultVariableChanged() const override; bool resultVariableChanged() const override;
void clearResultVariable() override; void clearResultVariable() override;
RimGridView* baseView() const override; RimGridView* baseView() const override;
@@ -78,14 +78,16 @@ protected:
RimGeoMechCase* geoMechCase() const; RimGeoMechCase* geoMechCase() const;
RimGeoMechContourMapView* view() const; RimGeoMechContourMapView* view() const;
protected: protected:
// Framework overrides // Framework overrides
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions,
bool* useOptionsOnly) override; bool* useOptionsOnly) override;
void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
protected: protected:
caf::PdmField<bool> m_limitToPorePressureRegions;
caf::PdmField<bool> m_includePaddingAroundPorePressureRegion;
cvf::ref<RigFemPart> m_femPart; cvf::ref<RigFemPart> m_femPart;
cvf::cref<RigFemPartGrid> m_femPartGrid; cvf::cref<RigFemPartGrid> m_femPartGrid;
RigFemResultAddress m_currentResultAddr; RigFemResultAddress m_currentResultAddr;