domainDecompositionDryRun.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) 2018 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 
29 #include "volFields.H"
30 #include "decompositionModel.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
37 (
38  const IOobject& io,
39  const fileName& decompDictFile,
40  const label nDomains,
41  const word& methodName
42 )
43 :
44  mesh_(io),
45  decompDictFile_(decompDictFile),
46  nDomainsOverride_(nDomains),
47  methodNameOverride_(methodName)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
54 (
55  const bool writeCellDist,
56  const bool verbose
57 )
58 {
59  cpuTime decompositionTime;
60 
61  Info<< "\nCalculating distribution of cells. nCells = "
62  << mesh_.nCells() << endl;
63 
64  const decompositionModel& model = decompositionModel::New
65  (
66  mesh_,
67  decompDictFile_
68  );
69 
70  // Allow overrides for testing
71 
72  dictionary& modelDict = const_cast<decompositionModel&>(model);
73 
74  if (nDomainsOverride_ > 0)
75  {
76  modelDict.add
77  (
78  word("numberOfSubdomains"),
79  nDomainsOverride_,
80  true
81  );
82  }
83 
84  if (!methodNameOverride_.empty())
85  {
86  modelDict.add
87  (
88  word("method"),
89  methodNameOverride_,
90  true
91  );
92  }
93 
94  scalarField cellWeights;
95  word weightName;
96  if (model.readIfPresent("weightField", weightName))
97  {
98  volScalarField weights
99  (
100  IOobject
101  (
102  weightName,
103  mesh_.time().timeName(),
104  mesh_,
107  ),
108  mesh_
109  );
110  cellWeights = weights.primitiveField();
111  }
112 
113  decompositionMethod& method = model.decomposer();
114 
115  CompactListList<label> cellCells;
117  (
118  mesh_,
119  identity(mesh_.nCells()),
120  mesh_.nCells(),
121  false,
122  cellCells
123  );
124 
125  labelList cellToProc = method.decompose(mesh_, cellWeights);
126 
127  Info<< "\nFinished decomposition into "
128  << method.nDomains() << " domains in "
129  << decompositionTime.elapsedCpuTime() << " s" << nl << nl;
130 
131  decompositionInformation info
132  (
133  cellCells,
134  cellToProc,
135  method.nDomains()
136  );
137 
138  if (writeCellDist)
139  {
140  // Write decomposition as volScalarField for visualization
141  volScalarField cellDist
142  (
143  IOobject
144  (
145  "cellDist",
146  mesh_.time().timeName(),
147  mesh_,
150  ),
151  mesh_,
152  dimensionedScalar("cellDist", dimless, -1),
153  zeroGradientFvPatchScalarField::typeName
154  );
155 
156  forAll(cellToProc, celli)
157  {
158  cellDist[celli] = cellToProc[celli];
159  }
160 
161  cellDist.correctBoundaryConditions();
162  cellDist.write();
163 
164  Info<< "Wrote decomposition as volScalarField for visualization:"
165  << nl << cellDist.objectPath() << nl;
166 
167 // Less likely that this is actually required, but may be useful...
168 //
169 // // Write decomposition as labelList for use with 'manual'
170 // // decomposition method.
171 // labelIOList cellDecomposition
172 // (
173 // IOobject
174 // (
175 // "cellDecomposition",
176 // mesh_.facesInstance(),
177 // mesh_,
178 // IOobject::NO_READ,
179 // IOobject::NO_WRITE,
180 // false
181 // ),
182 // std::move(cellToProc)
183 // );
184 // cellDecomposition.write();
185 //
186 // Info<< "Wrote decomposition for use in manual decomposition:"
187 // << nl << cellDecomposition.objectPath() << nl;
188 // #endif
189 
190  Info<< nl;
191  }
192 
193  if (verbose)
194  {
195  info.printDetails(Info);
196  Info<< nl;
197  }
198  info.printSummary(Info);
199 }
200 
201 
202 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
volFields.H
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::decompositionMethod::calcCellCells
static void calcCellCells(const polyMesh &mesh, const labelList &agglom, const label nLocalCoarse, const bool global, CompactListList< label > &cellCells)
Helper: determine (local or global) cellCells from mesh.
Definition: decompositionMethod.C:517
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::domainDecompositionDryRun::domainDecompositionDryRun
domainDecompositionDryRun(const IOobject &io, const fileName &decompDictFile="", const label nDomains=0, const word &methodName="")
Construct from components.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
domainDecompositionDryRun.H
Foam::cpuTime
cpuTimeCxx cpuTime
Selection of preferred clock mechanism for the elapsed cpu time.
Definition: cpuTimeFwd.H:41
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::domainDecompositionDryRun::execute
void execute(const bool writeCellDist, const bool verbose=false)
Perform dry-run.
Foam::decompositionModel::New
static const decompositionModel & New(const polyMesh &mesh, const fileName &decompDictFile="")
Read (optionally from absolute path) and register on mesh.
Definition: decompositionModel.C:116
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
decompositionModel.H
Foam::IOobject::NO_READ
Definition: IOobject.H:123
zeroGradientFvPatchFields.H
decompositionInformation.H
Foam::IOobject::MUST_READ
Definition: IOobject.H:120