regionFunctionObject.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) 2016 OpenFOAM Foundation
9  Copyright (C) 2016-2019 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 "regionFunctionObject.H"
30 #include "Time.H"
31 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
39  defineTypeNameAndDebug(regionFunctionObject, 0);
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
45 
48 {
49  if (!obrPtr_ && !subRegistryName_.empty())
50  {
51  // Recursive - so we also find things registered on Time
53 
54  // Also search functionObject output ("functionObjectObjects")
55  if (!obrPtr_)
56  {
57  obrPtr_ =
59  }
60  }
61 
62  return (obrPtr_ ? *obrPtr_ : obr_);
63 }
64 
65 
67 (
68  const word& fieldName
69 )
70 {
71  const regIOobject* ptr = this->cfindObject<regIOobject>(fieldName);
72 
73  if (ptr)
74  {
75  Log << " functionObjects::" << type() << " " << name()
76  << " writing field: " << ptr->name() << endl;
77 
78  ptr->write();
79 
80  return true;
81  }
82 
83  return false;
84 }
85 
86 
88 (
89  const word& fieldName
90 )
91 {
92  // Same as getObjectPtr, since the object is already non-const
93  regIOobject* ptr = this->findObject<regIOobject>(fieldName);
94 
95  if (ptr)
96  {
97  if (ptr->ownedByRegistry())
98  {
99  return ptr->checkOut();
100  }
101  else
102  {
103  return false;
104  }
105  }
106 
107  return true;
108 }
109 
110 
112 (
113  const wordList& objNames
114 )
115 {
116  for (const word& objName : objNames)
117  {
118  regIOobject* ptr = this->findObject<regIOobject>(objName);
119 
120  if (ptr && ptr->ownedByRegistry())
121  {
122  ptr->checkOut();
123  }
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
129 
131 (
132  const word& name,
133  const Time& runTime,
134  const dictionary& dict
135 )
136 :
138  subRegistryName_(dict.lookupOrDefault<word>("subRegion", word::null)),
139  obr_
140  (
141  runTime.lookupObject<objectRegistry>
142  (
143  dict.lookupOrDefault("region", polyMesh::defaultRegion)
144  )
145  ),
146  obrPtr_(nullptr)
147 {}
148 
149 
151 (
152  const word& name,
153  const objectRegistry& obr,
154  const dictionary& dict
155 )
156 :
157  stateFunctionObject(name, obr.time()),
158  subRegistryName_(dict.lookupOrDefault<word>("subRegion", word::null)),
159  obr_(obr),
160  obrPtr_(nullptr)
161 {}
162 
163 
164 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 
167 {
169 
170  subRegistryName_ = dict.lookupOrDefault<word>("subRegion", word::null);
171 
172  obrPtr_ = nullptr;
173 
174  return true;
175 }
176 
177 
178 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::regionFunctionObject::obr_
const objectRegistry & obr_
Reference to the region objectRegistry.
Definition: regionFunctionObject.H:100
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::regionFunctionObject::subRegistryName_
word subRegistryName_
Name for alternative object registry.
Definition: regionFunctionObject.H:97
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:312
Foam::functionObjects::timeFunctionObject::storedObjects
objectRegistry & storedObjects()
Definition: timeFunctionObject.C:63
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::functionObjects::stateFunctionObject
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: stateFunctionObject.H:67
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
polyMesh.H
Foam::functionObjects::regionFunctionObject::clearObjects
void clearObjects(const wordList &objNames)
Clear fields from the (sub) objectRegistry if present.
Definition: regionFunctionObject.C:112
Foam::functionObjects::regionFunctionObject::regionFunctionObject
regionFunctionObject(const regionFunctionObject &)=delete
No copy construct.
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::regionFunctionObject::clearObject
bool clearObject(const word &fieldName)
Clear field from the (sub) objectRegistry if present.
Definition: regionFunctionObject.C:88
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: regIOobjectWrite.C:170
Foam::functionObjects::regionFunctionObject::obrPtr_
const objectRegistry * obrPtr_
Pointer to alternative (eg, sub-region) objectRegistry.
Definition: regionFunctionObject.H:104
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::functionObject::read
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Definition: functionObject.C:137
regionFunctionObject.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:121
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
Foam::regIOobject::ownedByRegistry
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:31
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Time.H
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::regIOobject::checkOut
bool checkOut()
Remove all file watches and remove object from registry.
Definition: regIOobject.C:237
Foam::objectRegistry::cfindObject
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:390
Foam::List< word >
Foam::functionObjects::regionFunctionObject::obr
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Definition: regionFunctionObject.C:47
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::functionObjects::regionFunctionObject::writeObject
bool writeObject(const word &fieldName)
Write field if present in the (sub) objectRegistry.
Definition: regionFunctionObject.C:67
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332