function1Base.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) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::function1Base
28 
29 Description
30  Base class for template-invariant parts of Function1
31 
32 SourceFiles
33  function1Base.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef function1Base_H
38 #define function1Base_H
39 
40 #include "dictionary.H"
41 #include "objectRegistry.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward Declarations
49 template<class Type> class Function1;
50 
51 /*---------------------------------------------------------------------------*\
52  Class function1Base Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class function1Base
56 :
57  public refCount
58 {
59  // Private Member Functions
60 
61  //- The associated registry, the time registry or nullptr
62  const objectRegistry* whichDb(const bool useTime) const noexcept;
63 
64 
65 protected:
66 
67  // Protected Data
68 
69  //- Name of entry
70  const word name_;
71 
72  //- Pointer to an object registry
73  const objectRegistry* obrPtr_;
74 
75 
76  // Protected Member Functions
77 
78  //- No copy assignment
79  void operator=(const function1Base&) = delete;
80 
81 
82 public:
83 
84  // Constructors
85 
86  //- Construct from entry name and optional registry
87  explicit function1Base
88  (
89  const word& entryName,
90  const objectRegistry* obrPtr = nullptr
91  );
92 
93  //- Construct from entry name, dictionary (unused) and optional registry
95  (
96  const word& entryName,
97  const dictionary& dict,
98  const objectRegistry* obrPtr = nullptr
99  );
100 
101  //- Copy construct
102  explicit function1Base(const function1Base& rhs);
103 
104 
105  //- Destructor
106  virtual ~function1Base();
107 
108 
109  // Member Functions
110 
111  // Access
112 
113  //- The name of the entry
114  const word& name() const noexcept
115  {
116  return name_;
117  }
118 
119  //- Return the associated registry or nullptr.
120  const objectRegistry* whichDb() const noexcept
121  {
122  return obrPtr_;
123  }
124 
125  //- Reset the associated objectRegistry
126  void resetDb(const objectRegistry* obrPtr = nullptr) noexcept;
127 
128  //- Reset the associated objectRegistry
129  void resetDb(const objectRegistry& db) noexcept;
130 
131  //- Return the object registry
132  // FatalError if object registry is not set
133  const objectRegistry& obr() const;
134 
135  //- Return true if this function was created with the time database
136  bool isTime() const noexcept;
137 
138  //- Return the time database
139  // FatalError if object registry is not set
140  const Time& time() const;
141 
142  //- Return the mesh database if this Function1 was created using a mesh
143  // Note: relies on refCast failure if the type is not correct
144  template<class MeshType>
145  const MeshType& mesh(const word& regionName = word::null) const
146  {
147  const objectRegistry* ptr = whichDb(!regionName.empty());
148 
149  if (!ptr)
150  {
152  << "Object registry not set"
153  << abort(FatalError);
154  }
155 
156  if (regionName.empty())
157  {
158  return refCast<const MeshType>(*ptr);
159  }
160  else
161  {
162  return ptr->lookupObject<MeshType>(regionName);
163  }
164  }
165 
166 
167  // Manipulation
168 
169  //- Convert time
170  virtual void userTimeToTime(const Time& t);
171 };
172 
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 } // End namespace Foam
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 #endif
181 
182 // ************************************************************************* //
Foam::function1Base::whichDb
const objectRegistry * whichDb() const noexcept
Return the associated registry or nullptr.
Definition: function1Base.H:119
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::function1Base::isTime
bool isTime() const noexcept
Return true if this function was created with the time database.
Definition: function1Base.C:117
Foam::function1Base::resetDb
void resetDb(const objectRegistry *obrPtr=nullptr) noexcept
Reset the associated objectRegistry.
Definition: function1Base.C:123
Foam::refCount
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
Foam::function1Base::obrPtr_
const objectRegistry * obrPtr_
Pointer to an object registry.
Definition: function1Base.H:72
Foam::function1Base::name_
const word name_
Name of entry.
Definition: function1Base.H:69
objectRegistry.H
Foam::function1Base::time
const Time & time() const
Return the time database.
Definition: function1Base.C:104
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::function1Base::obr
const objectRegistry & obr() const
Return the object registry.
Definition: function1Base.C:92
Foam::function1Base
Base class for template-invariant parts of Function1.
Definition: function1Base.H:54
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
Foam::function1Base::function1Base
function1Base(const word &entryName, const objectRegistry *obrPtr=nullptr)
Construct from entry name and optional registry.
Definition: function1Base.C:51
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::function1Base::~function1Base
virtual ~function1Base()
Destructor.
Definition: function1Base.C:86
Foam::function1Base::name
const word & name() const noexcept
The name of the entry.
Definition: function1Base.H:113
Foam::function1Base::operator=
void operator=(const function1Base &)=delete
No copy assignment.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
dictionary.H
Foam::function1Base::mesh
const MeshType & mesh(const word &regionName=word::null) const
Return the mesh database if this Function1 was created using a mesh.
Definition: function1Base.H:144
Foam::function1Base::userTimeToTime
virtual void userTimeToTime(const Time &t)
Convert time.
Definition: function1Base.C:135