randomDecomp.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) 2019-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "randomDecomp.H"
29 #include "Random.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeName(randomDecomp);
38  (
39  decompositionMethod,
40  randomDecomp,
41  dictionary
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 Foam::labelList Foam::randomDecomp::randomMap(const label nCells) const
49 {
50  Random rndGen(0);
51 
52  labelList finalDecomp(nCells);
53 
54  if (agglom_ > 1)
55  {
56  label cached = 0;
57  label repeat = 0;
58 
59  for (label& val : finalDecomp)
60  {
61  if (!repeat)
62  {
63  cached = rndGen.position<label>(0, nDomains_ - 1);
64  repeat = agglom_;
65  }
66  --repeat;
67 
68  val = cached;
69  }
70  }
71  else
72  {
73  for (label& val : finalDecomp)
74  {
75  val = rndGen.position<label>(0, nDomains_ - 1);
76  }
77  }
78 
79  return finalDecomp;
80 }
81 
82 
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
84 
85 Foam::randomDecomp::randomDecomp(const label numDomains)
86 :
87  decompositionMethod(numDomains),
88  agglom_(0)
89 {}
90 
91 
93 (
94  const dictionary& decompDict,
95  const word& regionName,
96  int select
97 )
98 :
99  decompositionMethod(decompDict, regionName),
100  agglom_(0)
101 {
102  const dictionary& coeffs = findCoeffsDict(typeName + "Coeffs", select);
103 
104  // No sanity check needed here (done in randomMap routine)
105  coeffs.readIfPresent("agglom", agglom_);
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
112 (
113  const pointField& points,
114  const scalarField&
115 ) const
116 {
117  return randomMap(points.size());
118 }
119 
120 
122 (
123  const polyMesh& mesh,
124  const pointField&,
125  const scalarField&
126 ) const
127 {
128  return randomMap(mesh.nCells());
129 }
130 
131 
133 (
134  const CompactListList<label>& globalCellCells,
135  const pointField&,
136  const scalarField&
137 ) const
138 {
139  return randomMap(globalCellCells.size());
140 }
141 
142 
144 (
145  const labelListList& globalCellCells,
146  const pointField&,
147  const scalarField&
148 ) const
149 {
150  return randomMap(globalCellCells.size());
151 }
152 
153 
154 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
label size() const noexcept
The primary size (the number of rows/sublists)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label nDomains_
Number of domains for the decomposition.
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
Random rndGen
Definition: createFields.H:23
Macros for easy insertion into run-time selection tables.
defineTypeName(manifoldCellsMeshObject)
dynamicFvMesh & mesh
const pointField & points
A class for handling words, derived from Foam::string.
Definition: word.H:63
randomDecomp(const randomDecomp &)=delete
No copy construct.
Abstract base class for domain decomposition.
virtual labelList decompose(const pointField &points, const scalarField &pointWeights_unused=scalarField::null()) const
Return for every coordinate the wanted processor number.
Definition: randomDecomp.C:105
static const dictionary & findCoeffsDict(const dictionary &dict, const word &coeffsName, int select=selectionType::DEFAULT)
Locate coeffsName dictionary or the fallback "coeffs" dictionary within an enclosing dictionary...
A packed storage of objects of type <T> using an offset table for access.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
label nCells() const noexcept
Number of mesh cells.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)