checkFieldAvailability.H
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) 2021-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
14  Check field availability for last time.
15  Done to avoid mapping 'undefined' when a field only exists as time 0.
16 
17 Requires
18  readFields.H (for the checkData function)
19 
20 \*---------------------------------------------------------------------------*/
21 
22 // Initially all possible objects that are available at the final time
23 List<wordHashSet> availableRegionObjectNames(meshes.size());
24 List<wordHashSet> availableFaRegionObjectNames(meshes.size());
25 
26 forAll(meshes, regioni)
27 {
28  const auto& mesh = meshes[regioni];
29 
30  IOobjectList objects;
31  IOobjectList faObjects;
32 
33  if (doConvertFields && !timeDirs.empty())
34  {
35  // List of volume mesh objects for this instance
36  objects = IOobjectList(mesh, timeDirs.back().name());
37 
38  // List of area mesh objects (assuming single region)
39  faObjects = IOobjectList
40  (
41  mesh.time(),
42  timeDirs.back().name(),
43  faMesh::dbDir(mesh, word::null),
44  IOobjectOption::NO_REGISTER
45  );
46 
47  if (fieldSelector && !fieldSelector().empty())
48  {
49  objects.filterObjects(fieldSelector());
50  faObjects.filterObjects(fieldSelector());
51  }
52 
53  // Remove "*_0" restart fields
54  objects.prune_0();
55  faObjects.prune_0();
56 
57  if (!doPointValues)
58  {
59  // Prune point fields if disabled
60  objects.filterClasses
61  (
62  [](const word& clsName)
63  {
64  return fieldTypes::point.found(clsName);
65  },
66  true // prune
67  );
68  }
69  }
70 
71  // Volume fields
72  if (!objects.empty())
73  {
74  wordList objectNames(objects.sortedNames());
75 
76  // Check availability for all times...
77  checkData
78  (
79  mesh.thisDb(),
80  timeDirs,
81  objectNames
82  );
83 
84  availableRegionObjectNames[regioni] = objectNames;
85  }
86 
87  // Area fields
88  if (!faObjects.empty())
89  {
90  wordList objectNames(faObjects.sortedNames());
91 
92  // Check availability for all times... (assuming single region)
93  checkData
94  (
95  mesh.time(),
96  timeDirs,
97  objectNames,
98  faMesh::dbDir(mesh, word::null)
99  );
100 
101  availableFaRegionObjectNames[regioni] = objectNames;
102  }
103 }
104 
105 
106 // ************************************************************************* //
forAll(meshes, regioni)
List< wordHashSet > availableFaRegionObjectNames(meshes.size())
dynamicFvMesh & mesh
List< wordHashSet > availableRegionObjectNames(meshes.size())
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
List< word > wordList
List of word.
Definition: fileName.H:59
vector point
Point is a vector.
Definition: point.H:37
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)