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-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(randomRenumber, 0);
38 
40  (
41  renumberMethod,
42  randomRenumber,
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 Foam::randomRenumber::randomRenumber(const dictionary& dict)
51 :
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
59 (
60  const pointField& points
61 ) const
62 {
63  Random rndGen(0);
64 
65  labelList newToOld(identity(points.size()));
66 
67  for (label iter = 0; iter < 10; iter++)
68  {
69  forAll(newToOld, i)
70  {
71  label j = rndGen.position<label>(0, newToOld.size()-1);
72  std::swap(newToOld[i], newToOld[j]);
73  }
74  }
75  return newToOld;
76 }
77 
78 
80 (
81  const polyMesh& mesh,
82  const pointField& points
83 ) const
84 {
85  return renumber(points);
86 }
87 
88 
90 (
91  const CompactListList<label>& cellCells,
92  const pointField& points
93 ) const
94 {
95  return renumber(points);
96 }
97 
98 
100 (
101  const labelListList& cellCells,
102  const pointField& points
103 ) const
104 {
105  return renumber(points);
106 }
107 
108 
109 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values (not the indices) of a list.
Random rndGen
Definition: createFields.H:23
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Abstract base class for renumbering.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const pointField & points
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...
Definition: labelLists.C:44
virtual labelList renumber(const pointField &) const
Return the order in which cells need to be visited (ie. from ordered back to original cell label)...
Random number generator.
Definition: Random.H:55
A packed storage of objects of type <T> using an offset table for access.
defineTypeNameAndDebug(combustionModel, 0)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)