printMeshStats.C
Go to the documentation of this file.
1 #include "printMeshStats.H"
2 #include "polyMesh.H"
3 #include "globalMeshData.H"
4 
5 #include "hexMatcher.H"
6 #include "wedgeMatcher.H"
7 #include "prismMatcher.H"
8 #include "pyrMatcher.H"
9 #include "tetWedgeMatcher.H"
10 #include "tetMatcher.H"
11 #include "IOmanip.H"
12 
13 
14 void Foam::printMeshStats(const polyMesh& mesh, const bool allTopology)
15 {
16  Info<< "Mesh stats" << nl
17  << " points: "
18  << returnReduce(mesh.points().size(), sumOp<label>()) << nl;
19 
20  label nInternalPoints = returnReduce
21  (
22  mesh.nInternalPoints(),
23  sumOp<label>()
24  );
25 
26  if (nInternalPoints != -Pstream::nProcs())
27  {
28  Info<< " internal points: " << nInternalPoints << nl;
29 
30  if (returnReduce(mesh.nInternalPoints(), minOp<label>()) == -1)
31  {
33  << "Some processors have their points sorted into internal"
34  << " and external and some do not." << endl
35  << "This can cause problems later on." << endl;
36  }
37  }
38 
39  if (allTopology && nInternalPoints != -Pstream::nProcs())
40  {
41  label nEdges = returnReduce(mesh.nEdges(), sumOp<label>());
42  label nInternalEdges = returnReduce
43  (
44  mesh.nInternalEdges(),
45  sumOp<label>()
46  );
47  label nInternal1Edges = returnReduce
48  (
49  mesh.nInternal1Edges(),
50  sumOp<label>()
51  );
52  label nInternal0Edges = returnReduce
53  (
54  mesh.nInternal0Edges(),
55  sumOp<label>()
56  );
57 
58  Info<< " edges: " << nEdges << nl
59  << " internal edges: " << nInternalEdges << nl
60  << " internal edges using one boundary point: "
61  << nInternal1Edges-nInternal0Edges << nl
62  << " internal edges using two boundary points: "
63  << nInternalEdges-nInternal1Edges << nl;
64  }
65 
66  label nFaces = returnReduce(mesh.faces().size(), sumOp<label>());
67  label nIntFaces = returnReduce(mesh.faceNeighbour().size(), sumOp<label>());
68  label nCells = returnReduce(mesh.cells().size(), sumOp<label>());
69 
70  Info<< " faces: " << nFaces << nl
71  << " internal faces: " << nIntFaces << nl
72  << " cells: " << nCells << nl
73  << " faces per cell: "
74  << scalar(nFaces + nIntFaces)/max(1, nCells) << nl
75  << " boundary patches: " << mesh.boundaryMesh().size() << nl
76  << " point zones: " << mesh.pointZones().size() << nl
77  << " face zones: " << mesh.faceZones().size() << nl
78  << " cell zones: " << mesh.cellZones().size() << nl
79  << endl;
80 
81  // Construct shape recognizers
82  hexMatcher hex;
83  prismMatcher prism;
84  wedgeMatcher wedge;
85  pyrMatcher pyr;
86  tetWedgeMatcher tetWedge;
87  tetMatcher tet;
88 
89  // Counters for different cell types
90  label nHex = 0;
91  label nWedge = 0;
92  label nPrism = 0;
93  label nPyr = 0;
94  label nTet = 0;
95  label nTetWedge = 0;
96  label nUnknown = 0;
97 
98  Map<label> polyhedralFaces;
99 
100  for (label celli = 0; celli < mesh.nCells(); celli++)
101  {
102  if (hex.isA(mesh, celli))
103  {
104  nHex++;
105  }
106  else if (tet.isA(mesh, celli))
107  {
108  nTet++;
109  }
110  else if (pyr.isA(mesh, celli))
111  {
112  nPyr++;
113  }
114  else if (prism.isA(mesh, celli))
115  {
116  nPrism++;
117  }
118  else if (wedge.isA(mesh, celli))
119  {
120  nWedge++;
121  }
122  else if (tetWedge.isA(mesh, celli))
123  {
124  nTetWedge++;
125  }
126  else
127  {
128  nUnknown++;
129  polyhedralFaces(mesh.cells()[celli].size())++;
130  }
131  }
132 
133  reduce(nHex,sumOp<label>());
134  reduce(nPrism,sumOp<label>());
135  reduce(nWedge,sumOp<label>());
136  reduce(nPyr,sumOp<label>());
137  reduce(nTetWedge,sumOp<label>());
138  reduce(nTet,sumOp<label>());
139  reduce(nUnknown,sumOp<label>());
140 
141  Info<< "Overall number of cells of each type:" << nl
142  << " hexahedra: " << nHex << nl
143  << " prisms: " << nPrism << nl
144  << " wedges: " << nWedge << nl
145  << " pyramids: " << nPyr << nl
146  << " tet wedges: " << nTetWedge << nl
147  << " tetrahedra: " << nTet << nl
148  << " polyhedra: " << nUnknown
149  << endl;
150 
151  if (nUnknown > 0)
152  {
153  Pstream::mapCombineGather(polyhedralFaces, plusEqOp<label>());
154 
155  Info<< " Breakdown of polyhedra by number of faces:" << nl
156  << " faces" << " number of cells" << endl;
157 
158  const labelList sortedKeys = polyhedralFaces.sortedToc();
159 
160  forAll(sortedKeys, keyI)
161  {
162  const label nFaces = sortedKeys[keyI];
163 
164  Info<< setf(std::ios::right) << setw(13)
165  << nFaces << " " << polyhedralFaces[nFaces] << nl;
166  }
167  }
168 
169  Info<< endl;
170 }
#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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
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
Istream and Ostream manipulators taking arguments.
static const char nl
Definition: Ostream.H:262
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
void printMeshStats(const polyMesh &mesh, const bool allTopology)
#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