randomRenumber.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 
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.sampleAB<label>(0, newToOld.size());
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 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Type sampleAB(const Type &a, const Type &b)
Advance the state and return a sample of a given type from a.
Definition: RandomI.H:98
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
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.
Random rndGen(label(0))
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.
Random number generator.
Definition: Random.H:57
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
randomRenumber(const dictionary &renumberDict)
Construct given the renumber dictionary.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
Namespace for OpenFOAM.