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.empty())
55  {
56  fi.found(true);
57  }
58  for (const word& name : names)
59  {
60  set.emplace_back(wordRe(name));
61  }
62  }
63 }
64 
65 
66 template<template<class> class PatchType, class MeshType>
67 void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes
68 (
69  const IOobjectList& objects,
70  DynamicList<fieldInfo>& set
71 ) const
72 {
73  #undef doLocalCode
74  #define doLocalCode(DataType) \
75  addFromFile<GeometricField<DataType, PatchType, MeshType>>(objects, set);
76 
77  doLocalCode(scalar);
82  #undef doLocalCode
83 }
84 
85 
86 void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
87 (
88  const IOobjectList& objects,
89  DynamicList<fieldInfo>& set
90 ) const
91 {
92  #undef doLocalCode
93  #define doLocalCode(DataType) \
94  addFromFile<DimensionedField<DataType, volMesh>>(objects, set);
95 
96  doLocalCode(scalar);
101  #undef doLocalCode
102 }
103 
104 
105 void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
106 (
107  const IOobjectList& objects,
108  DynamicList<fieldInfo>& set
109 ) const
110 {
111  #undef doLocalCode
112  #define doLocalCode(DataType) \
113  addFromFile<UniformDimensionedField<DataType>>(objects, set);
114 
115  doLocalCode(scalar);
120  #undef doLocalCode
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
125 
127 (
128  const objectRegistry& obr,
129  const bool includeComponents
130 )
131 :
132  fieldSelection(obr, includeComponents)
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137 
139 {
140  const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
141  const IOobjectList objects(mesh, mesh.time().timeName());
142 
143  List<fieldInfo> oldSet(std::move(selection_));
144 
145  DynamicList<fieldInfo> newSelection(oldSet.size());
146 
147  // Geometric fields
148  addGeoFieldTypes<fvPatchField, volMesh>(objects, newSelection);
149  addGeoFieldTypes<fvsPatchField, surfaceMesh>(objects, newSelection);
150  addGeoFieldTypes<pointPatchField, pointMesh>(objects, newSelection);
151 
152  // Internal fields
153  addInternalFieldTypes(objects, newSelection);
154 
155  // Uniform fields
156  addUniformFieldTypes(objects, newSelection);
157 
158  selection_.transfer(newSelection);
159 
161 
162  return selection_ != oldSet;
163 }
164 
165 
166 // ************************************************************************* //
virtual bool checkSelection()
Check that all requested fielda have been found.
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
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
Tensor< scalar > tensor
Definition: symmTensor.H:57
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
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
fileFieldSelection(const fileFieldSelection &)=delete
No copy construct.
#define doLocalCode(DataType)
List< word > wordList
List of word.
Definition: fileName.H:59
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
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.