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-2024 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 "globalMeshData.H"
31 #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 auto& model = decompositionModel::New(mesh_, decompDictFile_);
65 
66  // Allow overrides for testing
67  dictionary& modelDict = const_cast<decompositionModel&>(model);
68 
69  if (nDomainsOverride_ > 0)
70  {
71  modelDict.add
72  (
73  word("numberOfSubdomains"),
74  nDomainsOverride_,
75  true
76  );
77  }
78 
79  if (!methodNameOverride_.empty())
80  {
81  modelDict.add
82  (
83  word("method"),
84  methodNameOverride_,
85  true
86  );
87  }
88 
89  scalarField cellWeights;
90  if (word name; model.readIfPresent("weightField", name))
91  {
92  volScalarField weights
93  (
94  IOobject
95  (
96  name,
97  mesh_.time().timeName(),
98  mesh_,
102  ),
103  mesh_
104  );
105  cellWeights = std::move(weights.primitiveFieldRef(false));
106  }
107 
108  const auto& decomposer = model.decomposer();
109 
110  // Local mesh connectivity
111  CompactListList<label> cellCells;
112  globalMeshData::calcCellCells(mesh_, cellCells);
113 
114  labelList cellToProc = decomposer.decompose(mesh_, cellWeights);
115 
116  Info<< "\nFinished decomposition into "
117  << decomposer.nDomains() << " domains in "
118  << decompositionTime.elapsedCpuTime() << " s" << nl << nl;
119 
120  decompositionInformation info
121  (
122  cellCells,
123  cellToProc,
124  decomposer.nDomains()
125  );
126 
127  if (writeCellDist)
128  {
129  // Write decomposition for visualization
130  // - write as VTU to avoid any impact
131  writeVTK("cellDist", cellToProc);
132 
133 // Less likely that this is actually required, but may be useful...
134 //
135 // // Write decomposition as labelList for use with 'manual'
136 // // decomposition method.
137 // labelIOList cellDecomposition
138 // (
139 // IOobject
140 // (
141 // "cellDecomposition",
142 // mesh_.facesInstance(),
143 // mesh_,
144 // IOobject::NO_READ,
145 // IOobject::NO_WRITE,
146 // IOobject::NO_REGISTER
147 // ),
148 // std::move(cellToProc)
149 // );
150 // cellDecomposition.write();
151 //
152 // Info<< nl << "Wrote decomposition to "
153 // << cellDecomposition.objectRelPath()
154 // << " for use in manual decomposition." << endl;
155 
156  Info<< nl;
157  }
158 
159  if (verbose)
160  {
161  info.printDetails(Info);
162  Info<< nl;
163  }
164  info.printSummary(Info);
165 }
166 
167 
168 // ************************************************************************* //
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:518
Ignore writing from objectRegistry::writeObject()
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:72
void execute(const bool writeCellDist, const bool verbose=false)
Perform dry-run.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const auto & io
static const decompositionModel & New(const polyMesh &mesh, const fileName &decompDictFile="", const dictionary *fallback=nullptr)
Read and register on mesh, optionally with alternative decomposeParDict path/name or with fallback co...
cpuTimePosix cpuTime
Selection of preferred clock mechanism for the elapsed cpu time.
Definition: cpuTimeFwd.H:36
messageStream Info
Information stream (stdout output on master, null elsewhere)
static void calcCellCells(const polyMesh &mesh, const labelUList &agglom, const label nLocalCoarse, const bool parallel, CompactListList< label > &cellCells)
Determine (local or global) cellCells from mesh agglomeration.
void writeVTK(OFstream &os, const Type &value)
List< label > labelList
A List of labels.
Definition: List.H:61
domainDecompositionDryRun(const IOobject &io, const fileName &decompDictFile="", const label nDomains=0, const word &methodName="")
Construct from components.
Do not request registration (bool: false)