sortLabelledTri.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-2018 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 "sortLabelledTri.H"
27 #include "labelledTri.H"
28 #include "triSurface.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //
36 
37 inline bool surfAndLabel::less::operator()
38 (
39  const surfAndLabel& one,
40  const surfAndLabel& two
41 ) const
42 {
43  const triSurface& surf = *one.surfPtr_;
44  return surf[one.index_].region() < surf[two.index_].region();
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 // Construct from components
52 :
53  List<surfAndLabel>(surf.size(), surfAndLabel(surf, -1))
54 {
55 
56  // Set the face label
57  forAll(surf, facei)
58  {
59  operator[](facei).index_ = facei;
60  }
61 
62  // Sort according to region number.
63  sort(*this, surfAndLabel::less());
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
69 void sortLabelledTri::indices(labelList& newIndices) const
70 {
71  newIndices.setSize(size());
72 
73  forAll(newIndices, i)
74  {
75  newIndices[i] = operator[](i).index_;
76  }
77 }
78 
79 
81 {
82  labelList newIndices(size());
83  indices(newIndices);
84  return newIndices;
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 
90 } // End namespace Foam
91 
92 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
sortLabelledTri(const triSurface &)
Construct from surface, sorting the faces according to patch.
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
labelList indices() const
Return the list of sorted point indices.
static bool less(const vector &x, const vector &y)
To compare normals.
void sort(UList< T > &)
Definition: UList.C:115
Hold surface and label.
void setSize(const label)
Reset size of List.
Definition: List.C:281
Triangulated surface description with patch information.
Definition: triSurface.H:66
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
Namespace for OpenFOAM.