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-2020 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(structuredDecomp, 0);
40 
42  (
43  decompositionMethod,
44  structuredDecomp,
45  dictionary
46  );
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 Foam::structuredDecomp::structuredDecomp(const dictionary& decompDict)
53 :
54  decompositionMethod(decompDict),
55  methodDict_(findCoeffsDict(typeName + "Coeffs", selectionType::MANDATORY)),
56  patches_(methodDict_.get<wordRes>("patches"))
57 {
58  methodDict_.set("numberOfSubdomains", nDomains());
59  method_ = decompositionMethod::New(methodDict_);
60 }
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
66 {
67  return method_().parallelAware();
68 }
69 
70 
72 (
73  const polyMesh& mesh,
74  const pointField& cc,
75  const scalarField& cWeights
76 ) const
77 {
78  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
79  const labelHashSet patchIDs(pbm.patchSet(patches_));
80 
81  label nFaces = 0;
82  for (const label patchi : patchIDs)
83  {
84  nFaces += pbm[patchi].size();
85  }
86 
87  // Extract a submesh.
88  labelHashSet patchCells(2*nFaces);
89  for (const label patchi : patchIDs)
90  {
91  patchCells.insert(pbm[patchi].faceCells());
92  }
93 
94  // Subset the layer of cells next to the patch
95  fvMeshSubset subsetter
96  (
97  dynamic_cast<const fvMesh&>(mesh),
98  patchCells
99  );
100  const fvMesh& subMesh = subsetter.subMesh();
101  pointField subCc(cc, subsetter.cellMap());
102  scalarField subWeights(cWeights, subsetter.cellMap());
103 
104  // Decompose the layer of cells
105  labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
106 
107 
108  // Transfer to final decomposition
109  labelList finalDecomp(cc.size(), -1);
110  forAll(subDecomp, i)
111  {
112  finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
113  }
114 
115  // Field on cells and faces.
118 
119  // Start of changes
120  labelList patchFaces(nFaces);
121  List<topoDistanceData<label>> patchData(nFaces);
122  nFaces = 0;
123  for (const label patchi : patchIDs)
124  {
125  const polyPatch& pp = pbm[patchi];
126  const labelUList& fc = pp.faceCells();
127  forAll(fc, i)
128  {
129  patchFaces[nFaces] = pp.start()+i;
130  patchData[nFaces] = topoDistanceData<label>(0, finalDecomp[fc[i]]);
131  nFaces++;
132  }
133  }
134 
135  // Propagate information inwards
137  (
138  mesh,
139  patchFaces,
140  patchData,
141  faceData,
142  cellData,
144  );
145 
146  // And extract
147  bool haveWarned = false;
148  forAll(finalDecomp, celli)
149  {
150  if (!cellData[celli].valid(deltaCalc.data()))
151  {
152  if (!haveWarned)
153  {
155  << "Did not visit some cells, e.g. cell " << celli
156  << " at " << mesh.cellCentres()[celli] << nl
157  << "Assigning these cells to domain 0." << endl;
158  haveWarned = true;
159  }
160  finalDecomp[celli] = 0;
161  }
162  else
163  {
164  finalDecomp[celli] = cellData[celli].data();
165  }
166  }
167 
168  return finalDecomp;
169 }
170 
171 
172 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
topoDistanceData.H
Foam::topoDistanceData
For use with FaceCellWave. Determines topological distance to starting faces. Templated on passive tr...
Definition: topoDistanceData.H:53
Foam::fvMeshSubset::cellMap
const labelList & cellMap() const
Return cell map.
Definition: fvMeshSubsetI.H:91
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
fvMeshSubset.H
Foam::primitiveMesh::nFaces
label nFaces() const
Number of mesh faces.
Definition: primitiveMeshI.H:90
Foam::globalMeshData::nTotalCells
label nTotalCells() const
Return total number of cells in decomposed mesh.
Definition: globalMeshData.H:371
Foam::FaceCellWave::data
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:348
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::dictionary::set
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:847
Foam::HashSet< label, Hash< label > >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::decompositionMethod::selectionType
selectionType
Selection type when handling the coefficients dictionary.
Definition: decompositionMethod.H:76
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Field< vector >
Foam::fvMeshSubset::subMesh
const fvMesh & subMesh() const
Return reference to subset mesh.
Definition: fvMeshSubsetI.H:48
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::structuredDecomp::parallelAware
virtual bool parallelAware() const
Is method parallel aware.
Definition: structuredDecomp.C:65
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::decompositionMethod::nDomains
label nDomains() const
Number of domains.
Definition: decompositionMethod.H:230
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::decompositionMethod
Abstract base class for domain decomposition.
Definition: decompositionMethod.H:51
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyPatch::faceCells
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:363
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:313
Foam::FaceCellWave
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:78
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::List< label >
FaceCellWave.H
Foam::UList< label >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::polyBoundaryMesh::patchSet
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.
Definition: polyBoundaryMesh.C:862
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:181
structuredDecomp.H
Foam::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1295
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::decompositionMethod::New
static autoPtr< decompositionMethod > New(const dictionary &decompDict)
Return a reference to the selected decomposition method.
Definition: decompositionMethod.C:359
Foam::structuredDecomp::decompose
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights) const
Return for every coordinate the wanted processor number.
Definition: structuredDecomp.C:72