walkPatch.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 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "walkPatch.H"
29 #include "ListOps.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 // Get other face using v0, v1 (in localFaces numbering). Or -1.
39 (
40  const label faceI,
41  const label fp,
42  const label v0,
43  const label v1
44 ) const
45 {
46  const labelList& fEdges = pp_.faceEdges()[faceI];
47 
48  const edgeList& edges = pp_.edges();
49 
50 
51  label nbrEdgeI = -1;
52 
53  // Shortcut: maybe faceEdges are sorted(?) in which case fEdges[fp] is
54  // edge between v0 and v1.
55  const edge& e = edges[fEdges[fp]];
56 
57  if ((e[0] == v0 && e[1] == v1) || (e[0] == v1 && e[1] == v0))
58  {
59  // Correct edge.
60  nbrEdgeI = fEdges[fp];
61  }
62  else
63  {
64  // Loop over all faceEdges.
65  forAll(fEdges, i)
66  {
67  label edgeI = fEdges[i];
68 
69  const edge& e = edges[edgeI];
70 
71  if
72  (
73  (e[0] == v0 && e[1] == v1)
74  || (e[0] == v1 && e[1] == v0)
75  )
76  {
77  // Found edge on face which uses v0, v1.
78  nbrEdgeI = edgeI;
79 
80  break;
81  }
82  }
83  }
84 
85 
86  if (nbrEdgeI == -1)
87  {
88  FatalErrorIn("getNeighbour")
89  << "Did not find edge on face " << faceI << " that uses vertices"
90  << v0 << " and " << v1 << abort(FatalError);
91  }
92 
93 
94  // Get neighbouring face.
95 
96  const labelList& eFaces = pp_.edgeFaces()[nbrEdgeI];
97 
98  if (eFaces.size() == 1)
99  {
100  return -1;
101  }
102  else if (eFaces.size() == 2)
103  {
104  label nbrFaceI = eFaces[0];
105 
106  if (nbrFaceI == faceI)
107  {
108  nbrFaceI = eFaces[1];
109  }
110 
111  return nbrFaceI;
112  }
113  else
114  {
115  FatalErrorIn("getNeighbour")
116  << "Illegal surface on patch. Face " << faceI
117  << " at vertices " << v0 << ',' << v1
118  << " has fewer than 1 or more than 2 neighbours"
119  << abort(FatalError);
120  return -1;
121  }
122 }
123 
124 
125 // Gets labels of changed faces and enterVertices on faces.
126 // Returns labels of faces changed and enterVertices on them.
128 (
129  const labelList& changedFaces,
130  const labelList& enterVerts,
131 
132  labelList& nbrFaces,
133  labelList& nbrEnterVerts
134 )
135 {
136  nbrFaces.setSize(pp_.size());
137  nbrEnterVerts.setSize(pp_.size());
138  label changedI = 0;
139 
140  forAll(changedFaces, i)
141  {
142  label faceI = changedFaces[i];
143  label enterVertI = enterVerts[i];
144 
145  if (!visited_[faceI])
146  {
147  // Do this face
148  visited_[faceI] = true;
149  visitOrder_.append(faceI);
150 
151  const face& f = pp_.localFaces()[faceI];
152 
153  label fp = findIndex(f, enterVertI);
154 
155  indexInFace_.append(fp);
156 
157  // Visit neighbouring faces in order, starting at fp.
158  for (label i = 0; i < f.size(); i++)
159  {
160  label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp);
161  label nbr = getNeighbour(faceI, fp, f[fp], f[fp1]);
162 
163  if
164  (
165  nbr != -1
166  && !visited_[nbr]
167  && faceZone_[nbr] == faceZone_[faceI]
168  )
169  {
170  nbrFaces[changedI] = nbr;
171  nbrEnterVerts[changedI] = f[fp];
172  changedI++;
173  }
174 
175  fp = fp1;
176  }
177  }
178  }
179 
180  nbrFaces.setSize(changedI);
181  nbrEnterVerts.setSize(changedI);
182 }
183 
184 
185 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
186 
187 // Construct from components
189 (
190  const primitivePatch& pp,
191  const labelList& faceZone,
192  const bool reverse,
193  const label faceI,
194  const label enterVertI,
195  boolList& visited
196 )
197 :
198  pp_(pp),
199  faceZone_(faceZone),
200  reverse_(reverse),
201  visited_(visited),
202  visitOrder_(pp.size()),
203  indexInFace_(pp.size())
204 {
205  // List of faces that have been visited in the current iteration.
206  labelList changedFaces(1, faceI);
207  // Corresponding list of entry vertices
208  labelList enterVerts(1, enterVertI);
209 
210  while (true)
211  {
212  labelList nbrFaces;
213  labelList nbrEnterVerts;
214 
215  faceToFace
216  (
217  changedFaces,
218  enterVerts,
219 
220  nbrFaces,
221  nbrEnterVerts
222  );
223 
224 
225  if (nbrFaces.empty())
226  {
227  break;
228  }
229 
230  changedFaces = nbrFaces;
231  enterVerts = nbrEnterVerts;
232  }
233 
234  visitOrder_.shrink();
235  indexInFace_.shrink();
236 }
237 
238 
239 // ************************************************************************* //
Foam::walkPatch::walkPatch
walkPatch(const walkPatch &)
Disallow default bitwise copy construct.
walkPatch.H
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::walkPatch::faceToFace
void faceToFace(const labelList &changedFaces, const labelList &enterVerts, labelList &nbrFaces, labelList &nbrEnterVerts)
Gets labels of changed faces and enterVertices on faces.
Definition: walkPatch.C:128
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::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::faceToFace
A topoSetSource to select faces based on usage in another faceSet.
Definition: faceToFace.H:48
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::List::append
void append(const T &)
Append an element at the end of the list.
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
f
labelList f(nPoints)
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::walkPatch::getNeighbour
label getNeighbour(const label faceI, const label fp, const label v0, const label v1) const
Get other face using v0, v1. Returns -1 if none.
Definition: walkPatch.C:39
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:94
defineTypeNameAndDebug
defineTypeNameAndDebug(Foam::walkPatch, 0)
Foam::walkPatch
Collection of static functions to do various simple patch related things.
Definition: walkPatch.H:49
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
ListOps.H
Various functions to operate on Lists.
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88
Foam::reverse
void reverse(UList< T > &, const label n)
Definition: UListI.H:322