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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
34namespace Foam
35{
38 (
42 );
43}
44
45
46// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47
48Foam::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
86(
87 const dictionary& decompDict,
88 const word& regionName,
89 int select
90)
91:
93 agglom_(1)
94{
95 const dictionary& coeffs = findCoeffsDict(typeName + "Coeffs", select);
96
97 // No sanity check needed here (done in randomMap routine)
98 coeffs.readIfPresent("agglom", agglom_);
99}
100
101
102// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103
105(
106 const pointField& points,
107 const scalarField& pointWeights
108) const
109{
110 return randomMap(points.size());
111}
112
113
115(
116 const pointField& points
117) const
118{
119 return randomMap(points.size());
120}
121
122
124(
125 const polyMesh& mesh,
126 const pointField&,
127 const scalarField&
128) const
129{
130 return randomMap(mesh.nCells()); // or cc.size()
131}
132
133
135(
136 const labelListList& globalCellCells,
137 const pointField&,
138 const scalarField&
139) const
140{
141 return randomMap(globalCellCells.size()); // or cc.size()
142}
143
144
145// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Type position(const Type &start, const Type &end)
Return a sample on the interval [start,end].
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Abstract base class for domain decomposition.
label nDomains_
Number of domains for the decomposition.
static const dictionary & findCoeffsDict(const dictionary &dict, const word &coeffsName, int select=selectionType::DEFAULT)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
label nCells() const noexcept
Number of mesh cells.
Decomposition according to pseudo-random number generator, which is useful for development and stress...
Definition: randomDecomp.H:71
bool decompose() const noexcept
Query the decompose flag (normally off)
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeName(Type)
Define the typeName.
Definition: className.H:96
dynamicFvMesh & mesh
Foam::word regionName(Foam::polyMesh::defaultRegion)
const pointField & points
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
Random rndGen
Definition: createFields.H:23