regionFunctionObject.H
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-2021 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
27Class
28 Foam::functionObjects::regionFunctionObject
29
30Description
31 Specialization of Foam::functionObject for a region and providing a
32 reference to the region Foam::objectRegistry.
33
34 Also provides support for referencing an alternative objectRegistry
35 that can hold fields. This may be used, for example, to access
36 stored surfaces and fields.
37
38 Dictionary controls
39 \table
40 Property | Description | Type | Req'd | Dflt
41 region | Name of the mesh region | word | no | region0
42 subRegion | Name for alternative objectRegistry | word | no | ""
43 \endtable
44
45See also
46 Foam::functionObjects::stateFunctionObject
47
48SourceFiles
49 regionFunctionObject.C
50
51\*---------------------------------------------------------------------------*/
52
53#ifndef functionObjects_regionFunctionObject_H
54#define functionObjects_regionFunctionObject_H
55
56#include "stateFunctionObject.H"
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59
60namespace Foam
61{
62
63// Forward Declarations
64class objectRegistry;
65
66namespace functionObjects
67{
68
69/*---------------------------------------------------------------------------*\
70 Class regionFunctionObject Declaration
71\*---------------------------------------------------------------------------*/
72
73class regionFunctionObject
74:
75 public stateFunctionObject
76{
77protected:
78
79 // Protected Member Data
80
81 //- Name for alternative object registry
83
84 //- Reference to the region objectRegistry
85 const objectRegistry& obr_;
86
87 //- Pointer to alternative (eg, sub-region) objectRegistry.
88 // If a sub-region is not in effect, this is a nullptr
89 mutable const objectRegistry* obrPtr_;
91
92 // Protected Member Functions
93
94 //- The region or sub-region registry being used
95 virtual const objectRegistry& obr() const;
96
97
98 //- Find object (eg, a field) in the (sub) objectRegistry
99 template<class ObjectType>
100 bool foundObject(const word& fieldName) const;
101
102 //- Return const pointer to the object (eg, a field) in the
103 //- (sub) objectRegistry.
104 //
105 // \return nullptr if the object was not found or had incorrect type.
106 template<class ObjectType>
107 const ObjectType* cfindObject(const word& fieldName) const;
108
109 //- Return const pointer to the object (eg, a field) in the
110 //- (sub) objectRegistry.
111 //
112 // \return nullptr if the object was not found or had incorrect type.
113 template<class ObjectType>
114 const ObjectType* findObject(const word& fieldName) const;
115
116 //- Return non-const pointer to the object of the given Type,
117 //- (sub) objectRegistry.
118 //
119 // \return nullptr if the object was not found or had incorrect type.
120 template<class ObjectType>
121 ObjectType* findObject(const word& fieldName);
122
123 //- Return non-const pointer to the object of the given Type,
124 //- using a const-cast to have it behave like a mutable.
125 // Exercise caution when using.
126 //
127 // \return nullptr if the object was not found or had incorrect type.
128 template<class ObjectType>
129 ObjectType* getObjectPtr(const word& fieldName) const;
130
131 //- Lookup and return object (eg, a field) from the (sub) objectRegistry
132 template<class ObjectType>
133 const ObjectType& lookupObject(const word& fieldName) const;
134
135 //- Lookup and return object (eg, a field) from the (sub) objectRegistry
136 template<class ObjectType>
137 ObjectType& lookupObjectRef(const word& fieldName) const;
138
139 //- Store the field in the (sub) objectRegistry under the given name
140 // Note: sets the fieldName to tfield().name() if not already set
141 template<class ObjectType>
142 bool store
143 (
144 word& fieldName,
145 const tmp<ObjectType>& tfield,
146 bool cacheable = false
147 );
148
149 //- Store the field in an optional objectRegistry under the given name
150 template<class ObjectType>
151 bool storeInDb
152 (
153 const word& fieldName,
154 const tmp<ObjectType>& tfield,
155 const objectRegistry& obr
156 );
157
158 //- Write field if present in the (sub) objectRegistry
159 bool writeObject(const word& fieldName);
160
161 //- Clear field from the (sub) objectRegistry if present
162 bool clearObject(const word& fieldName);
163
164 //- Clear fields from the (sub) objectRegistry if present
165 void clearObjects(const wordList& objNames);
166
167
168 //- No copy construct
170
171 //- No copy assignment
172 void operator=(const regionFunctionObject&) = delete;
173
174
175public:
176
177 //- Runtime type information
178 TypeName("regionFunctionObject");
179
180
181 // Constructors
182
183 //- Construct from Time and dictionary.
184 // The region objectRegistry is looked-up runTime with the name
185 // looked-up from the dictionary (defaults to polyMesh::defaultRegion)
187 (
188 const word& name,
189 const Time& runTime,
190 const dictionary& dict
191 );
192
193 //- Construct from the region objectRegistry and dictionary
196 const word& name,
197 const objectRegistry& obr,
198 const dictionary& dict
199 );
200
201
202 //- Destructor
203 virtual ~regionFunctionObject() = default;
204
205
206 // Member Functions
207
208 //- Read optional controls
209 virtual bool read(const dictionary& dict);
210
211
212 // Housekeeping
213
214 //- Deprecated(2018-10)
215 // \deprecated(2018-10) - use findObject() method
216 template<class ObjectType>
217 FOAM_DEPRECATED_FOR(2018-10, "findObject / cfindObject() methods")
218 const ObjectType* lookupObjectPtr(const word& fieldName) const
219 {
220 return this->cfindObject<ObjectType>(fieldName);
221 }
222
223 //- Deprecated(2018-10)
224 // \deprecated(2018-10) - use getObjectPtr() method
225 template<class ObjectType>
226 FOAM_DEPRECATED_FOR(2018-10, "getObjectPtr() method")
227 ObjectType* lookupObjectRefPtr(const word& fieldName) const
228 {
229 return this->getObjectPtr<ObjectType>(fieldName);
230 }
231};
232
233
234// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236} // End namespace functionObjects
237} // End namespace Foam
238
239// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240
241#ifdef NoRepository
243#endif
245// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246
247#endif
248
249// ************************************************************************* //
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
const word & name() const noexcept
Return the name of this functionObject.
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
ObjectType * lookupObjectRefPtr(const word &fieldName) const
Deprecated(2018-10)
const ObjectType & lookupObject(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
const ObjectType * cfindObject(const word &fieldName) const
bool foundObject(const word &fieldName) const
Find object (eg, a field) in the (sub) objectRegistry.
const ObjectType * lookupObjectPtr(const word &fieldName) const
Deprecated(2018-10)
ObjectType * getObjectPtr(const word &fieldName) const
const objectRegistry & obr_
Reference to the region objectRegistry.
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
virtual ~regionFunctionObject()=default
Destructor.
void clearObjects(const wordList &objNames)
Clear fields from the (sub) objectRegistry if present.
regionFunctionObject(const regionFunctionObject &)=delete
No copy construct.
virtual bool read(const dictionary &dict)
Read optional controls.
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.
word subRegistryName_
Name for alternative object registry.
const objectRegistry * obrPtr_
Pointer to alternative (eg, sub-region) objectRegistry.
const ObjectType * findObject(const word &fieldName) const
void operator=(const regionFunctionObject &)=delete
No copy assignment.
bool writeObject(const word &fieldName)
Write field if present in the (sub) objectRegistry.
bool storeInDb(const word &fieldName, const tmp< ObjectType > &tfield, const objectRegistry &obr)
Store the field in an optional objectRegistry under the given name.
bool clearObject(const word &fieldName)
Clear field from the (sub) objectRegistry if present.
ObjectType & lookupObjectRef(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
TypeName("regionFunctionObject")
Runtime type information.
Base class for function objects, adding functionality to read/write state information (data required ...
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
Namespace for OpenFOAM.
dictionary dict
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73