structuredDecomp.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "structuredDecomp.H"
28 #include "FaceCellWave.H"
29 #include "topoDistanceData.H"
30 #include "fvMeshSubset.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(structuredDecomp, 0);
37 
39  (
40  decompositionMethod,
41  structuredDecomp,
42  dictionary
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 :
51  decompositionMethod(decompositionDict),
52  methodDict_(decompositionDict_.optionalSubDict(typeName + "Coeffs")),
53  patches_(methodDict_.lookup("patches"))
54 {
55  methodDict_.set("numberOfSubdomains", nDomains());
56  method_ = decompositionMethod::New(methodDict_);
57 }
58 
59 
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
61 
63 {
64  return method_().parallelAware();
65 }
66 
67 
69 (
70  const polyMesh& mesh,
71  const pointField& cc,
72  const scalarField& cWeights
73 )
74 {
75  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
76  const labelHashSet patchIDs(pbm.patchSet(patches_));
77 
78  label nFaces = 0;
79  forAllConstIter(labelHashSet, patchIDs, iter)
80  {
81  nFaces += pbm[iter.key()].size();
82  }
83 
84  // Extract a submesh.
85  labelHashSet patchCells(2*nFaces);
86  forAllConstIter(labelHashSet, patchIDs, iter)
87  {
88  const labelUList& fc = pbm[iter.key()].faceCells();
89  forAll(fc, i)
90  {
91  patchCells.insert(fc[i]);
92  }
93  }
94 
95  // Subset the layer of cells next to the patch
96  fvMeshSubset subsetter(dynamic_cast<const fvMesh&>(mesh));
97  subsetter.setLargeCellSubset(patchCells);
98  const fvMesh& subMesh = subsetter.subMesh();
99  pointField subCc(cc, subsetter.cellMap());
100  scalarField subWeights(cWeights, subsetter.cellMap());
101 
102  // Decompose the layer of cells
103  labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
104 
105 
106  // Transfer to final decomposition
107  labelList finalDecomp(cc.size(), -1);
108  forAll(subDecomp, i)
109  {
110  finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
111  }
112 
113  // Field on cells and faces.
114  List<topoDistanceData> cellData(mesh.nCells());
115  List<topoDistanceData> faceData(mesh.nFaces());
116 
117  // Start of changes
118  labelList patchFaces(nFaces);
119  List<topoDistanceData> patchData(nFaces);
120  nFaces = 0;
121  forAllConstIter(labelHashSet, patchIDs, iter)
122  {
123  const polyPatch& pp = pbm[iter.key()];
124  const labelUList& fc = pp.faceCells();
125  forAll(fc, i)
126  {
127  patchFaces[nFaces] = pp.start()+i;
128  patchData[nFaces] = topoDistanceData(finalDecomp[fc[i]], 0);
129  nFaces++;
130  }
131  }
132 
133  // Propagate information inwards
135  (
136  mesh,
137  patchFaces,
138  patchData,
139  faceData,
140  cellData,
141  mesh.globalData().nTotalCells()+1
142  );
143 
144  // And extract
145  bool haveWarned = false;
146  forAll(finalDecomp, celli)
147  {
148  if (!cellData[celli].valid(deltaCalc.data()))
149  {
150  if (!haveWarned)
151  {
153  << "Did not visit some cells, e.g. cell " << celli
154  << " at " << mesh.cellCentres()[celli] << endl
155  << "Assigning these cells to domain 0." << endl;
156  haveWarned = true;
157  }
158  finalDecomp[celli] = 0;
159  }
160  else
161  {
162  finalDecomp[celli] = cellData[celli].data();
163  }
164  }
165 
166  return finalDecomp;
167 }
168 
169 
171 (
172  const labelListList& globalPointPoints,
173  const pointField& points,
174  const scalarField& pointWeights
175 )
176 {
178 
179  return labelList::null();
180 }
181 
182 
183 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
label nFaces() const
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
label nCells() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:76
label nTotalCells() const
Return total number of cells in decomposed mesh.
static const List< label > & null()
Return a null List.
Definition: ListI.H:118
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
Macros for easy insertion into run-time selection tables.
const fvMesh & subMesh() const
Return reference to subset mesh.
stressControl lookup("compactNormalStress") >> compactNormalStress
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:334
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights)
Return for every coordinate the wanted processor number. Use the.
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1394
Abstract base class for decomposition.
const labelList & cellMap() const
Return cell map.
const vectorField & cellCentres() const
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
static autoPtr< decompositionMethod > New(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
Foam::polyBoundaryMesh.
virtual bool parallelAware() const
Is method parallel aware (i.e. does it synchronise domains across.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Post-processing mesh subset tool. Given the original mesh and the list of selected cells...
Definition: fvMeshSubset.H:73
structuredDecomp(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
#define WarningInFunction
Report a warning using Foam::Warning.
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:340
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:309
For use with FaceCellWave. Determines topological distance to starting faces.
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:1271
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:370
void setLargeCellSubset(const labelList &region, const label currentRegion, const label patchID=-1, const bool syncCouples=true)
Set the subset from all cells with region == currentRegion.
Definition: fvMeshSubset.C:881
Namespace for OpenFOAM.