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 | Copyright (C) 2016-2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "regionFunctionObject.H"
27 #include "objectRegistry.H"
28 
29 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
30 
31 template<class ObjectType>
33 (
34  const word& fieldName
35 ) const
36 {
37  return obr_.foundObject<ObjectType>(fieldName);
38 }
39 
40 
41 template<class ObjectType>
43 (
44  const word& fieldName
45 ) const
46 {
47  return obr_.lookupObject<ObjectType>(fieldName);
48 }
49 
50 
51 template<class ObjectType>
53 (
54  const word& fieldName
55 )
56 {
57  return obr_.lookupObjectRef<ObjectType>(fieldName);
58 }
59 
60 
61 template<class ObjectType>
63 (
64  word& fieldName,
65  const tmp<ObjectType>& tfield,
66  bool cacheable
67 )
68 {
69  if (cacheable && fieldName == tfield().name())
70  {
72  << "Cannot store cache-able field with the name used in the cache."
73  << nl
74  << " Either choose a different name or cache the field"
75  << " and use the 'writeObjects' functionObject."
76  << endl;
77 
78  return false;
79  }
80 
81  if
82  (
83  fieldName.size()
84  && obr_.foundObject<ObjectType>(fieldName)
85  )
86  {
87  ObjectType& field = obr_.lookupObjectRef<ObjectType>(fieldName);
88 
89  // If there is a result field already registered assign to the new
90  // result field otherwise transfer ownership of the new result field to
91  // the object registry
92  if (&field != &tfield())
93  {
94  field = tfield;
95  }
96  else
97  {
98  obr_.objectRegistry::store(tfield.ptr());
99  }
100  }
101  else
102  {
103  if (fieldName.size() && fieldName != tfield().name())
104  {
105  tfield.ref().rename(fieldName);
106  }
107  else
108  {
109  fieldName = tfield().name();
110  }
111 
112  obr_.objectRegistry::store(tfield.ptr());
113  }
114 
115  return true;
116 }
117 
118 
119 // ************************************************************************* //
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const ObjectType & lookupObject(const word &fieldName) const
Lookup object from the objectRegistry.
A class for handling words, derived from string.
Definition: word.H:59
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the given field in the objectRegistry under the given name.
bool foundObject(const word &fieldName) const
Find field in the objectRegistry.
static const char nl
Definition: Ostream.H:262
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
#define WarningInFunction
Report a warning using Foam::Warning.
ObjectType & lookupObjectRef(const word &fieldName)
Lookup non-const object reference from the objectRegistry.
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:198
A class for managing temporary objects.
Definition: PtrList.H:53