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