initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / sampling / sampledSurface / sampledSurface / sampledSurface.H
blob265b5c3db784b5f60892571101b75faea3d400a3
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::sampledSurface
28 Description
29     An abstract class for surfaces with sampling.
31     The constructors for the derived classes should generally start in a
32     'expired' condition (ie, needsUpdate() == true) and rely on a
33     subsequent call to the update() method to complete the initialization.
34     Delaying the final construction as late as possible allows the
35     construction of surfaces that may depend on intermediate calculation
36     results (eg, iso-surfaces) and also avoids the unnecessary
37     reconstruction of surfaces between sampling intervals.
39     It is the responsibility of the caller to ensure that the surface
40     update() is called before the surface is used.  The update() method
41     implementation should do nothing when the surface is already
42     up-to-date.
44 SourceFiles
45     sampledSurface.C
46     sampledSurfaceTemplates.C
48 \*---------------------------------------------------------------------------*/
50 #ifndef sampledSurface_H
51 #define sampledSurface_H
53 #include "pointField.H"
54 #include "word.H"
55 #include "labelList.H"
56 #include "faceList.H"
57 #include "typeInfo.H"
58 #include "runTimeSelectionTables.H"
59 #include "autoPtr.H"
60 #include "volFieldsFwd.H"
61 #include "polyMesh.H"
62 #include "coordinateSystems.H"
63 #include "interpolation.H"
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 namespace Foam
70 /*---------------------------------------------------------------------------*\
71                       Class sampledSurface Declaration
72 \*---------------------------------------------------------------------------*/
74 class sampledSurface
76     // Private data
78         //- Name of sample surface
79         word name_;
81         //- Reference to mesh
82         const polyMesh& mesh_;
84         //- Do we intend to interpolate the information?
85         bool interpolate_;
88     // Demand-driven data
90         //- Face area vectors
91         mutable vectorField* SfPtr_;
93         //- Mag face area vectors
94         mutable scalarField* magSfPtr_;
96         //- Face centres
97         mutable vectorField* CfPtr_;
99         //- Total surface area
100         mutable scalar area_;
102     // Make geometric data
104         //- Make Sf
105         void makeSf() const;
107         //- Make magSf
108         void makeMagSf() const;
110         //- Make Cf
111         void makeCf() const;
113     // Service methods
115         //- Check field size matches surface size
116         template<class Type>
117         bool checkFieldSize(const Field<Type>&) const;
119         //- Project field onto surface
120         template<class ReturnType, class Type>
121         void project
122         (
123             Field<ReturnType>&,
124             const Field<Type>&
125         ) const;
127         //- Project field onto surface
128         template<class ReturnType, class Type>
129         void project
130         (
131             Field<ReturnType>&,
132             const tmp<Field<Type> >&
133         ) const;
135         //- Project field onto surface
136         template<class ReturnType, class Type>
137         tmp<Field<ReturnType> > project(const tmp<Field<Type> >&) const;
139 protected:
141     // Protected Member functions
143         virtual void clearGeom() const;
145 public:
147     //- Runtime type information
148       TypeName("sampledSurface");
151     // Declare run-time constructor selection table
153         declareRunTimeSelectionTable
154         (
155             autoPtr,
156             sampledSurface,
157             word,
158             (
159                 const word& name,
160                 const polyMesh& mesh,
161                 const dictionary& dict
162             ),
163             (name, mesh, dict)
164         );
167         //- Class used for the PtrLists read-construction
168         class iNew
169         {
170             //- Reference to the volume mesh
171             const polyMesh& mesh_;
173         public:
175             iNew(const polyMesh& mesh)
176             :
177                 mesh_(mesh)
178             {}
180             autoPtr<sampledSurface> operator()(Istream& is) const
181             {
182                 word name(is);
183                 dictionary dict(is);
185                 return sampledSurface::New(name, mesh_, dict);
186             }
187         };
190     // Constructors
192         //- Construct from name, mesh
193         sampledSurface
194         (
195             const word& name,
196             const polyMesh&
197         );
199         //- Construct from dictionary
200         sampledSurface
201         (
202             const word& name,
203             const polyMesh&,
204             const dictionary&
205         );
207         //- Clone
208         autoPtr<sampledSurface> clone() const
209         {
210             notImplemented("autoPtr<sampledSurface> clone() const");
211             return autoPtr<sampledSurface>(NULL);
212         }
215     // Selectors
217         //- Return a reference to the selected surface
218         static autoPtr<sampledSurface> New
219         (
220             const word& name,
221             const polyMesh&,
222             const dictionary&
223         );
226     // Destructor
228         virtual ~sampledSurface();
231     // Member Functions
233       // Access
235         //- Access to the underlying mesh
236         const polyMesh& mesh() const
237         {
238             return mesh_;
239         }
241         //- Name of surface
242         const word& name() const
243         {
244             return name_;
245         }
247         //- interpolation requested for surface
248         bool interpolate() const
249         {
250             return interpolate_;
251         }
253         //- Does the surface need an update?
254         virtual bool needsUpdate() const = 0;
256         //- Mark the surface as needing an update.
257         //  May also free up unneeded data.
258         //  Return false if surface was already marked as expired.
259         virtual bool expire() = 0;
261         //- Update the surface as required.
262         //  Do nothing (and return false) if no update was required
263         virtual bool update() = 0;
266         //- Points of surface
267         virtual const pointField& points() const = 0;
269         //- Faces of surface
270         virtual const faceList& faces() const = 0;
272         //- Return face area vectors
273         virtual const vectorField& Sf() const;
275         //- Return face area magnitudes
276         virtual const scalarField& magSf() const;
278         //- Return face centres as vectorField
279         virtual const vectorField& Cf() const;
281         //- The total surface area
282         scalar area() const;
284         //- Integration of a field across the surface
285         template<class Type>
286         Type integrate(const Field<Type>&) const;
288         //- Integration of a field across the surface
289         template<class Type>
290         Type integrate(const tmp<Field<Type> >&) const;
292         //- Area-averaged value of a field across the surface
293         template<class Type>
294         Type average(const Field<Type>&) const;
296         //- Area-averaged value of a field across the surface
297         template<class Type>
298         Type average(const tmp<Field<Type> >&) const;
300         //- Project field onto surface
301         tmp<Field<scalar> > project(const Field<scalar>&) const;
303         //- Project field onto surface
304         tmp<Field<scalar> > project(const Field<vector>&) const;
306         //- Project field onto surface
307         tmp<Field<vector> > project(const Field<sphericalTensor>&) const;
309         //- Project field onto surface
310         tmp<Field<vector> > project(const Field<symmTensor>&) const;
312         //- Project field onto surface
313         tmp<Field<vector> > project(const Field<tensor>&) const;
315         //- Sample field on surface
316         virtual tmp<scalarField> sample
317         (
318             const volScalarField&
319         ) const = 0;
321         //- Sample field on surface
322         virtual tmp<vectorField> sample
323         (
324             const volVectorField&
325         ) const = 0;
327         //- Sample field on surface
328         virtual tmp<sphericalTensorField> sample
329         (
330             const volSphericalTensorField&
331         ) const = 0;
333         //- Sample field on surface
334         virtual tmp<symmTensorField> sample
335         (
336             const volSymmTensorField&
337         ) const = 0;
339         //- Sample field on surface
340         virtual tmp<tensorField> sample
341         (
342             const volTensorField&
343         ) const = 0;
346         //- Interpolate field on surface
347         virtual tmp<scalarField> interpolate
348         (
349             const interpolation<scalar>&
350         ) const = 0;
353         //- Interpolate field on surface
354         virtual tmp<vectorField> interpolate
355         (
356             const interpolation<vector>&
357         ) const = 0;
359         //- Interpolate field on surface
360         virtual tmp<sphericalTensorField> interpolate
361         (
362             const interpolation<sphericalTensor>&
363         ) const = 0;
365         //- Interpolate field on surface
366         virtual tmp<symmTensorField> interpolate
367         (
368             const interpolation<symmTensor>&
369         ) const = 0;
371         //- Interpolate field on surface
372         virtual tmp<tensorField> interpolate
373         (
374             const interpolation<tensor>&
375         ) const = 0;
378       // Edit
380         //- Rename
381         virtual void rename(const word& newName)
382         {
383             name_ = newName;
384         }
387       // Write
389         //- Write
390         virtual void print(Ostream&) const;
393        // IOstream operators
395         friend Ostream& operator<<(Ostream&, const sampledSurface&);
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
401 } // End namespace Foam
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 #ifdef NoRepository
406 #   include "sampledSurfaceTemplates.C"
407 #endif
409 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 #endif
413 // ************************************************************************* //