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-------------------------------------------------------------------------------
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
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;
115 decompositionMethod::calcCellCells
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// ************************************************************************* //
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Testing of domain decomposition for finite-volume meshes.
virtual bool execute()
Calculate the output fields.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
label nCells() const noexcept
Number of mesh cells.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
List< label > labelList
A List of labels.
Definition: List.H:66
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:82
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
cpuTimeCxx cpuTime
Selection of preferred clock mechanism for the elapsed cpu time.
Definition: cpuTimeFwd.H:43
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53