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-------------------------------------------------------------------------------
11License
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
30#include "Time.H"
31#include "polyMesh.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
37namespace functionObjects
38{
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// ************************************************************************* //
#define Log
Definition: PDRblock.C:35
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
const objectRegistry & obr_
Reference to the region objectRegistry.
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
void clearObjects(const wordList &objNames)
Clear fields from the (sub) objectRegistry if present.
word subRegistryName_
Name for alternative object registry.
const objectRegistry * obrPtr_
Pointer to alternative (eg, sub-region) objectRegistry.
bool writeObject(const word &fieldName)
Write field if present in the (sub) objectRegistry.
bool clearObject(const word &fieldName)
Clear field from the (sub) objectRegistry if present.
Base class for function objects, adding functionality to read/write state information (data required ...
Registry of regIOobjects.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
virtual bool write(const bool valid=true) const
Write using setting from DB.
bool ownedByRegistry() const noexcept
Is this object owned by the registry?
Definition: regIOobjectI.H:37
bool checkOut()
Remove all file watches and remove object from registry.
Definition: regIOobject.C:224
A class for handling words, derived from Foam::string.
Definition: word.H:68
static const word null
An empty word.
Definition: word.H:80
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict