writeMeshChecks.H
Go to the documentation of this file.
2 {
3  none,
5  JSON
6 };
7 const Enum<writeChecksFormatType> writeChecksFormatTypeNames
8 {
9  { writeChecksFormatType::none, "none" },
10  { writeChecksFormatType::dictionary, "dictionary" },
11  { writeChecksFormatType::JSON, "json" },
12 };
13 
15 
16 auto writeMeshChecks = [&](const fvMesh& mesh, const writeChecksFormatType fmt)
17 {
18  // Early exit if 'none' option is set
19  if (fmt == writeChecksFormatType::none)
20  {
21  return;
22  }
23 
24  auto& dataRef = mesh.dataRef();
25 
26  // Add base count metrics
27  dataRef.setMeshMetric
28  (
29  "geometry", "cellCount", mesh.globalData().nTotalCells()
30  );
31  dataRef.setMeshMetric
32  (
33  "geometry", "faceCount", mesh.globalData().nTotalFaces()
34  );
35  dataRef.setMeshMetric
36  (
37  "geometry", "pointCount", mesh.globalData().nTotalPoints()
38  );
39  dataRef.setMeshMetric
40  (
41  "geometry", "patchCount", mesh.boundaryMesh().nNonProcessor()
42  );
43 
44  // Summarise errors
45  {
46  DynamicList<Tuple2<word, label>> errorCounts;
47  DynamicList<Tuple2<word, label>> warningCounts;
48  forAllConstIters(mesh.data().meshDict(), iter)
49  {
50  if (iter().isDict())
51  {
52  const dictionary& metricDict = iter().dict();
53 
54  auto* warnPtr = metricDict.findEntry("warningCount");
55  if (warnPtr)
56  {
57  if (label nWarn(readLabel(warnPtr->stream())); nWarn > 0)
58  {
59  warningCounts.emplace_back(iter().keyword(), nWarn);
60  }
61  }
62 
63  auto* errPtr = metricDict.findEntry("errorCount");
64  if (errPtr)
65  {
66  if (label nErr(readLabel(errPtr->stream())); nErr > 0)
67  {
68  errorCounts.emplace_back(iter().keyword(), nErr);
69  }
70  }
71  }
72  }
73 
74  if (warningCounts.size())
75  {
76  dataRef.setMeshMetric("summary", "warningCounts", warningCounts);
77  }
78 
79  if (errorCounts.size())
80  {
81  dataRef.setMeshMetric("summary", "state", "fail");
82  dataRef.setMeshMetric("summary", "errorCounts", errorCounts);
83  }
84  else
85  {
86  dataRef.setMeshMetric("summary", "state", "pass");
87  }
88  }
89 
90  if (UPstream::master())
91  {
92  fileName path(mesh.time().globalPath()/"checkMesh");
93  if (mesh.name() != polyMesh::defaultRegion)
94  {
95  path += "_" + mesh.name();
96  }
97 
98  OFstream os(path.ext(writeChecksFormatTypeNames[fmt]));
99 
100  Info<< "Writing mesh data to " << os.name() << nl << endl;
101 
102  switch (fmt)
103  {
105  {
106  IOdictionary data
107  (
108  IOobject
109  (
110  os.name(),
111  mesh,
112  IOobject::NO_READ
113  )
114  );
115 
116  data.writeHeader(os);
117 
118  mesh.data().meshDict().write(os, false);
119 
120  IOobject::writeEndDivider(os);
121 
122  break;
123  }
125  {
126  JSONformatter json(os);
127  json.writeDict(mesh.data().meshDict());
128 
129  break;
130  }
131  default:
132  {
133  // Do nothing
134  }
135  }
136  }
137 };
const Enum< writeChecksFormatType > writeChecksFormatTypeNames
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:518
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:63
dynamicFvMesh & mesh
writeChecksFormatType writeChecksFormat(writeChecksFormatType::none)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
messageStream Info
Information stream (stdout output on master, null elsewhere)
writeChecksFormatType
auto writeMeshChecks
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28