diff --git a/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp b/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp index f9d820ae75..e6846e563a 100644 --- a/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp @@ -610,7 +610,7 @@ caf::FaceCulling RivFaultPartMgr::faceCullingMode() const { if (m_rimFaultCollection->faultResult() == RimFaultCollection::FAULT_BACK_FACE_CULLING) { - if (m_grid->mainGrid()->faceNormalsIsOutwards()) + if (m_grid->mainGrid()->isFaceNormalsOutwards()) { return caf::FC_BACK; } @@ -621,7 +621,7 @@ caf::FaceCulling RivFaultPartMgr::faceCullingMode() const } else if (m_rimFaultCollection->faultResult() == RimFaultCollection::FAULT_FRONT_FACE_CULLING) { - if (m_grid->mainGrid()->faceNormalsIsOutwards()) + if (m_grid->mainGrid()->isFaceNormalsOutwards()) { return caf::FC_FRONT; } diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp index 24820f5aee..3c93cdfb29 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp @@ -846,7 +846,7 @@ void RimReservoirCellResultsStorage::computeRiTransComponent(const QString& riTr const RigActiveCellInfo* activeCellInfo = m_cellResults->activeCellInfo(); const std::vector& nodes = m_ownerMainGrid->nodes(); - bool isFaceNormalsOutwards = m_ownerMainGrid->faceNormalsIsOutwards(); + bool isFaceNormalsOutwards = m_ownerMainGrid->isFaceNormalsOutwards(); for (size_t nativeResvCellIndex = 0; nativeResvCellIndex < m_ownerMainGrid->cells().size(); nativeResvCellIndex++) { @@ -990,7 +990,7 @@ void RimReservoirCellResultsStorage::computeNncCombRiTrans() const RigActiveCellInfo* activeCellInfo = m_cellResults->activeCellInfo(); const std::vector& nodes = m_ownerMainGrid->nodes(); - bool isFaceNormalsOutwards = m_ownerMainGrid->faceNormalsIsOutwards(); + bool isFaceNormalsOutwards = m_ownerMainGrid->isFaceNormalsOutwards(); // NNC calculation std::vector& nncConnections = m_ownerMainGrid->nncData()->connections(); @@ -1274,7 +1274,7 @@ void RimReservoirCellResultsStorage::computeRiTRANSbyAreaComponent(const QString const RigActiveCellInfo* activeCellInfo = m_cellResults->activeCellInfo(); const std::vector& nodes = m_ownerMainGrid->nodes(); - bool isFaceNormalsOutwards = m_ownerMainGrid->faceNormalsIsOutwards(); + bool isFaceNormalsOutwards = m_ownerMainGrid->isFaceNormalsOutwards(); for (size_t nativeResvCellIndex = 0; nativeResvCellIndex < m_ownerMainGrid->cells().size(); nativeResvCellIndex++) { diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp index a7ab0b6391..c727ecfcca 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp @@ -351,7 +351,7 @@ cvf::Vec3d RigGridBase::displayModelOffset() const //-------------------------------------------------------------------------------------------------- /// Returns the min size of the I and J charactristic cell sizes //-------------------------------------------------------------------------------------------------- -double RigGridBase::characteristicIJCellSize() +double RigGridBase::characteristicIJCellSize() const { double characteristicCellSize = HUGE_VAL; diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.h b/ApplicationCode/ReservoirDataModel/RigGridBase.h index 2ce18bd867..733de4ec99 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.h +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.h @@ -60,7 +60,7 @@ public: void setGridId(int id) { m_gridId = id; } int gridId() const { return m_gridId; } - double characteristicIJCellSize(); + double characteristicIJCellSize() const; std::string gridName() const; void setGridName(const std::string& gridName); diff --git a/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp b/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp index 118f22fb3b..eca3f8e973 100644 --- a/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp +++ b/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp @@ -363,9 +363,39 @@ void RigMainGrid::calculateFaults() /// The cell is normally inverted due to Depth becoming -Z at import, /// but if (only) one of the flipX/Y is done, the cell is back to normal //-------------------------------------------------------------------------------------------------- -bool RigMainGrid::faceNormalsIsOutwards() const +bool RigMainGrid::isFaceNormalsOutwards() const { - return m_flipXAxis ^ m_flipYAxis; + + for (int gcIdx = 0 ; gcIdx < static_cast(m_cells.size()); ++gcIdx) + { + if (!m_cells[gcIdx].isInvalid()) + { + cvf::Vec3d cellCenter = m_cells[gcIdx].center(); + cvf::Vec3d faceCenter = m_cells[gcIdx].faceCenter(StructGridInterface::POS_I); + cvf::Vec3d faceNormal = m_cells[gcIdx].faceNormalWithAreaLenght(StructGridInterface::POS_I); + + double typicalIJCellSize = characteristicIJCellSize(); + double dummy, dummy2, typicalKSize; + characteristicCellSizes(&dummy, &dummy2, &typicalKSize); + + if ( (faceCenter - cellCenter).length() > 0.2 * typicalIJCellSize + && (faceNormal.length() > (0.2 * typicalIJCellSize * 0.2* typicalKSize))) + { + // Cell is assumed ok to use, so calculate whether the normals are outwards or inwards + + if ((faceCenter - cellCenter) * faceNormal >= 0) + { + return true; + } + else + { + return false; + } + } + } + } + + return false; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigMainGrid.h b/ApplicationCode/ReservoirDataModel/RigMainGrid.h index 525293239b..8b0210d2ea 100644 --- a/ApplicationCode/ReservoirDataModel/RigMainGrid.h +++ b/ApplicationCode/ReservoirDataModel/RigMainGrid.h @@ -52,7 +52,7 @@ public: const cvf::Collection& faults() { return m_faults; } void calculateFaults(); const RigFault* findFaultFromCellIndexAndCellFace(size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face) const; - bool faceNormalsIsOutwards() const; + bool isFaceNormalsOutwards() const; void computeCachedData(); diff --git a/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp b/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp index 9575d3afb4..708e3ad558 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp +++ b/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp @@ -220,7 +220,7 @@ cvf::Vec3d StructGridInterface::displayModelOffset() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void StructGridInterface::characteristicCellSizes(double* iSize, double* jSize, double* kSize) +void StructGridInterface::characteristicCellSizes(double* iSize, double* jSize, double* kSize) const { CVF_ASSERT(iSize && jSize && kSize); diff --git a/Fwk/AppFwk/CommonCode/cvfStructGrid.h b/Fwk/AppFwk/CommonCode/cvfStructGrid.h index 8f6019bdc9..0ed191f09a 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGrid.h +++ b/Fwk/AppFwk/CommonCode/cvfStructGrid.h @@ -84,7 +84,7 @@ public: virtual cvf::Vec3d minCoordinate() const = 0; virtual cvf::Vec3d maxCoordinate() const = 0; - void characteristicCellSizes(double* iSize, double* jSize, double* kSize); + void characteristicCellSizes(double* iSize, double* jSize, double* kSize) const; virtual cvf::Vec3d displayModelOffset() const; @@ -109,9 +109,9 @@ public: static void neighborIJKAtCellFace(size_t i, size_t j, size_t k, StructGridInterface::FaceType face, size_t* ni, size_t* nj, size_t* nk); private: - double m_characteristicCellSizeI; - double m_characteristicCellSizeJ; - double m_characteristicCellSizeK; + mutable double m_characteristicCellSizeI; + mutable double m_characteristicCellSizeJ; + mutable double m_characteristicCellSizeK; }; } // namespace cvf