Loading...
Searching...
No Matches
readFields.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2018-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "readFields.H"
29
30// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
31
32Foam::label Foam::checkData
33(
34 const objectRegistry& obr,
35 const instantList& timeDirs,
36 wordList& objectNames,
37 const fileName& local
38)
39{
40 // Assume prune_0() was used prior to calling this
41
42 wordHashSet goodFields;
43
44 IOobject io
45 (
46 "any-name", // placeholder
47 "constant", // placeholder
48 local,
49 obr,
50 IOobjectOption::NO_READ,
51 IOobjectOption::NO_WRITE,
52 IOobjectOption::NO_REGISTER
53 );
54
55 for (const word& fieldName : objectNames)
56 {
57 // In case prune_0() not previously used...
58 if (fieldName.ends_with("_0")) continue;
59
60 bool good = false;
61
62 for (const instant& inst : timeDirs)
63 {
64 io.resetHeader(fieldName);
65 io.instance() = inst.name();
66
67 good = io.typeHeaderOk<regIOobject>(false, false);
68
69 if (!good)
70 {
71 break;
72 }
73 }
74
75 if (returnReduceAnd(good))
76 {
77 goodFields.insert(fieldName);
78 }
79 }
80
81 objectNames = goodFields.sortedToc();
82
83 return objectNames.size();
84}
85
86
87// ************************************************************************* //
Helper routines for reading a field or fields, for foamToEnsight.
bool local
Definition EEqn.H:20
const auto & io
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
label checkData(const objectRegistry &obr, const instantList &timeDirs, wordList &objectNames, const fileName &local=fileName::null)
Check if fields are good to use (available at all times).
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.