FreeFOAM The Cross-Platform CFD Toolkit
sampledSurfaces.H
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 Class
25  Foam::sampledSurfaces
26 
27 Description
28  Set of surfaces to sample.
29 
30  The write() method is used to sample and write files.
31 
32 SourceFiles
33  sampledSurfaces.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef sampledSurfaces_H
38 #define sampledSurfaces_H
39 
41 #include <sampling/surfaceWriter.H>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 class fvMesh;
50 class dictionary;
51 
52 /*---------------------------------------------------------------------------*\
53  Class sampledSurfaces Declaration
54 \*---------------------------------------------------------------------------*/
55 
57 :
58  public PtrList<sampledSurface>
59 {
60  // Private classes
61 
62  //- Class used for grouping field types
63  template<class Type>
64  class fieldGroup
65  :
66  public DynamicList<word>
67  {
68  public:
69 
70  //- Surface formatter
71  autoPtr< surfaceWriter<Type> > formatter;
72 
73  //- Construct null
74  fieldGroup()
75  :
77  formatter(NULL)
78  {}
79 
80  //- Construct for a particular surface format
81  fieldGroup(const word& writeFormat)
82  :
84  formatter(surfaceWriter<Type>::New(writeFormat))
85  {}
86 
87  //- Construct for a particular surface format and a list of field
88  // names
89  fieldGroup
90  (
91  const word& writeFormat,
92  const wordList& fieldNames
93  )
94  :
96  formatter(surfaceWriter<Type>::New(writeFormat))
97  {}
98 
99  void reset(const label nElem)
100  {
101  formatter.clear();
104  }
105 
106  void operator=(const word& writeFormat)
107  {
108  formatter = surfaceWriter<Type>::New(writeFormat);
109  }
110 
111  void operator=(const wordList& fieldNames)
112  {
113  DynamicList<word>::operator=(fieldNames);
114  }
115  };
116 
117 
118  //- Class used for surface merging information
119  class mergeInfo
120  {
121  public:
123  faceList faces;
124  labelList pointsMap;
125 
126  //- Clear all storage
127  void clear()
128  {
129  points.clear();
130  faces.clear();
131  pointsMap.clear();
132  }
133  };
134 
135 
136  // Static data members
137 
138  //- output verbosity
139  static bool verbose_;
140 
141  //- Tolerance for merging points (fraction of mesh bounding box)
142  static scalar mergeTol_;
143 
144  // Private data
145 
146  //- Name of this set of surfaces,
147  // Also used as the name of the sampledSurfaces directory.
148  const word name_;
149 
150  //- Const reference to fvMesh
151  const fvMesh& mesh_;
152 
153  //- Load fields from files (not from objectRegistry)
154  const bool loadFromFiles_;
155 
156  //- output path
157  fileName outputPath_;
158 
159 
160  // Read from dictonary
161 
162  //- Names of fields to sample
163  wordList fieldNames_;
164 
165  //- Interpolation scheme to use
166  word interpolationScheme_;
167 
168  //- Output format to use
169  word writeFormat_;
170 
171 
172  // surfaces
173 
174  //- Information for merging surfaces
175  List<mergeInfo> mergeList_;
176 
177 
178  // Calculated
179 
180  //- Generic surface formatter
181  autoPtr< surfaceWriter<bool> > genericFormatter_;
182 
183  //- Categorized scalar/vector/tensor fields
184  fieldGroup<scalar> scalarFields_;
185  fieldGroup<vector> vectorFields_;
186  fieldGroup<sphericalTensor> sphericalTensorFields_;
187  fieldGroup<symmTensor> symmTensorFields_;
188  fieldGroup<tensor> tensorFields_;
189 
190 
191  // Private Member Functions
192 
193  //- Classify field types, returns the number of fields
194  label classifyFieldTypes();
195 
196  //- Write geometry only
197  void writeGeometry() const;
198 
199  //- Sample and write a particular volume field
200  template<class Type>
201  void sampleAndWrite
202  (
204  const surfaceWriter<Type>& formatter
205  );
206 
207  //- Sample and write all the fields of the given type
208  template <class Type>
209  void sampleAndWrite(fieldGroup<Type>&);
210 
211  //- Disallow default bitwise copy construct and assignment
213  void operator=(const sampledSurfaces&);
214 
215 
216 public:
217 
218  //- Runtime type information
219  TypeName("surfaces");
220 
221 
222  // Constructors
223 
224  //- Construct for given objectRegistry and dictionary
225  // allow the possibility to load fields from files
227  (
228  const word& name,
229  const objectRegistry&,
230  const dictionary&,
231  const bool loadFromFiles = false
232  );
233 
234 
235  // Destructor
236 
237  virtual ~sampledSurfaces();
238 
239 
240  // Member Functions
241 
242  //- Does any of the surfaces need an update?
243  virtual bool needsUpdate() const;
244 
245  //- Mark the surfaces as needing an update.
246  // May also free up unneeded data.
247  // Return false if all surfaces were already marked as expired.
248  virtual bool expire();
249 
250  //- Update the surfaces as required and merge surface points (parallel).
251  // Return false if no surfaces required an update.
252  virtual bool update();
253 
254 
255  //- Return name of the set of surfaces
256  virtual const word& name() const
257  {
258  return name_;
259  }
260 
261  //- set verbosity level
262  void verbose(const bool verbosity = true);
263 
264  //- Execute, currently does nothing
265  virtual void execute();
266 
267  //- Execute at the final time-loop, currently does nothing
268  virtual void end();
269 
270  //- Sample and write
271  virtual void write();
272 
273  //- Read the sampledSurfaces dictionary
274  virtual void read(const dictionary&);
275 
276  //- Update for changes of mesh - expires the surfaces
277  virtual void updateMesh(const mapPolyMesh&);
278 
279  //- Update for mesh point-motion - expires the surfaces
280  virtual void movePoints(const pointField&);
281 
282  //- Update for changes of mesh due to readUpdate - expires the surfaces
283  virtual void readUpdate(const polyMesh::readUpdateState state);
284 
285 };
286 
287 
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 } // End namespace Foam
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #ifdef NoRepository
295 # include "sampledSurfacesTemplates.C"
296 #endif
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 #endif
301 
302 // ************************ vim: set sw=4 sts=4 et: ************************ //