diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.cpp b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.cpp index 20b6012568..18274d3b40 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.cpp +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.cpp @@ -71,7 +71,7 @@ void RigFemPart::appendElement(RigElementType elmType, int id, const int* connec //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const RigFemPartGrid* RigFemPart::structGrid() const +const RigFemPartGrid* RigFemPart::getOrCreateStructGrid() const { if (m_structGrid.isNull()) { diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.h b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.h index c2eb6a799e..cae026c8e9 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.h +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.h @@ -85,7 +85,7 @@ public: cvf::Vec3f faceNormal(int elmentIndex, int faceIndex) const; - const RigFemPartGrid* structGrid() const; + const RigFemPartGrid* getOrCreateStructGrid() const; const std::vector& elementIdxToId() const { return m_elementId; } private: diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp index 3657789b4c..85dcabcc25 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp @@ -1516,7 +1516,7 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::calculateCompactionValues part->findIntersectingCells(bb, &refElementCandidates); // Also make sure the struct grid is created, as this is required before using OpenMP - part->structGrid(); + part->getOrCreateStructGrid(); } #pragma omp parallel for @@ -1832,6 +1832,9 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::calculateFormationIndices if (activeFormNames) { + // Has to be done before the parallel loop because the first call allocates. + const RigFemPartGrid* structGrid = femPart->getOrCreateStructGrid(); + int elementCount = femPart->elementCount(); #pragma omp parallel for @@ -1841,7 +1844,7 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::calculateFormationIndices int elmNodeCount = RigFemTypes::elmentNodeCount(elmType); size_t i, j, k; - bool validIndex = femPart->structGrid()->ijkFromCellIndex(elmIdx, &i, &j, &k); + bool validIndex = structGrid->ijkFromCellIndex(elmIdx, &i, &j, &k); if (validIndex) { int formNameIdx = activeFormNames->formationIndexFromKLayerIdx(k); @@ -2771,7 +2774,7 @@ void findReferenceElementForNode(const RigFemPart& part, size_t nodeIdx, size_t std::vector refElementCandidates; part.findIntersectingCells(bb, &refElementCandidates); - const RigFemPartGrid* grid = part.structGrid(); + const RigFemPartGrid* grid = part.getOrCreateStructGrid(); const std::vector& nodeCoords = part.nodes().coordinates; refElement->elementIdx = cvf::UNDEFINED_SIZE_T; diff --git a/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp b/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp index 7b79840584..07eb7bcc6e 100644 --- a/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp +++ b/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp @@ -57,7 +57,7 @@ void RivFemElmVisibilityCalculator::computeRangeVisibility(cvf::UByteArray* elmV { elmVisibilities->resize(femPart->elementCount()); - const RigFemPartGrid* grid = femPart->structGrid(); + const RigFemPartGrid* grid = femPart->getOrCreateStructGrid(); if (rangeFilter.hasIncludeRanges()) { diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechResultDefinition.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechResultDefinition.cpp index 06bf63fe4c..9bc8ed4b64 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechResultDefinition.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechResultDefinition.cpp @@ -145,7 +145,7 @@ void RimGeoMechResultDefinition::defineUiOrdering(QString uiConfigName, caf::Pdm { if (m_geomCase && m_geomCase->geoMechData() ) { - m_compactionRefLayerUiField = (int)m_geomCase->geoMechData()->femParts()->part(0)->structGrid()->reservoirIJKBoundingBox().first.z(); + m_compactionRefLayerUiField = (int)m_geomCase->geoMechData()->femParts()->part(0)->getOrCreateStructGrid()->reservoirIJKBoundingBox().first.z(); } } } @@ -220,7 +220,7 @@ QList RimGeoMechResultDefinition::calculateValueOptions( { if (m_geomCase->geoMechData()) { - size_t kCount = m_geomCase->geoMechData()->femParts()->part(0)->structGrid()->gridPointCountK() - 1; + size_t kCount = m_geomCase->geoMechData()->femParts()->part(0)->getOrCreateStructGrid()->gridPointCountK() - 1; for ( size_t layerIdx = 0; layerIdx < kCount; ++layerIdx ) { options.push_back(caf::PdmOptionItemInfo(QString::number(layerIdx + 1), (int)layerIdx)); diff --git a/ApplicationCode/ReservoirDataModel/RigCaseToCaseRangeFilterMapper.cpp b/ApplicationCode/ReservoirDataModel/RigCaseToCaseRangeFilterMapper.cpp index 274457d7bb..fc99f16db9 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseToCaseRangeFilterMapper.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseToCaseRangeFilterMapper.cpp @@ -108,9 +108,9 @@ void RigCaseToCaseRangeFilterMapper::convertRangeFilter(const RimCellRangeFilter } else { - maxIIndex = femPart->structGrid()->cellCountI()- 1; - maxJIndex = femPart->structGrid()->cellCountJ()- 1; - maxKIndex = femPart->structGrid()->cellCountK()- 1; + maxIIndex = femPart->getOrCreateStructGrid()->cellCountI()- 1; + maxJIndex = femPart->getOrCreateStructGrid()->cellCountJ()- 1; + maxKIndex = femPart->getOrCreateStructGrid()->cellCountK()- 1; } src.EndI = CVF_MIN(src.EndI, maxIIndex); @@ -398,7 +398,7 @@ RigCaseToCaseRangeFilterMapper::findBestFemCellFromEclCell(const RigMainGrid* ma if (elmIdxToBestMatch != -1) { - bool validIndex = dependentFemPart->structGrid()->ijkFromCellIndex(elmIdxToBestMatch, fi, fj, fk); + bool validIndex = dependentFemPart->getOrCreateStructGrid()->ijkFromCellIndex(elmIdxToBestMatch, fi, fj, fk); CVF_ASSERT(validIndex); } else @@ -429,7 +429,7 @@ RigCaseToCaseRangeFilterMapper::findBestEclCellFromFemCell(const RigFemPart* dep bool isEclFaceNormalsOutwards = masterEclGrid->isFaceNormalsOutwards(); - int elementIdx = static_cast(dependentFemPart->structGrid()->cellIndexFromIJK(fi, fj, fk)); + int elementIdx = static_cast(dependentFemPart->getOrCreateStructGrid()->cellIndexFromIJK(fi, fj, fk)); cvf::Vec3d elmCorners[8]; RigCaseToCaseCellMapperTools::elementCorners(dependentFemPart, elementIdx, elmCorners); diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirGridTools.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirGridTools.cpp index 1883b3765b..c61c2e7ca0 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirGridTools.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirGridTools.cpp @@ -74,7 +74,7 @@ const cvf::StructGridInterface* RigReservoirGridTools::gridByIndex(RimCase* rimC } else if (geoMechPartCollection) { - return geoMechPartCollection->part(gridIndex)->structGrid(); + return geoMechPartCollection->part(gridIndex)->getOrCreateStructGrid(); } return nullptr; diff --git a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp index 6156e0fe5e..08bfca40f3 100644 --- a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp @@ -618,7 +618,7 @@ public: else if (item->type() == RiuSelectionItem::GEOMECH_SELECTION_OBJECT) { const RiuGeoMechSelectionItem* geomechItem = static_cast(item); - validIndex = geomechItem->m_view->femParts()->part(geomechItem->m_gridIndex)->structGrid()->ijkFromCellIndex(geomechItem->m_cellIndex, &i, &j, &k); + validIndex = geomechItem->m_view->femParts()->part(geomechItem->m_gridIndex)->getOrCreateStructGrid()->ijkFromCellIndex(geomechItem->m_cellIndex, &i, &j, &k); CVF_ASSERT(validIndex); gridIndex = geomechItem->m_gridIndex; caseId = geomechItem->m_view->geoMechCase()->caseId; diff --git a/ApplicationCode/UserInterface/RiuFemResultTextBuilder.cpp b/ApplicationCode/UserInterface/RiuFemResultTextBuilder.cpp index d0fcd44f82..f00611921b 100644 --- a/ApplicationCode/UserInterface/RiuFemResultTextBuilder.cpp +++ b/ApplicationCode/UserInterface/RiuFemResultTextBuilder.cpp @@ -141,7 +141,7 @@ QString RiuFemResultTextBuilder::geometrySelectionText(QString itemSeparator) size_t i = 0; size_t j = 0; size_t k = 0; - if (geomData->femParts()->part(m_gridIndex)->structGrid()->ijkFromCellIndex(m_cellIndex, &i, &j, &k)) + if (geomData->femParts()->part(m_gridIndex)->getOrCreateStructGrid()->ijkFromCellIndex(m_cellIndex, &i, &j, &k)) { // Adjust to 1-based Eclipse indexing i++; @@ -224,7 +224,7 @@ QString RiuFemResultTextBuilder::formationDetails() { size_t i = 0; size_t j = 0; - geomData->femParts()->part(m_gridIndex)->structGrid()->ijkFromCellIndex(m_cellIndex, &i, &j, &k); + geomData->femParts()->part(m_gridIndex)->getOrCreateStructGrid()->ijkFromCellIndex(m_cellIndex, &i, &j, &k); } } } diff --git a/ApplicationCode/UserInterface/RiuFemTimeHistoryResultAccessor.cpp b/ApplicationCode/UserInterface/RiuFemTimeHistoryResultAccessor.cpp index a0db095e51..9f7d3a3a73 100644 --- a/ApplicationCode/UserInterface/RiuFemTimeHistoryResultAccessor.cpp +++ b/ApplicationCode/UserInterface/RiuFemTimeHistoryResultAccessor.cpp @@ -87,7 +87,7 @@ QString RiuFemTimeHistoryResultAccessor::geometrySelectionText() const size_t i = 0; size_t j = 0; size_t k = 0; - if (m_geoMechCaseData->femParts()->part(m_gridIndex)->structGrid()->ijkFromCellIndex(m_elementIndex, &i, &j, &k)) + if (m_geoMechCaseData->femParts()->part(m_gridIndex)->getOrCreateStructGrid()->ijkFromCellIndex(m_elementIndex, &i, &j, &k)) { // Adjust to 1-based Eclipse indexing i++; diff --git a/ApplicationCode/UserInterface/RiuMohrsCirclePlot.cpp b/ApplicationCode/UserInterface/RiuMohrsCirclePlot.cpp index 2188fdf1df..7eac3f6953 100644 --- a/ApplicationCode/UserInterface/RiuMohrsCirclePlot.cpp +++ b/ApplicationCode/UserInterface/RiuMohrsCirclePlot.cpp @@ -379,7 +379,7 @@ void RiuMohrsCirclePlot::queryData(RimGeoMechView* geoMechView, size_t gridIndex double frictionAngleDeg = geoMechView->geoMechCase()->frictionAngleDeg(); size_t i, j, k; - bool validIndex = femPart->structGrid()->ijkFromCellIndex(elmIndex, &i, &j, &k); + bool validIndex = femPart->getOrCreateStructGrid()->ijkFromCellIndex(elmIndex, &i, &j, &k); CVF_ASSERT(validIndex); if (validIndex) diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index cbf695edeb..61468c11f7 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -1079,7 +1079,7 @@ void RiuViewerCommands::ijkFromCellIndex(size_t gridIdx, size_t cellIndex, size if (geomView && geomView->geoMechCase()) { - geomView->femParts()->part(gridIdx)->structGrid()->ijkFromCellIndex(cellIndex, i, j, k); + geomView->femParts()->part(gridIdx)->getOrCreateStructGrid()->ijkFromCellIndex(cellIndex, i, j, k); } }