Loading...
Searching...
No Matches
randomRenumber.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-2012 OpenFOAM Foundation
9 Copyright (C) 2021-2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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\*---------------------------------------------------------------------------*/
28
29#include "randomRenumber.H"
30#include "Random.H"
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
38
40 (
44 );
45}
47
48// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53labelList randomMap(const label nCells)
54{
55 Random rndGen(0);
56
57 // Full coverage
58 labelList newToOld(Foam::identity(nCells));
59
60 // Fisher-Yates shuffle algorithm
61 for (label i = nCells - 1; i > 0; --i)
62 {
63 label j = rndGen.position<label>(0, i);
64 std::swap(newToOld[i], newToOld[j]);
65 }
66
67 return newToOld;
69
70} // End namespace Foam
71
72
73// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78{}
79
80
84{}
85
86
87// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88
90(
91 const label nCells
92) const
93{
94 return randomMap(nCells);
95}
96
97
99(
100 const pointField& cellCentres
101) const
102{
103 return randomMap(cellCentres.size());
104}
105
106
108(
110) const
111{
112 return randomMap(mesh.nCells());
113}
114
115
117(
118 const CompactListList<label>& cellCells
119) const
120{
121 return randomMap(cellCells.size());
122}
123
124
126(
127 const labelListList& cellCells
128) const
129{
130 return randomMap(cellCells.size());
131}
132
133
134// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A packed storage of objects of type <T> using an offset table for access.
label size() const noexcept
The primary size (the number of rows/sublists).
Random number generator.
Definition Random.H:56
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Random renumber. Just to see effect of renumbering.
virtual labelList renumber(const label nCells) const
Return the cell visit order (from ordered back to original cell id) based solely on the number of cel...
randomRenumber()
Default construct.
Abstract base class for renumbering.
renumberMethod()
Default construct.
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
dynamicFvMesh & mesh
Namespace for OpenFOAM.
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
labelList randomMap(const label nCells)
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
vectorField pointField
pointField is a vectorField.
dictionary dict
Random rndGen