Run the consistency check.
164 """!
165 @brief Run the consistency check.
166 @param[in] argv Optional argument override for tests.
167 @return Process exit code.
168 """
169 numpy = require_numpy()
170 args =
list(sys.argv[1:]
if argv
is None else argv)
171 if len(args) != 2:
172 print(USAGE, file=sys.stderr)
173 return 2
174 run_dir, window = args
175
176
177
178 viz_dir = sole_recipe_dir(run_dir, os.path.join("output", "visualization"))
179 stats_dir = sole_recipe_dir(run_dir, os.path.join("output", "analysis", "statistics"))
180
181 try:
182 vts_path = newest_window_vts(viz_dir, window)
183 nodes, arrays = read_vts_point_arrays(vts_path)
184
185 periodic = read_checkpoint_periodicity(run_dir)
186 if periodic and any(periodic):
187 if check_periodic_wrap(arrays, nodes, periodic) != 0:
188 return 1
189
190 tke_name = next((n for n in arrays if n.endswith("_tke")), None)
191 if tke_name is None:
192 print(f"[SKIP] {os.path.basename(vts_path)} carries no turbulent kinetic energy field.")
193 return 0
194 field = arrays[tke_name].reshape(nodes[2], nodes[1], nodes[0])
195
196 csv_path = next(
197 (os.path.join(stats_dir, n) for n in sorted(os.listdir(stats_dir))
198 if n.endswith(f"_statistics_{window}.csv")), None
199 )
200 if csv_path is None:
201 raise ValueError(f"no convergence-history CSV for window '{window}' in {stats_dir}.")
202 rows =
list(csv.DictReader(open(csv_path,
"r", encoding=
"utf-8")))
203 if not rows or "mean_tke" not in rows[0]:
204 print(f"[SKIP] {os.path.basename(csv_path)} records no mean_tke column.")
205 return 0
206 reference = float(rows[-1]["mean_tke"])
207 if reference <= 0.0:
208 print(f"[SKIP] window '{window}' has no accumulated energy to compare.")
209 return 0
210
211
212
213 interior = field[1:-1, 1:-1, 1:-1].mean()
214 deviation = abs(interior / reference - 1.0)
215 tolerance = 0.05
216 print(f"[INFO] {window}: nodal interior mean {interior:.6e} vs CSV mean_tke "
217 f"{reference:.6e} ({100*deviation:+.2f}%)")
218 if deviation > tolerance:
219 print(
220 f"[FAIL] derived statistics VTK and convergence CSV disagree by "
221 f"{100*deviation:.2f}%, above the {100*tolerance:.0f}% interpolation "
222 f"allowance. A layout boundary left unwritten by an interior-only "
223 f"producer is the usual cause; see SynchronizePeriodicCellFields().",
224 file=sys.stderr,
225 )
226 return 1
227
228 if periodic and all(periodic):
229
230
231
232
233 whole = field.mean()
234 whole_deviation = abs(whole / reference - 1.0)
235 print(f"[INFO] {window}: whole-domain nodal mean {whole:.6e} "
236 f"({100*whole_deviation:+.2f}%)")
237 if whole_deviation > tolerance:
238 print(
239 f"[FAIL] every boundary node is defined on a fully periodic layout, "
240 f"but the whole-domain nodal mean is off by {100*whole_deviation:.2f}%. "
241 f"The layout boundary was left unwritten; see SynchronizePeriodicCellFields().",
242 file=sys.stderr,
243 )
244 return 1
245
246 print("[PASS] derived statistics VTK is consistent with the convergence CSV.")
247 return 0
248 except Exception as exc:
249 print(f"[ERROR] statistics nodal consistency check failed: {exc}", file=sys.stderr)
250 return 1
251
252
int main(int argc, char **argv)
Entry point for the postprocessor executable.
Head of a generic C-style linked list.