PrimitivePatchLocalPointOrder.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Description
28  Orders the local points on the patch for most efficient search
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "boolList.H"
33 #include "CircularBuffer.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 template<class FaceList, class PointField>
38 void
40 {
41  // Note: Cannot use bandCompressing as point-point addressing does
42  // not exist and is not considered generally useful.
43 
44  DebugInFunction << "Calculating local point order" << endl;
45 
46  if (localPointOrderPtr_)
47  {
48  // An error to recalculate if already allocated
50  << "local point order already calculated"
51  << abort(FatalError);
52  }
53 
54  const List<face_type>& lf = localFaces();
55 
56  const labelListList& ff = faceFaces();
57 
58  localPointOrderPtr_.reset(new labelList(meshPoints().size(), -1));
59  auto& pointOrder = *localPointOrderPtr_;
60 
61  boolList visitedFace(lf.size(), false);
62  boolList visitedPoint(pointOrder.size(), false);
63 
64  label nPoints = 0;
65 
66  // FIFO buffer managing point/face insertion order
67  CircularBuffer<label> faceOrder(32);
68 
69  forAll(lf, facei)
70  {
71  if (!visitedFace[facei])
72  {
73  faceOrder.push_back(facei);
74 
75  while (!faceOrder.empty())
76  {
77  // Process as FIFO
78  const label curFace = faceOrder.front();
79  faceOrder.pop_front();
80 
81  if (!visitedFace[curFace])
82  {
83  visitedFace[curFace] = true;
84 
85  // mark points
86  for (const label pointi : lf[curFace])
87  {
88  if (!visitedPoint[pointi])
89  {
90  visitedPoint[pointi] = true;
91 
92  pointOrder[nPoints] = pointi;
93 
94  ++nPoints;
95  }
96  }
97 
98  // Add unvisited face neighbours to the list
99 
100  for (const label nbrFacei : ff[curFace])
101  {
102  if (!visitedFace[nbrFacei])
103  {
104  faceOrder.push_back(nbrFacei);
105  }
106  }
107  }
108  }
109  }
110  }
111 
112  DebugInfo << "Calculated local point order" << endl;
113 }
114 
115 
116 // ************************************************************************* //
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
A list of faces which address into the list of points.
label nPoints
#define DebugInFunction
Report an information message using Foam::Info.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
#define DebugInfo
Report an information message using Foam::Info.
List< label > labelList
A List of labels.
Definition: List.H:62
List< bool > boolList
A List of bools.
Definition: List.H:60
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)