functionObject.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "functionObject.H"
27 #include "dictionary.H"
28 #include "dlLibraryTable.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
37 }
38 
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  const word& name,
47  const Time& runTime
48 )
49 :
50  name_(name),
51  time_(runTime),
52  log(false),
53  executeAtStart_(true)
54 {}
55 
56 
58 (
59  const word& name,
60  const Time& runTime,
61  const dictionary& dict
62 )
63 :
64  functionObject(name, runTime)
65 {
66  read(dict);
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
71 
73 (
74  const word& name,
75  const Time& runTime,
76  const dictionary& dict
77 )
78 {
79  const word functionType(dict.lookup("type"));
80 
81  if (debug)
82  {
83  Info<< "Selecting function " << functionType << endl;
84  }
85 
86  if
87  (
88  !dictionaryConstructorTablePtr_
89  || dictionaryConstructorTablePtr_->find(functionType)
90  == dictionaryConstructorTablePtr_->end()
91  )
92  {
93  if
94  (
95  !libs.open
96  (
97  dict,
98  "libs",
99  dictionaryConstructorTablePtr_
100  )
101  )
102  {
103  libs.open("lib" + functionType.remove(':') + ".so", false);
104  }
105 
106  if (!dictionaryConstructorTablePtr_)
107  {
109  << "Unknown function type "
110  << functionType << nl << nl
111  << "Table of functionObjects is empty"
112  << exit(FatalError);
113  }
114  }
115 
116  dictionaryConstructorTable::iterator cstrIter =
117  dictionaryConstructorTablePtr_->find(functionType);
118 
119  if (cstrIter == dictionaryConstructorTablePtr_->end())
120  {
122  << "Unknown function type "
123  << functionType << nl << nl
124  << "Valid functions are : " << nl
125  << dictionaryConstructorTablePtr_->sortedToc()
126  << exit(FatalError);
127  }
128 
129  return autoPtr<functionObject>(cstrIter()(name, runTime, dict));
130 }
131 
132 
133 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
134 
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 
142 {
143  return name_;
144 }
145 
146 
148 {
149  log = dict.lookupOrDefault<Switch>("log", postProcess);
150 
151  if (!postProcess)
152  {
153  executeAtStart_ =
154  dict.lookupOrDefault<Switch>("executeAtStart", executeAtStart_);
155  }
156 
157  return true;
158 }
159 
160 
162 {
163  return executeAtStart_;
164 }
165 
166 
168 {
169  return true;
170 }
171 
172 
174 {
175  return vGreat;
176 }
177 
178 
180 {
181  return vGreat;
182 }
183 
184 
186 {}
187 
188 
190 {}
191 
192 
194 {}
195 
196 
198 {}
199 
200 
201 // ************************************************************************* //
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
T lookupOrDefault(const word &, const T &, const bool writeDefault=writeOptionalEntries > 0) const
Find and return a T, if not found return the given default.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
Abstract base-class for Time/database functionObjects.
functionObject(const word &name, const Time &runTime)
Construct from components.
virtual ~functionObject()
Destructor.
virtual bool executeAtStart() const
Return true if the functionObject should be executed at the start.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual scalar maxDeltaT() const
Return the maximum time-step for stable operation.
virtual void movePoints(const polyMesh &mesh)
Update topology using the given map.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
static autoPtr< functionObject > New(const word &name, const Time &, const dictionary &)
Select from dictionary, based on its "type" entry.
static bool postProcess
Global post-processing mode switch.
virtual scalar timeToNextAction()
Called by Time::adjustTimeStep(). Allows the functionObject to.
const word & name() const
Return the name of this functionObject.
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
bool remove(const char)
Remove all occurrences of character returning true if string changed.
Definition: string.C:132
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dlLibraryTable libs
Table of loaded dynamic libraries.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
dimensionedScalar log(const dimensionedScalar &ds)
defineTypeNameAndDebug(combustionModel, 0)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
static const char nl
Definition: Ostream.H:267
dictionary dict