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

sampledSets.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::sampledSets
00027 
00028 Description
00029     Set of sets to sample.
00030     Call sampledSets.write() to sample&write files.
00031 
00032 SourceFiles
00033     sampledSets.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef sampledSets_H
00038 #define sampledSets_H
00039 
00040 #include "sampledSet.H"
00041 #include "volFieldsFwd.H"
00042 #include "meshSearch.H"
00043 #include "interpolation.H"
00044 #include "coordSet.H"
00045 #include "writer.H"
00046 
00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00048 
00049 namespace Foam
00050 {
00051 
00052 class objectRegistry;
00053 class dictionary;
00054 class fvMesh;
00055 
00056 /*---------------------------------------------------------------------------*\
00057                       Class sampledSets Declaration
00058 \*---------------------------------------------------------------------------*/
00059 
00060 class sampledSets
00061 :
00062     public PtrList<sampledSet>
00063 {
00064     // Private classes
00065 
00066         //- Class used for grouping field types
00067         template<class Type>
00068         class fieldGroup
00069         :
00070             public wordList
00071         {
00072         public:
00073 
00074             //- Set formatter
00075             autoPtr<writer<Type> > formatter;
00076 
00077             //- Construct null
00078             fieldGroup()
00079             :
00080                 wordList(0),
00081                 formatter(NULL)
00082             {}
00083 
00084             void clear()
00085             {
00086                 wordList::clear();
00087                 formatter.clear();
00088             }
00089         };
00090 
00091 
00092         //- Class used for sampling volFields
00093         template <class Type>
00094         class volFieldSampler
00095         :
00096             public List<Field<Type> >
00097         {
00098             //- Name of this collection of values
00099             const word name_;
00100 
00101         public:
00102 
00103             //- Construct interpolating field to the sampleSets
00104             volFieldSampler
00105             (
00106                 const word& interpolationScheme,
00107                 const GeometricField<Type, fvPatchField, volMesh>& field,
00108                 const PtrList<sampledSet>&
00109             );
00110 
00111             //- Construct mapping field to the sampleSets
00112             volFieldSampler
00113             (
00114                 const GeometricField<Type, fvPatchField, volMesh>& field,
00115                 const PtrList<sampledSet>&
00116             );
00117 
00118             //- Construct from components
00119             volFieldSampler
00120             (
00121                 const List<Field<Type> >& values,
00122                 const word& name
00123             );
00124 
00125             //- Return the field name
00126             const word& name() const
00127             {
00128                 return name_;
00129             }
00130         };
00131 
00132 
00133     // Static data members
00134 
00135         //- output verbosity
00136         static bool verbose_;
00137 
00138 
00139     // Private data
00140 
00141         //- Name of this set of sets,
00142         //  Also used as the name of the sampledSets directory.
00143         word name_;
00144 
00145         //- Const reference to fvMesh
00146         const fvMesh& mesh_;
00147 
00148         //- Keep the dictionary to recreate sets for moving mesh cases
00149         dictionary dict_;
00150 
00151         //- Load fields from files (not from objectRegistry)
00152         bool loadFromFiles_;
00153 
00154         //- Output path
00155         fileName outputPath_;
00156 
00157         //- Mesh search engine
00158         meshSearch searchEngine_;
00159 
00160 
00161         // Read from dictonary
00162 
00163             //- Names of fields to sample
00164             wordList fieldNames_;
00165 
00166             //- Interpolation scheme to use
00167             word interpolationScheme_;
00168 
00169             //- Output format to use
00170             word writeFormat_;
00171 
00172 
00173         // Categorized scalar/vector/tensor fields
00174 
00175             fieldGroup<scalar> scalarFields_;
00176             fieldGroup<vector> vectorFields_;
00177             fieldGroup<sphericalTensor> sphericalTensorFields_;
00178             fieldGroup<symmTensor> symmTensorFields_;
00179             fieldGroup<tensor> tensorFields_;
00180 
00181 
00182         // Merging structures
00183 
00184             PtrList<coordSet> masterSampledSets_;
00185             labelListList indexSets_;
00186 
00187 
00188     // Private Member Functions
00189 
00190         //- Classify field types, return true if nFields > 0
00191         bool checkFieldTypes();
00192 
00193         //- Find the fields in the list of the given type, return count
00194         template<class Type>
00195         label grep
00196         (
00197             fieldGroup<Type>& fieldList,
00198             const wordList& fieldTypes
00199         ) const;
00200 
00201         //- Combine points from all processors. Sort by curveDist and produce
00202         //  index list. Valid result only on master processor.
00203         void combineSampledSets
00204         (
00205             PtrList<coordSet>& masterSampledSets,
00206             labelListList& indexSets
00207         );
00208 
00209         //- Combine values from all processors.
00210         //  Valid result only on master processor.
00211         template<class T>
00212         void combineSampledValues
00213         (
00214             const PtrList<volFieldSampler<T> >& sampledFields,
00215             const labelListList& indexSets,
00216             PtrList<volFieldSampler<T> >& masterFields
00217         );
00218 
00219         template<class Type>
00220         void writeSampleFile
00221         (
00222             const coordSet& masterSampleSet,
00223             const PtrList<volFieldSampler<Type> >& masterFields,
00224             const label setI,
00225             const fileName& timeDir,
00226             const writer<Type>& formatter
00227         );
00228 
00229         template<class Type>
00230         void sampleAndWrite(fieldGroup<Type>& fields);
00231 
00232 
00233         //- Disallow default bitwise copy construct and assignment
00234         sampledSets(const sampledSets&);
00235         void operator=(const sampledSets&);
00236 
00237 
00238 public:
00239 
00240     //- Runtime type information
00241     TypeName("sets");
00242 
00243 
00244     // Constructors
00245 
00246         //- Construct for given objectRegistry and dictionary
00247         //  allow the possibility to load fields from files
00248         sampledSets
00249         (
00250             const word& name,
00251             const objectRegistry&,
00252             const dictionary&,
00253             const bool loadFromFiles = false
00254         );
00255 
00256 
00257     // Destructor
00258 
00259         virtual ~sampledSets();
00260 
00261 
00262     // Member Functions
00263 
00264         //- Return name of the set of probes
00265         virtual const word& name() const
00266         {
00267             return name_;
00268         }
00269 
00270         //- set verbosity level
00271         void verbose(const bool verbosity = true);
00272 
00273         //- Execute, currently does nothing
00274         virtual void execute();
00275 
00276         //- Execute at the final time-loop, currently does nothing
00277         virtual void end();
00278 
00279         //- Sample and write
00280         virtual void write();
00281 
00282         //- Read the sampledSets
00283         virtual void read(const dictionary&);
00284 
00285         //- Correct for mesh changes
00286         void correct();
00287 
00288         //- Update for changes of mesh
00289         virtual void updateMesh(const mapPolyMesh&);
00290 
00291         //- Update for mesh point-motion
00292         virtual void movePoints(const pointField&);
00293 
00294         //- Update for changes of mesh due to readUpdate
00295         virtual void readUpdate(const polyMesh::readUpdateState state);
00296 };
00297 
00298 
00299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00300 
00301 } // End namespace Foam
00302 
00303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00304 
00305 #ifdef NoRepository
00306 #   include "sampledSetsTemplates.C"
00307 #endif
00308 
00309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00310 
00311 #endif
00312 
00313 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd