OpenFOAM
v2312
The open source CFD toolbox
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) 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
Class
27
Foam::readFieldsHandler
28
29
Description
30
A simple field-loader, as per the readFields function object
31
32
\*---------------------------------------------------------------------------*/
33
34
#ifndef readFieldsHander_H
35
#define readFieldsHander_H
36
37
#include "
fvMesh.H
"
38
#include "
volFields.H
"
39
#include "
surfaceFields.H
"
40
#include "
messageStream.H
"
41
42
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44
namespace
Foam
45
{
46
47
/*---------------------------------------------------------------------------*\
48
Class readFieldsHandler Declaration
49
\*---------------------------------------------------------------------------*/
50
51
class
readFieldsHandler
52
{
53
// Private Data
54
55
//- Mesh reference
56
fvMesh& mesh_;
57
58
//- Output logging (verbosity)
59
bool
log
;
60
61
62
// Private Member Functions
63
64
//- Attempt load from io, store on database if successful
65
template
<
class
FieldType>
66
bool
loadAndStore(
const
IOobject&
io
)
67
{
68
if
(
io
.isHeaderClass<FieldType>())
69
{
70
// Store field on mesh database
71
Log
<<
" Reading "
<<
io
.name()
72
<<
" ("
<< FieldType::typeName <<
')'
<<
endl
;
73
74
mesh_.objectRegistry::store(
new
FieldType(
io
, mesh_));
75
return
true
;
76
}
77
78
return
false
;
79
}
80
81
//- Forward to loadAndStore for supported types
82
template
<
class
Type>
83
bool
loadField(
const
IOobject&
io
)
84
{
85
typedef
GeometricField<Type, fvPatchField, volMesh> VolFieldType;
86
typedef
typename
VolFieldType::Internal IntVolFieldType;
87
typedef
GeometricField<Type, fvsPatchField, surfaceMesh>
88
SurfaceFieldType;
89
90
return
91
(
92
loadAndStore<VolFieldType>(
io
)
93
|| loadAndStore<IntVolFieldType>(
io
)
94
|| loadAndStore<SurfaceFieldType>(
io
)
95
);
96
}
97
98
99
//- Load all fields
100
label loadFields(
const
UList<word>& fieldSet_)
101
{
102
label nLoaded = 0;
103
104
for
(
const
word& fieldName : fieldSet_)
105
{
106
// Already loaded?
107
const
auto
* ptr = mesh_.cfindObject<regIOobject>(fieldName);
108
109
if
(ptr)
110
{
111
++nLoaded;
112
DebugInfo
113
<<
"readFields : "
114
<< ptr->name() <<
" ("
<< ptr->type()
115
<<
") already in database"
<<
endl
;
116
continue
;
117
}
118
119
// Load field as necessary
120
IOobject
io
121
(
122
fieldName,
123
mesh_.time().timeName(),
124
mesh_.thisDb(),
125
IOobject::MUST_READ
,
126
IOobject::NO_WRITE
127
);
128
129
const
bool
ok =
130
(
131
io
.typeHeaderOk<regIOobject>(
false
)
132
&&
133
(
134
loadField<scalar>(
io
)
135
|| loadField<vector>(
io
)
136
|| loadField<sphericalTensor>(
io
)
137
|| loadField<symmTensor>(
io
)
138
|| loadField<tensor>(
io
)
139
)
140
);
141
142
if
(ok)
143
{
144
++nLoaded;
145
}
146
else
147
{
148
DebugInfo
149
<<
"readFields : failed to load "
<< fieldName
150
<<
endl
;
151
}
152
}
153
154
return
nLoaded;
155
}
156
157
158
public
:
159
160
static
const
bool
debug
=
false
;
161
162
163
// Constructors
164
165
//- Construct
166
explicit
readFieldsHandler
(fvMesh&
mesh
,
bool
verbose=
true
)
167
:
168
mesh_(
mesh
),
169
log
(verbose)
170
{}
171
172
173
// Member Functions
174
175
bool
execute
(
const
UList<word>
& fieldNames)
176
{
177
loadFields(fieldNames);
178
return
true
;
179
}
180
};
181
182
183
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184
185
}
// End namespace Foam
186
187
#endif
188
189
// ************************************************************************* //
surfaceFields.H
Foam::surfaceFields.
Foam::log
dimensionedScalar log(const dimensionedScalar &ds)
Definition:
dimensionedScalar.C:255
fvMesh.H
Foam::readFieldsHandler::debug
static const bool debug
Definition:
readFields.H:163
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition:
Ostream.H:531
Foam::IOobjectOption::NO_WRITE
Ignore writing from objectRegistry::writeObject()
Definition:
IOobjectOption.H:86
mesh
dynamicFvMesh & mesh
Definition:
createDynamicFvMesh.H:6
Foam::readFieldsHandler::readFieldsHandler
readFieldsHandler(fvMesh &mesh, bool verbose=true)
Construct.
Definition:
readFields.H:171
Foam::IOobjectOption::MUST_READ
Reading required.
Definition:
IOobjectOption.H:63
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition:
HashTable.H:105
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition:
messageStream.H:511
Log
#define Log
Definition:
PDRblock.C:28
messageStream.H
volFields.H
io
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Foam::readFieldsHandler::execute
bool execute(const UList< word > &fieldNames)
Definition:
readFields.H:180
Foam
Namespace for OpenFOAM.
Definition:
atmBoundaryLayer.C:26
applications
utilities
preProcessing
setExprBoundaryFields
readFields.H
Generated by
1.8.14