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 | Copyright (C) 2011-2016 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 {
35  defineDebugSwitchWithName(functionObject, "functionObject", 0);
36  defineRunTimeSelectionTable(functionObject, dictionary);
37 }
38 
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
44 Foam::functionObject::functionObject(const word& name)
45 :
46  name_(name),
47  log(postProcess)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
52 
54 (
55  const word& name,
56  const Time& runTime,
57  const dictionary& dict
58 )
59 {
60  const word functionType(dict.lookup("type"));
61 
62  if (debug)
63  {
64  Info<< "Selecting function " << functionType << endl;
65  }
66 
67  if (dict.found("functionObjectLibs"))
68  {
69  const_cast<Time&>(runTime).libs().open
70  (
71  dict,
72  "functionObjectLibs",
73  dictionaryConstructorTablePtr_
74  );
75  }
76  else
77  {
78  const_cast<Time&>(runTime).libs().open
79  (
80  dict,
81  "libs",
82  dictionaryConstructorTablePtr_
83  );
84  }
85 
86  if (!dictionaryConstructorTablePtr_)
87  {
89  << "Unknown function type "
90  << functionType << nl << nl
91  << "Table of functionObjects is empty" << endl
92  << exit(FatalError);
93  }
94 
95  dictionaryConstructorTable::iterator cstrIter =
96  dictionaryConstructorTablePtr_->find(functionType);
97 
98  if (cstrIter == dictionaryConstructorTablePtr_->end())
99  {
101  << "Unknown function type "
102  << functionType << nl << nl
103  << "Valid functions are : " << nl
104  << dictionaryConstructorTablePtr_->sortedToc() << endl
105  << exit(FatalError);
106  }
107 
108  return autoPtr<functionObject>(cstrIter()(name, runTime, dict));
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
113 
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
121 {
122  return name_;
123 }
124 
125 
127 {
128  if (!postProcess)
129  {
130  log = dict.lookupOrDefault<Switch>("log", true);
131  }
132 
133  return true;
134 }
135 
136 
138 {
139  return true;
140 }
141 
142 
144 {
145  return false;
146 }
147 
148 
150 {}
151 
152 
154 {}
155 
156 
157 // ************************************************************************* //
dictionary dict
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
virtual ~functionObject()
Destructor.
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const word & name() const
Return the name of this functionObject.
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
defineDebugSwitchWithName(pointMVCWeight, "pointMVCWeight", 0)
static bool postProcess
Global post-processing mode switch.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
virtual bool end()
Called when Time::run() determines that the time-loop exits.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
static const char nl
Definition: Ostream.H:262
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
static autoPtr< functionObject > New(const word &name, const Time &, const dictionary &)
Select from dictionary, based on its "type" entry.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Switch log
Switch write log to Info.
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576