regionFunctionObject.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-2020 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 
26 #include "regionFunctionObject.H"
27 #include "Time.H"
28 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
36  defineTypeNameAndDebug(regionFunctionObject, 0);
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
42 
44 (
45  const word& fieldName
46 )
47 {
48  Warning
49  << " functionObjects::" << type() << " " << name()
50  << " cannot find required object " << fieldName << endl;
51 }
52 
53 
55 (
56  const word& fieldName
57 )
58 {
59  if (obr_.foundObject<regIOobject>(fieldName))
60  {
61  const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
62 
63  Log << " functionObjects::" << type() << " " << name()
64  << " writing field: " << field.name() << endl;
65 
66  field.write();
67 
68  return true;
69  }
70  else
71  {
72  return false;
73  }
74 }
75 
76 
78 (
79  const word& fieldName
80 )
81 {
82  if (foundObject<regIOobject>(fieldName))
83  {
84  regIOobject& resultObject = lookupObjectRef<regIOobject>(fieldName);
85 
86  if (resultObject.ownedByRegistry())
87  {
88  return resultObject.checkOut();
89  }
90  else
91  {
92  return false;
93  }
94  }
95  else
96  {
97  return true;
98  }
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
103 
105 (
106  const word& name,
107  const Time& runTime,
108  const dictionary& dict
109 )
110 :
111  functionObject(name),
112  time_(runTime),
113  obr_
114  (
116  (
118  )
119  )
120 {}
121 
122 
124 (
125  const word& name,
126  const objectRegistry& obr,
127  const dictionary& dict
128 )
129 :
130  functionObject(name),
131  time_(obr.time()),
132  obr_(obr)
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
137 
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
145 {
146  return functionObject::read(dict);
147 }
148 
149 
150 // ************************************************************************* //
const word & name() const
Return name.
Definition: IOobject.H:315
bool writeObject(const word &fieldName)
Write field if present in objectRegistry.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:325
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Abstract base-class for Time/database functionObjects.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:34
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
void cannotFindObject(const word &fieldName)
Prints a warning message that fieldName cannot be found.
virtual bool read(const dictionary &)
Read optional controls.
A class for handling words, derived from string.
Definition: word.H:59
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:241
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
const Time & time() const
Return time.
bool clearObject(const word &fieldName)
Clear field from the objectRegistry if present.
regionFunctionObject(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
defineTypeNameAndDebug(Qdot, 0)
messageStream Warning
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
#define Log
Report write to Foam::Info if the local log switch is true.
virtual bool write(const bool write=true) const
Write using setting from DB.
rDeltaTY field()
Registry of regIOobjects.
Namespace for OpenFOAM.