OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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) 1991-2009 OpenCFD Ltd.
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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "functionObject.H"
00028 #include "dictionary.H"
00029 #include "dlLibraryTable.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 defineRunTimeSelectionTable(Foam::functionObject, dictionary);
00034 int Foam::functionObject::debug(Foam::debug::debugSwitch("functionObject", 0));
00035 
00036 
00037 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00038 
00039 Foam::functionObject::functionObject(const word& name)
00040 :
00041     name_(name)
00042 {}
00043 
00044 
00045 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00046 
00047 Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
00048 (
00049     const word& name,
00050     const Time& t,
00051     const dictionary& functionDict
00052 )
00053 {
00054     word functionType(functionDict.lookup("type"));
00055 
00056     if (debug)
00057     {
00058         Info<< "Selecting function " << functionType << endl;
00059     }
00060 
00061     dlLibraryTable::open
00062     (
00063         functionDict,
00064         "functionObjectLibs",
00065         dictionaryConstructorTablePtr_
00066     );
00067 
00068     if (!dictionaryConstructorTablePtr_)
00069     {
00070         FatalErrorIn
00071         (
00072             "functionObject::New"
00073             "(const word& name, const Time&, const dictionary&)"
00074         )   << "Unknown function type "
00075             << functionType << nl << nl
00076             << "Table of functionObjects is empty" << endl
00077             << exit(FatalError);
00078     }
00079 
00080     dictionaryConstructorTable::iterator cstrIter =
00081         dictionaryConstructorTablePtr_->find(functionType);
00082 
00083     if (cstrIter == dictionaryConstructorTablePtr_->end())
00084     {
00085         FatalErrorIn
00086         (
00087             "functionObject::New"
00088             "(const word& name, const Time&, const dictionary&)"
00089         )   << "Unknown function type "
00090             << functionType << nl << nl
00091             << "Valid functions are : " << nl
00092             << dictionaryConstructorTablePtr_->toc() << endl
00093             << exit(FatalError);
00094     }
00095 
00096     return autoPtr<functionObject>(cstrIter()(name, t, functionDict));
00097 }
00098 
00099 
00100 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00101 
00102 Foam::functionObject::~functionObject()
00103 {}
00104 
00105 
00106 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00107 
00108 const Foam::word& Foam::functionObject::name() const
00109 {
00110     return name_;
00111 }
00112 
00113 
00114 bool Foam::functionObject::end()
00115 {
00116     return execute();
00117 }
00118 
00119 
00120 Foam::autoPtr<Foam::functionObject> Foam::functionObject::iNew::operator()
00121 (
00122     const word& name,
00123     Istream& is
00124 ) const
00125 {
00126     dictionary dict(is);
00127     return functionObject::New(name, time_, dict);
00128 }
00129 
00130 
00131 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd