Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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\*---------------------------------------------------------------------------*/
28#include "OSspecific.H"
29#include <algorithm>
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
33template <class Type>
35:
36 List<Type>(values),
37 indices_(values.size())
38{
39 sort();
40}
41
42
43template <class Type>
46 List<Type>(size),
47 indices_(size)
48{}
49
50
51template <class Type>
53(
54 const label size,
55 const Type& val
56)
58 List<Type>(size, val),
59 indices_(size)
60{}
61
62
63template <class Type>
65(
67)
68:
69 List<Type>(lst),
70 indices_(lst.indices())
71{}
72
73
74// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75
76template <class Type>
77void Foam::SortableListDRGEP<Type>::setSize(const label newSize)
79 List<Type>::setSize(newSize);
80 indices_.setSize(newSize);
81}
82
83
84template <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
105template <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
123template <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);
142
143
144// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
145
146template <class Type>
147void
149{
151 indices_ = rhs.indices();
152}
153
154
155// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define M(I)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void operator=(const UList< T > &list)
Assignment to UList operator. Takes linear time.
Definition List.C:381
void setSize(label n)
Alias for resize().
Definition List.H:536
Less function class used by the sort function.
A list that is sorted upon construction or when explicitly requested with the sort() method.
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
void stableSort()
Sort the list (if changed after construction time).
void partialSort(int M)
Partial sort the list (if changed after construction time).
void sort()
Sort the list (if changed after construction time).
void operator=(const SortableListDRGEP< Type > &)
SortableListDRGEP(const List< Type > &)
Construct from List, sorting the elements. Starts with indices set.
void setSize(const label)
Size the list. If grow can cause undefined indices (until next sort).
void size(const label n)
Definition UList.H:118
Type & operator[](const label i)
Definition UListI.H:363
static bool less(const vector &x, const vector &y)
To compare normals.
void sort(UList< T > &list)
Sort the list.
Definition UList.C:283
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
void stableSort(UList< T > &list)
Stable sort the list.
Definition UList.C:299
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299