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-2023 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 
57 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
58 
60 (
61  const word& name,
62  const Time& runTime,
63  const dictionary& dict
64 )
65 {
66  const word functionType(dict.lookup("type"));
67 
68  if (debug)
69  {
70  Info<< "Selecting function " << functionType << endl;
71  }
72 
73  if
74  (
75  !dictionaryConstructorTablePtr_
76  || dictionaryConstructorTablePtr_->find(functionType)
77  == dictionaryConstructorTablePtr_->end()
78  )
79  {
80  if
81  (
82  !libs.open
83  (
84  dict,
85  "libs",
86  dictionaryConstructorTablePtr_
87  )
88  )
89  {
90  libs.open("lib" + functionType.remove(':') + ".so", false);
91  }
92 
93  if (!dictionaryConstructorTablePtr_)
94  {
96  << "Unknown function type "
97  << functionType << nl << nl
98  << "Table of functionObjects is empty"
99  << exit(FatalError);
100  }
101  }
102 
103  dictionaryConstructorTable::iterator cstrIter =
104  dictionaryConstructorTablePtr_->find(functionType);
105 
106  if (cstrIter == dictionaryConstructorTablePtr_->end())
107  {
109  << "Unknown function type "
110  << functionType << nl << nl
111  << "Valid functions are : " << nl
112  << dictionaryConstructorTablePtr_->sortedToc()
113  << exit(FatalError);
114  }
115 
116  return autoPtr<functionObject>(cstrIter()(name, runTime, dict));
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
121 
123 {}
124 
125 
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127 
129 {
130  return name_;
131 }
132 
133 
135 {
136  log = dict.lookupOrDefault<Switch>("log", postProcess);
137 
138  if (!postProcess)
139  {
140  executeAtStart_ =
141  dict.lookupOrDefault<Switch>("executeAtStart", executeAtStart_);
142  }
143 
144  return true;
145 }
146 
147 
149 {
150  return executeAtStart_;
151 }
152 
153 
155 {
156  return true;
157 }
158 
159 
161 {
162  return vGreat;
163 }
164 
165 
167 {}
168 
169 
171 {}
172 
173 
175 {}
176 
177 
179 {}
180 
181 
182 // ************************************************************************* //
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:860
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 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:306
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:251
messageStream Info
dimensionedScalar log(const dimensionedScalar &ds)
defineTypeNameAndDebug(combustionModel, 0)
error FatalError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static const char nl
Definition: Ostream.H:260
dictionary dict