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-------------------------------------------------------------------------------
10License
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
26InNamespace
27 Foam
28
29Description
30 Helper routines for reading a field or fields,
31 for foamToEnsight
32
33SourceFiles
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
47namespace Foam
48{
49
50//- Get the field or return nullptr
51template<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.
68template<class GeoField>
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
83template<class Type>
85(
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
117template<class Type>
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
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// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricField class.
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:293
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:63
List< instant > instantList
List of instants.
Definition: instantList.H:47
tmp< VolumeField< Type > > makeZeroGradientField(const tmp< VolumeInternalField< Type > > &tdf)
Convert an internal field to zero-gradient volume field.
Definition: readFields.H:85
tmp< GeoField > getField(const IOobject *io, const typename GeoField::Mesh &mesh)
Get the field or return nullptr.
Definition: readFields.H:53
label checkData(const fvMesh &mesh, const instantList &timeDirs, wordList &objectNames)
Check if fields are good to use (available at all times)