From 727129921097faa3e64b2983eb7485b7ec0e1783 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Wed, 15 Nov 2023 20:01:46 +0100 Subject: [PATCH 1/3] Refactor Intersection::indexInInside to work without switch-case. --- opm/grid/cpgrid/Intersection.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/opm/grid/cpgrid/Intersection.cpp b/opm/grid/cpgrid/Intersection.cpp index f589a90ab8..8a670935dd 100644 --- a/opm/grid/cpgrid/Intersection.cpp +++ b/opm/grid/cpgrid/Intersection.cpp @@ -127,28 +127,18 @@ void Intersection::increment() int Intersection::indexInInside() const { - // Use the face tags to decide if an intersection is + // Use the face tags (I_FACE = 0, J_FACE = 1, K_FACE = 2) + // to decide if an intersection is // on an x, y, or z face and use orientations to decide // if its (for example) an xmin or xmax face. - typedef OrientedEntityTable<0,1>::ToType Face; - const Face& f = faces_of_cell_[subindex_]; - const bool normal_is_in = !f.orientation(); - enum face_tag tag = pgrid_->face_tag_[f]; - switch (tag) { - case I_FACE: - return normal_is_in ? 0 : 1; // min(I) : max(I) - case J_FACE: - return normal_is_in ? 2 : 3; // min(J) : max(J) - case K_FACE: - return normal_is_in ? 4 : 5; // min(K) : max(K) - case NNC_FACE: - // For nnc faces we return the otherwise unused value -1. - // The Dune grid interface is essentially meaningless - // for non-neighbouring "intersections". + const auto& face = faces_of_cell_[subindex_]; + const auto tag = pgrid_->face_tag_[face]; + if (tag == NNC_FACE) { return -1; - default: - OPM_THROW(std::runtime_error, - "Unhandled face tag: " + std::to_string(tag)); + } + else { + return 2 * static_cast(tag) + + static_cast(face.orientation()); } } From 7fa451ecb9d1256f6992b3ac9f1dd2df7757cd05 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Wed, 15 Nov 2023 20:02:03 +0100 Subject: [PATCH 2/3] Clarify that Intersection::indexInInside returns FaceDir non-NNC --- opm/grid/cpgrid/Intersection.hpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/opm/grid/cpgrid/Intersection.hpp b/opm/grid/cpgrid/Intersection.hpp index e1cf057abf..84bd9930d8 100644 --- a/opm/grid/cpgrid/Intersection.hpp +++ b/opm/grid/cpgrid/Intersection.hpp @@ -191,12 +191,28 @@ namespace Dune return geometry().type(); } - /// Local index of codim 1 entity in the inside() entity + /// \brief Local index of codim 1 entity in the inside() entity /// where intersection is contained in. + /// + /// Note that CpGrid does not support codim-1 entities and return + /// the index of the face of the underlying cartesian grid assuming that + /// all faces are perpendicular to the axis: + /// For faces perpendicular to x-axis: 0 (normal points contrary to axis) 1 (else) + /// For faces perpendicular to x-axis: 2 (normal points contrary to axis) 3 (else) + /// For faces perpendicular to x-axis: 4 (normal points contrary to axis) 5 (else) + /// For faces not connecting neighboring elements: -1 int indexInInside() const; - /// Local index of codim 1 entity in outside() entity + /// \brief Local index of codim 1 entity in outside() entity /// where intersection is contained in. + /// + /// Note that CpGrid does not support codim-1 entities and return + /// the index of the face of the underlying cartesian grid assuming that + /// all faces are perpendicular to the axis: + /// For faces perpendicular to x-axis: 0 (normal points contrary to axis) 1 (else) + /// For faces perpendicular to x-axis: 2 (normal points contrary to axis) 3 (else) + /// For faces perpendicular to x-axis: 4 (normal points contrary to axis) 5 (else) + /// For faces not connecting neighboring elements: -1 int indexInOutside() const { int in_inside = indexInInside(); From fc39898522bc4d69c6c86cd5fcb4e7ef3f4a7fcd Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Fri, 17 Nov 2023 10:31:11 +0100 Subject: [PATCH 3/3] Reuse indexInSide in boundaryId. We were using the same value incremented by 0 already, anyway. Reduces code. --- opm/grid/cpgrid/Intersection.cpp | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/opm/grid/cpgrid/Intersection.cpp b/opm/grid/cpgrid/Intersection.cpp index 8a670935dd..581717cda2 100644 --- a/opm/grid/cpgrid/Intersection.cpp +++ b/opm/grid/cpgrid/Intersection.cpp @@ -46,42 +46,26 @@ Intersection::Intersection(const CpGridData& grid, const EntityRep<0>& cell, int } int Intersection::boundaryId() const { - int ret = 0; if (boundary()) { if (pgrid_->uniqueBoundaryIds()) { // Use the unique boundary ids. OrientedEntityTable<0,1>::ToType face = faces_of_cell_[subindex_]; - ret = pgrid_->unique_boundary_ids_[face]; + return pgrid_->unique_boundary_ids_[face]; } else { // Use the face tag based ids, i.e. 1-6 for i-, i+, j-, j+, k-, k+. - typedef OrientedEntityTable<0,1>::ToType Face; - const Face& f = faces_of_cell_[subindex_]; - const bool normal_is_in = !f.orientation(); - enum face_tag tag = pgrid_->face_tag_[f]; - - switch (tag) { - case I_FACE: - // LEFT : RIGHT - ret = normal_is_in ? 1 : 2; // min(I) : max(I) - break; - case J_FACE: - // BACK : FRONT - ret = normal_is_in ? 3 : 4; // min(J) : max(J) - break; - case K_FACE: - // Note: TOP at min(K) as 'z' measures *depth*. - // TOP : BOTTOM - ret = normal_is_in ? 5 : 6; // min(K) : max(K) - break; - case NNC_FACE: + if (pgrid_->face_tag_[faces_of_cell_[subindex_]] == NNC_FACE) + { // This should not be possible, as NNC "faces" always // have two cell neighbours and thus are not on the boundary. OPM_THROW(std::logic_error, "NNC face at boundary. This should never happen!"); } + + return indexInInside() + 1; } } - return ret; + return 0; } + int Intersection::boundarySegmentIndex() const { // Since this is almost the same that we did for