PrimitivePatchCheck.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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  Checks topology of the patch.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "PrimitivePatch.H"
30 #include "Map.H"
31 #include "ListOps.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 template<class FaceList, class PointField>
37 (
38  const label pointi,
39  const labelList& pFaces,
40  const label startFacei,
41  const label startEdgeI,
42  boolList& pFacesHad
43 ) const
44 {
45  label index = findIndex(pFaces, startFacei);
46 
47  if (!pFacesHad[index])
48  {
49  // Mark face as been visited.
50  pFacesHad[index] = true;
51 
52  // Step to next edge on face which is still using pointi
53  const labelList& fEdges = faceEdges()[startFacei];
54 
55  label nextEdgeI = -1;
56 
57  forAll(fEdges, i)
58  {
59  label edgeI = fEdges[i];
60 
61  const edge& e = edges()[edgeI];
62 
63  if (edgeI != startEdgeI && (e[0] == pointi || e[1] == pointi))
64  {
65  nextEdgeI = edgeI;
66 
67  break;
68  }
69  }
70 
71  if (nextEdgeI == -1)
72  {
74  << "Problem: cannot find edge out of " << fEdges
75  << "on face " << startFacei << " that uses point " << pointi
76  << " and is not edge " << startEdgeI << abort(FatalError);
77  }
78 
79  // Walk to next face(s) across edge.
80  const labelList& eFaces = edgeFaces()[nextEdgeI];
81 
82  forAll(eFaces, i)
83  {
84  if (eFaces[i] != startFacei)
85  {
86  visitPointRegion
87  (
88  pointi,
89  pFaces,
90  eFaces[i],
91  nextEdgeI,
92  pFacesHad
93  );
94  }
95  }
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
102 template<class FaceList, class PointField>
103 typename
106 surfaceType() const
107 {
108  if (debug)
109  {
110  InfoInFunction << "Calculating patch topology" << endl;
111  }
112 
113  const labelListList& edgeFcs = edgeFaces();
114 
115  surfaceTopo pType = MANIFOLD;
116 
117  forAll(edgeFcs, edgeI)
118  {
119  label nNbrs = edgeFcs[edgeI].size();
120 
121  if (nNbrs < 1 || nNbrs > 2)
122  {
123  pType = ILLEGAL;
124 
125  // Can exit now. Surface is illegal.
126  return pType;
127  }
128  else if (nNbrs == 1)
129  {
130  // Surface might be open or illegal so keep looping.
131  pType = OPEN;
132  }
133  }
134 
135  if (debug)
136  {
137  Info<< " Finished." << endl;
138  }
139 
140  return pType;
141 }
142 
143 
144 template<class FaceList, class PointField>
145 bool
148 (
149  const bool report,
150  labelHashSet* setPtr
151 ) const
152 {
153  if (debug)
154  {
155  InfoInFunction << "Checking patch topology" << endl;
156  }
157 
158  // Check edgeFaces
159 
160  const labelListList& edgeFcs = edgeFaces();
161 
162  bool illegalTopo = false;
163 
164  forAll(edgeFcs, edgeI)
165  {
166  label nNbrs = edgeFcs[edgeI].size();
167 
168  if (nNbrs < 1 || nNbrs > 2)
169  {
170  illegalTopo = true;
171 
172  if (report)
173  {
174  Info<< "Edge " << edgeI << " with vertices:" << edges()[edgeI]
175  << " has " << nNbrs << " face neighbours"
176  << endl;
177  }
178 
179  if (setPtr)
180  {
181  const edge& e = edges()[edgeI];
182 
183  setPtr->insert(meshPoints()[e.start()]);
184  setPtr->insert(meshPoints()[e.end()]);
185  }
186  }
187  }
188 
189  if (debug)
190  {
191  Info<< " Finished." << endl;
192  }
193 
194  return illegalTopo;
195 }
196 
197 
198 template<class FaceList, class PointField>
199 bool
202 (
203  const bool report,
204  labelHashSet* setPtr
205 ) const
206 {
207  const labelListList& pf = pointFaces();
208  const labelListList& pe = pointEdges();
209  const labelListList& ef = edgeFaces();
210  const labelList& mp = meshPoints();
211 
212  bool foundError = false;
213 
214  forAll(pf, pointi)
215  {
216  const labelList& pFaces = pf[pointi];
217 
218  // Visited faces (as indices into pFaces)
219  boolList pFacesHad(pFaces.size(), false);
220 
221  // Starting edge
222  const labelList& pEdges = pe[pointi];
223  label startEdgeI = pEdges[0];
224 
225  const labelList& eFaces = ef[startEdgeI];
226 
227  forAll(eFaces, i)
228  {
229  // Visit all faces using pointi, starting from eFaces[i] and
230  // startEdgeI. Mark off all faces visited in pFacesHad.
231  this->visitPointRegion
232  (
233  pointi,
234  pFaces,
235  eFaces[i], // starting face for walk
236  startEdgeI, // starting edge for walk
237  pFacesHad
238  );
239  }
240 
241  // After this all faces using pointi should have been visited and
242  // marked off in pFacesHad.
243 
244  label unset = findIndex(pFacesHad, false);
245 
246  if (unset != -1)
247  {
248  foundError = true;
249 
250  label meshPointi = mp[pointi];
251 
252  if (setPtr)
253  {
254  setPtr->insert(meshPointi);
255  }
256 
257  if (report)
258  {
259  Info<< "Point " << meshPointi
260  << " uses faces which are not connected through an edge"
261  << nl
262  << "This means that the surface formed by this patched"
263  << " is multiply connected at this point" << nl
264  << "Connected (patch) faces:" << nl;
265 
266  forAll(pFacesHad, i)
267  {
268  if (pFacesHad[i])
269  {
270  Info<< " " << pFaces[i] << endl;
271  }
272  }
273 
274  Info<< nl << "Unconnected (patch) faces:" << nl;
275  forAll(pFacesHad, i)
276  {
277  if (!pFacesHad[i])
278  {
279  Info<< " " << pFaces[i] << endl;
280  }
281  }
282  }
283  }
284  }
285 
286  return foundError;
287 }
288 
289 
290 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
surfaceTopo
Enumeration defining the surface type. Used in check routines.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool checkPointManifold(const bool report=false, labelHashSet *setPtr=nullptr) const
Checks primitivePatch for faces sharing point but not edge.
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
bool checkTopology(const bool report=false, labelHashSet *setPtr=nullptr) const
Check surface formed by patch for manifoldness (see above).
Various functions to operate on Lists.
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
A list of faces which address into the list of points.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
surfaceTopo surfaceType() const
Calculate surface type formed by patch.
const dimensionedScalar mp
Proton mass.
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
static const char nl
Definition: Ostream.H:260
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
label end() const
Return end vertex label.
Definition: edgeI.H:92
messageStream Info
label start() const
Return start vertex label.
Definition: edgeI.H:81
#define InfoInFunction
Report an information message using Foam::Info.