initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / functionObjects / OutputFilterFunctionObject / OutputFilterFunctionObject.C
blob4e3bf3fad6849ce9daa4d5c6189716b91bd139f8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "OutputFilterFunctionObject.H"
28 #include "IOOutputFilter.H"
29 #include "polyMesh.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
34 template<class OutputFilter>
35 void Foam::OutputFilterFunctionObject<OutputFilter>::readDict()
37     dict_.readIfPresent("region", regionName_);
38     dict_.readIfPresent("dictionary", dictName_);
39     dict_.readIfPresent("enabled", enabled_);
43 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
45 template<class OutputFilter>
46 Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
48     const word& name,
49     const Time& t,
50     const dictionary& dict
53     functionObject(name),
54     time_(t),
55     dict_(dict),
56     regionName_(polyMesh::defaultRegion),
57     dictName_(),
58     enabled_(true),
59     outputControl_(t, dict)
61     readDict();
65 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
67 template<class OutputFilter>
68 void Foam::OutputFilterFunctionObject<OutputFilter>::on()
70     enabled_ = true;
74 template<class OutputFilter>
75 void Foam::OutputFilterFunctionObject<OutputFilter>::off()
77     enabled_ = false;
81 template<class OutputFilter>
82 bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
84     readDict();
86     if (enabled_)
87     {
88         if (dictName_.size())
89         {
90             ptr_.reset
91             (
92                 new IOOutputFilter<OutputFilter>
93                 (
94                     name(),
95                     time_.lookupObject<objectRegistry>(regionName_),
96                     dictName_
97                 )
98             );
99         }
100         else
101         {
102             ptr_.reset
103             (
104                 new OutputFilter
105                 (
106                     name(),
107                     time_.lookupObject<objectRegistry>(regionName_),
108                     dict_
109                 )
110             );
111         }
112     }
114     return true;
118 template<class OutputFilter>
119 bool Foam::OutputFilterFunctionObject<OutputFilter>::execute()
121     if (enabled_)
122     {
123         ptr_->execute();
125         if (enabled_ && outputControl_.output())
126         {
127             ptr_->write();
128         }
129     }
131     return true;
135 template<class OutputFilter>
136 bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
138     if (enabled_)
139     {
140         ptr_->end();
142         if (enabled_ && outputControl_.output())
143         {
144             ptr_->write();
145         }
146     }
148     return true;
152 template<class OutputFilter>
153 bool Foam::OutputFilterFunctionObject<OutputFilter>::read
155     const dictionary& dict
158     if (dict != dict_)
159     {
160         dict_ = dict;
161         outputControl_.read(dict);
163         return start();
164     }
165     else
166     {
167         return false;
168     }
172 // ************************************************************************* //