functionObject.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "functionObject.H"
30#include "dictionary.H"
31#include "dlLibraryTable.H"
32#include "Time.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
40}
41
43
45
47
48
49// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
50
52{
53 if (useNamePrefix_)
54 {
55 return IOobject::scopedName(name_, name);
56 }
57
58 return name;
59}
60
61
62// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63
65(
66 const word& name,
67 const bool withNamePrefix
68)
69:
70 name_(name),
71 useNamePrefix_(withNamePrefix),
72 log(postProcess)
73{}
74
75
76// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
77
79(
80 const word& name,
81 const Time& runTime,
82 const dictionary& dict
83)
84{
85 const word functionType(dict.get<word>("type"));
86
88 << "Selecting function " << functionType << endl;
89
90
91 // Load any additional libraries
92 {
93 const auto finder =
94 dict.csearchCompat("libs", {{"functionObjectLibs", 1612}});
95
96 if (finder.found())
97 {
99 (
100 dict,
101 finder.ref().keyword(),
102 dictionaryConstructorTablePtr_
103 );
104 }
105 }
106
107 // This is the simplified version without compatibility messages
108 // runTime.libs().open
109 // (
110 // dict,
111 // "libs",
112 // dictionaryConstructorTablePtr_
113 // );
114
115 if (!dictionaryConstructorTablePtr_)
116 {
118 << "Cannot load function type " << functionType << nl << nl
119 << "Table of functionObjects is empty" << endl
120 << exit(FatalError);
121 }
122
123 auto* ctorPtr = dictionaryConstructorTable(functionType);
124
125 if (!ctorPtr)
126 {
127 // FatalError (not FatalIOError) to ensure it can be caught
128 // as an exception and ignored
130 (
131 "function",
132 functionType,
133 *dictionaryConstructorTablePtr_
134 ) << exit(FatalError);
135 }
136
137 return autoPtr<functionObject>(ctorPtr(name, runTime, dict));
138}
139
140
141// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142
144{
145 return name_;
146}
147
148
150{
151 return useNamePrefix_;
152}
153
154
156{
157 bool old(useNamePrefix_);
158 useNamePrefix_ = on;
159 return old;
160}
161
162
164{
165// OR
166// useNamePrefix_ = Switch("useNamePrefix", dict, defaultUseNamePrefix);
167
168 useNamePrefix_ =
170 (
171 "useNamePrefix",
172 defaultUseNamePrefix,
174 );
175
176
177 if (!postProcess)
178 {
179 log = dict.getOrDefault("log", true);
180 }
181
182 return true;
183}
184
185
187{
188 return true;
189}
190
191
193{
194 return true;
195}
196
197
199{
200 return false;
201}
202
203
205{
206 return false;
207}
208
209
211{}
212
213
215{}
216
217
218// * * * * * * * * * * * * unavailableFunctionObject * * * * * * * * * * * * //
219
221(
222 const word& name
223)
224:
226{}
227
228
230(
231 std::string message
232) const
233{
235 << "####" << nl
236 << " " << type() << " not available" << nl
237 << "####" << nl;
238
239 if (message.size())
240 {
242 << message.c_str() << nl;
243 }
244
246 << exit(FatalError);
247}
248
249
251{
252 return true;
253}
254
255
257{
258 return true;
259}
260
261
262// ************************************************************************* //
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: Time.H:510
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
const_searcher csearchCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
bool open(bool verbose=true)
Abstract functionObject to report when a real version is unavailable.
void carp(std::string message="") const
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
virtual bool filesModified() const
Did any file get changed during execution?
virtual bool execute()=0
Called at each ++ or += of the time-loop.
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
static word outputPrefix
Directory prefix.
bool useNamePrefix() const noexcept
Return the flag for adding a scoping name prefix.
static bool defaultUseNamePrefix
Global default for useNamePrefix.
word scopedName(const word &name) const
Return a scoped (prefixed) name.
static bool postProcess
Global post-processing mode switch.
virtual const word & type() const =0
Runtime type information.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
@ LITERAL
String literal.
Definition: keyType.H:81
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
void movePoints()
Update for new mesh geometry.
void updateMesh()
Update for new mesh topology.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
#define defineDebugSwitchWithName(Type, Name, Value)
Define the debug information, lookup as Name.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:457
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define DebugInfo
Report an information message using Foam::Info.
Namespace for OpenFOAM.
dimensionedScalar log(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
const direction noexcept
Definition: Scalar.H:223
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict