fileFieldSelection.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) 2017-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 "fileFieldSelection.H"
29 #include "objectRegistry.H"
30 #include "IOobjectList.H"
31 #include "fvMesh.H"
32 #include "volMesh.H"
33 #include "fvPatchField.H"
34 #include "surfaceMesh.H"
35 #include "fvsPatchField.H"
36 #include "pointMesh.H"
37 #include "pointPatchField.H"
38 #include "GeometricField.H"
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 template<class Type>
44 void Foam::functionObjects::fileFieldSelection::addFromFile
45 (
46  const IOobjectList& objects,
47  DynamicList<fieldInfo>& set
48 ) const
49 {
50  for (const fieldInfo& fi : *this)
51  {
52  const wordList names(objects.sortedNames<Type>(fi.name()));
53 
54  if (names.size())
55  {
56  for (const word& name : names)
57  {
58  set.append(fieldInfo(wordRe(name)));
59  }
60 
61  fi.found() = true;
62  }
63  }
64 }
65 
66 
67 template<template<class> class PatchType, class MeshType>
68 void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes
69 (
70  const IOobjectList& objects,
71  DynamicList<fieldInfo>& set
72 ) const
73 {
74  #undef doLocalCode
75  #define doLocalCode(DataType) \
76  addFromFile<GeometricField<DataType, PatchType, MeshType>>(objects, set);
77 
78  doLocalCode(scalar);
83  #undef doLocalCode
84 }
85 
86 
87 void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
88 (
89  const IOobjectList& objects,
90  DynamicList<fieldInfo>& set
91 ) const
92 {
93  #undef doLocalCode
94  #define doLocalCode(DataType) \
95  addFromFile<DimensionedField<DataType, volMesh>>(objects, set);
96 
97  doLocalCode(scalar);
102  #undef doLocalCode
103 }
104 
105 
106 void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
107 (
108  const IOobjectList& objects,
109  DynamicList<fieldInfo>& set
110 ) const
111 {
112  #undef doLocalCode
113  #define doLocalCode(DataType) \
114  addFromFile<UniformDimensionedField<DataType>>(objects, set);
115 
116  doLocalCode(scalar);
121  #undef doLocalCode
122 }
123 
124 
125 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126 
127 Foam::functionObjects::fileFieldSelection::fileFieldSelection
128 (
129  const objectRegistry& obr,
130  const bool includeComponents
131 )
132 :
133  fieldSelection(obr, includeComponents)
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
140 {
141  const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
142  const IOobjectList objects(mesh, mesh.time().timeName());
143 
144  List<fieldInfo> oldSet(std::move(selection_));
145 
146  DynamicList<fieldInfo> newSelection(oldSet.size());
147 
148  // Geometric fields
149  addGeoFieldTypes<fvPatchField, volMesh>(objects, newSelection);
150  addGeoFieldTypes<fvsPatchField, surfaceMesh>(objects, newSelection);
151  addGeoFieldTypes<pointPatchField, pointMesh>(objects, newSelection);
152 
153  // Internal fields
154  addInternalFieldTypes(objects, newSelection);
155 
156  // Uniform fields
157  addUniformFieldTypes(objects, newSelection);
158 
159  selection_.transfer(newSelection);
160 
162 
163  return selection_ != oldSet;
164 }
165 
166 
167 // ************************************************************************* //
virtual bool checkSelection()
Check that all requested fielda have been found.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
Tensor< scalar > tensor
Definition: symmTensor.H:57
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:55
Vector< scalar > vector
Definition: vector.H:57
#define doLocalCode(DataType)
List< word > wordList
List of word.
Definition: fileName.H:58
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
Helper class to manage field selections.
virtual bool updateSelection()
Update the selection.
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
Registry of regIOobjects.