Changed the IOOutputFilter constructor to accept a "name" argument. For details...
[OpenFOAM-1.5.x.git] / src / sampling / outputFilters / OutputFilterFunctionObject / OutputFilterFunctionObject.C
blob3dcec1000358002d018a0f61fb9812a674e392b0
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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("interval", interval_);
40     dict_.readIfPresent("enabled", execution_);
44 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
46 template<class OutputFilter>
47 Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
49     const word& name,
50     const Time& t,
51     const dictionary& dict
54     functionObject(),
55     name_(name),
56     time_(t),
57     dict_(dict),
58     regionName_(polyMesh::defaultRegion),
59     dictName_(),
60     interval_(0),
61     execution_(true)
63     readDict();
67 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
69 template<class OutputFilter>
70 bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
72     readDict();
74     if (execution_)
75     {
76         if (dictName_.size())
77         {
78             ptr_.reset
79             (
80                 new IOOutputFilter<OutputFilter>
81                 (
82                     name_,
83                     time_.lookupObject<objectRegistry>(regionName_),
84                     dictName_
85                 )
86             );
87         }
88         else
89         {
90             ptr_.reset
91             (
92                 new OutputFilter
93                 (
94                     name_,
95                     time_.lookupObject<objectRegistry>(regionName_),
96                     dict_
97                 )
98             );
99         }
100     }
102     return true;
106 template<class OutputFilter>
107 bool Foam::OutputFilterFunctionObject<OutputFilter>::execute()
109     if (execution_ && (interval_ <= 1 || !(time_.timeIndex() % interval_)) )
110     {
111         ptr_->write();
112     }
114     return true;
118 template<class OutputFilter>
119 void Foam::OutputFilterFunctionObject<OutputFilter>::on()
121     execution_ = true;
125 template<class OutputFilter>
126 void Foam::OutputFilterFunctionObject<OutputFilter>::off()
128     execution_ = false;
132 template<class OutputFilter>
133 bool Foam::OutputFilterFunctionObject<OutputFilter>::read
135     const dictionary& dict
138     if (dict != dict_)
139     {
140         dict_ = dict;
141         return start();
142     }
143     else
144     {
145         return false;
146     }
150 // ************************************************************************* //