initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / sampling / sampledSet / sampledSet / sampledSet.H
blob10248f7817a8f11b909d5f30570b1bfec0f4d7cc
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::sampledSet
28 Description
29     Holds list of sampling points which is filled at construction time.
30     Various implementations of this base class to e.g. get sampling points
31     at uniform distance along a line (uniformSet) or directly specified
32     (cloudSet)
34     Each 'sampledSet' has a name and a specifier of how the axis should be
35     write (x/y/z component or all 3 components)
37 SourceFiles
38     sampledSet.C
40 \*---------------------------------------------------------------------------*/
42 #ifndef sampledSet_H
43 #define sampledSet_H
45 #include "pointField.H"
46 #include "word.H"
47 #include "labelList.H"
48 #include "typeInfo.H"
49 #include "runTimeSelectionTables.H"
50 #include "autoPtr.H"
51 #include "coordSet.H"
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 namespace Foam
58 // Forward declaration of classes
59 class polyMesh;
60 class meshSearch;
62 /*---------------------------------------------------------------------------*\
63                            Class sampledSet Declaration
64 \*---------------------------------------------------------------------------*/
66 class sampledSet
68     public coordSet
70     // Private data
72         //- Reference to mesh
73         const polyMesh& mesh_;
75         //- Reference to mesh searching class
76         meshSearch& searchEngine_;
79 protected:
81         //- Segment numbers
82         labelList segments_;
84         //- Parameter along sample curve. Uniquely identifies position
85         //  along sampling. Used for combining parallel results.
86         scalarList curveDist_;
88         //- Cell numbers
89         labelList cells_;
91         //- Face numbers (-1 if not known)
92         labelList faces_;
95     // Protected Member Functions
97         //- Returns cell next to boundary face
98         label getBoundaryCell(const label) const;
100         //- Returns cell using face and containing sample
101         label getCell
102         (
103             const label faceI,
104             const point& sample
105         ) const;
107         //- Calculates inproduct of face normal and vector sample-face centre
108         //  <0 if sample inside.
109         scalar calcSign(const label faceI, const point& sample) const;
111         //- Returns face label (or -1) of face which is close to sample
112         label findNearFace
113         (
114             const label cellI,
115             const point& sample,
116             const scalar smallDist
117         ) const;
119         //- Moves sample in direction of -n to it is 'inside' of faceI
120         point pushIn
121         (
122             const point& sample,
123             const label faceI
124         ) const;
126         //- Calculates start of tracking given samplePt and first boundary
127         //  intersection
128         //  (bPoint, bFaceI) (bFaceI == -1 if no boundary intersection)
129         //  Returns true if trackPt is valid sampling point. Sets trackPt,
130         //  trackFaceI, trackCellI (-1 if no tracking point found)
131         bool getTrackingPoint
132         (
133             const vector& offset,
134             const point& samplePt,
135             const point& bPoint,
136             const label bFaceI,
138             point& trackPt,
139             label& trackCellI,
140             label& trackFaceI
141         ) const;
143         //- Sets sample data
144         void setSamples
145         (
146             const List<point>& samplingPts,
147             const labelList& samplingCells,
148             const labelList& samplingFaces,
149             const labelList& samplingSegments,
150             const scalarList& samplingCurveDist
151         );
154 public:
156     //- Runtime type information
157     TypeName("sampledSet");
160     // Declare run-time constructor selection table
162         declareRunTimeSelectionTable
163         (
164             autoPtr,
165             sampledSet,
166             word,
167             (
168                 const word& name,
169                 const polyMesh& mesh,
170                 meshSearch& searchEngine,
171                 const dictionary& dict
172             ),
173             (name, mesh, searchEngine, dict)
174         );
177         //- Class used for the read-construction of
178         //  PtrLists of sampledSet
179         class iNew
180         {
181             const polyMesh& mesh_;
182             meshSearch& searchEngine_;
184         public:
186             iNew(const polyMesh& mesh, meshSearch& searchEngine)
187             :
188                 mesh_(mesh),
189                 searchEngine_(searchEngine)
190             {}
192             autoPtr<sampledSet> operator()(Istream& is) const
193             {
194                 word name(is);
195                 dictionary dict(is);
196                 return sampledSet::New(name, mesh_, searchEngine_, dict);
197             }
198         };
201     // Static data
203         //- Tolerance when comparing points. Usually relative to difference
204         //  between start_ and end_
205         const static scalar tol;
208     // Constructors
210         //- Construct from components
211         sampledSet
212         (
213             const word& name,
214             const polyMesh& mesh,
215             meshSearch& searchEngine,
216             const word& axis
217         );
219         //- Construct from dictionary
220         sampledSet
221         (
222             const word& name,
223             const polyMesh& mesh,
224             meshSearch& searchEngine,
225             const dictionary& dict
226         );
228         //- Clone
229         autoPtr<sampledSet> clone() const
230         {
231             notImplemented("autoPtr<sampledSet> clone() const");
232             return autoPtr<sampledSet>(NULL);
233         }
236     // Selectors
238         //- Return a reference to the selected sampledSet
239         static autoPtr<sampledSet> New
240         (
241             const word& name,
242             const polyMesh& mesh,
243             meshSearch& searchEngine,
244             const dictionary& dict
245         );
248     // Destructor
250         virtual ~sampledSet();
253     // Member Functions
255         const polyMesh& mesh() const
256         {
257             return mesh_;
258         }
260         meshSearch& searchEngine() const
261         {
262             return searchEngine_;
263         }
265         const labelList& segments() const
266         {
267             return segments_;
268         }
270         const scalarList& curveDist() const
271         {
272             return curveDist_;
273         }
275         const labelList& cells() const
276         {
277             return cells_;
278         }
280         const labelList& faces() const
281         {
282             return faces_;
283         }
285         //- Given all sampling points (on all processors) return reference point
286         virtual point getRefPoint(const List<point>&) const = 0;
288         //- Output for debugging
289         Ostream& write(Ostream&) const;
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 } // End namespace Foam
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 #endif
301 // ************************************************************************* //