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-2020 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 :
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  {
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_,
102  );
103 
104  const bool ok =
105  (
106  io.typeHeaderOk<regIOobject>(false) // Preload header info
107  && !io.headerClassName().empty() // 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 
130 {
131  return true;
132 }
133 
134 
135 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::readFields::readFields
readFields(const word &name, const Time &runTime, const dictionary &dict)
Construct for given objectRegistry and dictionary.
Definition: readFields.C:47
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::IOobject::headerClassName
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:83
Foam::functionObjects::readFields::execute
virtual bool execute()
Read the fields.
Definition: readFields.C:78
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
readFields.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::readFields::write
virtual bool write()
Do nothing.
Definition: readFields.C:129
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::functionObjects::readFields::fieldSet_
wordList fieldSet_
Fields to load.
Definition: readFields.H:167
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::readFields::read
virtual bool read(const dictionary &dict)
Read the set of fields from dictionary.
Definition: readFields.C:68
Foam::IOobject::MUST_READ
Definition: IOobject.H:185