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-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 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 
78 protected:
79 
80  // Protected Member Data
81 
82  //- Name for alternative object registry
83  word subRegistryName_;
84 
85  //- Reference to the region objectRegistry
86  const objectRegistry& obr_;
87 
88  //- Pointer to alternative (eg, sub-region) objectRegistry.
89  // If a sub-region is not in effect, this is a nullptr
90  mutable const objectRegistry* obrPtr_;
91 
92 
93  // Protected Member Functions
94 
95  //- The region or sub-region registry being used
96  virtual const objectRegistry& obr() const;
97 
98 
99  //- Find object (eg, a field) in the (sub) objectRegistry
100  template<class ObjectType>
101  bool foundObject(const word& fieldName) const;
102 
103  //- Return const pointer to the object (eg, a field) in the
104  //- (sub) objectRegistry.
105  //
106  // \return nullptr if the object was not found or had incorrect type.
107  template<class ObjectType>
108  const ObjectType* cfindObject(const word& fieldName) const;
109 
110  //- Return const pointer to the object (eg, a field) in the
111  //- (sub) objectRegistry.
112  //
113  // \return nullptr if the object was not found or had incorrect type.
114  template<class ObjectType>
115  const ObjectType* findObject(const word& fieldName) const;
116 
117  //- Return non-const pointer to the object of the given Type,
118  //- (sub) objectRegistry.
119  //
120  // \return nullptr if the object was not found or had incorrect type.
121  template<class ObjectType>
122  ObjectType* findObject(const word& fieldName);
123 
124  //- Return non-const pointer to the object of the given Type,
125  //- using a const-cast to have it behave like a mutable.
126  // Exercise caution when using.
127  //
128  // \return nullptr if the object was not found or had incorrect type.
129  template<class ObjectType>
130  ObjectType* getObjectPtr(const word& fieldName) const;
131 
132  //- Lookup and return object (eg, a field) from the (sub) objectRegistry
133  template<class ObjectType>
134  const ObjectType& lookupObject(const word& fieldName) const;
135 
136  //- Lookup and return object (eg, a field) from the (sub) objectRegistry
137  template<class ObjectType>
138  ObjectType& lookupObjectRef(const word& fieldName) const;
139 
140  //- Store the field in the (sub) objectRegistry under the given name
141  // Note: sets the fieldName to tfield().name() if not already set
142  template<class ObjectType>
143  bool store
144  (
145  word& fieldName,
146  const tmp<ObjectType>& tfield,
147  bool cacheable = false
148  );
149 
150  //- Write field if present in the (sub) objectRegistry
151  bool writeObject(const word& fieldName);
152 
153  //- Clear field from the (sub) objectRegistry if present
154  bool clearObject(const word& fieldName);
155 
156  //- Clear fields from the (sub) objectRegistry if present
157  void clearObjects(const wordList& objNames);
158 
159 
160  //- No copy construct
162 
163  //- No copy assignment
164  void operator=(const regionFunctionObject&) = delete;
165 
166 
167 public:
168 
169  //- Runtime type information
170  TypeName("regionFunctionObject");
171 
172 
173  // Constructors
174 
175  //- Construct from Time and dictionary.
176  // The region objectRegistry is looked-up runTime with the name
177  // looked-up from the dictionary (defaults to polyMesh::defaultRegion)
179  (
180  const word& name,
181  const Time& runTime,
182  const dictionary& dict
183  );
184 
185  //- Construct from the region objectRegistry and dictionary
187  (
188  const word& name,
189  const objectRegistry& obr,
190  const dictionary& dict
191  );
192 
193 
194  //- Destructor
195  virtual ~regionFunctionObject() = default;
196 
197 
198  // Member Functions
199 
200  //- Read optional controls
201  virtual bool read(const dictionary& dict);
202 
203 
204  // Housekeeping
205 
206  //- Deprecated(2018-10)
207  // \deprecated(2018-10) - use findObject() method
208  template<class ObjectType>
209  FOAM_DEPRECATED_FOR(2018-10, "findObject / cfindObject() methods")
210  const ObjectType* lookupObjectPtr(const word& fieldName) const
211  {
212  return this->cfindObject<ObjectType>(fieldName);
213  }
214 
215  //- Deprecated(2018-10)
216  // \deprecated(2018-10) - use getObjectPtr() method
217  template<class ObjectType>
218  FOAM_DEPRECATED_FOR(2018-10, "getObjectPtr() method")
219  ObjectType* lookupObjectRefPtr(const word& fieldName) const
220  {
221  return this->getObjectPtr<ObjectType>(fieldName);
222  }
223 };
224 
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
228 } // End namespace functionObjects
229 } // End namespace Foam
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 #ifdef NoRepository
235 #endif
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 #endif
240 
241 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::regionFunctionObject::obr_
const objectRegistry & obr_
Reference to the region objectRegistry.
Definition: regionFunctionObject.H:103
Foam::functionObjects::regionFunctionObject::lookupObjectPtr
const ObjectType * lookupObjectPtr(const word &fieldName) const
Deprecated(2018-10)
Definition: regionFunctionObject.H:227
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:62
Foam::functionObjects::regionFunctionObject::subRegistryName_
word subRegistryName_
Name for alternative object registry.
Definition: regionFunctionObject.H:100
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:67
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:107
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:121
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:236
Foam::functionObjects::regionFunctionObject::TypeName
TypeName("regionFunctionObject")
Runtime type information.
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::List< word >
Foam::functionObjects::regionFunctionObject::obr
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Definition: regionFunctionObject.C:47
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