PrimitivePatchLocalPointOrder.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  Orders the local points on the patch for most efficient search
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "SLList.H"
30 #include "boolList.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template
35 <
36  class Face,
37  template<class> class FaceList,
38  class PointField,
39  class PointType
40 >
41 void
44 {
45  // Note: Cannot use bandCompressing as point-point addressing does
46  // not exist and is not considered generally useful.
47  //
48 
49  if (debug)
50  {
51  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
52  << "calcLocalPointOrder() : "
53  << "calculating local point order"
54  << endl;
55  }
56 
57  if (localPointOrderPtr_)
58  {
59  // it is considered an error to attempt to recalculate
60  // if already allocated
62  (
63  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
64  "calcLocalPointOrder()"
65  ) << "local point order already calculated"
66  << abort(FatalError);
67  }
68 
69  const List<Face>& lf = localFaces();
70 
71  const labelListList& ff = faceFaces();
72 
73  boolList visitedFace(lf.size(), false);
74 
75  localPointOrderPtr_ = new labelList(meshPoints().size(), -1);
76 
77  labelList& pointOrder = *localPointOrderPtr_;
78 
79  boolList visitedPoint(pointOrder.size(), false);
80 
81  label nPoints = 0;
82 
83  forAll (lf, faceI)
84  {
85  if (!visitedFace[faceI])
86  {
87  SLList<label> faceOrder(faceI);
88 
89  do
90  {
91  const label curFace = faceOrder.first();
92 
93  faceOrder.removeHead();
94 
95  if (!visitedFace[curFace])
96  {
97  visitedFace[curFace] = true;
98 
99  const labelList& curPoints = lf[curFace];
100 
101  // mark points
102  forAll (curPoints, pointI)
103  {
104  if (!visitedPoint[curPoints[pointI]])
105  {
106  visitedPoint[curPoints[pointI]] = true;
107 
108  pointOrder[nPoints] = curPoints[pointI];
109 
110  nPoints++;
111  }
112  }
113 
114  // add face neighbours to the list
115  const labelList& nbrs = ff[curFace];
116 
117  forAll (nbrs, nbrI)
118  {
119  if (!visitedFace[nbrs[nbrI]])
120  {
121  faceOrder.append(nbrs[nbrI]);
122  }
123  }
124  }
125  } while (faceOrder.size());
126  }
127  }
128 
129  if (debug)
130  {
131  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
132  << "calcLocalPointOrder() "
133  << "finished calculating local point order"
134  << endl;
135  }
136 }
137 
138 
139 // ************************************************************************* //
boolList.H
Foam::LList::append
void append(const T &a)
Add at tail of list.
Definition: LList.H:166
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::SLList< label >
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::PrimitivePatch::calcLocalPointOrder
void calcLocalPointOrder() const
Calculate local point order.
Definition: PrimitivePatchLocalPointOrder.C:43
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
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::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::fv::ff
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)
Definition: CrankNicolsonDdtScheme.C:272
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
SLList.H
Foam::List< Face >
Foam::LList::first
T & first()
Return the first entry added.
Definition: LList.H:133
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::LList::removeHead
T removeHead()
Remove and return head.
Definition: LList.H:172