readFields.H
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) 2018-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 InNamespace
27  Foam
28 
29 Description
30  Helper routines for reading a field or fields,
31  for foamToEnsight
32 
33 SourceFiles
34  readFields.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef ensight_readFields_H
39 #define ensight_readFields_H
40 
41 #include "instantList.H"
42 #include "IOobjectList.H"
43 #include "fvPatchField.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 //- Get the field or FatalError
51 template<class GeoField>
53 (
54  const IOobject& io,
55  const typename GeoField::Mesh& mesh
56 )
57 {
58  return tmp<GeoField>::New(io, mesh);
59 }
60 
61 
62 //- Get the field or return nullptr
63 template<class GeoField>
64 tmp<GeoField> getField
65 (
66  const IOobject* io,
67  const typename GeoField::Mesh& mesh
68 )
69 {
70  if (io)
71  {
72  return tmp<GeoField>::New(*io, mesh);
73  }
74 
75  return nullptr;
76 }
77 
78 
79 //- Get the named field from the objects, or return nullptr.
80 template<class GeoField>
81 tmp<GeoField> getField
82 (
83  const typename GeoField::Mesh& mesh,
84  const IOobjectList& objects,
85  const word& fieldName
86 )
87 {
88  // Can do something with syncPar on failure ...
89 
90  return getField<GeoField>(objects.findObject(fieldName), mesh);
91 }
92 
93 
94 //- Convert an internal field to zero-gradient volume field
95 template<class Type>
96 tmp<VolumeField<Type>> makeZeroGradientField
97 (
98  const tmp<VolumeInternalField<Type>>& tdf
99 )
100 {
101  if (tdf)
102  {
103  auto& df = tdf.ref();
104 
105  auto tfield = VolumeField<Type>::New
106  (
107  df.name(),
108  df.mesh(),
109  df.dimensions(),
110  std::move(df.field()),
112  );
113 
114  tfield.ref().oriented() = df.oriented();
115  tfield.ref().correctBoundaryConditions();
116 
117  tdf.clear();
118 
119  return tfield;
120  }
121 
122  tdf.clear();
123 
124  return nullptr;
125 }
126 
127 
128 //- Convert a volume field to zero-gradient volume field
129 template<class Type>
130 tmp<VolumeField<Type>> makeZeroGradientField
131 (
132  const tmp<VolumeField<Type>>& tdf
133 )
134 {
135  if (tdf)
136  {
137  auto& df = tdf.ref();
138 
139  auto tfield = VolumeField<Type>::New
140  (
141  df.name(),
142  df.mesh(),
143  df.dimensions(),
144  std::move(df.primitiveFieldRef(false)), // No update accessTime
146  );
147 
148  tfield.ref().oriented() = df.oriented();
149  tfield.ref().correctBoundaryConditions();
150 
151  tdf.clear();
152 
153  return tfield;
154  }
155 
156  tdf.clear();
157 
158  return nullptr;
159 }
160 
161 
162 //- Check if fields are good to use (available at all times)
163 // ignore special fields (_0 fields),
164 // ignore fields that are not available for all time-steps
165 label checkData
166 (
167  const fvMesh& mesh,
168  const instantList& timeDirs,
169  wordList& objectNames
170 );
171 
172 
173 } // End namespace Foam
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #endif
178 
179 // ************************************************************************* //
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: fvPatchField.H:221
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
dynamicFvMesh & mesh
label checkData(const fvMesh &mesh, const instantList &timeDirs, wordList &objectNames)
Check if fields are good to use (available at all times)
A class for handling words, derived from Foam::string.
Definition: word.H:63
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:176
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=PatchField< Type >::calculatedType())
Return tmp field (NO_READ, NO_WRITE) from name, mesh, dimensions and patch type. [Takes current timeN...
tmp< GeoField > getField(const IOobject &io, const typename GeoField::Mesh &mesh)
Get the field or FatalError.
Definition: readFields.H:51
tmp< VolumeField< Type > > makeZeroGradientField(const tmp< VolumeInternalField< Type >> &tdf)
Convert an internal field to zero-gradient volume field.
Definition: readFields.H:101
List< word > wordList
List of word.
Definition: fileName.H:59
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
List< instant > instantList
List of instants.
Definition: instantList.H:41
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Namespace for OpenFOAM.