Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::function1Base
28
29Description
30 Base class for template-invariant parts of Function1
31
32SourceFiles
33 function1Base.C
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef Foam_function1Base_H
38#define Foam_function1Base_H
39
40#include "dictionary.H"
41#include "objectRegistry.H"
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45namespace Foam
46{
47
48// Forward Declarations
49template<class Type> class Function1;
51/*---------------------------------------------------------------------------*\
52 Class function1Base Declaration
53\*---------------------------------------------------------------------------*/
54
55class 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
65protected:
66
67 // Protected Data
68
69 //- Name of entry
70 const word name_;
71
72 //- Pointer to an object registry
75
76 // Protected Member Functions
77
78 //- No copy assignment
79 void operator=(const function1Base&) = delete;
80
81
82public:
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;
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176} // End namespace Foam
177
178// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179
180#endif
181
182// ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition Function1.H:92
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const Time & time() const
Return the time database.
void resetDb(const objectRegistry *obrPtr=nullptr) noexcept
Reset the associated objectRegistry.
void operator=(const function1Base &)=delete
No copy assignment.
const objectRegistry & obr() const
Return the object registry.
bool isTime() const noexcept
Return true if this function was created with the time database.
const objectRegistry * obrPtr_
Pointer to an object registry.
const word & name() const noexcept
The name of the entry.
function1Base(const word &entryName, const objectRegistry *obrPtr=nullptr)
Construct from entry name and optional registry.
const MeshType & mesh(const word &regionName=word::null) const
Return the mesh database if this Function1 was created using a mesh.
const objectRegistry * whichDb() const noexcept
Return the associated registry or nullptr.
virtual ~function1Base()
Destructor.
virtual void userTimeToTime(const Time &t)
Convert time.
const word name_
Name of entry.
Registry of regIOobjects.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
constexpr refCount() noexcept
Default construct, initializing count to 0.
Definition refCount.H:63
A class for handling words, derived from Foam::string.
Definition word.H:66
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Namespace for OpenFOAM.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
errorManip< error > abort(error &err)
Definition errorManip.H:139
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
dictionary dict