BUG: cloudSet.C: force early construction of tetBasePtIs to avoid demand-driven comms
[OpenFOAM-2.0.x.git] / src / sampling / sampledSet / sampledSets / sampledSets.H
blob2007cda3d5af6d49873371f0a7443c126b641fd1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::sampledSets
27 Description
28     Set of sets to sample.
29     Call sampledSets.write() to sample&write files.
31 SourceFiles
32     sampledSets.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef sampledSets_H
37 #define sampledSets_H
39 #include "sampledSet.H"
40 #include "volFieldsFwd.H"
41 #include "meshSearch.H"
42 #include "interpolation.H"
43 #include "coordSet.H"
44 #include "writer.H"
45 #include "wordReList.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 class objectRegistry;
53 class dictionary;
54 class fvMesh;
56 /*---------------------------------------------------------------------------*\
57                          Class sampledSets Declaration
58 \*---------------------------------------------------------------------------*/
60 class sampledSets
62     public PtrList<sampledSet>
64     // Private classes
66         //- Class used for grouping field types
67         template<class Type>
68         class fieldGroup
69         :
70             public DynamicList<word>
71         {
72         public:
74             //- The set formatter
75             autoPtr< writer<Type> > formatter;
77             //- Construct null
78             fieldGroup()
79             :
80                 DynamicList<word>(0),
81                 formatter(NULL)
82             {}
84             //- Construct for a particular format
85             fieldGroup(const word& writeFormat)
86             :
87                 DynamicList<word>(0),
88                 formatter(writer<Type>::New(writeFormat))
89             {}
91             //- Reset format and field list
92             void clear()
93             {
94                 DynamicList<word>::clear();
95                 formatter.clear();
96             }
98             //- Assign a new formatter
99             void operator=(const word& writeFormat)
100             {
101                 formatter = writer<Type>::New(writeFormat);
102             }
104         };
107         //- Class used for sampling volFields
108         template <class Type>
109         class volFieldSampler
110         :
111             public List<Field<Type> >
112         {
113             //- Name of this collection of values
114             const word name_;
116         public:
118             //- Construct interpolating field to the sampleSets
119             volFieldSampler
120             (
121                 const word& interpolationScheme,
122                 const GeometricField<Type, fvPatchField, volMesh>& field,
123                 const PtrList<sampledSet>&
124             );
126             //- Construct mapping field to the sampleSets
127             volFieldSampler
128             (
129                 const GeometricField<Type, fvPatchField, volMesh>& field,
130                 const PtrList<sampledSet>&
131             );
133             //- Construct from components
134             volFieldSampler
135             (
136                 const List<Field<Type> >& values,
137                 const word& name
138             );
140             //- Return the field name
141             const word& name() const
142             {
143                 return name_;
144             }
145         };
148     // Static data members
150         //- output verbosity
151         static bool verbose_;
154     // Private data
156         //- Name of this set of sets,
157         //  Also used as the name of the sampledSets directory.
158         word name_;
160         //- Const reference to fvMesh
161         const fvMesh& mesh_;
163         //- Keep the dictionary to recreate sets for moving mesh cases
164         dictionary dict_;
166         //- Load fields from files (not from objectRegistry)
167         bool loadFromFiles_;
169         //- Output path
170         fileName outputPath_;
172         //- Mesh search engine
173         meshSearch searchEngine_;
176         // Read from dictonary
178             //- Names of fields to sample
179             wordReList fieldSelection_;
181             //- Interpolation scheme to use
182             word interpolationScheme_;
184             //- Output format to use
185             word writeFormat_;
188         // Categorized scalar/vector/tensor fields
190             fieldGroup<scalar> scalarFields_;
191             fieldGroup<vector> vectorFields_;
192             fieldGroup<sphericalTensor> sphericalTensorFields_;
193             fieldGroup<symmTensor> symmTensorFields_;
194             fieldGroup<tensor> tensorFields_;
197         // Merging structures
199             PtrList<coordSet> masterSampledSets_;
200             labelListList indexSets_;
203     // Private Member Functions
205         //- Clear old field groups
206         void clearFieldGroups();
208         //- Append fieldName to the appropriate group
209         label appendFieldGroup(const word& fieldName, const word& fieldType);
211         //- Classify field types, returns the number of fields
212         label classifyFields();
214         //- Combine points from all processors. Sort by curveDist and produce
215         //  index list. Valid result only on master processor.
216         void combineSampledSets
217         (
218             PtrList<coordSet>& masterSampledSets,
219             labelListList& indexSets
220         );
222         //- Combine values from all processors.
223         //  Valid result only on master processor.
224         template<class T>
225         void combineSampledValues
226         (
227             const PtrList<volFieldSampler<T> >& sampledFields,
228             const labelListList& indexSets,
229             PtrList<volFieldSampler<T> >& masterFields
230         );
232         template<class Type>
233         void writeSampleFile
234         (
235             const coordSet& masterSampleSet,
236             const PtrList<volFieldSampler<Type> >& masterFields,
237             const label setI,
238             const fileName& timeDir,
239             const writer<Type>& formatter
240         );
242         template<class Type>
243         void sampleAndWrite(fieldGroup<Type>& fields);
246         //- Disallow default bitwise copy construct and assignment
247         sampledSets(const sampledSets&);
248         void operator=(const sampledSets&);
251 public:
253     //- Runtime type information
254     TypeName("sets");
257     // Constructors
259         //- Construct for given objectRegistry and dictionary
260         //  allow the possibility to load fields from files
261         sampledSets
262         (
263             const word& name,
264             const objectRegistry&,
265             const dictionary&,
266             const bool loadFromFiles = false
267         );
270     //- Destructor
271     virtual ~sampledSets();
274     // Member Functions
276         //- Return name of the set of probes
277         virtual const word& name() const
278         {
279             return name_;
280         }
282         //- set verbosity level
283         void verbose(const bool verbosity = true);
285         //- Execute, currently does nothing
286         virtual void execute();
288         //- Execute at the final time-loop, currently does nothing
289         virtual void end();
291         //- Sample and write
292         virtual void write();
294         //- Read the sampledSets
295         virtual void read(const dictionary&);
297         //- Correct for mesh changes
298         void correct();
300         //- Update for changes of mesh
301         virtual void updateMesh(const mapPolyMesh&);
303         //- Update for mesh point-motion
304         virtual void movePoints(const pointField&);
306         //- Update for changes of mesh due to readUpdate
307         virtual void readUpdate(const polyMesh::readUpdateState state);
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313 } // End namespace Foam
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 #ifdef NoRepository
318 #   include "sampledSetsTemplates.C"
319 #endif
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 #endif
325 // ************************************************************************* //