initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / sampling / sampledSurface / sampledSurfaces / sampledSurfaces.H
blob4ad59c486f70e1fb8271fddee07bdc03eaf54a47
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 Class
26     Foam::sampledSurfaces
28 Description
29     Set of surfaces to sample.
31     The write() method is used to sample and write files.
33 SourceFiles
34     sampledSurfaces.C
36 \*---------------------------------------------------------------------------*/
38 #ifndef sampledSurfaces_H
39 #define sampledSurfaces_H
41 #include "sampledSurface.H"
42 #include "surfaceWriter.H"
43 #include "volFieldsFwd.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 namespace Foam
50 class fvMesh;
51 class dictionary;
53 /*---------------------------------------------------------------------------*\
54                       Class sampledSurfaces Declaration
55 \*---------------------------------------------------------------------------*/
57 class sampledSurfaces
59     public PtrList<sampledSurface>
61     // Private classes
63         //- Class used for grouping field types
64         template<class Type>
65         class fieldGroup
66         :
67             public DynamicList<word>
68         {
69         public:
71             //- Surface formatter
72             autoPtr< surfaceWriter<Type> > formatter;
74             //- Construct null
75             fieldGroup()
76             :
77                 DynamicList<word>(0),
78                 formatter(NULL)
79             {}
81             //- Construct for a particular surface format
82             fieldGroup(const word& writeFormat)
83             :
84                 DynamicList<word>(0),
85                 formatter(surfaceWriter<Type>::New(writeFormat))
86             {}
88             //- Construct for a particular surface format and a list of field
89             //  names
90             fieldGroup
91             (
92                 const word& writeFormat,
93                 const wordList& fieldNames
94             )
95             :
96                 DynamicList<word>(fieldNames),
97                 formatter(surfaceWriter<Type>::New(writeFormat))
98             {}
100             void reset(const label nElem)
101             {
102                 formatter.clear();
103                 DynamicList<word>::setCapacity(nElem);
104                 DynamicList<word>::clear(); 
105             }
107             void operator=(const word& writeFormat)
108             {
109                 formatter = surfaceWriter<Type>::New(writeFormat);
110             }
112             void operator=(const wordList& fieldNames)
113             {
114                 DynamicList<word>::operator=(fieldNames);
115             }
116         };
119         //- Class used for surface merging information
120         class mergeInfo
121         {
122         public:
123             pointField points;
124             faceList   faces;
125             labelList  pointsMap;
127             //- Clear all storage
128             void clear()
129             {
130                 points.clear();
131                 faces.clear();
132                 pointsMap.clear();
133             }
134         };
137     // Static data members
139         //- output verbosity
140         static bool verbose_;
142         //- Tolerance for merging points (fraction of mesh bounding box)
143         static scalar mergeTol_;
145     // Private data
147         //- Name of this set of surfaces,
148         //  Also used as the name of the sampledSurfaces directory.
149         const word name_;
151         //- Const reference to fvMesh
152         const fvMesh& mesh_;
154         //- Load fields from files (not from objectRegistry)
155         const bool loadFromFiles_;
157         //- output path
158         fileName outputPath_;
161         // Read from dictonary
163             //- Names of fields to sample
164             wordList fieldNames_;
166             //- Interpolation scheme to use
167             word interpolationScheme_;
169             //- Output format to use
170             word writeFormat_;
173         // surfaces
175             //- Information for merging surfaces
176             List<mergeInfo> mergeList_;
179         // Calculated
181             //- Generic surface formatter
182             autoPtr< surfaceWriter<bool> > genericFormatter_;
184             //- Categorized scalar/vector/tensor fields
185             fieldGroup<scalar> scalarFields_;
186             fieldGroup<vector> vectorFields_;
187             fieldGroup<sphericalTensor> sphericalTensorFields_;
188             fieldGroup<symmTensor> symmTensorFields_;
189             fieldGroup<tensor> tensorFields_;
192     // Private Member Functions
194         //- Classify field types, returns the number of fields
195         label classifyFieldTypes();
197         //- Write geometry only
198         void writeGeometry() const;
200         //- Sample and write a particular volume field
201         template<class Type>
202         void sampleAndWrite
203         (
204             const GeometricField<Type, fvPatchField, volMesh>&,
205             const surfaceWriter<Type>& formatter
206         );
208         //- Sample and write all the fields of the given type
209         template <class Type>
210         void sampleAndWrite(fieldGroup<Type>&);
212         //- Disallow default bitwise copy construct and assignment
213         sampledSurfaces(const sampledSurfaces&);
214         void operator=(const sampledSurfaces&);
217 public:
219     //- Runtime type information
220     TypeName("surfaces");
223     // Constructors
225         //- Construct for given objectRegistry and dictionary
226         //  allow the possibility to load fields from files
227         sampledSurfaces
228         (
229             const word& name,
230             const objectRegistry&,
231             const dictionary&,
232             const bool loadFromFiles = false
233         );
236     // Destructor
238         virtual ~sampledSurfaces();
241     // Member Functions
243         //- Does any of the surfaces need an update?
244         virtual bool needsUpdate() const;
246         //- Mark the surfaces as needing an update.
247         //  May also free up unneeded data.
248         //  Return false if all surfaces were already marked as expired.
249         virtual bool expire();
251         //- Update the surfaces as required and merge surface points (parallel).
252         //  Return false if no surfaces required an update.
253         virtual bool update();
256         //- Return name of the set of surfaces
257         virtual const word& name() const
258         {
259             return name_;
260         }
262         //- set verbosity level
263         void verbose(const bool verbosity = true);
265         //- Execute, currently does nothing
266         virtual void execute();
268         //- Execute at the final time-loop, currently does nothing
269         virtual void end();
271         //- Sample and write
272         virtual void write();
274         //- Read the sampledSurfaces dictionary
275         virtual void read(const dictionary&);
277         //- Update for changes of mesh - expires the surfaces
278         virtual void updateMesh(const mapPolyMesh&);
280         //- Update for mesh point-motion - expires the surfaces
281         virtual void movePoints(const pointField&);
283         //- Update for changes of mesh due to readUpdate - expires the surfaces
284         virtual void readUpdate(const polyMesh::readUpdateState state);
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 } // End namespace Foam
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 #ifdef NoRepository
296 #   include "sampledSurfacesTemplates.C"
297 #endif
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 #endif
303 // ************************************************************************* //