FreeFOAM The Cross-Platform CFD Toolkit
OutputFilterFunctionObject.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include <OpenFOAM/polyMesh.H>
30 
31 // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
32 
33 template<class OutputFilter>
35 {
36  dict_.readIfPresent("region", regionName_);
37  dict_.readIfPresent("dictionary", dictName_);
38  dict_.readIfPresent("enabled", enabled_);
39  dict_.readIfPresent("storeFilter", storeFilter_);
40 }
41 
42 template<class OutputFilter>
44 {
45  if (dictName_.size())
46  {
47  ptr_.reset
48  (
49  new IOOutputFilter<OutputFilter>
50  (
51  name(),
52  time_.lookupObject<objectRegistry>(regionName_),
53  dictName_
54  )
55  );
56  }
57  else
58  {
59  ptr_.reset
60  (
61  new OutputFilter
62  (
63  name(),
64  time_.lookupObject<objectRegistry>(regionName_),
65  dict_
66  )
67  );
68  }
69 }
70 
71 template<class OutputFilter>
73 {
74  ptr_.reset();
75 }
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
79 template<class OutputFilter>
81 (
82  const word& name,
83  const Time& t,
84  const dictionary& dict
85 )
86 :
87  functionObject(name),
88  time_(t),
89  dict_(dict),
90  regionName_(polyMesh::defaultRegion),
91  dictName_(),
92  enabled_(true),
93  storeFilter_(true),
94  outputControl_(t, dict)
95 {
96  readDict();
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
102 template<class OutputFilter>
104 {
105  enabled_ = true;
106 }
107 
108 
109 template<class OutputFilter>
111 {
112  enabled_ = false;
113 }
114 
115 
116 template<class OutputFilter>
118 {
119  readDict();
120 
121  if (enabled_&&storeFilter_)
122  {
123  allocateFilter();
124  }
125 
126  return true;
127 }
128 
129 
130 template<class OutputFilter>
132 {
133  if (enabled_)
134  {
135  if (!storeFilter_)
136  {
137  allocateFilter();
138  }
139 
140  ptr_->execute();
141 
142  if (enabled_ && outputControl_.output())
143  {
144  ptr_->write();
145  }
146 
147  if (!storeFilter_)
148  {
149  destroyFilter();
150  }
151  }
152 
153  return true;
154 }
155 
156 
157 template<class OutputFilter>
159 {
160  if (enabled_)
161  {
162  if (!storeFilter_)
163  {
164  allocateFilter();
165  }
166 
167  ptr_->end();
168 
169  if (enabled_ && outputControl_.output())
170  {
171  ptr_->write();
172  }
173 
174  if (!storeFilter_)
175  {
176  destroyFilter();
177  }
178  }
179 
180  return true;
181 }
182 
183 
184 template<class OutputFilter>
186 (
187  const dictionary& dict
188 )
189 {
190  if (dict != dict_)
191  {
192  dict_ = dict;
193  outputControl_.read(dict);
194 
195  return start();
196  }
197  else
198  {
199  return false;
200  }
201 }
202 
203 
204 // ************************ vim: set sw=4 sts=4 et: ************************ //