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 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(randomDecomp, 0);
37 
39  (
40  decompositionMethod,
41  randomDecomp,
42  dictionary
43  );
44 
46  (
47  decompositionMethod,
48  randomDecomp,
49  dictionaryRegion
50  );
51 }
52 
53 
54 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 
56 Foam::labelList Foam::randomDecomp::randomMap(const label nCells) const
57 {
58  Random rndGen(0);
59 
60  labelList finalDecomp(nCells);
61 
62  for (label& val : finalDecomp)
63  {
64  val = rndGen.position<label>(0, nDomains_ - 1);
65  }
66 
67  return finalDecomp;
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 
73 Foam::randomDecomp::randomDecomp(const dictionary& decompDict)
74 :
75  decompositionMethod(decompDict)
76 {}
77 
78 
79 Foam::randomDecomp::randomDecomp
80 (
81  const dictionary& decompDict,
82  const word& regionName
83 )
84 :
85  decompositionMethod(decompDict, regionName)
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
92 (
93  const pointField& points,
94  const scalarField& pointWeights
95 ) const
96 {
97  return randomMap(points.size());
98 }
99 
100 
102 (
103  const pointField& points
104 ) const
105 {
106  return randomMap(points.size());
107 }
108 
109 
111 (
112  const polyMesh& mesh,
113  const pointField&,
114  const scalarField&
115 ) const
116 {
117  return randomMap(mesh.nCells()); // or cc.size()
118 }
119 
120 
122 (
123  const labelListList& globalCellCells,
124  const pointField&,
125  const scalarField&
126 ) const
127 {
128  return randomMap(globalCellCells.size()); // or cc.size()
129 }
130 
131 
132 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::decompositionMethod::nDomains_
label nDomains_
Number of domains for the decomposition.
Definition: decompositionMethod.H:95
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::randomDecomp::decompose
virtual labelList decompose(const pointField &points, const scalarField &pointWeights) const
Return for every coordinate the wanted processor number.
Definition: randomDecomp.C:92
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
randomDecomp.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Field< vector >
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::decompositionMethod
Abstract base class for domain decomposition.
Definition: decompositionMethod.H:51
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Random.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
points
const pointField & points
Definition: gmvOutputHeader.H:1
rndGen
Random rndGen
Definition: createFields.H:23
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)