randomDecomp.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 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 "randomDecomp.H"
27 #include "clock.H"
28 #include "Random.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 
38  (
41  decomposer
42  );
43 
45  (
48  distributor
49  );
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
56 :
57  decompositionMethod(decompositionDict),
58  seed_
59  (
60  decompositionDict.optionalSubDict
61  (
62  word(decompositionDict.lookup("method")) + "Coeffs"
63  ).lookupOrDefault<label>("seed", clock::getTime())
64  )
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
71 (
72  const polyMesh& mesh,
73  const pointField& points,
74  const scalarField& pointWeights
75 )
76 {
77  Random rndGen(seed_);
78 
79  // Simple random integer. No guarantees about balance.
80  /*
81  labelList result(points.size());
82  forAll(result, i)
83  {
84  result[i] = rndGen.sampleAB<label>(0, nDomains());
85  }
86  */
87 
88  // Sorted random scalar. Equal balance.
89  scalarList position(points.size());
90  forAll(points, i)
91  {
92  position[i] = rndGen.sample01<scalar>();
93  }
94 
95  labelList order(points.size());
96  sortedOrder(position, order);
97 
98  labelList result(points.size());
99  forAll(points, i)
100  {
101  result[i] = (nDomains()*order[i])/points.size();
102  }
103 
104  return result;
105 }
106 
107 
108 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Random number generator.
Definition: Random.H:58
Type sample01()
Advance the state and return a sample of a given type from a.
Definition: RandomI.H:69
Read access to the system clock with formatting.
Definition: clock.H:51
Abstract base class for decomposition.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Random decomposition. Good for testing. Very bad for anything else.
Definition: randomDecomp.H:51
virtual labelList decompose(const polyMesh &mesh, const pointField &cc, const scalarField &cWeights)
Return for every coordinate the wanted processor number. Use the.
Definition: randomDecomp.C:71
randomDecomp(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
Definition: randomDecomp.C:55
A class for handling words, derived from string.
Definition: word.H:62
const pointField & points
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
defineTypeNameAndDebug(combustionModel, 0)
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Random rndGen(label(0))