random.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) 2022-2024 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 "random.H"
27 #include "clock.H"
28 #include "randomGenerator.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace decompositionMethods
36 {
38 
40  (
42  random,
43  decomposer
44  );
45 
47  (
49  random,
50  distributor
51  );
52 }
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
59 (
60  const dictionary& decompositionDict,
61  const dictionary& methodDict
62 )
63 :
64  decompositionMethod(decompositionDict),
65  seed_(methodDict.lookupOrDefault<label>("seed", clock::getTime()))
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 
72 (
73  const polyMesh& mesh,
74  const pointField& points,
75  const scalarField& pointWeights
76 )
77 {
78  checkWeights(points, pointWeights);
79 
80  randomGenerator rndGen(seed_, true);
81 
82  // Simple random integer. No guarantees about balance.
83  /*
84  labelList result(points.size());
85  forAll(result, i)
86  {
87  result[i] = rndGen.sampleAB<label>(0, nDomains());
88  }
89  */
90 
91  // Sorted random scalar. Equal balance.
92  scalarList position(points.size());
93  forAll(points, i)
94  {
95  position[i] = rndGen.sample01<scalar>();
96  }
97 
98  labelList order(points.size());
100 
101  labelList result(points.size());
102  forAll(points, i)
103  {
104  result[i] = (nDomains()*order[i])/points.size();
105  }
106 
107  return result;
108 }
109 
110 
111 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
Read access to the system clock with formatting.
Definition: clock.H:51
Abstract base class for decomposition.
Random decomposition. Good for testing. Very bad for anything else.
Definition: random.H:53
virtual labelList decompose(const polyMesh &mesh, const pointField &cellCentres, const scalarField &cellWeights)
Return for every coordinate the wanted processor number. Use the.
Definition: random.C:72
random(const dictionary &decompositionDict, const dictionary &methodDict)
Construct given the decomposition dictionary.
Definition: random.C:59
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Random number generator.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const pointField & points
addToRunTimeSelectionTable(decompositionMethod, metis, decomposer)
point position(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the position given the coordinates and tet topology.
Definition: trackingI.H:224
Namespace for OpenFOAM.
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
int order(const scalar s)
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
randomGenerator rndGen(653213)