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-------------------------------------------------------------------------------
11License
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"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace functionObjects
37{
40}
41}
42
43
44// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45
47(
48 const word& name,
49 const Time& runTime,
50 const dictionary& dict
51)
52:
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
69{
71
72 dict.readEntry("fields", fieldSet_);
73
74 return true;
75}
76
77
79{
80 for (const word& fieldName : fieldSet_)
81 {
82 // Already loaded?
83 const auto* ptr = mesh_.cfindObject<regIOobject>(fieldName);
84
85 if (ptr)
86 {
88 << "readFields : "
89 << ptr->name() << " (" << ptr->type()
90 << ") already in database" << endl;
91 continue;
92 }
93
94 // Load field as necessary
96 (
97 fieldName,
98 mesh_.time().timeName(),
99 mesh_,
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 {
121 << "readFields : failed to load " << fieldName << endl;
122 }
123 }
124
125 return true;
126}
127
128
130{
131 return true;
132}
133
134
135// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:158
bool readOnStart_
Read immediately on construction (default: true)
Definition: readFields.H:164
virtual bool read(const dictionary &dict)
Read the set of fields from dictionary.
Definition: readFields.C:68
virtual bool execute()
Read the fields.
Definition: readFields.C:78
virtual bool write()
Do nothing.
Definition: readFields.C:129
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define DebugInfo
Report an information message using Foam::Info.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
dictionary dict