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 | Copyright (C) 2011-2012 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 "randomRenumber.H"
28 #include "Random.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(randomRenumber, 0);
35 
37  (
38  renumberMethod,
39  randomRenumber,
40  dictionary
41  );
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
47 Foam::randomRenumber::randomRenumber(const dictionary& renumberDict)
48 :
49  renumberMethod(renumberDict)
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
56 (
57  const pointField& points
58 ) const
59 {
60  Random rndGen(0);
61 
62  labelList newToOld(identity(points.size()));
63 
64  for (label iter = 0; iter < 10; iter++)
65  {
66  forAll(newToOld, i)
67  {
68  label j = rndGen.integer(0, newToOld.size()-1);
69  Swap(newToOld[i], newToOld[j]);
70  }
71  }
72  return newToOld;
73 }
74 
75 
77 (
78  const polyMesh& mesh,
79  const pointField& points
80 ) const
81 {
82  return renumber(points);
83 }
84 
85 
87 (
88  const labelListList& cellCells,
89  const pointField& points
90 ) const
91 {
92  return renumber(points);
93 }
94 
95 
96 // ************************************************************************* //
cachedRandom rndGen(label(0),-1)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
label integer(const label lower, const label upper)
Label [lower..upper].
Definition: Random.C:118
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
Macros for easy insertion into run-time selection tables.
Abstract base class for renumbering.
void Swap(T &a, T &b)
Definition: Swap.H:43
virtual labelList renumber(const pointField &) const
Return the order in which cells need to be visited, i.e.
Simple random number generator.
Definition: Random.H:49
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.