Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 FoamToEnsight_readFields_H
39#define FoamToEnsight_readFields_H
40
41#include "instantList.H"
42#include "IOobjectList.H"
43#include "fvPatchField.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50//- Get the field or FatalError
51template<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
63template<class GeoField>
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.
80template<class GeoField>
81tmp<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
95template<class Type>
96tmp<VolumeField<Type>> makeZeroGradientField
97(
98 const tmp<VolumeInternalField<Type>>& tdf
99)
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
129template<class Type>
130tmp<VolumeField<Type>> makeZeroGradientField
131(
132 const tmp<VolumeField<Type>>& tdf
133)
134{
135 if (tdf)
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
165label checkData
166(
167 const objectRegistry& obr,
168 const instantList& timeDirs,
169 wordList& objectNames,
171);
172
173
174} // End namespace Foam
175
176// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177
178#endif
179
180// ************************************************************************* //
static tmp< GeometricField< Type, fvPatchField, volMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=fvPatchField< Type >::calculatedType())
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A class for handling file names.
Definition fileName.H:75
static const fileName null
An empty fileName.
Definition fileName.H:111
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Registry of regIOobjects.
A class for managing temporary objects.
Definition tmp.H:75
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition tmpI.H:289
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
A class for handling words, derived from Foam::string.
Definition word.H:66
bool local
Definition EEqn.H:20
dynamicFvMesh & mesh
const auto & io
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
GeometricField< Type, fvPatchField, volMesh > VolumeField
A volume field for a given type.
List< instant > instantList
List of instants.
Definition instantList.H:41
label checkData(const objectRegistry &obr, const instantList &timeDirs, wordList &objectNames, const fileName &local=fileName::null)
Check if fields are good to use (available at all times).
DimensionedField< Type, volMesh > VolumeInternalField
A volume internal field for a given Type.
tmp< VolumeField< Type > > makeZeroGradientField(const tmp< VolumeInternalField< Type > > &tdf)
Convert an internal field to zero-gradient volume field.
Definition readFields.H:101
tmp< GeoField > getField(const IOobject &io, const typename GeoField::Mesh &mesh)
Get the field or FatalError.
Definition readFields.H:51