Loading...
Searching...
No Matches
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"
32#include "Time.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38 defineDebugSwitchWithName(functionObject, "functionObject", 0);
40}
41
43
45
47
48
49// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
50
52{
53 if (useNamePrefix_)
54 {
55 return IOobject::scopedName(name_, name);
56 }
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),
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.good())
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 }
137 return autoPtr<functionObject>(ctorPtr(name, runTime, dict));
138}
139
140
141// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144{
145 return name_;
146}
147
150{
151 return useNamePrefix_;
152}
153
154
155bool Foam::functionObject::useNamePrefix(bool on) noexcept
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_ =
169 dict.getOrDefault
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
186bool Foam::functionObject::execute(const label)
187{
188 return true;
189}
190
193{
194 return true;
195}
196
199{
200 return false;
201}
202
205{
206 return false;
208
209
211{}
212
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;
244
246 << exit(FatalError);
247}
248
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:50
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
dlLibraryTable & libs() const noexcept
Mutable access to the loaded dynamic libraries.
Definition Time.H:722
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
bool open(bool verbose=true)
Open named, but unopened libraries. These names will normally have been added with push_back().
void carp(std::string message="") const
Report it is unavailable, emitting a FatalError for try/catch in the caller.
unavailableFunctionObject(const word &name)
Construct with name.
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 void movePoints(const polyMesh &mesh)
Update for changes of mesh.
virtual bool execute()=0
Called at each ++ or += of the time-loop.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
static word outputPrefix
Directory prefix.
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
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.
bool log
Flag to write log into Info.
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
functionObject(const word &name, const bool withNamePrefix=defaultUseNamePrefix)
Construct from components.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
@ LITERAL
String literal.
Definition keyType.H:82
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A class for handling words, derived from Foam::string.
Definition word.H:66
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:607
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
#define DebugInfo
Report an information message using Foam::Info.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
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...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict