From 9f2bc4f1d02073f54444e157a0b40ce68ce66061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 26 Aug 2013 14:22:20 +0200 Subject: [PATCH] MswRollUp: Made neighbour calculations handle cells on edge This is an intermediate commit and does not compile p4#: 22219 --- ApplicationCode/ReservoirDataModel/RigCaseData.cpp | 13 +++++++++---- CommonCode/cvfStructGrid.cpp | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ApplicationCode/ReservoirDataModel/RigCaseData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseData.cpp index ad3152f368..e477f9ab08 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseData.cpp @@ -267,12 +267,17 @@ bool RigCaseData::findSharedSourceFace(cvf::StructGridInterface::FaceType& share size_t ni, nj, nk; grid->neighborIJKAtCellFace(i, j, k, sourceFace, &ni, &nj, &nk); - size_t neighborCellIndex = grid->cellIndexFromIJK(ni, nj, nk); - if (neighborCellIndex == otherGridCellIndex) + if (grid->isCellValid(ni, nj, nk)) { - sharedSourceFace = sourceFace; - return true; + + size_t neighborCellIndex = grid->cellIndexFromIJK(ni, nj, nk); + + if (neighborCellIndex == otherGridCellIndex) + { + sharedSourceFace = sourceFace; + return true; + } } } diff --git a/CommonCode/cvfStructGrid.cpp b/CommonCode/cvfStructGrid.cpp index a268228b9a..b9cc9d35fb 100644 --- a/CommonCode/cvfStructGrid.cpp +++ b/CommonCode/cvfStructGrid.cpp @@ -160,11 +160,11 @@ void StructGridInterface::neighborIJKAtCellFace(size_t i, size_t j, size_t k, Fa switch (face) { case POS_I : (*ni)++; break; - case NEG_I : (*ni)--; break; + case NEG_I : if (i > 0) (*ni)--; else (*ni) = cvf::UNDEFINED_SIZE_T; break; case POS_J : (*nj)++; break; - case NEG_J : (*nj)--; break; + case NEG_J : if (i > 0) (*nj)--; else (*nj) = cvf::UNDEFINED_SIZE_T; break; case POS_K : (*nk)++; break; - case NEG_K : (*nk)--; break; + case NEG_K : if (i > 0) (*nj)--; else (*nj) = cvf::UNDEFINED_SIZE_T; break; } }