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"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
39  addToRunTimeSelectionTable(functionObject, readFields, dictionary);
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 {
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  auto* ptr = mesh_.getObjectPtr<regIOobject>(fieldName);
84 
85  if (ptr)
86  {
88  {
89  DebugInfo
90  << "readFields : "
91  << ptr->name() << " (" << ptr->type()
92  << ") already in database - removing" << endl;
93 
94  ptr->checkOut();
95  }
96  else
97  {
98  DebugInfo
99  << "readFields : "
100  << ptr->name() << " (" << ptr->type()
101  << ") already in database" << endl;
102 
103  continue;
104  }
105  }
106 
107  // Load field as necessary
108  IOobject io
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  {
133  DebugInfo
134  << "readFields : failed to load " << fieldName << endl;
135  }
136  }
137 
138  return true;
139 }
140 
141 
143 {
144  return true;
145 }
146 
147 
148 // ************************************************************************* //
dictionary dict
defineTypeNameAndDebug(ObukhovLength, 0)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static bool postProcess
Global post-processing mode switch.
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Ignore writing from objectRegistry::writeObject()
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
virtual bool execute()
Read the fields.
Definition: readFields.C:71
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
readFields(const word &name, const Time &runTime, const dictionary &dict)
Construct for given objectRegistry and dictionary.
Definition: readFields.C:40
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool read(const dictionary &dict)
Read the set of fields from dictionary.
Definition: readFields.C:61
virtual bool write()
Do nothing.
Definition: readFields.C:135
#define DebugInfo
Report an information message using Foam::Info.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
bool readOnStart_
Read immediately on construction (default: true)
Definition: readFields.H:162
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
virtual bool read(const dictionary &dict)
Read optional controls.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Request registration (bool: true)
Namespace for OpenFOAM.