readFields.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) 2016-2018 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 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
29 
30 template<class GeoField>
32 (
33  const IOobject* io,
34  const typename GeoField::Mesh& mesh,
35  const bool syncPar
36 )
37 {
38  if (io)
39  {
40  return tmp<GeoField>::New(*io, mesh);
41  }
42 
43  return nullptr;
44 }
45 
46 
47 template<class GeoField>
49 (
50  const IOobject* io,
51  const fvMeshSubsetProxy& proxy,
52  const bool syncPar
53 )
54 {
55  return
56  proxy.interpolate
57  (
58  getField<GeoField>(io, proxy.baseMesh(), syncPar)
59  );
60 }
61 
62 
63 template<class GeoField>
65 (
66  const typename GeoField::Mesh& mesh,
67  const IOobjectList& objects,
68  const word& fieldName,
69  const bool syncPar
70 )
71 {
72  // Can do something with syncPar on failure ...
73 
74  return getField<GeoField>(objects.findObject(fieldName), mesh, syncPar);
75 }
76 
77 
78 template<class GeoField>
80 (
81  const fvMeshSubsetProxy& proxy,
82  const IOobjectList& objects,
83  const word& fieldName,
84  const bool syncPar
85 )
86 {
87  // Can do something with syncPar on failure ...
88 
89  return getField<GeoField>(objects.findObject(fieldName), proxy, syncPar);
90 }
91 
92 
93 template<class GeoField>
95 (
96  const typename GeoField::Mesh& mesh,
97  const IOobjectList& objects,
98  const wordRes& selection
99 )
100 {
101  const bool syncPar = true;
102 
103  // Available fields of type GeoField, sorted order
104  const wordList fieldNames =
105  (
106  selection.empty()
107  ? objects.sortedNames<GeoField>()
108  : objects.sortedNames<GeoField>(selection)
109  );
110 
111  // Construct the fields
112  PtrList<const GeoField> fields(fieldNames.size());
113 
114  label nFields = 0;
115 
116  for (const word& fieldName : fieldNames)
117  {
118  auto tfield =
119  getField<GeoField>(mesh, objects, fieldName, syncPar);
120 
121  if (tfield.valid())
122  {
123  fields.set(nFields++, tfield.ptr());
124  }
125  }
126 
127  fields.resize(nFields);
128  return fields;
129 }
130 
131 
132 template<class GeoField>
134 (
135  const fvMeshSubsetProxy& proxy,
136  const IOobjectList& objects,
137  const wordRes& selection
138 )
139 {
140  const bool syncPar = true;
141 
142  // Available fields of type GeoField, sorted order
143  const wordList fieldNames =
144  (
145  selection.empty()
146  ? objects.sortedNames<GeoField>()
147  : objects.sortedNames<GeoField>(selection)
148  );
149 
150  // Construct the fields
151  PtrList<const GeoField> fields(fieldNames.size());
152 
153  label nFields = 0;
154 
155  for (const word& fieldName : fieldNames)
156  {
157  auto tfield =
158  getField<GeoField>(proxy, objects, fieldName, syncPar);
159 
160  if (tfield.valid())
161  {
162  fields.set(nFields++, tfield.ptr());
163  }
164  }
165 
166  fields.resize(nFields);
167  return fields;
168 }
169 
170 
171 // ************************************************************************* //
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
fieldNames
const wordRes fieldNames(propsDict.getOrDefault< wordRes >("fields", wordRes()))
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::getField
tmp< GeoField > getField(const IOobject *io, const typename GeoField::Mesh &mesh)
Get the field or return nullptr.
Definition: readFields.H:53
fields
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97