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 -------------------------------------------------------------------------------
11 License
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 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(structuredDecomp, 0);
41  (
42  decompositionMethod,
43  structuredDecomp,
44  dictionary
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 {
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.
123  List<topoDistanceData<label>> cellData(mesh.nCells());
124  List<topoDistanceData<label>> faceData(mesh.nFaces());
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
143  FaceCellWave<topoDistanceData<label>> deltaCalc
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 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
const labelList patchIDs(pbm.indices(polyPatchNames, true))
const polyBoundaryMesh & pbm
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights=scalarField::null()) const
Return for every coordinate the wanted processor number.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
labelHashSet patchSet(const UList< wordRe > &select, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
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:529
label nFaces() const noexcept
Number of mesh faces.
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
Definition: UList.H:76
structuredDecomp(const structuredDecomp &)=delete
No copy construct.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:609
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
const globalMeshData & globalData() const
Return parallel info (demand-driven)
Definition: polyMesh.C:1296
Abstract base class for domain decomposition.
const vectorField & cellCentres() const
label nDomains() const noexcept
Number of domains.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh...
virtual bool parallelAware() const
Is method parallel aware.
defineTypeNameAndDebug(combustionModel, 0)
label nTotalCells() const noexcept
Total global number of mesh cells.
static autoPtr< decompositionMethod > New(const dictionary &decompDict, const word &regionName="")
Return a reference to the selected decomposition method, optionally region-specific.
#define WarningInFunction
Report a warning using Foam::Warning.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
label nCells() const noexcept
Number of mesh cells.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:765
List< label > labelList
A List of labels.
Definition: List.H:61
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)