triSurfaceAddressing.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Contains fix for PrimitivePatch addressing (which doesn't work if surface
26  is non-manifold). Should be moved into PrimitivePatch.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "triSurface.H"
31 #include "HashTable.H"
32 #include "SortableList.H"
33 #include "transform.H"
34 #include "PatchTools.H"
35 
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 
38 void Foam::triSurface::calcSortedEdgeFaces() const
39 {
40  if (sortedEdgeFacesPtr_)
41  {
43  << "sortedEdgeFacesPtr_ already set"
44  << abort(FatalError);
45  }
46 
47  const labelListList& eFaces = edgeFaces();
48 
49  sortedEdgeFacesPtr_ = new labelListList(eFaces.size());
50  labelListList& sortedEdgeFaces = *sortedEdgeFacesPtr_;
51 
52  sortedEdgeFaces = PatchTools::sortedEdgeFaces(*this);
53 }
54 
55 
56 void Foam::triSurface::calcEdgeOwner() const
57 {
58  if (edgeOwnerPtr_)
59  {
61  << "edgeOwnerPtr_ already set"
62  << abort(FatalError);
63  }
64 
65  // create the owner list
66  edgeOwnerPtr_ = new labelList(nEdges());
67  labelList& edgeOwner = *edgeOwnerPtr_;
68 
69  forAll(edges(), edgeI)
70  {
71  const edge& e = edges()[edgeI];
72 
73  const labelList& myFaces = edgeFaces()[edgeI];
74 
75  if (myFaces.size() == 1)
76  {
77  edgeOwner[edgeI] = myFaces[0];
78  }
79  else
80  {
81  // Find the first face whose vertices are aligned with the edge.
82  // (in case of multiply connected edge the best we can do)
83  edgeOwner[edgeI] = -1;
84 
85  forAll(myFaces, i)
86  {
87  const labelledTri& f = localFaces()[myFaces[i]];
88 
89  if
90  (
91  ((f[0] == e.start()) && (f[1] == e.end()))
92  || ((f[1] == e.start()) && (f[2] == e.end()))
93  || ((f[2] == e.start()) && (f[0] == e.end()))
94  )
95  {
96  edgeOwner[edgeI] = myFaces[i];
97 
98  break;
99  }
100  }
101 
102  if (edgeOwner[edgeI] == -1)
103  {
105  << "Edge " << edgeI << " vertices:" << e
106  << " is used by faces " << myFaces
107  << " vertices:"
108  << UIndirectList<labelledTri>(localFaces(), myFaces)()
109  << " none of which use the edge vertices in the same order"
110  << nl << "I give up" << abort(FatalError);
111  }
112  }
113  }
114 }
115 
116 
117 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
static labelListList sortedEdgeFaces(const PrimitivePatch< Face, FaceList, PointField, PointType > &)
Return edge-face addressing sorted by angle around the edge.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const List< labelledTri > & localFaces() const
Return patch faces addressing into local point list.
const labelListList & sortedEdgeFaces() const
Return edge-face addressing sorted (for edges with more than.
Definition: triSurface.C:768
3D tensor transformation operations.
const labelListList & edgeFaces() const
Return edge-face addressing.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
label nEdges() const
Return number of edges in patch.
static const char nl
Definition: Ostream.H:262