checkTools.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) 2015-2016 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 "checkTools.H"
27 #include "polyMesh.H"
28 #include "globalMeshData.H"
29 #include "hexMatcher.H"
30 #include "wedgeMatcher.H"
31 #include "prismMatcher.H"
32 #include "pyrMatcher.H"
33 #include "tetWedgeMatcher.H"
34 #include "tetMatcher.H"
35 #include "IOmanip.H"
36 #include "faceSet.H"
37 #include "cellSet.H"
38 #include "Time.H"
39 #include "surfaceWriter.H"
40 #include "syncTools.H"
41 #include "globalIndex.H"
42 #include "PatchTools.H"
43 
44 
45 void Foam::printMeshStats(const polyMesh& mesh, const bool allTopology)
46 {
47  Info<< "Mesh stats" << nl
48  << " points: "
49  << returnReduce(mesh.points().size(), sumOp<label>()) << nl;
50 
51  label nInternalPoints = returnReduce
52  (
53  mesh.nInternalPoints(),
54  sumOp<label>()
55  );
56 
57  if (nInternalPoints != -Pstream::nProcs())
58  {
59  Info<< " internal points: " << nInternalPoints << nl;
60 
61  if (returnReduce(mesh.nInternalPoints(), minOp<label>()) == -1)
62  {
64  << "Some processors have their points sorted into internal"
65  << " and external and some do not." << endl
66  << "This can cause problems later on." << endl;
67  }
68  }
69 
70  if (allTopology && nInternalPoints != -Pstream::nProcs())
71  {
72  label nEdges = returnReduce(mesh.nEdges(), sumOp<label>());
73  label nInternalEdges = returnReduce
74  (
75  mesh.nInternalEdges(),
76  sumOp<label>()
77  );
78  label nInternal1Edges = returnReduce
79  (
80  mesh.nInternal1Edges(),
81  sumOp<label>()
82  );
83  label nInternal0Edges = returnReduce
84  (
85  mesh.nInternal0Edges(),
86  sumOp<label>()
87  );
88 
89  Info<< " edges: " << nEdges << nl
90  << " internal edges: " << nInternalEdges << nl
91  << " internal edges using one boundary point: "
92  << nInternal1Edges-nInternal0Edges << nl
93  << " internal edges using two boundary points: "
94  << nInternalEdges-nInternal1Edges << nl;
95  }
96 
97  label nFaces = returnReduce(mesh.faces().size(), sumOp<label>());
98  label nIntFaces = returnReduce(mesh.faceNeighbour().size(), sumOp<label>());
99  label nCells = returnReduce(mesh.cells().size(), sumOp<label>());
100 
101  Info<< " faces: " << nFaces << nl
102  << " internal faces: " << nIntFaces << nl
103  << " cells: " << nCells << nl
104  << " faces per cell: "
105  << scalar(nFaces + nIntFaces)/max(1, nCells) << nl
106  << " boundary patches: " << mesh.boundaryMesh().size() << nl
107  << " point zones: " << mesh.pointZones().size() << nl
108  << " face zones: " << mesh.faceZones().size() << nl
109  << " cell zones: " << mesh.cellZones().size() << nl
110  << endl;
111 
112  // Construct shape recognizers
113  hexMatcher hex;
114  prismMatcher prism;
115  wedgeMatcher wedge;
116  pyrMatcher pyr;
117  tetWedgeMatcher tetWedge;
118  tetMatcher tet;
119 
120  // Counters for different cell types
121  label nHex = 0;
122  label nWedge = 0;
123  label nPrism = 0;
124  label nPyr = 0;
125  label nTet = 0;
126  label nTetWedge = 0;
127  label nUnknown = 0;
128 
129  Map<label> polyhedralFaces;
130 
131  for (label celli = 0; celli < mesh.nCells(); celli++)
132  {
133  if (hex.isA(mesh, celli))
134  {
135  nHex++;
136  }
137  else if (tet.isA(mesh, celli))
138  {
139  nTet++;
140  }
141  else if (pyr.isA(mesh, celli))
142  {
143  nPyr++;
144  }
145  else if (prism.isA(mesh, celli))
146  {
147  nPrism++;
148  }
149  else if (wedge.isA(mesh, celli))
150  {
151  nWedge++;
152  }
153  else if (tetWedge.isA(mesh, celli))
154  {
155  nTetWedge++;
156  }
157  else
158  {
159  nUnknown++;
160  polyhedralFaces(mesh.cells()[celli].size())++;
161  }
162  }
163 
164  reduce(nHex,sumOp<label>());
165  reduce(nPrism,sumOp<label>());
166  reduce(nWedge,sumOp<label>());
167  reduce(nPyr,sumOp<label>());
168  reduce(nTetWedge,sumOp<label>());
169  reduce(nTet,sumOp<label>());
170  reduce(nUnknown,sumOp<label>());
171 
172  Info<< "Overall number of cells of each type:" << nl
173  << " hexahedra: " << nHex << nl
174  << " prisms: " << nPrism << nl
175  << " wedges: " << nWedge << nl
176  << " pyramids: " << nPyr << nl
177  << " tet wedges: " << nTetWedge << nl
178  << " tetrahedra: " << nTet << nl
179  << " polyhedra: " << nUnknown
180  << endl;
181 
182  if (nUnknown > 0)
183  {
184  Pstream::mapCombineGather(polyhedralFaces, plusEqOp<label>());
185 
186  Info<< " Breakdown of polyhedra by number of faces:" << nl
187  << " faces" << " number of cells" << endl;
188 
189  const labelList sortedKeys = polyhedralFaces.sortedToc();
190 
191  forAll(sortedKeys, keyI)
192  {
193  const label nFaces = sortedKeys[keyI];
194 
195  Info<< setf(std::ios::right) << setw(13)
196  << nFaces << " " << polyhedralFaces[nFaces] << nl;
197  }
198  }
199 
200  Info<< endl;
201 }
202 
203 
205 (
206  const polyMesh& mesh,
207  const surfaceWriter& writer,
208  const word& name,
209  const indirectPrimitivePatch setPatch,
210  const fileName& outputDir
211 )
212 {
213  if (Pstream::parRun())
214  {
215  labelList pointToGlobal;
216  labelList uniqueMeshPointLabels;
217  autoPtr<globalIndex> globalPoints;
218  autoPtr<globalIndex> globalFaces;
219  faceList mergedFaces;
220  pointField mergedPoints;
222  (
223  mesh,
224  setPatch.localFaces(),
225  setPatch.meshPoints(),
226  setPatch.meshPointMap(),
227 
228  pointToGlobal,
229  uniqueMeshPointLabels,
230  globalPoints,
231  globalFaces,
232 
233  mergedFaces,
234  mergedPoints
235  );
236 
237  // Write
238  if (Pstream::master())
239  {
240  writer.write(outputDir, name, mergedPoints, mergedFaces);
241  }
242  }
243  else
244  {
245  writer.write
246  (
247  outputDir,
248  name,
249  setPatch.localPoints(),
250  setPatch.localFaces()
251  );
252  }
253 }
254 
255 
257 (
258  const surfaceWriter& writer,
259  const faceSet& set
260 )
261 {
262  const polyMesh& mesh = refCast<const polyMesh>(set.db());
263 
264  const indirectPrimitivePatch setPatch
265  (
266  IndirectList<face>(mesh.faces(), set.sortedToc()),
267  mesh.points()
268  );
269 
270  const fileName outputDir
271  (
272  set.time().path()
273  / (Pstream::parRun() ? ".." : "")
274  / "postProcessing"
275  / mesh.pointsInstance()
276  / set.name()
277  );
278 
279  mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
280 }
281 
282 
284 (
285  const surfaceWriter& writer,
286  const cellSet& set
287 )
288 {
289  const polyMesh& mesh = refCast<const polyMesh>(set.db());
290  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
291 
292 
293  // Determine faces on outside of cellSet
294  PackedBoolList isInSet(mesh.nCells());
295  forAllConstIter(cellSet, set, iter)
296  {
297  isInSet[iter.key()] = true;
298  }
299 
300 
301  boolList bndInSet(mesh.nFaces()-mesh.nInternalFaces());
302  forAll(pbm, patchi)
303  {
304  const polyPatch& pp = pbm[patchi];
305  const labelList& fc = pp.faceCells();
306  forAll(fc, i)
307  {
308  bndInSet[pp.start()+i-mesh.nInternalFaces()] = isInSet[fc[i]];
309  }
310  }
311  syncTools::swapBoundaryFaceList(mesh, bndInSet);
312 
313 
314  DynamicList<label> outsideFaces(3*set.size());
315  for (label facei = 0; facei < mesh.nInternalFaces(); facei++)
316  {
317  bool ownVal = isInSet[mesh.faceOwner()[facei]];
318  bool neiVal = isInSet[mesh.faceNeighbour()[facei]];
319 
320  if (ownVal != neiVal)
321  {
322  outsideFaces.append(facei);
323  }
324  }
325 
326 
327  forAll(pbm, patchi)
328  {
329  const polyPatch& pp = pbm[patchi];
330  const labelList& fc = pp.faceCells();
331  if (pp.coupled())
332  {
333  forAll(fc, i)
334  {
335  label facei = pp.start()+i;
336 
337  bool neiVal = bndInSet[facei-mesh.nInternalFaces()];
338  if (isInSet[fc[i]] && !neiVal)
339  {
340  outsideFaces.append(facei);
341  }
342  }
343  }
344  else
345  {
346  forAll(fc, i)
347  {
348  if (isInSet[fc[i]])
349  {
350  outsideFaces.append(pp.start()+i);
351  }
352  }
353  }
354  }
355 
356 
357  const indirectPrimitivePatch setPatch
358  (
359  IndirectList<face>(mesh.faces(), outsideFaces),
360  mesh.points()
361  );
362 
363  const fileName outputDir
364  (
365  set.time().path()
366  / (Pstream::parRun() ? ".." : "")
367  / "postProcessing"
368  / mesh.pointsInstance()
369  / set.name()
370  );
371 
372 
373  mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
374 }
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< Face, FaceList, PointField, PointType > &p, Field< PointType > &mergedPoints, List< Face > &mergedFaces, labelList &pointMergeMap)
Gather points and faces onto master and merge into single patch.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
IOstream & hex(IOstream &io)
Definition: IOstream.H:564
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
PrimitivePatch< face, IndirectList, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
Definition: IOmanip.H:164
List< label > labelList
A List of labels.
Definition: labelList.H:56
void mergeAndWrite(const polyMesh &mesh, const surfaceWriter &writer, const word &name, const indirectPrimitivePatch setPatch, const fileName &outputDir)
Generate merged surface on master and write. Needs input patch.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
Istream and Ostream manipulators taking arguments.
static const char nl
Definition: Ostream.H:262
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
void printMeshStats(const polyMesh &mesh, const bool allTopology)
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Omanip< int > setw(const int i)
Definition: IOmanip.H:199