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-2023 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  objectRegistry* cache
54 )
55 {
56  tmp<GeoField> tfield;
57 
58  if (io)
59  {
60  const word& fieldName = io->name();
61 
62  if (cache)
63  {
64  // Get reference from cache if possible
65  tfield.cref(cache->cfindObject<GeoField>(fieldName));
66 
67  if (tfield)
68  {
69  return tfield;
70  }
71  }
72 
73  tfield = proxy.interpolate
74  (
75  getField<GeoField>(io, proxy.baseMesh(), syncPar)
76  );
77 
78  if (tfield && cache)
79  {
80  // Move field to the cache
81  IOobject newIO(tfield(), *cache);
82  newIO.readOpt(IOobjectOption::NO_READ);
83  newIO.writeOpt(IOobjectOption::NO_WRITE);
84 
85  tfield.ref().checkOut(); // Paranoid
86  cache->store(new GeoField(newIO, tfield));
87 
88  tfield.cref(cache->cfindObject<GeoField>(fieldName));
89  }
90  }
91 
92  return tfield;
93 }
94 
95 
96 template<class GeoField>
98 (
99  const typename GeoField::Mesh& mesh,
100  const IOobjectList& objects,
101  const word& fieldName,
102  const bool syncPar
103 )
104 {
105  // Can do something with syncPar on failure ...
106 
107  return getField<GeoField>
108  (
109  objects.findObject(fieldName),
110  mesh,
111  syncPar
112  );
113 }
114 
115 
116 template<class GeoField>
118 (
119  const fvMeshSubsetProxy& proxy,
120  const IOobjectList& objects,
121  const word& fieldName,
122  const bool syncPar,
123  objectRegistry* cache
124 )
125 {
126  // Can do something with syncPar on failure ...
127 
128  return getField<GeoField>
129  (
130  objects.findObject(fieldName),
131  proxy,
132  syncPar,
133  cache
134  );
135 }
136 
137 
138 template<class GeoField>
140 (
141  const typename GeoField::Mesh& mesh,
142  const IOobjectList& objects
143 )
144 {
145  const bool syncPar = true;
146 
147  // Available fields of type GeoField, sorted order
148  const wordList fieldNames(objects.sortedNames<GeoField>());
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>(mesh, objects, fieldName, syncPar);
159 
160  if (tfield)
161  {
162  fields.set(nFields++, tfield.ptr());
163  }
164  }
165 
166  fields.resize(nFields);
167  return fields;
168 }
169 
170 
171 template<class GeoField>
173 (
174  const fvMeshSubsetProxy& proxy,
175  const IOobjectList& objects
176 )
177 {
178  const bool syncPar = true;
179 
180  // Available fields of type GeoField, sorted order
181  const wordList fieldNames(objects.sortedNames<GeoField>());
182 
183  // Construct the fields
184  PtrList<const GeoField> fields(fieldNames.size());
185 
186  label nFields = 0;
187 
188  for (const word& fieldName : fieldNames)
189  {
190  auto tfield =
191  getField<GeoField>(proxy, objects, fieldName, syncPar);
192 
193  if (tfield)
194  {
195  fields.set(nFields++, tfield.ptr());
196  }
197  }
198 
199  fields.resize(nFields);
200  return fields;
201 }
202 
203 
204 // ************************************************************************* //
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
dynamicFvMesh & mesh
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
tmp< GeoField > getField(const IOobject &io, const typename GeoField::Mesh &mesh)
Get the field or FatalError.
Definition: readFields.H:51
List< word > wordList
List of word.
Definition: fileName.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50