functionObject.C
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 \*---------------------------------------------------------------------------*/ 00025 00026 #include "functionObject.H" 00027 #include "dictionary.H" 00028 #include "dlLibraryTable.H" 00029 #include "Time.H" 00030 00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // 00032 00033 namespace Foam 00034 { 00035 defineDebugSwitchWithName(functionObject, "functionObject", 0); 00036 defineRunTimeSelectionTable(functionObject, dictionary); 00037 } 00038 00039 00040 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // 00041 00042 Foam::functionObject::functionObject(const word& name) 00043 : 00044 name_(name) 00045 {} 00046 00047 00048 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // 00049 00050 Foam::autoPtr<Foam::functionObject> Foam::functionObject::New 00051 ( 00052 const word& name, 00053 const Time& t, 00054 const dictionary& functionDict 00055 ) 00056 { 00057 const word functionType(functionDict.lookup("type")); 00058 00059 if (debug) 00060 { 00061 Info<< "Selecting function " << functionType << endl; 00062 } 00063 00064 const_cast<Time&>(t).libs().open 00065 ( 00066 functionDict, 00067 "functionObjectLibs", 00068 dictionaryConstructorTablePtr_ 00069 ); 00070 00071 if (!dictionaryConstructorTablePtr_) 00072 { 00073 FatalErrorIn 00074 ( 00075 "functionObject::New" 00076 "(const word& name, const Time&, const dictionary&)" 00077 ) << "Unknown function type " 00078 << functionType << nl << nl 00079 << "Table of functionObjects is empty" << endl 00080 << exit(FatalError); 00081 } 00082 00083 dictionaryConstructorTable::iterator cstrIter = 00084 dictionaryConstructorTablePtr_->find(functionType); 00085 00086 if (cstrIter == dictionaryConstructorTablePtr_->end()) 00087 { 00088 FatalErrorIn 00089 ( 00090 "functionObject::New" 00091 "(const word& name, const Time&, const dictionary&)" 00092 ) << "Unknown function type " 00093 << functionType << nl << nl 00094 << "Valid functions are : " << nl 00095 << dictionaryConstructorTablePtr_->sortedToc() << endl 00096 << exit(FatalError); 00097 } 00098 00099 return autoPtr<functionObject>(cstrIter()(name, t, functionDict)); 00100 } 00101 00102 00103 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // 00104 00105 Foam::functionObject::~functionObject() 00106 {} 00107 00108 00109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // 00110 00111 const Foam::word& Foam::functionObject::name() const 00112 { 00113 return name_; 00114 } 00115 00116 00117 bool Foam::functionObject::end() 00118 { 00119 return execute(false); 00120 } 00121 00122 00123 Foam::autoPtr<Foam::functionObject> Foam::functionObject::iNew::operator() 00124 ( 00125 const word& name, 00126 Istream& is 00127 ) const 00128 { 00129 dictionary dict(is); 00130 return functionObject::New(name, time_, dict); 00131 } 00132 00133 00134 // ************************************************************************* //
