objectRegistryFunctionObject.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 #include "objectRegistry.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace functionObjects
34 {
36 }
37 }
38 
39 
40 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
41 
43 (
44  const word& fieldName
45 )
46 {
47  Warning
48  << " functionObjects::" << type() << " " << name()
49  << " cannot find required object " << fieldName << endl;
50 }
51 
52 
54 (
55  const wordList& fieldNames
56 )
57 {
58  Warning
59  << " functionObjects::" << type() << " " << name()
60  << " cannot find required objects " << fieldNames << endl;
61 }
62 
63 
65 (
66  const word& fieldName
67 )
68 {
69  if (obr_.foundObject<regIOobject>(fieldName))
70  {
71  const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
72 
73  Log << " functionObjects::" << type() << " " << name()
74  << " writing field: " << field.name() << endl;
75 
76  field.write();
77 
78  return true;
79  }
80  else
81  {
82  return false;
83  }
84 }
85 
86 
88 (
89  const word& fieldName
90 )
91 {
92  if (foundObject<regIOobject>(fieldName))
93  {
94  regIOobject& resultObject = lookupObjectRef<regIOobject>(fieldName);
95 
96  if (resultObject.ownedByRegistry())
97  {
98  return resultObject.checkOut();
99  }
100  else
101  {
102  return false;
103  }
104  }
105  else
106  {
107  return true;
108  }
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113 
116 (
117  const word& name,
118  const objectRegistry& obr,
119  const dictionary& dict
120 )
121 :
122  functionObject(name, obr.time(), dict),
123  obr_(obr)
124 {}
125 
126 
129 (
130  const word& name,
131  const objectRegistry& obr
132 )
133 :
134  functionObject(name, obr.time()),
135  obr_(obr)
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
140 
143 {}
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
149 (
150  const dictionary& dict
151 )
152 {
153  return functionObject::read(dict);
154 }
155 
156 
157 // ************************************************************************* //
const word & name() const
Return name.
Definition: IOobject.H:307
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
virtual const word & type() const =0
Runtime type information.
const word & name() const
Return the name of this functionObject.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
Specialisation of Foam::functionObject which holds a reference to an object registry....
objectRegistryFunctionObject(const word &name, const objectRegistry &obr, const dictionary &dict)
Construct from an objectRegistry and dictionary.
void cannotFindObjects(const wordList &fieldNames)
Prints a warning message that fieldNames cannot be found.
bool writeObject(const word &fieldName)
Write field if present in objectRegistry.
bool clearObject(const word &fieldName)
Clear field from the objectRegistry if present.
void cannotFindObject(const word &fieldName)
Prints a warning message that fieldName cannot be found.
virtual bool read(const dictionary &)
Read optional controls.
Writes run time, CPU time and clock time and optionally the CPU and clock times per time step.
Registry of regIOobjects.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:34
virtual bool write(const bool write=true) const
Write using setting from DB.
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:241
A class for handling words, derived from string.
Definition: word.H:62
static List< word > fieldNames
Definition: globalFoam.H:46
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
messageStream Warning
dictionary dict