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-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
36 namespace Foam
37 {
38  defineDebugSwitchWithName(functionObject, "functionObject", 0);
39  defineRunTimeSelectionTable(functionObject, dictionary);
40 }
41 
43 
45 
46 
47 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
48 
50 {
51  return name_ + ":" + name;
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 :
59  name_(name),
60  log(postProcess)
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
65 
67 (
68  const word& name,
69  const Time& runTime,
70  const dictionary& dict
71 )
72 {
73  const word functionType(dict.get<word>("type"));
74 
75  DebugInfo
76  << "Selecting function " << functionType << endl;
77 
78 
79  // Load any additional libraries
80  {
81  const auto finder =
82  dict.csearchCompat("libs", {{"functionObjectLibs", 1612}});
83 
84  if (finder.found())
85  {
86  runTime.libs().open
87  (
88  dict,
89  finder.ref().keyword(),
90  dictionaryConstructorTablePtr_
91  );
92  }
93  }
94 
95  // This is the simplified version without compatibility messages
96  // runTime.libs().open
97  // (
98  // dict,
99  // "libs",
100  // dictionaryConstructorTablePtr_
101  // );
102 
103  if (!dictionaryConstructorTablePtr_)
104  {
106  << "Cannot load function type " << functionType << nl << nl
107  << "Table of functionObjects is empty" << endl
108  << exit(FatalError);
109  }
110 
111  auto cstrIter = dictionaryConstructorTablePtr_->cfind(functionType);
112 
113  if (!cstrIter.found())
114  {
115  // FatalError (not FatalIOError) to ensure it can be caught
116  // as an exception and ignored
118  (
119  "function",
120  functionType,
121  *dictionaryConstructorTablePtr_
122  ) << exit(FatalError);
123  }
124 
125  return autoPtr<functionObject>(cstrIter()(name, runTime, dict));
126 }
127 
128 
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 
132 {
133  return name_;
134 }
135 
136 
138 {
139  if (!postProcess)
140  {
141  log = dict.getOrDefault("log", true);
142  }
143 
144  return true;
145 }
146 
147 
149 {
150  return true;
151 }
152 
153 
155 {
156  return true;
157 }
158 
159 
161 {
162  return false;
163 }
164 
165 
167 {
168  return false;
169 }
170 
171 
173 {}
174 
175 
177 {}
178 
179 
180 // * * * * * * * * * * * * unavailableFunctionObject * * * * * * * * * * * * //
181 
183 (
184  const word& name
185 )
186 :
188 {}
189 
190 
192 (
193  std::string message
194 ) const
195 {
196  FatalError
197  << "####" << nl
198  << " " << type() << " not available" << nl
199  << "####" << nl;
200 
201  if (message.size())
202  {
203  FatalError
204  << message.c_str() << nl;
205  }
206 
207  FatalError
208  << exit(FatalError);
209 }
210 
211 
213 {
214  return true;
215 }
216 
217 
219 {
220  return true;
221 }
222 
223 
224 // ************************************************************************* //
Foam::functionObject::unavailableFunctionObject::execute
virtual bool execute()
No nothing.
Definition: functionObject.C:212
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObject::execute
virtual bool execute()=0
Called at each ++ or += of the time-loop.
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:62
Foam::defineDebugSwitchWithName
defineDebugSwitchWithName(pointMVCWeight, "pointMVCWeight", 0)
Foam::functionObject::New
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
Definition: functionObject.C:67
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:321
Foam::functionObject::unavailableFunctionObject::unavailableFunctionObject
unavailableFunctionObject(const word &name)
Construct with name.
Definition: functionObject.C:183
Foam::functionObject::unavailableFunctionObject::write
virtual bool write()
No nothing.
Definition: functionObject.C:218
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::functionObject::postProcess
static bool postProcess
Global post-processing mode switch.
Definition: functionObject.H:349
Foam::functionObject::read
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Definition: functionObject.C:137
Foam::functionObject::outputPrefix
static word outputPrefix
Directory prefix.
Definition: functionObject.H:352
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:121
FatalErrorInLookup
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:385
Foam::Time::libs
dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: Time.H:505
Foam::log
dimensionedScalar log(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:262
Foam::functionObject::adjustTimeStep
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Definition: functionObject.C:160
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObject::movePoints
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Definition: functionObject.C:176
Foam::dlLibraryTable::open
bool open(bool verbose=true)
Definition: dlLibraryTable.C:409
Foam::functionObject::unavailableFunctionObject::carp
void carp(std::string message="") const
Definition: functionObject.C:192
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::dictionary::csearchCompat
const_searcher csearchCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
Definition: dictionaryCompat.C:51
Foam::functionObject::end
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Definition: functionObject.C:154
Foam::functionObject::scopedName
word scopedName(const word &name) const
Return a scoped name, e.g. used to construct local field names.
Definition: functionObject.C:49
Time.H
Foam::autoPtr< Foam::functionObject >
Foam::functionObject::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: functionObject.C:172
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:359
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
dlLibraryTable.H
dictionary.H
Foam::functionObject::filesModified
virtual bool filesModified() const
Did any file get changed during execution?
Definition: functionObject.C:166
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
functionObject.H
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:122
Foam::functionObject::functionObject
functionObject(const word &name)
Construct from components.
Definition: functionObject.C:57