diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtra.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtra.C new file mode 100644 index 0000000000..7ab4c43084 --- /dev/null +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtra.C @@ -0,0 +1,173 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "PrimitivePatchExtra.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +// Construct from components +template +< + class Face, + template class ListType, + class PointField, + class PointType +> +Foam::PrimitivePatchExtra:: +PrimitivePatchExtra +( + const ListType& faces, + const pointField& points +) +: + PrimitivePatch(faces, points), + sortedEdgeFacesPtr_(NULL), + edgeOwnerPtr_(NULL) +{} + + +// Construct as copy +template +< + class Face, + template class ListType, + class PointField, + class PointType +> +Foam::PrimitivePatchExtra:: +PrimitivePatchExtra +( + const PrimitivePatchExtra& pp +) +: + PrimitivePatch(pp), + sortedEdgeFacesPtr_(NULL), + edgeOwnerPtr_(NULL) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +< + class Face, + template class ListType, + class PointField, + class PointType +> +Foam::PrimitivePatchExtra:: +~PrimitivePatchExtra() +{ + clearOut(); +} + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +< + class Face, + template class ListType, + class PointField, + class PointType +> +void Foam::PrimitivePatchExtra:: +clearOut() +{ + PrimitivePatch::clearOut(); + clearTopology(); +} + + +template +< + class Face, + template class ListType, + class PointField, + class PointType +> +void Foam::PrimitivePatchExtra:: +clearTopology() +{ + PrimitivePatch::clearTopology(); + deleteDemandDrivenData(sortedEdgeFacesPtr_); + deleteDemandDrivenData(edgeOwnerPtr_); +} + + +template +< + class Face, + template class ListType, + class PointField, + class PointType +> +const Foam::labelListList& +Foam::PrimitivePatchExtra:: +sortedEdgeFaces() const +{ + if (!sortedEdgeFacesPtr_) + { + calcSortedEdgeFaces(); + } + + return *sortedEdgeFacesPtr_; +} + + +template +< + class Face, + template class ListType, + class PointField, + class PointType +> +const Foam::labelList& +Foam::PrimitivePatchExtra:: +edgeOwner() const +{ + if (!edgeOwnerPtr_) + { + calcEdgeOwner(); + } + + return *edgeOwnerPtr_; +} + + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "PrimitivePatchExtraAddressing.C" +#include "PrimitivePatchExtraCleanup.C" +#include "PrimitivePatchExtraSearch.C" + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtra.H b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtra.H new file mode 100644 index 0000000000..094dfb7340 --- /dev/null +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtra.H @@ -0,0 +1,211 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::PrimitivePatchExtra + +Description + PrimitivePatch with some extra functionality. + +SourceFiles + PrimitivePatchExtra.C + +\*---------------------------------------------------------------------------*/ + +#ifndef PrimitivePatchExtra_H +#define PrimitivePatchExtra_H + +#include "PrimitivePatch.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class PrimitivePatchExtra Declaration +\*---------------------------------------------------------------------------*/ + +template +< + class Face, + template class ListType, + class PointField, + class PointType=point +> +class PrimitivePatchExtra +: + public PrimitivePatch +{ + +public: + + // Public typedefs + + typedef Face FaceType; + typedef ListType FaceListType; + typedef PointField PointFieldType; + +private: + + // Private typedefs + typedef PrimitivePatch TemplateType; + + // Private data + + // Demand driven private data + + //- Edge-face addressing (sorted) + mutable labelListList* sortedEdgeFacesPtr_; + + //- Label of face that 'owns' edge (i.e. e.vec() is righthanded walk + // along face) + mutable labelList* edgeOwnerPtr_; + + + // Private Member Functions + + //- Calculate sorted edgeFaces + void calcSortedEdgeFaces() const; + + //- Calculate owner + void calcEdgeOwner() const; + +protected: + // Protected Member Functions + + // Edit + + //- Fill faceZone with currentZone for every face reachable + // from faceI without crossing edge marked in borderEdge. + // Note: faceZone has to be sized nFaces before calling this fun. + void markZone + ( + const boolList& borderEdge, + const label faceI, + const label currentZone, + labelList& faceZone + ) const; + + //- (size and) fills faceZone with zone of face. + // Zone is area reachable by edge crossing without crossing borderEdge + // (bool for every edge in surface). Returns number of zones. + label markZones + ( + const boolList& borderEdge, + labelList& faceZone + ) const; + + //- Determine the mapping for a sub mesh. + // Only include faces for which boolList entry is true + // Sets: pointMap: from new to old localPoints + // faceMap: new to old faces + void subsetMap + ( + const boolList& include, + labelList& pointMap, + labelList& faceMap + ) const; + +public: + + // Constructors + + //- Construct from components + PrimitivePatchExtra + ( + const ListType& faces, + const pointField& points + ); + + //- Construct as copy + PrimitivePatchExtra + ( + const PrimitivePatchExtra& + ); + + + // Destructor + + virtual ~PrimitivePatchExtra(); + + void clearOut(); + + void clearTopology(); + + + // Member Functions + + // Access functions for demand driven data + + // Topological data; no mesh required. + + //- Return edge-face addressing sorted + // (for edges with more than 2 faces) according to the + // angle around the edge. + // Orientation is anticlockwise looking from + // edge.vec(localPoints()) + const labelListList& sortedEdgeFaces() const; + + //- If 2 face neighbours: label of face where ordering of edge + // is consistent with righthand walk. + // If 1 neighbour: label of only face. + // If >2 neighbours: undetermined. + const labelList& edgeOwner() const; + + + // Addressing into mesh + + + // Other patch operations + + + // Check + + //- Check triply (or more) connected edges. + // Return list of faces sharing these edges. + void checkEdges(const bool verbose) const; + + //- Check orientation (normals) and normals of neighbouring faces + boolList checkOrientation(const bool verbose) const; + + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "PrimitivePatchExtra.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtraAddressing.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtraAddressing.C new file mode 100644 index 0000000000..1773014a4d --- /dev/null +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtraAddressing.C @@ -0,0 +1,210 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Description + Contains fix for PrimitivePatch addressing (which doesn't work if surface + is non-manifold). Should be moved into PrimitivePatch. + +\*---------------------------------------------------------------------------*/ + +#include "PrimitivePatchExtra.H" +#include "HashTable.H" +#include "SortableList.H" +#include "transform.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +< + class Face, + template class ListType, + class PointField, + class PointType +> +void Foam::PrimitivePatchExtra:: +calcSortedEdgeFaces() const +{ + if (sortedEdgeFacesPtr_) + { + FatalErrorIn("PrimitivePatchExtra::calcSortedEdgeFaces()") + << "sortedEdgeFacesPtr_ already set" + << abort(FatalError); + } + + const labelListList& eFaces = TemplateType::edgeFaces(); + const edgeList& edgeLst = TemplateType::edges(); + const pointField& locPointLst = TemplateType::localPoints(); + const List& locFaceLst = TemplateType::localFaces(); + + // create the lists for the various results. (resized on completion) + sortedEdgeFacesPtr_ = new labelListList(eFaces.size()); + labelListList& sortedEdgeFaces = *sortedEdgeFacesPtr_; + + forAll(eFaces, edgeI) + { + const labelList& myFaceNbs = eFaces[edgeI]; + + if (myFaceNbs.size() > 2) + { + // Get point on edge and normalized direction of edge (= e2 base + // of our coordinate system) + const edge& e = edgeLst[edgeI]; + + const point& edgePt = locPointLst[e.start()]; + + vector e2 = e.vec(locPointLst); + e2 /= mag(e2) + VSMALL; + + // Get opposite vertex for 0th face + const Face& f = locFaceLst[myFaceNbs[0]]; + + label fp0 = findIndex(f, e[0]); + label fp1 = f.fcIndex(fp0); + label vertI = (f[fp1] != e[1] ? f[fp1] : f.fcIndex(fp1)); + + // Get vector normal both to e2 and to edge from opposite vertex + // to edge (will be x-axis of our coordinate system) + vector e0 = e2 ^ (locPointLst[vertI] - edgePt); + e0 /= mag(e0) + VSMALL; + + // Get y-axis of coordinate system + vector e1 = e2 ^ e0; + + SortableList faceAngles(myFaceNbs.size()); + + // e0 is reference so angle is 0 + faceAngles[0] = 0; + + for (label nbI = 1; nbI < myFaceNbs.size(); nbI++) + { + // Get opposite vertex + const FaceType& f = locFaceLst[myFaceNbs[nbI]]; + label fp0 = findIndex(f, e[0]); + label fp1 = f.fcIndex(fp0); + label vertI = (f[fp1] != e[1] ? f[fp1] : f.fcIndex(fp1)); + + vector vec = e2 ^ (locPointLst[vertI] - edgePt); + vec /= mag(vec) + VSMALL; + + faceAngles[nbI] = pseudoAngle + ( + e0, + e1, + vec + ); + } + + faceAngles.sort(); + + sortedEdgeFaces[edgeI] = IndirectList