Loading...
Searching...
No Matches
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"
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:
53 fvMeshFunctionObject(name, runTime, dict),
54 readOnStart_(dict.getOrDefault("readOnStart", true)),
55 fieldSet_()
56{
57 read(dict);
58
59 if (readOnStart_)
60 {
62 }
63}
64
65
66// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67
69{
72 dict.readEntry("fields", fieldSet_);
73
74 return true;
75}
76
77
79{
80 for (const word& fieldName : fieldSet_)
81 {
82 // Already loaded?
83 auto* ptr = mesh_.getObjectPtr<regIOobject>(fieldName);
84
85 if (ptr)
86 {
88 {
90 << "readFields : "
91 << ptr->name() << " (" << ptr->type()
92 << ") already in database - removing" << endl;
93
94 ptr->checkOut();
95 }
96 else
97 {
99 << "readFields : "
100 << ptr->name() << " (" << ptr->type()
101 << ") already in database" << endl;
102
103 continue;
104 }
105 }
106
107 // Load field as necessary
109 (
110 fieldName,
111 mesh_.time().timeName(),
112 mesh_,
116 );
117
118 const bool ok =
119 (
120 io.typeHeaderOk<regIOobject>(false)
121 &&
122 (
123 loadField<scalar>(io)
124 || loadField<vector>(io)
125 || loadField<sphericalTensor>(io)
126 || loadField<symmTensor>(io)
127 || loadField<tensor>(io)
128 )
129 );
130
131 if (!ok)
132 {
134 << "readFields : failed to load " << fieldName << endl;
136 }
137
138 return true;
139}
140
141
143{
144 return true;
145}
146
147
148// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
@ REGISTER
Request registration (bool: true).
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Abstract base-class for Time/database function objects.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
static bool postProcess
Global post-processing mode switch.
const fvMesh & mesh_
Reference to the fvMesh.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition readFields.H:146
bool readOnStart_
Read immediately on construction (default: true).
Definition readFields.H:154
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition readFields.C:61
readFields(const word &name, const Time &runTime, const dictionary &dict)
Construct for given objectRegistry and dictionary.
Definition readFields.C:40
wordList fieldSet_
Fields to load.
Definition readFields.H:159
virtual bool execute()
Execute the function-object operations.
Definition readFields.C:71
virtual bool write()
Write the function-object results.
Definition readFields.C:135
bool loadField(const IOobject &io)
Forward to loadAndStore for supported types.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
engineTime & runTime
const auto & io
#define DebugInfo
Report an information message using Foam::Info.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dictionary dict