diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C index dcbf6d0b16..8c21017269 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C @@ -66,6 +66,9 @@ primitiveMesh::primitiveMesh() ppPtr_(NULL), cpPtr_(NULL), + allocSize_(0), + labels_(0), + cellCentresPtr_(NULL), faceCentresPtr_(NULL), cellVolumesPtr_(NULL), @@ -106,6 +109,9 @@ primitiveMesh::primitiveMesh ppPtr_(NULL), cpPtr_(NULL), + allocSize_(0), + labels_(0), + cellCentresPtr_(NULL), faceCentresPtr_(NULL), cellVolumesPtr_(NULL), diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H index 0609c453d3..3868ba2b25 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H @@ -155,6 +155,17 @@ class primitiveMesh mutable labelListList* cpPtr_; + // On-the-fly edge addresing storage + + //- Temporary storage for addressing. allocSize is the real size + // of the labelList. + mutable label allocSize_; + mutable labelList labels_; + + //- Temporary storage for addressing + mutable labelHashSet labelSet_; + + // Geometric data //- Cell centres @@ -209,8 +220,14 @@ class primitiveMesh ( List >&, DynamicList&, - const label pA, - const label pB + const label, + const label + ); + //- For on-the-fly addressing calculation + static label findFirstCommonElementFromSortedLists + ( + const labelList&, + const labelList& ); @@ -667,6 +684,55 @@ public: //- Print a list of all the currently allocated mesh data void printAllocated() const; + // Per storage whether allocated + inline bool hasCellShapes() const; + inline bool hasEdges() const; + inline bool hasCellCells() const; + inline bool hasEdgeCells() const; + inline bool hasPointCells() const; + inline bool hasCells() const; + inline bool hasEdgeFaces() const; + inline bool hasPointFaces() const; + inline bool hasCellEdges() const; + inline bool hasFaceEdges() const; + inline bool hasPointEdges() const; + inline bool hasPointPoints() const; + inline bool hasCellPoints() const; + inline bool hasCellCentres() const; + inline bool hasFaceCentres() const; + inline bool hasCellVolumes() const; + inline bool hasFaceAreas() const; + + // On-the-fly addressing calculation. These functions return either + // a reference to the full addressing (if already calculated) or + // a reference to member data labels_ so be careful when not storing + // result. + + //- cellCells using cells + const labelList& cellCells(const label cellI) const; + + //- cellPoints using cells + const labelList& cellPoints(const label cellI) const; + + //- pointCells using pointFaces + const labelList& pointCells(const label pointI) const; + + //- pointPoints using edges, pointEdges + const labelList& pointPoints(const label pointI) const; + + //- faceEdges using pointFaces, edges, pointEdges + const labelList& faceEdges(const label faceI) const; + + //- edgeFaces using pointFaces, edges, pointEdges + const labelList& edgeFaces(const label edgeI) const; + + //- edgeCells using pointFaces, edges, pointEdges + const labelList& edgeCells(const label edgeI) const; + + //- cellEdges using cells, pointFaces, edges, pointEdges + const labelList& cellEdges(const label cellI) const; + + //- Clear geometry void clearGeom(); diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCells.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCells.C index d17228c7bd..3c8f896bbe 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCells.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCells.C @@ -105,6 +105,53 @@ const labelListList& primitiveMesh::cellCells() const } +const labelList& primitiveMesh::cellCells(const label cellI) const +{ + if (hasCellCells()) + { + return cellCells()[cellI]; + } + else + { + const labelList& own = faceOwner(); + const labelList& nei = faceNeighbour(); + const cell& cFaces = cells()[cellI]; + + labels_.size() = allocSize_; + + if (cFaces.size() > allocSize_) + { + labels_.clear(); + allocSize_ = cFaces.size(); + labels_.setSize(allocSize_); + } + + label n = 0; + + forAll(cFaces, i) + { + label faceI = cFaces[i]; + + if (faceI < nInternalFaces()) + { + if (own[faceI] == cellI) + { + labels_[n++] = nei[faceI]; + } + else + { + labels_[n++] = own[faceI]; + } + } + } + + labels_.size() = n; + + return labels_; + } +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C index 542952019b..c8f63e1eef 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C @@ -53,6 +53,52 @@ const labelListList& primitiveMesh::cellPoints() const } +const labelList& primitiveMesh::cellPoints(const label cellI) const +{ + if (hasCellPoints()) + { + return cellPoints()[cellI]; + } + else + { + const faceList& fcs = faces(); + const labelList& cFaces = cells()[cellI]; + + labelSet_.clear(); + + forAll(cFaces, i) + { + const labelList& f = fcs[cFaces[i]]; + + forAll(f, fp) + { + labelSet_.insert(f[fp]); + } + } + + labels_.size() = allocSize_; + + if (labelSet_.size() > allocSize_) + { + labels_.clear(); + allocSize_ = labelSet_.size(); + labels_.setSize(allocSize_); + } + + label n = 0; + + forAllConstIter(labelHashSet, labelSet_, iter) + { + labels_[n++] = iter.key(); + } + + labels_.size() = n; + + return labels_; + } +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C index fd56846ebb..47360d4cf1 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C @@ -771,11 +771,12 @@ bool primitiveMesh::checkPoints } } - const labelListList& pc = pointCells(); - forAll (pc, pointI) + forAll (pf, pointI) { - if (pc[pointI].size() == 0) + const labelList& pc = pointCells(pointI); + + if (pc.size() == 0) { if (setPtr) { diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdgeCells.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdgeCells.C index 46173628d8..6a2f309dd3 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdgeCells.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdgeCells.C @@ -51,6 +51,86 @@ const labelListList& primitiveMesh::edgeCells() const } +const labelList& primitiveMesh::edgeCells(const label edgeI) const +{ + if (hasEdgeCells()) + { + return edgeCells()[edgeI]; + } + else + { + const labelList& own = faceOwner(); + const labelList& nei = faceNeighbour(); + + // edge faces can either return labels_ or reference in edgeLabels. + labelList labelsCopy; + if (!hasEdgeFaces()) + { + labelsCopy = edgeFaces(edgeI); + } + + const labelList& eFaces = + ( + hasEdgeFaces() + ? edgeFaces()[edgeI] + : labelsCopy + ); + + labels_.size() = allocSize_; + + // labels_ should certainly be big enough for edge cells. + label n = 0; + + // Do quadratic insertion. + forAll(eFaces, i) + { + label faceI = eFaces[i]; + + { + label ownCellI = own[faceI]; + + // Check if not already in labels_ + for (label j = 0; j < n; j++) + { + if (labels_[j] == ownCellI) + { + ownCellI = -1; + break; + } + } + + if (ownCellI != -1) + { + labels_[n++] = ownCellI; + } + } + + if (isInternalFace(faceI)) + { + label neiCellI = nei[faceI]; + + for (label j = 0; j < n; j++) + { + if (labels_[j] == neiCellI) + { + neiCellI = -1; + break; + } + } + + if (neiCellI != -1) + { + labels_[n++] = neiCellI; + } + } + } + + labels_.size() = n; + + return labels_; + } +} + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdgeFaces.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdgeFaces.C index 30390ce4eb..99536bcd33 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdgeFaces.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdgeFaces.C @@ -51,6 +51,59 @@ const labelListList& primitiveMesh::edgeFaces() const return *efPtr_; } + +const labelList& primitiveMesh::edgeFaces(const label edgeI) const +{ + if (hasEdgeFaces()) + { + return edgeFaces()[edgeI]; + } + else + { + // Use the fact that pointEdges are sorted in incrementing edge order + const edge& e = edges()[edgeI]; + const labelList& pFaces0 = pointFaces()[e[0]]; + const labelList& pFaces1 = pointFaces()[e[1]]; + + label i0 = 0; + label i1 = 0; + label n = 0; + + labels_.size() = allocSize_; + + while (i0 < pFaces0.size() && i1 < pFaces1.size()) + { + if (pFaces0[i0] < pFaces1[i1]) + { + ++i0; + } + else if (pFaces0[i0] > pFaces1[i1]) + { + ++i1; + } + else + { + // Equal. Append. + if (n == allocSize_) + { + // Have setSize copy contents so far + labels_.size() = n; + allocSize_ = allocSize_*2 + 1; + labels_.setSize(allocSize_); + } + labels_[n++] = pFaces0[i0]; + ++i0; + ++i1; + } + } + + labels_.size() = n; + + return labels_; + } +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C index 6b3039ff30..b60b366079 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C @@ -461,6 +461,46 @@ void primitiveMesh::calcEdges(const bool doFaceEdges) const } +label primitiveMesh::findFirstCommonElementFromSortedLists +( + const labelList& list1, + const labelList& list2 +) +{ + label result = -1; + + labelList::const_iterator iter1 = list1.begin(); + labelList::const_iterator iter2 = list2.begin(); + + while (iter1 != list1.end() && iter2 != list2.end()) + { + if( *iter1 < *iter2) + { + ++iter1; + } + else if (*iter1 > *iter2) + { + ++iter2; + } + else + { + result = *iter1; + break; + } + } + if (result == -1) + { + FatalErrorIn + ( + "primitiveMesh::findFirstCommonElementFromSortedLists" + "(const labelList&, const labelList&)" + ) << "No common elements in lists " << list1 << " and " << list2 + << abort(FatalError); + } + return result; +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // const edgeList& primitiveMesh::edges() const @@ -542,6 +582,91 @@ void primitiveMesh::clearOutEdges() deleteDemandDrivenData(edgesPtr_); deleteDemandDrivenData(pePtr_); deleteDemandDrivenData(fePtr_); + labels_.clear(); + allocSize_ = 0; +} + + +const labelList& primitiveMesh::faceEdges(const label faceI) const +{ + if (hasFaceEdges()) + { + return faceEdges()[faceI]; + } + else + { + const labelListList& pointEs = pointEdges(); + const face& f = faces()[faceI]; + + labels_.size() = allocSize_; + + if (f.size() > allocSize_) + { + labels_.clear(); + allocSize_ = f.size(); + labels_.setSize(allocSize_); + } + + label n = 0; + + forAll(f, fp) + { + labels_[n++] = findFirstCommonElementFromSortedLists + ( + pointEs[f[fp]], + pointEs[f.nextLabel(fp)] + ); + } + + labels_.size() = n; + + return labels_; + } +} + + +const labelList& primitiveMesh::cellEdges(const label cellI) const +{ + if (hasCellEdges()) + { + return cellEdges()[cellI]; + } + else + { + const labelList& cFaces = cells()[cellI]; + + labelSet_.clear(); + + forAll(cFaces, i) + { + const labelList& fe = faceEdges(cFaces[i]); + + forAll(fe, feI) + { + labelSet_.insert(fe[feI]); + } + } + + labels_.size() = allocSize_; + + if (labelSet_.size() > allocSize_) + { + labels_.clear(); + allocSize_ = labelSet_.size(); + labels_.setSize(allocSize_); + } + + label n =0; + + forAllConstIter(labelHashSet, labelSet_, iter) + { + labels_[n++] = iter.key(); + } + + labels_.size() = n; + + return labels_; + } } diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshI.H b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshI.H index fdaea6d1fc..98b32af1fc 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshI.H +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshI.H @@ -104,6 +104,108 @@ inline bool primitiveMesh::isInternalFace(const label faceIndex) const } +inline bool primitiveMesh::hasCellShapes() const +{ + return cellShapesPtr_; +} + + +inline bool primitiveMesh::hasEdges() const +{ + return edgesPtr_; +} + + +inline bool primitiveMesh::hasCellCells() const +{ + return ccPtr_; +} + + +inline bool primitiveMesh::hasEdgeCells() const +{ + return ecPtr_; +} + + +inline bool primitiveMesh::hasPointCells() const +{ + return pcPtr_; +} + + +inline bool primitiveMesh::hasCells() const +{ + return cfPtr_; +} + + +inline bool primitiveMesh::hasEdgeFaces() const +{ + return efPtr_; +} + + +inline bool primitiveMesh::hasPointFaces() const +{ + return pfPtr_; +} + + +inline bool primitiveMesh::hasCellEdges() const +{ + return cePtr_; +} + + +inline bool primitiveMesh::hasFaceEdges() const +{ + return fePtr_; +} + + +inline bool primitiveMesh::hasPointEdges() const +{ + return pePtr_; +} + + +inline bool primitiveMesh::hasPointPoints() const +{ + return ppPtr_; +} + + +inline bool primitiveMesh::hasCellPoints() const +{ + return cpPtr_; +} + + +inline bool primitiveMesh::hasCellCentres() const +{ + return cellCentresPtr_; +} + + +inline bool primitiveMesh::hasFaceCentres() const +{ + return faceCentresPtr_; +} + + +inline bool primitiveMesh::hasCellVolumes() const +{ + return cellVolumesPtr_; +} + + +inline bool primitiveMesh::hasFaceAreas() const +{ + return faceAreasPtr_; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C index 55d877902a..6d7af72e0b 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C @@ -114,6 +114,70 @@ const labelListList& primitiveMesh::pointCells() const } +const labelList& primitiveMesh::pointCells(const label pointI) const +{ + if (hasPointCells()) + { + return pointCells()[pointI]; + } + else + { + const labelList& own = faceOwner(); + const labelList& nei = faceNeighbour(); + const labelList& pFaces = pointFaces()[pointI]; + + labels_.size() = allocSize_; + + label n = 0; + + forAll(pFaces, i) + { + const label faceI = pFaces[i]; + + // Append owner + if (n == allocSize_) + { + labels_.size() = n; + allocSize_ = allocSize_*2 + 1; + labels_.setSize(allocSize_); + } + labels_[n++] = own[faceI]; + + // Append neighbour + if (faceI < nInternalFaces()) + { + if (n == allocSize_) + { + labels_.size() = n; + allocSize_ = allocSize_*2 + 1; + labels_.setSize(allocSize_); + } + labels_[n++] = nei[faceI]; + } + } + labels_.size() = n; + + + // Filter duplicates + sort(labels_); + + n = 1; + + for (label i = 1; i < labels_.size(); i++) + { + if (labels_[i] != labels_[i-1]) + { + labels_[n++] = labels_[i]; + } + } + + labels_.size() = n; + + return labels_; + } +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointPoints.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointPoints.C index c5df74a4fa..099e266941 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointPoints.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointPoints.C @@ -97,6 +97,40 @@ const labelListList& primitiveMesh::pointPoints() const } +const labelList& primitiveMesh::pointPoints(const label pointI) const +{ + if (hasPointPoints()) + { + return pointPoints()[pointI]; + } + else + { + const edgeList& edges = this->edges(); + const labelList& pEdges = pointEdges()[pointI]; + + labels_.size() = allocSize_; + + if (pEdges.size() > allocSize_) + { + // Set size() so memory allocation behaves as normal. + labels_.clear(); + allocSize_ = pEdges.size(); + labels_.setSize(allocSize_); + } + + label n = 0; + + forAll(pEdges, i) + { + labels_[n++] = edges[pEdges[i]].otherVertex(pointI); + } + + labels_.size() = n; + + return labels_; + } +} + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C index bfe18f3363..08e9566e48 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C @@ -1295,7 +1295,7 @@ void Foam::polyTopoChange::calcFaceInflationMaps selectFaces ( mesh, - mesh.edgeFaces()[iter()], + mesh.edgeFaces(iter()), true ) ); @@ -1309,7 +1309,7 @@ void Foam::polyTopoChange::calcFaceInflationMaps selectFaces ( mesh, - mesh.edgeFaces()[iter()], + mesh.edgeFaces(iter()), false ) ); diff --git a/src/meshTools/meshTools/meshTools.C b/src/meshTools/meshTools/meshTools.C index 49a06cf868..352de0feec 100644 --- a/src/meshTools/meshTools/meshTools.C +++ b/src/meshTools/meshTools/meshTools.C @@ -182,7 +182,7 @@ Foam::vectorField Foam::meshTools::calcBoxPointNormals(const primitivePatch& pp) "Foam::meshTools::calcBoxPointNormals" "(const primitivePatch& pp)" ) << "No visible octant for point:" << pp.meshPoints()[pointI] - << " cooord:" << pp.localPoints()[pointI] << nl + << " cooord:" << pp.points()[pp.meshPoints()[pointI]] << nl << "Normal set to " << pn[pointI] << endl; } } @@ -299,7 +299,7 @@ bool Foam::meshTools::edgeOnCell const label edgeI ) { - return findIndex(mesh.edgeCells()[edgeI], cellI) != -1; + return findIndex(mesh.edgeCells(edgeI), cellI) != -1; } @@ -310,7 +310,7 @@ bool Foam::meshTools::edgeOnFace const label edgeI ) { - return findIndex(mesh.faceEdges()[faceI], edgeI) != -1; + return findIndex(mesh.faceEdges(faceI), edgeI) != -1; } @@ -403,7 +403,6 @@ Foam::label Foam::meshTools::getSharedEdge const labelList& f0Edges = mesh.faceEdges()[f0]; const labelList& f1Edges = mesh.faceEdges()[f1]; - forAll(f0Edges, f0EdgeI) { label edge0 = f0Edges[f0EdgeI]; @@ -481,7 +480,7 @@ void Foam::meshTools::getEdgeFaces label& face1 ) { - const labelList& eFaces = mesh.edgeFaces()[edgeI]; + const labelList& eFaces = mesh.edgeFaces(edgeI); face0 = -1; face1 = -1; @@ -619,7 +618,7 @@ Foam::label Foam::meshTools::walkFace const label nEdges ) { - const labelList& fEdges = mesh.faceEdges()[faceI]; + const labelList& fEdges = mesh.faceEdges(faceI); label edgeI = startEdgeI; @@ -790,13 +789,4 @@ Foam::label Foam::meshTools::cutDirToEdge } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - - -// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // - - -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // - - // ************************************************************************* //