OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

sampledIsoSurface.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::sampledIsoSurface
00027 
00028 Description
00029     A sampledSurface defined by a surface of iso value. Always triangulated.
00030     To be used in sampleSurfaces / functionObjects. Recalculates iso surface
00031     only if time changes.
00032 
00033 SourceFiles
00034     sampledIsoSurface.C
00035 
00036 \*---------------------------------------------------------------------------*/
00037 
00038 #ifndef sampledIsoSurface_H
00039 #define sampledIsoSurface_H
00040 
00041 #include "isoSurface.H"
00042 #include "sampledSurface.H"
00043 #include "ZoneIDs.H"
00044 #include "fvMeshSubset.H"
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 /*---------------------------------------------------------------------------*\
00052                        Class sampledIsoSurface Declaration
00053 \*---------------------------------------------------------------------------*/
00054 
00055 class sampledIsoSurface
00056 :
00057     public sampledSurface
00058 {
00059     // Private data
00060 
00061         //- Field to get isoSurface of
00062         const word isoField_;
00063 
00064         //- iso value
00065         const scalar isoVal_;
00066 
00067         //- Merge tolerance
00068         const scalar mergeTol_;
00069 
00070         //- Whether to coarse
00071         const Switch regularise_;
00072 
00073         //- Whether to recalculate cell values as average of point values
00074         const Switch average_;
00075 
00076         //- zone name/index (if restricted to zones)
00077         mutable cellZoneID zoneID_;
00078 
00079         //- for zones: patch to put exposed faces into
00080         mutable word exposedPatchName_;
00081 
00082         mutable autoPtr<isoSurface> surfPtr_;
00083 
00084         //- triangles converted to faceList
00085         mutable autoPtr<faceList> facesPtr_;
00086 
00087 
00088         // Recreated for every isoSurface
00089 
00090             //- Time at last call, also track if surface needs an update
00091             mutable label prevTimeIndex_;
00092 
00093             //- Cached volfield
00094             mutable autoPtr<volScalarField> storedVolFieldPtr_;
00095             mutable const volScalarField* volFieldPtr_;
00096 
00097             //- Cached pointfield
00098             mutable autoPtr<pointScalarField> storedPointFieldPtr_;
00099             mutable const pointScalarField* pointFieldPtr_;
00100 
00101             // And on subsetted mesh
00102 
00103                 //- Cached submesh
00104                 mutable autoPtr<fvMeshSubset> subMeshPtr_;
00105 
00106                 //- Cached volfield
00107                 mutable autoPtr<volScalarField> storedVolSubFieldPtr_;
00108                 mutable const volScalarField* volSubFieldPtr_;
00109 
00110                 //- Cached pointfield
00111                 mutable autoPtr<pointScalarField> storedPointSubFieldPtr_;
00112                 mutable const pointScalarField* pointSubFieldPtr_;
00113 
00114 
00115 
00116     // Private Member Functions
00117 
00118         //- Get fields needed to recreate iso surface.
00119         void getIsoFields() const;
00120 
00121         tmp<volScalarField> average
00122         (
00123             const fvMesh&,
00124             const pointScalarField&
00125         ) const;
00126 
00127         tmp<pointScalarField> average
00128         (
00129             const pointMesh&,
00130             const volScalarField& fld
00131         ) const;
00132 
00133         //- Create iso surface (if time has changed)
00134         //  Do nothing (and return false) if no update was needed
00135         bool updateGeometry() const;
00136 
00137         //- sample field on faces
00138         template <class Type>
00139         tmp<Field<Type> > sampleField
00140         (
00141             const GeometricField<Type, fvPatchField, volMesh>& vField
00142         ) const;
00143 
00144 
00145         template <class Type>
00146         tmp<Field<Type> >
00147         interpolateField(const interpolation<Type>&) const;
00148 
00149 
00150 public:
00151 
00152     //- Runtime type information
00153     TypeName("sampledIsoSurface");
00154 
00155 
00156     // Constructors
00157 
00158         //- Construct from dictionary
00159         sampledIsoSurface
00160         (
00161             const word& name,
00162             const polyMesh& mesh,
00163             const dictionary& dict
00164         );
00165 
00166 
00167     // Destructor
00168 
00169         virtual ~sampledIsoSurface();
00170 
00171 
00172     // Member Functions
00173 
00174         //- Does the surface need an update?
00175         virtual bool needsUpdate() const;
00176 
00177         //- Mark the surface as needing an update.
00178         //  May also free up unneeded data.
00179         //  Return false if surface was already marked as expired.
00180         virtual bool expire();
00181 
00182         //- Update the surface as required.
00183         //  Do nothing (and return false) if no update was needed
00184         virtual bool update();
00185 
00186 
00187         //- Points of surface
00188         virtual const pointField& points() const
00189         {
00190             return surface().points();
00191         }
00192 
00193         //- Faces of surface
00194         virtual const faceList& faces() const
00195         {
00196             if (facesPtr_.empty())
00197             {
00198                 const triSurface& s = surface();
00199 
00200                 facesPtr_.reset(new faceList(s.size()));
00201 
00202                 forAll(s, i)
00203                 {
00204                     facesPtr_()[i] = s[i].triFaceFace();
00205                 }
00206             }
00207             return facesPtr_;
00208         }
00209 
00210 
00211         const isoSurface& surface() const
00212         {
00213             return surfPtr_();
00214         }
00215 
00216         //- Lookup or read isoField. Sets volFieldPtr_ and pointFieldPtr_.
00217         void getIsoField();
00218 
00219 
00220         //- sample field on surface
00221         virtual tmp<scalarField> sample
00222         (
00223             const volScalarField&
00224         ) const;
00225 
00226         //- sample field on surface
00227         virtual tmp<vectorField> sample
00228         (
00229             const volVectorField&
00230         ) const;
00231 
00232         //- sample field on surface
00233         virtual tmp<sphericalTensorField> sample
00234         (
00235             const volSphericalTensorField&
00236         ) const;
00237 
00238         //- sample field on surface
00239         virtual tmp<symmTensorField> sample
00240         (
00241             const volSymmTensorField&
00242         ) const;
00243 
00244         //- sample field on surface
00245         virtual tmp<tensorField> sample
00246         (
00247             const volTensorField&
00248         ) const;
00249 
00250 
00251         //- interpolate field on surface
00252         virtual tmp<scalarField> interpolate
00253         (
00254             const interpolation<scalar>&
00255         ) const;
00256 
00257         //- interpolate field on surface
00258         virtual tmp<vectorField> interpolate
00259         (
00260             const interpolation<vector>&
00261         ) const;
00262 
00263         //- interpolate field on surface
00264         virtual tmp<sphericalTensorField> interpolate
00265         (
00266             const interpolation<sphericalTensor>&
00267         ) const;
00268 
00269         //- interpolate field on surface
00270         virtual tmp<symmTensorField> interpolate
00271         (
00272             const interpolation<symmTensor>&
00273         ) const;
00274 
00275         //- interpolate field on surface
00276         virtual tmp<tensorField> interpolate
00277         (
00278             const interpolation<tensor>&
00279         ) const;
00280 
00281         //- Write
00282         virtual void print(Ostream&) const;
00283 };
00284 
00285 
00286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00287 
00288 } // End namespace Foam
00289 
00290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00291 
00292 #ifdef NoRepository
00293 #   include "sampledIsoSurfaceTemplates.C"
00294 #endif
00295 
00296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00297 
00298 #endif
00299 
00300 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd