Loading...
Searching...
No Matches
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.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
66template<template<class> class PatchType, class MeshType>
67void 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
86void 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
105void 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)
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// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
bool set(const label i, bool val=true)
Definition List.H:469
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
virtual bool checkSelection()
Check that all requested fielda have been found.
const objectRegistry & obr_
Reference to the database.
List< fieldInfo > selection_
Current field selection.
virtual bool updateSelection()
Update the selection.
fileFieldSelection(const fileFieldSelection &)=delete
No copy construct.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Registry of regIOobjects.
dynamicFvMesh & mesh
#define doLocalCode(FieldType, Variable)
auto & name
auto & names
List< word > wordList
List of word.
Definition fileName.H:60
Tensor< scalar > tensor
Definition symmTensor.H:57
Vector< scalar > vector
Definition vector.H:57
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition symmTensor.H:55