SortableListDRGEP.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) 2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "OSspecific.H"
29 #include <algorithm>
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template <class Type>
35 :
36  List<Type>(values),
37  indices_(values.size())
38 {
39  sort();
40 }
41 
42 
43 template <class Type>
45 :
46  List<Type>(size),
47  indices_(size)
48 {}
49 
50 
51 template <class Type>
53 (
54  const label size,
55  const Type& val
56 )
57 :
58  List<Type>(size, val),
59  indices_(size)
60 {}
61 
62 
63 template <class Type>
65 (
66  const SortableListDRGEP<Type>& lst
67 )
68 :
69  List<Type>(lst),
70  indices_(lst.indices())
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
76 template <class Type>
77 void Foam::SortableListDRGEP<Type>::setSize(const label newSize)
78 {
79  List<Type>::setSize(newSize);
80  indices_.setSize(newSize);
81 }
82 
83 
84 template <class Type>
86 {
87  forAll(indices_, i)
88  {
89  indices_[i] = i;
90  }
91 
92  Foam::sort(indices_, less(*this));
93 
94  List<Type> tmpValues(this->size());
95 
96  forAll(indices_, i)
97  {
98  tmpValues[i] = this->operator[](indices_[i]);
99  }
100 
101  List<Type>::transfer(tmpValues);
102 }
103 
104 
105 template <class Type>
107 {
108  forAll(indices_, i)
109  {
110  indices_[i] = i;
111  }
112 
113  std::partial_sort
114  (
115  indices_.begin(),
116  indices_.begin()+M,
117  indices_.end(),
118  less(*this)
119  );
120 }
121 
122 
123 template <class Type>
125 {
126  forAll(indices_, i)
127  {
128  indices_[i] = i;
129  }
130 
131  Foam::stableSort(indices_, less(*this));
132 
133  List<Type> tmpValues(this->size());
134 
135  forAll(indices_, i)
136  {
137  tmpValues[i] = this->operator[](indices_[i]);
138  }
139 
140  List<Type>::transfer(tmpValues);
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
145 
146 template <class Type>
147 void
149 {
151  indices_ = rhs.indices();
152 }
153 
154 
155 // ************************************************************************* //
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::SortableListDRGEP::operator=
void operator=(const SortableListDRGEP< Type > &)
Definition: SortableListDRGEP.C:148
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::less
static bool less(const vector &x, const vector &y)
To compare normals.
Definition: meshRefinementRefine.C:57
Foam::SortableListDRGEP::indices
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
Definition: SortableListDRGEP.H:104
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::stableSort
void stableSort(UList< T > &a)
Definition: UList.C:275
Foam::SortableListDRGEP::partialSort
void partialSort(int M)
Partial sort the list (if changed after construction time)
Definition: SortableListDRGEP.C:106
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::SortableListDRGEP
A list that is sorted upon construction or when explicitly requested with the sort() method.
Definition: SortableListDRGEP.H:52
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:261
Foam::List::operator=
void operator=(const UList< T > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:498
Foam::List< Type >
Foam::SortableListDRGEP::stableSort
void stableSort()
Sort the list (if changed after construction time)
Definition: SortableListDRGEP.C:124
M
#define M(I)
Foam::SortableListDRGEP::sort
void sort()
Sort the list (if changed after construction time)
Definition: SortableListDRGEP.C:85
Foam::SortableListDRGEP::setSize
void setSize(const label)
Size the list. If grow can cause undefined indices (until next sort)
Definition: SortableListDRGEP.C:77
Foam::SortableListDRGEP::SortableListDRGEP
SortableListDRGEP(const List< Type > &)
Construct from List, sorting the elements. Starts with indices set.
Definition: SortableListDRGEP.C:34