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

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-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 "OutputFilterFunctionObject.H"
00028 #include "IOOutputFilter.H"
00029 #include "polyMesh.H"
00030 #include "addToRunTimeSelectionTable.H"
00031 
00032 // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
00033 
00034 template<class OutputFilter>
00035 void Foam::OutputFilterFunctionObject<OutputFilter>::readDict()
00036 {
00037     dict_.readIfPresent("region", regionName_);
00038     dict_.readIfPresent("dictionary", dictName_);
00039     dict_.readIfPresent("enabled", enabled_);
00040 }
00041 
00042 
00043 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00044 
00045 template<class OutputFilter>
00046 Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
00047 (
00048     const word& name,
00049     const Time& t,
00050     const dictionary& dict
00051 )
00052 :
00053     functionObject(name),
00054     time_(t),
00055     dict_(dict),
00056     regionName_(polyMesh::defaultRegion),
00057     dictName_(),
00058     enabled_(true),
00059     outputControl_(t, dict)
00060 {
00061     readDict();
00062 }
00063 
00064 
00065 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00066 
00067 template<class OutputFilter>
00068 void Foam::OutputFilterFunctionObject<OutputFilter>::on()
00069 {
00070     enabled_ = true;
00071 }
00072 
00073 
00074 template<class OutputFilter>
00075 void Foam::OutputFilterFunctionObject<OutputFilter>::off()
00076 {
00077     enabled_ = false;
00078 }
00079 
00080 
00081 template<class OutputFilter>
00082 bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
00083 {
00084     readDict();
00085 
00086     if (enabled_)
00087     {
00088         if (dictName_.size())
00089         {
00090             ptr_.reset
00091             (
00092                 new IOOutputFilter<OutputFilter>
00093                 (
00094                     name(),
00095                     time_.lookupObject<objectRegistry>(regionName_),
00096                     dictName_
00097                 )
00098             );
00099         }
00100         else
00101         {
00102             ptr_.reset
00103             (
00104                 new OutputFilter
00105                 (
00106                     name(),
00107                     time_.lookupObject<objectRegistry>(regionName_),
00108                     dict_
00109                 )
00110             );
00111         }
00112     }
00113 
00114     return true;
00115 }
00116 
00117 
00118 template<class OutputFilter>
00119 bool Foam::OutputFilterFunctionObject<OutputFilter>::execute()
00120 {
00121     if (enabled_)
00122     {
00123         ptr_->execute();
00124 
00125         if (enabled_ && outputControl_.output())
00126         {
00127             ptr_->write();
00128         }
00129     }
00130 
00131     return true;
00132 }
00133 
00134 
00135 template<class OutputFilter>
00136 bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
00137 {
00138     if (enabled_)
00139     {
00140         ptr_->end();
00141 
00142         if (enabled_ && outputControl_.output())
00143         {
00144             ptr_->write();
00145         }
00146     }
00147 
00148     return true;
00149 }
00150 
00151 
00152 template<class OutputFilter>
00153 bool Foam::OutputFilterFunctionObject<OutputFilter>::read
00154 (
00155     const dictionary& dict
00156 )
00157 {
00158     if (dict != dict_)
00159     {
00160         dict_ = dict;
00161         outputControl_.read(dict);
00162 
00163         return start();
00164     }
00165     else
00166     {
00167         return false;
00168     }
00169 }
00170 
00171 
00172 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd