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-2021 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"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 (
37  const IOobject& io,
38  const fileName& decompDictFile,
39  const label nDomains,
40  const word& methodName
41 )
42 :
43  mesh_(io),
44  decompDictFile_(decompDictFile),
45  nDomainsOverride_(nDomains),
46  methodNameOverride_(methodName)
47 {}
48 
49 
50 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 
53 (
54  const bool writeCellDist,
55  const bool verbose
56 )
57 {
58  cpuTime decompositionTime;
59 
60  Info<< "\nCalculating distribution of cells. nCells = "
61  << mesh_.nCells() << endl;
62 
63  const decompositionModel& model = decompositionModel::New
64  (
65  mesh_,
66  decompDictFile_
67  );
68 
69  // Allow overrides for testing
70 
71  dictionary& modelDict = const_cast<decompositionModel&>(model);
72 
73  if (nDomainsOverride_ > 0)
74  {
75  modelDict.add
76  (
77  word("numberOfSubdomains"),
78  nDomainsOverride_,
79  true
80  );
81  }
82 
83  if (!methodNameOverride_.empty())
84  {
85  modelDict.add
86  (
87  word("method"),
88  methodNameOverride_,
89  true
90  );
91  }
92 
93  scalarField cellWeights;
94  word weightName;
95  if (model.readIfPresent("weightField", weightName))
96  {
97  volScalarField weights
98  (
99  IOobject
100  (
101  weightName,
102  mesh_.time().timeName(),
103  mesh_,
106  ),
107  mesh_
108  );
109  cellWeights = weights.primitiveField();
110  }
111 
112  decompositionMethod& method = model.decomposer();
113 
114  CompactListList<label> cellCells;
116  (
117  mesh_,
118  identity(mesh_.nCells()),
119  mesh_.nCells(),
120  false,
121  cellCells
122  );
123 
124  labelList cellToProc = method.decompose(mesh_, cellWeights);
125 
126  Info<< "\nFinished decomposition into "
127  << method.nDomains() << " domains in "
128  << decompositionTime.elapsedCpuTime() << " s" << nl << nl;
129 
130  decompositionInformation info
131  (
132  cellCells,
133  cellToProc,
134  method.nDomains()
135  );
136 
137  if (writeCellDist)
138  {
139  // Write decomposition for visualization
140  // - write as VTU to avoid any impact
141  writeVTK("cellDist", cellToProc);
142 
143 // Less likely that this is actually required, but may be useful...
144 //
145 // // Write decomposition as labelList for use with 'manual'
146 // // decomposition method.
147 // labelIOList cellDecomposition
148 // (
149 // IOobject
150 // (
151 // "cellDecomposition",
152 // mesh_.facesInstance(),
153 // mesh_,
154 // IOobject::NO_READ,
155 // IOobject::NO_WRITE,
156 // false
157 // ),
158 // std::move(cellToProc)
159 // );
160 // cellDecomposition.write();
161 //
162 // Info<< nl << "Wrote decomposition to "
163 // << cellDecomposition.objectRelPath()
164 // << " for use in manual decomposition." << endl;
165 
166  Info<< nl;
167  }
168 
169  if (verbose)
170  {
171  info.printDetails(Info);
172  Info<< nl;
173  }
174  info.printSummary(Info);
175 }
176 
177 
178 // ************************************************************************* //
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:191
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:63
volFields.H
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:46
Foam::decompositionMethod::calcCellCells
static void calcCellCells(const polyMesh &mesh, const labelList &agglom, const label nLocalCoarse, const bool global, CompactListList< label > &cellCells)
Definition: decompositionMethod.C:461
Foam::cpuTime
cpuTimePosix cpuTime
Selection of preferred clock mechanism for the elapsed cpu time.
Definition: cpuTimeFwd.H:36
Foam::domainDecompositionDryRun::domainDecompositionDryRun
domainDecompositionDryRun(const IOobject &io, const fileName &decompDictFile="", const label nDomains=0, const word &methodName="")
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::writeVTK
void writeVTK(OFstream &os, const Type &value)
Foam::decompositionModel::New
static const decompositionModel & New(const polyMesh &mesh, const fileName &decompDictFile="", const dictionary *fallback=nullptr)
Definition: decompositionModel.C:76
domainDecompositionDryRun.H
Foam::Info
messageStream Info
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:53
Foam::domainDecompositionDryRun::execute
void execute(const bool writeCellDist, const bool verbose=false)
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::identity
labelList identity(const label len, label start=0)
Definition: labelList.C:31
decompositionModel.H
decompositionInformation.H
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:181