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-------------------------------------------------------------------------------
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 "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
43template<class Type>
44void 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
67template<template<class> class PatchType, class MeshType>
68void 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
87void 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
106void 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
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// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:330
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Helper class to manage field selections.
virtual bool checkSelection()
Check that all requested fielda have been found.
Helper class to manage file-based field selections.
virtual bool updateSelection()
Update the selection.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Registry of regIOobjects.
Tensor of scalars, i.e. Tensor<scalar>.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
dynamicFvMesh & mesh
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List< word > wordList
A List of words.
Definition: fileName.H:63
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:59
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
#define doLocalCode(GeoField)