structuredRenumber.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 | Copyright (C) 2012-2013 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 "structuredRenumber.H"
28 #include "topoDistanceData.H"
29 #include "fvMeshSubset.H"
30 #include "FaceCellWave.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(structuredRenumber, 0);
37 
39  (
40  renumberMethod,
41  structuredRenumber,
42  dictionary
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::structuredRenumber::structuredRenumber
50 (
51  const dictionary& renumberDict
52 )
53 :
54  renumberMethod(renumberDict),
55  methodDict_(renumberDict.subDict(typeName + "Coeffs")),
56  patches_(methodDict_.lookup("patches")),
57  //nLayers_(readLabel(methodDict_.lookup("nLayers"))),
58  depthFirst_(methodDict_.lookup("depthFirst")),
59  method_(renumberMethod::New(methodDict_)),
60  reverse_(methodDict_.lookup("reverse"))
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
67 (
68  const polyMesh& mesh,
69  const pointField& points
70 ) const
71 {
72  if (points.size() != mesh.nCells())
73  {
75  (
76  "structuredDecomp::renumber(const polyMesh&, const pointField&)"
77  ) << "Number of points " << points.size()
78  << " should equal the number of cells " << mesh.nCells()
79  << exit(FatalError);
80  }
81 
82  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
83  const labelHashSet patchIDs(pbm.patchSet(patches_));
84 
85  label nFaces = 0;
86  forAllConstIter(labelHashSet, patchIDs, iter)
87  {
88  nFaces += pbm[iter.key()].size();
89  }
90 
91 
92  // Extract a submesh.
93  labelHashSet patchCells(2*nFaces);
94  forAllConstIter(labelHashSet, patchIDs, iter)
95  {
96  const labelUList& fc = pbm[iter.key()].faceCells();
97  forAll(fc, i)
98  {
99  patchCells.insert(fc[i]);
100  }
101  }
102 
103  label nTotalSeeds = returnReduce(patchCells.size(), sumOp<label>());
104 
105  label nTotalCells = mesh.globalData().nTotalCells();
106  const label nLayers = nTotalCells/nTotalSeeds;
107 
108  Info<< type() << " : seeding " << nTotalSeeds
109  << " cells on " << nLayers << " layers" << nl
110  << endl;
111 
112 
113  // Avoid subsetMesh, FaceCellWave going through proc boundaries
114  bool oldParRun = Pstream::parRun();
115  Pstream::parRun() = false;
116 
117 
118  // Work array. Used here to temporarily store the original-to-ordered
119  // index. Later on used to store the ordered-to-original.
120  labelList orderedToOld(points.size(), -1);
121 
122  // Subset the layer of cells next to the patch
123  {
124  fvMeshSubset subsetter(dynamic_cast<const fvMesh&>(mesh));
125  subsetter.setLargeCellSubset(patchCells);
126  const fvMesh& subMesh = subsetter.subMesh();
127 
128  pointField subPoints(points, subsetter.cellMap());
129 
130  // Decompose the layer of cells
131  labelList subOrder(method_().renumber(subMesh, subPoints));
132 
133  labelList subOrigToOrdered(invert(subOrder.size(), subOrder));
134 
135  // Transfer to final decomposition
136  forAll(subOrder, i)
137  {
138  orderedToOld[subsetter.cellMap()[i]] = subOrigToOrdered[i];
139  }
140  }
141 
142 
143  // Walk out.
144  labelList patchFaces(nFaces);
145  List<topoDistanceData> patchData(nFaces);
146  nFaces = 0;
147  forAllConstIter(labelHashSet, patchIDs, iter)
148  {
149  const polyPatch& pp = pbm[iter.key()];
150  const labelUList& fc = pp.faceCells();
151  forAll(fc, i)
152  {
153  patchFaces[nFaces] = pp.start()+i;
154  patchData[nFaces] = topoDistanceData
155  (
156  orderedToOld[fc[i]],// passive data: order of originating face
157  0 // distance: layer
158  );
159  nFaces++;
160  }
161  }
162 
163  // Field on cells and faces.
164  List<topoDistanceData> cellData(mesh.nCells());
165  List<topoDistanceData> faceData(mesh.nFaces());
166 
167  // Propagate information inwards
169  (
170  mesh,
171  patchFaces,
172  patchData,
173  faceData,
174  cellData,
175  nTotalCells+1
176  );
177 
178 
179  Pstream::parRun() = oldParRun;
180 
181 
182  // And extract.
183  // Note that distance is distance from face so starts at 1.
184  bool haveWarned = false;
185  forAll(orderedToOld, cellI)
186  {
187  if (!cellData[cellI].valid(deltaCalc.data()))
188  {
189  if (!haveWarned)
190  {
191  WarningIn("structuredDecomp::renumber(..)")
192  << "Did not visit some cells, e.g. cell " << cellI
193  << " at " << mesh.cellCentres()[cellI] << endl
194  << "Assigning these cells to domain 0." << endl;
195  haveWarned = true;
196  }
197  orderedToOld[cellI] = 0;
198  }
199  else
200  {
201  label layerI = cellData[cellI].distance();
202  if (depthFirst_)
203  {
204  orderedToOld[nLayers*cellData[cellI].data()+layerI] = cellI;
205  }
206  else
207  {
208  orderedToOld[cellData[cellI].data()+nLayers*layerI] = cellI;
209  }
210  }
211  }
212 
213  // Return furthest away cell first
214  if (reverse_)
215  {
216  reverse(orderedToOld);
217  }
218 
219  return orderedToOld;
220 }
221 
222 
223 // ************************************************************************* //
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:380
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
label nFaces() const
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
static autoPtr< renumberMethod > New(const dictionary &renumberDict)
Return a reference to the selected renumbering method.
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:758
For use with FaceCellWave. Determines topological distance to starting faces.
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:316
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
label nCells() const
const fvMesh & subMesh() const
Return reference to subset mesh.
const vectorField & cellCentres() const
messageStream Info
const labelList & cellMap() const
Return cell map.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
Namespace for OpenFOAM.
T * data()
Return a pointer to the first data element,.
Definition: UListI.H:152
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
static const char nl
Definition: Ostream.H:260
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:74
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Foam::polyBoundaryMesh.
#define forAll(list, i)
Definition: UList.H:421
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
label nTotalCells() const
Return total number of cells in decomposed mesh.
Macros for easy insertion into run-time selection tables.
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
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.
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:300
labelList invert(const label len, const labelUList &)
Invert one-to-one map. Unmapped elements will be -1.
Definition: ListOps.C:37
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
error FatalError
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
Abstract base class for renumbering.
void reverse(UList< T > &, const label n)
Definition: UListI.H:322
virtual labelList renumber(const pointField &) const
Return the order in which cells need to be visited, i.e.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1200
defineTypeNameAndDebug(combustionModel, 0)
Post-processing mesh subset tool. Given the original mesh and the list of selected cells...
Definition: fvMeshSubset.H:71
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116