Loading...
Searching...
No Matches
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-2023 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"
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 * * * * * * * * * * * * * //
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;
106 if (cWeights.size() == cc.size())
107 {
108 subWeights = scalarField(cWeights, subsetter.cellMap());
109 }
110
111 // Decompose the layer of cells
112 labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
113
114
115 // Transfer to final decomposition
116 labelList finalDecomp(cc.size(), -1);
117 forAll(subDecomp, i)
118 {
119 finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
120 }
121
122 // Field on cells and faces.
125
126 // Start of changes
127 labelList patchFaces(nFaces);
128 List<topoDistanceData<label>> patchData(nFaces);
129 nFaces = 0;
130 for (const label patchi : patchIDs)
131 {
132 const polyPatch& pp = pbm[patchi];
133 const labelUList& fc = pp.faceCells();
134 forAll(fc, i)
135 {
136 patchFaces[nFaces] = pp.start()+i;
137 patchData[nFaces] = topoDistanceData<label>(0, finalDecomp[fc[i]]);
138 nFaces++;
139 }
140 }
141
142 // Propagate information inwards
144 (
145 mesh,
146 patchFaces,
147 patchData,
148 faceData,
149 cellData,
151 );
152
153 // And extract
154 bool haveWarned = false;
155 forAll(finalDecomp, celli)
156 {
157 if (!cellData[celli].valid(deltaCalc.data()))
158 {
159 if (!haveWarned)
160 {
162 << "Did not visit some cells, e.g. cell " << celli
163 << " at " << mesh.cellCentres()[celli] << nl
164 << "Assigning these cells to domain 0." << endl;
165 haveWarned = true;
166 }
167 finalDecomp[celli] = 0;
168 }
169 else
170 {
171 finalDecomp[celli] = cellData[celli].data();
172 }
173 }
174
175 return finalDecomp;
176}
177
178
179// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
labelList patchIDs
const polyBoundaryMesh & pbm
Wave propagation of information through grid. Every iteration information goes through one layer of c...
const TrackingData & data() const noexcept
Additional data to be passed into container.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition HashSet.H:229
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition UListI.H:274
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Abstract base class for domain decomposition.
selectionType
Selection type when handling the coefficients dictionary.
@ MANDATORY
Fatal if dictionary could not be found.
decompositionMethod(const label numDomains)
Construct with specified number of domains, no coefficients or constraints.
static autoPtr< decompositionMethod > New(const dictionary &decompDict, const word &regionName="")
Return a reference to the selected decomposition method, optionally region-specific.
static FOAM_NO_DANGLING_REFERENCE const dictionary & findCoeffsDict(const dictionary &dict, const word &coeffsName, int select=selectionType::DEFAULT)
Locate coeffsName dictionary or the fallback "coeffs" dictionary within an enclosing 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:133
Smooth ATC in cells next to a set of patches supplied by type.
Definition faceCells.H:55
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
const labelList & cellMap() const
Return cell map.
const fvMesh & subMesh() const
Return reference to subset mesh.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
label nTotalCells() const noexcept
Total global number of mesh cells.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const globalMeshData & globalData() const
Return parallel info (demand-driven).
Definition polyMesh.C:1296
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
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.
structuredDecomp(const structuredDecomp &)=delete
No copy construct.
virtual bool parallelAware() const
Is method parallel aware.
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights=scalarField::null()) const
Return for every coordinate the wanted processor number.
For use with FaceCellWave. Determines topological distance to starting faces. Templated on passive tr...
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299