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-2020 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>
52 tmp<GeoField> getField
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<GeometricField<Type, fvPatchField, volMesh>>
86 (
87  const tmp
88  <
90  >& tdf
91 )
92 {
93  if (tdf.valid())
94  {
95  auto& df = tdf.ref();
96 
98  (
99  df.name(),
100  df.mesh(),
101  df.dimensions(),
102  std::move(df.field()),
103  zeroGradientFvPatchScalarField::typeName
104  );
105 
106  tfield.ref().oriented() = df.oriented();
107  tfield.ref().correctBoundaryConditions();
108 
109  tdf.clear();
110 
111  return tfield;
112  }
113 
114  tdf.clear();
115 
116  return nullptr;
117 }
118 
119 
120 //- Convert a volume field to zero-gradient volume field
121 template<class Type>
122 tmp<GeometricField<Type, fvPatchField, volMesh>>
124 (
126 )
127 {
128  if (tdf.valid())
129  {
130  auto& df = tdf.ref();
131 
133  (
134  df.name(),
135  df.mesh(),
136  df.dimensions(),
137  std::move(df.primitiveFieldRef(false)), // No update accessTime
138  zeroGradientFvPatchScalarField::typeName
139  );
140 
141  tfield.ref().oriented() = df.oriented();
142  tfield.ref().correctBoundaryConditions();
143 
144  tdf.clear();
145 
146  return tfield;
147  }
148 
149  tdf.clear();
150 
151  return nullptr;
152 }
153 
154 
155 //- Check if fields are good to use (available at all times)
156 // ignore special fields (_0 fields),
157 // ignore fields that are not available for all time-steps
158 label checkData
159 (
160  const fvMesh& mesh,
161  const instantList& timeDirs,
162  wordList& objectNames
163 );
164 
165 
166 } // End namespace Foam
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #endif
171 
172 // ************************************************************************* //
instantList.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::checkData
label checkData(const fvMesh &mesh, const instantList &timeDirs, wordList &objectNames)
Check if fields are good to use (available at all times)
Foam::IOobjectList::findObject
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:270
IOobjectList.H
Foam::instantList
List< instant > instantList
List of instants.
Definition: instantList.H:44
Foam::GeometricField::New
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.
Definition: GeometricFieldNew.C:34
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::getField
tmp< GeoField > getField(const IOobject *io, const typename GeoField::Mesh &mesh)
Get the field or return nullptr.
Definition: readFields.H:53
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::makeZeroGradientField
tmp< GeometricField< Type, fvPatchField, volMesh > > makeZeroGradientField(const tmp< typename GeometricField< Type, fvPatchField, volMesh >::Internal > &tdf)
Convert an internal field to zero-gradient volume field.
Definition: readFields.H:86
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
zeroGradientFvPatchFields.H