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 -------------------------------------------------------------------------------
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 Class
28  Foam::functionObjects::regionFunctionObject
29 
30 Description
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 
45 See also
46  Foam::functionObjects::stateFunctionObject
47 
48 SourceFiles
49  regionFunctionObject.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef functionObjects_regionFunctionObject_H
54 #define functionObjects_regionFunctionObject_H
55 
56 #include "stateFunctionObject.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 // Forward Declarations
64 class objectRegistry;
65 
66 namespace functionObjects
67 {
68 
69 /*---------------------------------------------------------------------------*\
70  Class regionFunctionObject Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 class regionFunctionObject
74 :
75  public stateFunctionObject
76 {
77 protected:
78 
79  // Protected Member Data
80 
81  //- Name for alternative object registry
82  word subRegistryName_;
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_;
90 
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 
175 public:
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
195  (
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 
236 } // End namespace functionObjects
237 } // End namespace Foam
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 #ifdef NoRepository
243 #endif
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #endif
248 
249 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::regionFunctionObject::obr_
const objectRegistry & obr_
Reference to the region objectRegistry.
Definition: regionFunctionObject.H:102
Foam::functionObjects::regionFunctionObject::lookupObjectPtr
const ObjectType * lookupObjectPtr(const word &fieldName) const
Deprecated(2018-10)
Definition: regionFunctionObject.H:235
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::regionFunctionObject::subRegistryName_
word subRegistryName_
Name for alternative object registry.
Definition: regionFunctionObject.H:99
Foam::functionObjects::regionFunctionObject::lookupObject
const ObjectType & lookupObject(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
Definition: regionFunctionObjectTemplates.C:87
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::functionObjects::regionFunctionObject::lookupObjectRef
ObjectType & lookupObjectRef(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
Definition: regionFunctionObjectTemplates.C:97
Foam::functionObjects::stateFunctionObject
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: stateFunctionObject.H:69
Foam::functionObjects::regionFunctionObject::store
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.
Definition: regionFunctionObjectTemplates.C:107
Foam::functionObjects::regionFunctionObject::cfindObject
const ObjectType * cfindObject(const word &fieldName) const
Definition: regionFunctionObjectTemplates.C:46
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::foundObject
bool foundObject(const word &fieldName) const
Find object (eg, a field) in the (sub) objectRegistry.
Definition: regionFunctionObjectTemplates.C:36
Foam::functionObjects::regionFunctionObject::clearObject
bool clearObject(const word &fieldName)
Clear field from the (sub) objectRegistry if present.
Definition: regionFunctionObject.C:95
Foam::functionObjects::regionFunctionObject::obrPtr_
const objectRegistry * obrPtr_
Pointer to alternative (eg, sub-region) objectRegistry.
Definition: regionFunctionObject.H:106
Foam::functionObjects::regionFunctionObject::~regionFunctionObject
virtual ~regionFunctionObject()=default
Destructor.
Foam::functionObjects::regionFunctionObject::operator=
void operator=(const regionFunctionObject &)=delete
No copy assignment.
Foam::functionObjects::regionFunctionObject::findObject
const ObjectType * findObject(const word &fieldName) const
Definition: regionFunctionObjectTemplates.C:56
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:123
regionFunctionObjectTemplates.C
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::regionFunctionObject::getObjectPtr
ObjectType * getObjectPtr(const word &fieldName) const
Definition: regionFunctionObjectTemplates.C:77
Foam::functionObjects::regionFunctionObject::lookupObjectRefPtr
ObjectType * lookupObjectRefPtr(const word &fieldName) const
Deprecated(2018-10)
Definition: regionFunctionObject.H:244
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObjects::regionFunctionObject::TypeName
TypeName("regionFunctionObject")
Runtime type information.
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::functionObjects::regionFunctionObject::storeInDb
bool storeInDb(const word &fieldName, const tmp< ObjectType > &tfield, const objectRegistry &obr)
Store the field in an optional objectRegistry under the given name.
Definition: regionFunctionObjectTemplates.C:165
stateFunctionObject.H
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
Foam::functionObjects::regionFunctionObject
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
Definition: regionFunctionObject.H:90
Foam::functionObjects::regionFunctionObject::writeObject
bool writeObject(const word &fieldName)
Write field if present in the (sub) objectRegistry.
Definition: regionFunctionObject.C:74