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-2022 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 readFields_H
39 #define readFields_H
40 
41 #include "instantList.H"
42 #include "IOobjectList.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 //- Get the field or return nullptr
51 template<class GeoField>
53 (
54  const IOobject* io,
55  const typename GeoField::Mesh& mesh
56 )
57 {
58  if (io)
59  {
60  return tmp<GeoField>::New(*io, mesh);
61  }
62 
63  return nullptr;
64 }
65 
66 
67 //- Get the named field from the objects, or return nullptr.
68 template<class GeoField>
69 tmp<GeoField> getField
70 (
71  const typename GeoField::Mesh& mesh,
72  const IOobjectList& objects,
73  const word& fieldName
74 )
75 {
76  // Can do something with syncPar on failure ...
77 
78  return getField<GeoField>(objects.findObject(fieldName), mesh);
79 }
80 
81 
82 //- Convert an internal field to zero-gradient volume field
83 template<class Type>
84 tmp<VolumeField<Type>> makeZeroGradientField
85 (
86  const tmp<VolumeInternalField<Type>>& tdf
87 )
88 {
89  if (tdf)
90  {
91  auto& df = tdf.ref();
92 
93  auto tfield = VolumeField<Type>::New
94  (
95  df.name(),
96  df.mesh(),
97  df.dimensions(),
98  std::move(df.field()),
99  zeroGradientFvPatchScalarField::typeName
100  );
101 
102  tfield.ref().oriented() = df.oriented();
103  tfield.ref().correctBoundaryConditions();
104 
105  tdf.clear();
106 
107  return tfield;
108  }
109 
110  tdf.clear();
111 
112  return nullptr;
113 }
114 
115 
116 //- Convert a volume field to zero-gradient volume field
117 template<class Type>
118 tmp<VolumeField<Type>> makeZeroGradientField
119 (
120  const tmp<VolumeField<Type>>& tdf
121 )
122 {
123  if (tdf)
124  {
125  auto& df = tdf.ref();
126 
127  auto tfield = VolumeField<Type>::New
128  (
129  df.name(),
130  df.mesh(),
131  df.dimensions(),
132  std::move(df.primitiveFieldRef(false)), // No update accessTime
133  zeroGradientFvPatchScalarField::typeName
134  );
135 
136  tfield.ref().oriented() = df.oriented();
137  tfield.ref().correctBoundaryConditions();
138 
139  tdf.clear();
140 
141  return tfield;
142  }
143 
144  tdf.clear();
145 
146  return nullptr;
147 }
148 
149 
150 //- Check if fields are good to use (available at all times)
151 // ignore special fields (_0 fields),
152 // ignore fields that are not available for all time-steps
153 label checkData
154 (
155  const fvMesh& mesh,
156  const instantList& timeDirs,
157  wordList& objectNames
158 );
159 
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
List< instant > instantList
List of instants.
Definition: instantList.H:41
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
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &ds, const word &patchFieldType=PatchField< Type >::calculatedType())
Return tmp field from name, mesh, dimensions and patch type.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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
tmp< GeoField > getField(const IOobject *io, const typename GeoField::Mesh &mesh)
Get the field or return nullptr.
Definition: readFields.H:51
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:203
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:211
tmp< VolumeField< Type > > makeZeroGradientField(const tmp< VolumeInternalField< Type >> &tdf)
Convert an internal field to zero-gradient volume field.
Definition: readFields.H:87
List< word > wordList
A List of words.
Definition: fileName.H:58
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
Namespace for OpenFOAM.