triSurfaceAddressing.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation, either version 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. 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 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
43 {
45  {
46  FatalErrorIn("triSurface::calcSortedEdgeFaces()")
47  << "sortedEdgeFacesPtr_ already set"
48  << abort(FatalError);
49  }
50 
51  const labelListList& eFaces = edgeFaces();
52 
53  // create the lists for the various results. (resized on completion)
54  sortedEdgeFacesPtr_ = new labelListList(eFaces.size());
56 
57  forAll(eFaces, edgeI)
58  {
59  const labelList& myFaceNbs = eFaces[edgeI];
60 
61  if (myFaceNbs.size() > 2)
62  {
63  // Get point on edge and normalized direction of edge (= e2 base
64  // of our coordinate system)
65  const edge& e = edges()[edgeI];
66 
67  const point& edgePt = localPoints()[e.start()];
68 
69  vector e2 = e.vec(localPoints());
70  e2 /= mag(e2) + VSMALL;
71 
72 
73  // Get opposite vertex for 0th face
74  const labelledTri& f = localFaces()[myFaceNbs[0]];
75  label fp0 = findIndex(f, e[0]);
76  label fp1 = f.fcIndex(fp0);
77  label vertI = (f[fp1] != e[1] ? f[fp1] : f.fcIndex(fp1));
78 
79  // Get vector normal both to e2 and to edge from opposite vertex
80  // to edge (will be x-axis of our coordinate system)
81  vector e0 = e2 ^ (localPoints()[vertI] - edgePt);
82  e0 /= mag(e0) + VSMALL;
83 
84  // Get y-axis of coordinate system
85  vector e1 = e2 ^ e0;
86 
87 
88  SortableList<scalar> faceAngles(myFaceNbs.size());
89 
90  // e0 is reference so angle is 0
91  faceAngles[0] = 0;
92 
93  for(label nbI = 1; nbI < myFaceNbs.size(); nbI++)
94  {
95  // Get opposite vertex
96  const labelledTri& f = localFaces()[myFaceNbs[nbI]];
97  label fp0 = findIndex(f, e[0]);
98  label fp1 = f.fcIndex(fp0);
99  label vertI = (f[fp1] != e[1] ? f[fp1] : f.fcIndex(fp1));
100 
101  vector vec = e2 ^ (localPoints()[vertI] - edgePt);
102  vec /= mag(vec) + VSMALL;
103 
104  faceAngles[nbI] = pseudoAngle
105  (
106  e0,
107  e1,
108  vec
109  );
110  }
111 
112  faceAngles.sort();
113 
115  (
116  myFaceNbs,
117  faceAngles.indices()
118  );
119  }
120  else
121  {
122  // No need to sort. Just copy.
123  sortedEdgeFaces[edgeI] = myFaceNbs;
124  }
125  }
126 }
127 
128 
130 {
131  if (edgeOwnerPtr_)
132  {
133  FatalErrorIn("triSurface::calcEdgeOwner()")
134  << "edgeOwnerPtr_ already set"
135  << abort(FatalError);
136  }
137 
138  // create the owner list
139  edgeOwnerPtr_ = new labelList(nEdges());
141 
142  forAll(edges(), edgeI)
143  {
144  const edge& e = edges()[edgeI];
145 
146  const labelList& myFaces = edgeFaces()[edgeI];
147 
148  if (myFaces.size() == 1)
149  {
150  edgeOwner[edgeI] = myFaces[0];
151  }
152  else
153  {
154  // Find the first face whose vertices are aligned with the edge.
155  // (in case of multiply connected edge the best we can do)
156  edgeOwner[edgeI] = -1;
157 
158  forAll(myFaces, i)
159  {
160  const labelledTri& f = localFaces()[myFaces[i]];
161 
162  if
163  (
164  ((f[0] == e.start()) && (f[1] == e.end()))
165  || ((f[1] == e.start()) && (f[2] == e.end()))
166  || ((f[2] == e.start()) && (f[0] == e.end()))
167  )
168  {
169  edgeOwner[edgeI] = myFaces[i];
170 
171  break;
172  }
173  }
174 
175  if (edgeOwner[edgeI] == -1)
176  {
177  FatalErrorIn("triSurface::calcEdgeOwner()")
178  << "Edge " << edgeI << " vertices:" << e
179  << " is used by faces " << myFaces
180  << " vertices:"
181  << UIndirectList<labelledTri>(localFaces(), myFaces)()
182  << " none of which use the edge vertices in the same order"
183  << nl << "I give up" << abort(FatalError);
184  }
185  }
186  }
187 }
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // ************************************************************************* //
Foam::PrimitivePatch< labelledTri, List, pointField, point >::edgeFaces
const labelListList & edgeFaces() const
Return edge-face addressing.
Definition: PrimitivePatchTemplate.C:292
HashTable.H
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::SortableList::sort
void sort()
(stable) sort the list (if changed after construction time)
Definition: SortableList.C:95
Foam::PrimitivePatch< labelledTri, List, pointField, point >::edges
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
Definition: PrimitivePatchTemplate.C:212
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::findIndex
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
Foam::PrimitivePatch< labelledTri, List, pointField, point >::localPoints
const Field< point > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatchTemplate.C:432
Foam::PrimitivePatch< labelledTri, List, pointField, point >::nEdges
label nEdges() const
Return number of edges in patch.
Definition: PrimitivePatchTemplate.H:299
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
SortableList.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::triSurface::edgeOwnerPtr_
labelList * edgeOwnerPtr_
Label of face that 'owns' edge (i.e. e.vec() is righthanded walk.
Definition: triSurface.H:93
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::triSurface::calcSortedEdgeFaces
void calcSortedEdgeFaces() const
Calculate sorted edgeFaces.
Definition: triSurfaceAddressing.C:42
Foam::FatalError
error FatalError
Foam::triSurface::calcEdgeOwner
void calcEdgeOwner() const
Calculate owner.
Definition: triSurfaceAddressing.C:129
Foam::SortableList
A list that is sorted upon construction or when explicitly requested with the sort() method.
Definition: List.H:65
Foam::pseudoAngle
scalar pseudoAngle(const vector &e0, const vector &e1, const vector &vec)
Estimate angle of vec in coordinate system (e0, e1, e0^e1).
Definition: transform.H:223
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::triSurface::edgeOwner
const labelList & edgeOwner() const
If 2 face neighbours: label of face where ordering of edge.
Definition: triSurface.C:777
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::triSurface::sortedEdgeFacesPtr_
labelListList * sortedEdgeFacesPtr_
Edge-face addressing (sorted)
Definition: triSurface.H:89
Foam::SortableList::indices
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
Definition: SortableList.H:90
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::PrimitivePatch< labelledTri, List, pointField, point >::localFaces
const List< labelledTri > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatchTemplate.C:372
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::triSurface::sortedEdgeFaces
const labelListList & sortedEdgeFaces() const
Return edge-face addressing sorted (for edges with more than.
Definition: triSurface.C:766
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
transform.H
3D tensor transformation operations.
triSurface.H