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-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 "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  if (!obrPtr_)
62  {
64  << "Could not locate subRegion \""
65  << subRegistryName_ << '"' << nl;
66  }
67  }
68 
69  return (obrPtr_ ? *obrPtr_ : obr_);
70 }
71 
72 
74 (
75  const word& fieldName
76 )
77 {
78  const regIOobject* ptr = this->cfindObject<regIOobject>(fieldName);
79 
80  if (ptr)
81  {
82  Log << " functionObjects::" << type() << " " << name()
83  << " writing field: " << ptr->name() << endl;
84 
85  ptr->write();
86 
87  return true;
88  }
89 
90  return false;
91 }
92 
93 
95 (
96  const word& fieldName
97 )
98 {
99  // Same as getObjectPtr, since the object is already non-const
100  regIOobject* ptr = this->findObject<regIOobject>(fieldName);
101 
102  if (ptr)
103  {
104  if (ptr->ownedByRegistry())
105  {
106  return ptr->checkOut();
107  }
108  else
109  {
110  return false;
111  }
112  }
113 
114  return true;
115 }
116 
117 
119 (
120  const wordList& objNames
121 )
122 {
123  for (const word& objName : objNames)
124  {
125  regIOobject* ptr = this->findObject<regIOobject>(objName);
126 
127  if (ptr && ptr->ownedByRegistry())
128  {
129  ptr->checkOut();
130  }
131  }
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
136 
138 (
139  const word& name,
140  const Time& runTime,
141  const dictionary& dict
142 )
143 :
145  subRegistryName_(dict.getOrDefault<word>("subRegion", word::null)),
146  obr_
147  (
148  runTime.lookupObject<objectRegistry>
149  (
150  dict.getOrDefault("region", polyMesh::defaultRegion)
151  )
152  ),
153  obrPtr_(nullptr)
154 {}
155 
156 
158 (
159  const word& name,
160  const objectRegistry& obr,
161  const dictionary& dict
162 )
163 :
164  stateFunctionObject(name, obr.time()),
165  subRegistryName_(dict.getOrDefault<word>("subRegion", word::null)),
166  obr_(obr),
167  obrPtr_(nullptr)
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
174 {
176 
177  subRegistryName_ = dict.getOrDefault<word>("subRegion", word::null);
178 
179  obrPtr_ = nullptr;
180 
181  return true;
182 }
183 
184 
185 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::regionFunctionObject::obr_
const objectRegistry & obr_
Reference to the region objectRegistry.
Definition: regionFunctionObject.H:103
Log
#define Log
Definition: PDRblock.C:35
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:70
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:100
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:318
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:350
polyMesh.H
Foam::functionObjects::regionFunctionObject::clearObjects
void clearObjects(const wordList &objNames)
Clear fields from the (sub) objectRegistry if present.
Definition: regionFunctionObject.C:119
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:95
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: regIOobjectWrite.C:165
Foam::functionObjects::regionFunctionObject::obrPtr_
const objectRegistry * obrPtr_
Pointer to alternative (eg, sub-region) objectRegistry.
Definition: regionFunctionObject.H:107
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:173
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
Time.H
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:71
Foam::regIOobject::checkOut
bool checkOut()
Remove all file watches and remove object from registry.
Definition: regIOobject.C:241
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::nl
constexpr char nl
Definition: Ostream.H:385
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::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
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:74
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303