FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
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 <OpenFOAM/dictionary.H>
00028 #include <OpenFOAM/dlLibraryTable.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 defineRunTimeSelectionTable(Foam::functionObject, dictionary);
00033 int Foam::functionObject::debug(Foam::debug::debugSwitch("functionObject", 0));
00034 
00035 
00036 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00037 
00038 Foam::functionObject::functionObject(const word& name)
00039 :
00040     name_(name)
00041 {}
00042 
00043 
00044 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00045 
00046 Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
00047 (
00048     const word& name,
00049     const Time& t,
00050     const dictionary& functionDict
00051 )
00052 {
00053     word functionType(functionDict.lookup("type"));
00054 
00055     if (debug)
00056     {
00057         Info<< "Selecting function " << functionType << endl;
00058     }
00059 
00060     dlLibraryTable::open
00061     (
00062         functionDict,
00063         "functionObjectLibs",
00064         dictionaryConstructorTablePtr_
00065     );
00066 
00067     if (!dictionaryConstructorTablePtr_)
00068     {
00069         FatalErrorIn
00070         (
00071             "functionObject::New"
00072             "(const word& name, const Time&, const dictionary&)"
00073         )   << "Unknown function type "
00074             << functionType << nl << nl
00075             << "Table of functionObjects is empty" << endl
00076             << exit(FatalError);
00077     }
00078 
00079     dictionaryConstructorTable::iterator cstrIter =
00080         dictionaryConstructorTablePtr_->find(functionType);
00081 
00082     if (cstrIter == dictionaryConstructorTablePtr_->end())
00083     {
00084         FatalErrorIn
00085         (
00086             "functionObject::New"
00087             "(const word& name, const Time&, const dictionary&)"
00088         )   << "Unknown function type "
00089             << functionType << nl << nl
00090             << "Valid functions are : " << nl
00091             << dictionaryConstructorTablePtr_->sortedToc() << endl
00092             << exit(FatalError);
00093     }
00094 
00095     return autoPtr<functionObject>(cstrIter()(name, t, functionDict));
00096 }
00097 
00098 
00099 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00100 
00101 Foam::functionObject::~functionObject()
00102 {}
00103 
00104 
00105 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00106 
00107 const Foam::word& Foam::functionObject::name() const
00108 {
00109     return name_;
00110 }
00111 
00112 
00113 bool Foam::functionObject::end()
00114 {
00115     return execute();
00116 }
00117 
00118 
00119 Foam::autoPtr<Foam::functionObject> Foam::functionObject::iNew::operator()
00120 (
00121     const word& name,
00122     Istream& is
00123 ) const
00124 {
00125     dictionary dict(is);
00126     return functionObject::New(name, time_, dict);
00127 }
00128 
00129 
00130 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines