regionFunctionObjectTemplates.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-2018 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 "objectRegistry.H"
31 
32 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
33 
34 template<class ObjectType>
36 (
37  const word& fieldName
38 ) const
39 {
40  return obr().foundObject<ObjectType>(fieldName);
41 }
42 
43 
44 template<class ObjectType>
46 (
47  const word& fieldName
48 ) const
49 {
50  return obr().cfindObject<ObjectType>(fieldName);
51 }
52 
53 
54 template<class ObjectType>
56 (
57  const word& fieldName
58 ) const
59 {
60  return obr().findObject<ObjectType>(fieldName);
61 }
62 
63 
64 template<class ObjectType>
66 (
67  const word& fieldName
68 )
69 {
70  // Need getObjectPtr to bypass const access on the objectRegistry
71  return obr().getObjectPtr<ObjectType>(fieldName);
72 }
73 
74 
75 template<class ObjectType>
77 (
78  const word& fieldName
79 ) const
80 {
81  return obr().getObjectPtr<ObjectType>(fieldName);
82 }
83 
84 
85 template<class ObjectType>
87 (
88  const word& fieldName
89 ) const
90 {
91  return obr().lookupObject<ObjectType>(fieldName);
92 }
93 
94 
95 template<class ObjectType>
97 (
98  const word& fieldName
99 ) const
100 {
101  return obr().lookupObjectRef<ObjectType>(fieldName);
102 }
103 
104 
105 template<class ObjectType>
107 (
108  word& fieldName,
109  const tmp<ObjectType>& tfield,
110  bool cacheable
111 )
112 {
113  if (cacheable && fieldName == tfield().name())
114  {
116  << "Cannot store cache-able field with the name used in the cache."
117  << nl
118  << " Either choose a different name or cache the field"
119  << " and use the 'writeObjects' functionObject."
120  << endl;
121 
122  return false;
123  }
124 
125  if (fieldName.size() && foundObject<ObjectType>(fieldName))
126  {
127  const ObjectType& field = lookupObject<ObjectType>(fieldName);
128 
129  // If there is a result field already registered, assign to the new
130  // result field. Otherwise transfer ownership of the new result field to
131  // the object registry
132  if (&field != &tfield())
133  {
134  const_cast<ObjectType&>(field) = tfield;
135  }
136  else
137  {
138  obr().objectRegistry::store(tfield.ptr());
139  }
140  }
141  else
142  {
143  if (fieldName.size() && fieldName != tfield().name())
144  {
145  tfield.ref().rename(fieldName);
146  }
147  else
148  {
149  fieldName = tfield().name();
150  }
151 
152  obr().objectRegistry::store(tfield.ptr());
153  }
154 
155  return true;
156 }
157 
158 
159 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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
objectRegistry.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
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::foundObject
bool foundObject(const word &fieldName) const
Find object (eg, a field) in the (sub) objectRegistry.
Definition: regionFunctionObjectTemplates.C:36
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:228
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
field
rDeltaTY field()
regionFunctionObject.H
Foam::functionObjects::regionFunctionObject::findObject
const ObjectType * findObject(const word &fieldName) const
Definition: regionFunctionObjectTemplates.C:56
Foam::tmp::ptr
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
Definition: tmpI.H:259
Foam::functionObjects::regionFunctionObject::getObjectPtr
ObjectType * getObjectPtr(const word &fieldName) const
Definition: regionFunctionObjectTemplates.C:77
Foam::nl
constexpr char nl
Definition: Ostream.H:385
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303