OpenFOAM: API Guide
v2112
The open source CFD toolbox
readFields.C
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) 2011-2016 OpenFOAM Foundation
9
Copyright (C) 2017-2022 OpenCFD Ltd.
10
-------------------------------------------------------------------------------
11
License
12
This file is part of OpenFOAM.
13
14
OpenFOAM is free software: you can redistribute it and/or modify it
15
under the terms of the GNU General Public License as published by
16
the Free Software Foundation, either version 3 of the License, or
17
(at your option) any later version.
18
19
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22
for more details.
23
24
You should have received a copy of the GNU General Public License
25
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27
\*---------------------------------------------------------------------------*/
28
29
#include "
readFields.H
"
30
#include "
addToRunTimeSelectionTable.H
"
31
32
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34
namespace
Foam
35
{
36
namespace
functionObjects
37
{
38
defineTypeNameAndDebug
(
readFields
, 0);
39
addToRunTimeSelectionTable
(
functionObject
,
readFields
,
dictionary
);
40
}
41
}
42
43
44
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45
46
Foam::functionObjects::readFields::readFields
47
(
48
const
word
& name,
49
const
Time
&
runTime
,
50
const
dictionary
&
dict
51
)
52
:
53
fvMeshFunctionObject
(
name
,
runTime
,
dict
),
54
readOnStart_(
dict
.getOrDefault(
"readOnStart"
, true)),
55
fieldSet_()
56
{
57
read
(
dict
);
58
59
if
(
readOnStart_
)
60
{
61
execute
();
62
}
63
}
64
65
66
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67
68
bool
Foam::functionObjects::readFields::read
(
const
dictionary
&
dict
)
69
{
70
fvMeshFunctionObject::read
(
dict
);
71
72
dict
.readEntry(
"fields"
, fieldSet_);
73
74
return
true
;
75
}
76
77
78
bool
Foam::functionObjects::readFields::execute
()
79
{
80
for
(
const
word
& fieldName : fieldSet_)
81
{
82
// Already loaded?
83
const
auto
* ptr = mesh_.cfindObject<
regIOobject
>(fieldName);
84
85
if
(ptr)
86
{
87
DebugInfo
88
<<
"readFields : "
89
<< ptr->name() <<
" ("
<< ptr->type()
90
<<
") already in database"
<<
endl
;
91
continue
;
92
}
93
94
// Load field as necessary
95
IOobject
io
96
(
97
fieldName,
98
mesh_.time().timeName(),
99
mesh_,
100
IOobject::MUST_READ
,
101
IOobject::NO_WRITE
102
);
103
104
const
bool
ok =
105
(
106
io
.typeHeaderOk<
regIOobject
>(
false
)
// Preload header info
107
&&
io
.hasHeaderClass()
// Extra safety
108
&&
109
(
110
loadField<scalar>(
io
)
111
|| loadField<vector>(
io
)
112
|| loadField<sphericalTensor>(
io
)
113
|| loadField<symmTensor>(
io
)
114
|| loadField<tensor>(
io
)
115
)
116
);
117
118
if
(!ok)
119
{
120
DebugInfo
121
<<
"readFields : failed to load "
<< fieldName <<
endl
;
122
}
123
}
124
125
return
true
;
126
}
127
128
129
bool
Foam::functionObjects::readFields::write
()
130
{
131
return
true
;
132
}
133
134
135
// ************************************************************************* //
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
addToRunTimeSelectionTable
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Definition:
addToRunTimeSelectionTable.H:42
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition:
IOobject.H:170
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition:
IOobject.H:187
Foam::IOobject::MUST_READ
@ MUST_READ
Definition:
IOobject.H:179
Foam::RASModels::kEpsilonLopesdaCosta::read
virtual bool read()
Re-read model coefficients if they have changed.
Definition:
kEpsilonLopesdaCosta.C:380
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition:
Time.H:80
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition:
dictionary.H:126
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition:
functionObject.H:333
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition:
fvMeshFunctionObject.H:67
Foam::functionObjects::readFields
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition:
readFields.H:158
Foam::functionObjects::readFields::readOnStart_
bool readOnStart_
Read immediately on construction (default: true)
Definition:
readFields.H:164
Foam::functionObjects::readFields::read
virtual bool read(const dictionary &dict)
Read the set of fields from dictionary.
Definition:
readFields.C:68
Foam::functionObjects::readFields::execute
virtual bool execute()
Read the fields.
Definition:
readFields.C:78
Foam::functionObjects::readFields::write
virtual bool write()
Do nothing.
Definition:
readFields.C:129
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition:
regIOobject.H:76
Foam::word
A class for handling words, derived from Foam::string.
Definition:
word.H:68
defineTypeNameAndDebug
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition:
className.H:121
runTime
engineTime & runTime
Definition:
createEngineTime.H:13
io
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition:
messageStream.H:382
Foam
Namespace for OpenFOAM.
Definition:
atmBoundaryLayer.C:34
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition:
Ostream.H:372
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition:
exprTraits.C:59
dict
dictionary dict
Definition:
searchingEngine.H:14
readFields.H
src
functionObjects
field
readFields
readFields.C
Generated by
1.9.5
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.