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

OutputFilterFunctionObject.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 "OutputFilterFunctionObject.H"
00027 #include <OpenFOAM/IOOutputFilter.H>
00028 #include <OpenFOAM/polyMesh.H>
00029 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00030 
00031 // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
00032 
00033 template<class OutputFilter>
00034 void Foam::OutputFilterFunctionObject<OutputFilter>::readDict()
00035 {
00036     dict_.readIfPresent("region", regionName_);
00037     dict_.readIfPresent("dictionary", dictName_);
00038     dict_.readIfPresent("enabled", enabled_);
00039     dict_.readIfPresent("storeFilter", storeFilter_);
00040 }
00041 
00042 template<class OutputFilter>
00043 void Foam::OutputFilterFunctionObject<OutputFilter>::allocateFilter()
00044 {
00045     if (dictName_.size())
00046     {
00047         ptr_.reset
00048         (
00049             new IOOutputFilter<OutputFilter>
00050             (
00051                 name(),
00052                 time_.lookupObject<objectRegistry>(regionName_),
00053                 dictName_
00054             )
00055         );
00056     }
00057     else
00058     {
00059         ptr_.reset
00060         (
00061             new OutputFilter
00062             (
00063                 name(),
00064                 time_.lookupObject<objectRegistry>(regionName_),
00065                 dict_
00066             )
00067         );
00068     }
00069 }
00070 
00071 template<class OutputFilter>
00072 void Foam::OutputFilterFunctionObject<OutputFilter>::destroyFilter()
00073 {
00074     ptr_.reset();
00075 }
00076 
00077 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00078 
00079 template<class OutputFilter>
00080 Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
00081 (
00082     const word& name,
00083     const Time& t,
00084     const dictionary& dict
00085 )
00086 :
00087     functionObject(name),
00088     time_(t),
00089     dict_(dict),
00090     regionName_(polyMesh::defaultRegion),
00091     dictName_(),
00092     enabled_(true),
00093     storeFilter_(true),
00094     outputControl_(t, dict)
00095 {
00096     readDict();
00097 }
00098 
00099 
00100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00101 
00102 template<class OutputFilter>
00103 void Foam::OutputFilterFunctionObject<OutputFilter>::on()
00104 {
00105     enabled_ = true;
00106 }
00107 
00108 
00109 template<class OutputFilter>
00110 void Foam::OutputFilterFunctionObject<OutputFilter>::off()
00111 {
00112     enabled_ = false;
00113 }
00114 
00115 
00116 template<class OutputFilter>
00117 bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
00118 {
00119     readDict();
00120 
00121     if (enabled_&&storeFilter_)
00122     {
00123         allocateFilter();
00124     }
00125 
00126     return true;
00127 }
00128 
00129 
00130 template<class OutputFilter>
00131 bool Foam::OutputFilterFunctionObject<OutputFilter>::execute()
00132 {
00133     if (enabled_)
00134     {
00135         if (!storeFilter_)
00136         {
00137             allocateFilter();
00138         }
00139 
00140         ptr_->execute();
00141 
00142         if (enabled_ && outputControl_.output())
00143         {
00144             ptr_->write();
00145         }
00146 
00147         if (!storeFilter_)
00148         {
00149             destroyFilter();
00150         }
00151     }
00152 
00153     return true;
00154 }
00155 
00156 
00157 template<class OutputFilter>
00158 bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
00159 {
00160     if (enabled_)
00161     {
00162         if (!storeFilter_)
00163         {
00164             allocateFilter();
00165         }
00166 
00167         ptr_->end();
00168 
00169         if (enabled_ && outputControl_.output())
00170         {
00171             ptr_->write();
00172         }
00173 
00174         if (!storeFilter_)
00175         {
00176             destroyFilter();
00177         }
00178     }
00179 
00180     return true;
00181 }
00182 
00183 
00184 template<class OutputFilter>
00185 bool Foam::OutputFilterFunctionObject<OutputFilter>::read
00186 (
00187     const dictionary& dict
00188 )
00189 {
00190     if (dict != dict_)
00191     {
00192         dict_ = dict;
00193         outputControl_.read(dict);
00194 
00195         return start();
00196     }
00197     else
00198     {
00199         return false;
00200     }
00201 }
00202 
00203 
00204 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines