structuredDecomp.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "structuredDecomp.H"
31#include "FaceCellWave.H"
32#include "topoDistanceData.H"
33#include "fvMeshSubset.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
41 (
45 );
46}
47
48
49// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50
52(
53 const dictionary& decompDict,
54 const word& regionName
55)
56:
57 decompositionMethod(decompDict),
58 methodDict_(findCoeffsDict(typeName + "Coeffs", selectionType::MANDATORY)),
59 patches_(methodDict_.get<wordRes>("patches"))
60{
61 methodDict_.set("numberOfSubdomains", nDomains());
62 method_ = decompositionMethod::New(methodDict_);
63}
64
65
66// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67
69{
70 return method_().parallelAware();
71}
72
73
75(
76 const polyMesh& mesh,
77 const pointField& cc,
78 const scalarField& cWeights
79) const
80{
81 const polyBoundaryMesh& pbm = mesh.boundaryMesh();
82 const labelHashSet patchIDs(pbm.patchSet(patches_));
83
84 label nFaces = 0;
85 for (const label patchi : patchIDs)
86 {
87 nFaces += pbm[patchi].size();
88 }
89
90 // Extract a submesh.
91 labelHashSet patchCells(2*nFaces);
92 for (const label patchi : patchIDs)
93 {
94 patchCells.insert(pbm[patchi].faceCells());
95 }
96
97 // Subset the layer of cells next to the patch
98 fvMeshSubset subsetter
99 (
100 dynamic_cast<const fvMesh&>(mesh),
101 patchCells
102 );
103 const fvMesh& subMesh = subsetter.subMesh();
104 pointField subCc(cc, subsetter.cellMap());
105 scalarField subWeights(cWeights, subsetter.cellMap());
106
107 // Decompose the layer of cells
108 labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
109
110
111 // Transfer to final decomposition
112 labelList finalDecomp(cc.size(), -1);
113 forAll(subDecomp, i)
114 {
115 finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
116 }
117
118 // Field on cells and faces.
121
122 // Start of changes
123 labelList patchFaces(nFaces);
125 nFaces = 0;
126 for (const label patchi : patchIDs)
127 {
128 const polyPatch& pp = pbm[patchi];
129 const labelUList& fc = pp.faceCells();
130 forAll(fc, i)
131 {
132 patchFaces[nFaces] = pp.start()+i;
133 patchData[nFaces] = topoDistanceData<label>(0, finalDecomp[fc[i]]);
134 nFaces++;
135 }
136 }
137
138 // Propagate information inwards
140 (
141 mesh,
142 patchFaces,
143 patchData,
144 faceData,
145 cellData,
147 );
148
149 // And extract
150 bool haveWarned = false;
151 forAll(finalDecomp, celli)
152 {
153 if (!cellData[celli].valid(deltaCalc.data()))
154 {
155 if (!haveWarned)
156 {
158 << "Did not visit some cells, e.g. cell " << celli
159 << " at " << mesh.cellCentres()[celli] << nl
160 << "Assigning these cells to domain 0." << endl;
161 haveWarned = true;
162 }
163 finalDecomp[celli] = 0;
164 }
165 else
166 {
167 finalDecomp[celli] = cellData[celli].data();
168 }
169 }
170
171 return finalDecomp;
172}
173
174
175// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:81
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:348
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:237
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Abstract base class for domain decomposition.
selectionType
Selection type when handling the coefficients dictionary.
label nDomains() const noexcept
Number of domains.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:780
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
Definition: fvMeshSubset.H:80
const labelList & cellMap() const
Return cell map.
Definition: fvMeshSubsetI.H:91
const fvMesh & subMesh() const
Return reference to subset mesh.
Definition: fvMeshSubsetI.H:48
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1310
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:364
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:371
const vectorField & cellCentres() const
label nCells() const noexcept
Number of mesh cells.
label nFaces() const noexcept
Number of mesh faces.
Walk out decomposition of patch cells mesh - selectable as structured.
virtual bool parallelAware() const
Is method parallel aware.
For use with FaceCellWave. Determines topological distance to starting faces. Templated on passive tr...
bool decompose() const noexcept
Query the decompose flag (normally off)
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
Foam::word regionName(Foam::polyMesh::defaultRegion)
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333