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 "SLList.H"
33 #include "boolList.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  boolList visitedFace(lf.size(), false);
59 
60  localPointOrderPtr_.reset(new labelList(meshPoints().size(), -1));
61  auto& pointOrder = *localPointOrderPtr_;
62 
63  boolList visitedPoint(pointOrder.size(), false);
64 
65  label nPoints = 0;
66 
67  forAll(lf, facei)
68  {
69  if (!visitedFace[facei])
70  {
71  SLList<label> faceOrder(facei);
72 
73  do
74  {
75  const label curFace = faceOrder.first();
76 
77  faceOrder.removeHead();
78 
79  if (!visitedFace[curFace])
80  {
81  visitedFace[curFace] = true;
82 
83  const labelList& curPoints = lf[curFace];
84 
85  // mark points
86  forAll(curPoints, pointi)
87  {
88  if (!visitedPoint[curPoints[pointi]])
89  {
90  visitedPoint[curPoints[pointi]] = true;
91 
92  pointOrder[nPoints] = curPoints[pointi];
93 
94  nPoints++;
95  }
96  }
97 
98  // add face neighbours to the list
99  const labelList& nbrs = ff[curFace];
100 
101  forAll(nbrs, nbrI)
102  {
103  if (!visitedFace[nbrs[nbrI]])
104  {
105  faceOrder.append(nbrs[nbrI]);
106  }
107  }
108  }
109  } while (faceOrder.size());
110  }
111  }
112 
113  DebugInfo << "Calculated local point order" << endl;
114 }
115 
116 
117 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
boolList.H
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:65
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
Foam::fv::ff
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)
Definition: CrankNicolsonDdtScheme.C:275
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
SLList.H
Non-intrusive singly-linked list.
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79