FreeFOAM The Cross-Platform CFD Toolkit
sampledSet.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::sampledSet
26 
27 Description
28  Holds list of sampling points which is filled at construction time.
29  Various implementations of this base class to e.g. get sampling points
30  at uniform distance along a line (uniformSet) or directly specified
31  (cloudSet)
32 
33  Each 'sampledSet' has a name and a specifier of how the axis should be
34  write (x/y/z component or all 3 components)
35 
36 SourceFiles
37  sampledSet.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef sampledSet_H
42 #define sampledSet_H
43 
44 #include <OpenFOAM/pointField.H>
45 #include <OpenFOAM/word.H>
46 #include <OpenFOAM/labelList.H>
47 #include <OpenFOAM/typeInfo.H>
49 #include <OpenFOAM/autoPtr.H>
50 #include <sampling/coordSet.H>
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward declaration of classes
58 class polyMesh;
59 class meshSearch;
60 
61 /*---------------------------------------------------------------------------*\
62  Class sampledSet Declaration
63 \*---------------------------------------------------------------------------*/
64 
66 :
67  public coordSet
68 {
69  // Private data
70 
71  //- Reference to mesh
72  const polyMesh& mesh_;
73 
74  //- Reference to mesh searching class
75  meshSearch& searchEngine_;
76 
77 
78 protected:
79 
80  //- Segment numbers
82 
83  //- Parameter along sample curve. Uniquely identifies position
84  // along sampling. Used for combining parallel results.
86 
87  //- Cell numbers
89 
90  //- Face numbers (-1 if not known)
92 
93 
94  // Protected Member Functions
95 
96  //- Returns cell next to boundary face
97  label getBoundaryCell(const label) const;
98 
99  //- Returns cell using face and containing sample
100  label getCell
101  (
102  const label faceI,
103  const point& sample
104  ) const;
105 
106  //- Calculates inproduct of face normal and vector sample-face centre
107  // <0 if sample inside.
108  scalar calcSign(const label faceI, const point& sample) const;
109 
110  //- Returns face label (or -1) of face which is close to sample
111  label findNearFace
112  (
113  const label cellI,
114  const point& sample,
115  const scalar smallDist
116  ) const;
117 
118  //- Moves sample in direction of -n to it is 'inside' of faceI
119  point pushIn
120  (
121  const point& sample,
122  const label faceI
123  ) const;
124 
125  //- Calculates start of tracking given samplePt and first boundary
126  // intersection
127  // (bPoint, bFaceI) (bFaceI == -1 if no boundary intersection)
128  // Returns true if trackPt is valid sampling point. Sets trackPt,
129  // trackFaceI, trackCellI (-1 if no tracking point found)
130  bool getTrackingPoint
131  (
132  const vector& offset,
133  const point& samplePt,
134  const point& bPoint,
135  const label bFaceI,
136 
137  point& trackPt,
138  label& trackCellI,
139  label& trackFaceI
140  ) const;
141 
142  //- Sets sample data
143  void setSamples
144  (
145  const List<point>& samplingPts,
146  const labelList& samplingCells,
147  const labelList& samplingFaces,
148  const labelList& samplingSegments,
149  const scalarList& samplingCurveDist
150  );
151 
152 
153 public:
154 
155  //- Runtime type information
156  TypeName("sampledSet");
157 
158 
159  // Declare run-time constructor selection table
160 
162  (
163  autoPtr,
164  sampledSet,
165  word,
166  (
167  const word& name,
168  const polyMesh& mesh,
170  const dictionary& dict
171  ),
172  (name, mesh, searchEngine, dict)
173  );
174 
175 
176  //- Class used for the read-construction of
177  // PtrLists of sampledSet
178  class iNew
179  {
180  const polyMesh& mesh_;
181  meshSearch& searchEngine_;
182 
183  public:
184 
185  iNew(const polyMesh& mesh, meshSearch& searchEngine)
186  :
187  mesh_(mesh),
188  searchEngine_(searchEngine)
189  {}
190 
192  {
193  word name(is);
194  dictionary dict(is);
195  return sampledSet::New(name, mesh_, searchEngine_, dict);
196  }
197  };
198 
199 
200  // Static data
201 
202  //- Tolerance when comparing points. Usually relative to difference
203  // between start_ and end_
204  const static scalar tol;
205 
206 
207  // Constructors
208 
209  //- Construct from components
210  sampledSet
211  (
212  const word& name,
213  const polyMesh& mesh,
214  meshSearch& searchEngine,
215  const word& axis
216  );
217 
218  //- Construct from dictionary
219  sampledSet
220  (
221  const word& name,
222  const polyMesh& mesh,
223  meshSearch& searchEngine,
224  const dictionary& dict
225  );
226 
227  //- Clone
229  {
230  notImplemented("autoPtr<sampledSet> clone() const");
231  return autoPtr<sampledSet>(NULL);
232  }
233 
234 
235  // Selectors
236 
237  //- Return a reference to the selected sampledSet
238  static autoPtr<sampledSet> New
239  (
240  const word& name,
241  const polyMesh& mesh,
242  meshSearch& searchEngine,
243  const dictionary& dict
244  );
245 
246 
247  // Destructor
248 
249  virtual ~sampledSet();
250 
251 
252  // Member Functions
253 
254  const polyMesh& mesh() const
255  {
256  return mesh_;
257  }
258 
260  {
261  return searchEngine_;
262  }
263 
264  const labelList& segments() const
265  {
266  return segments_;
267  }
268 
269  const scalarList& curveDist() const
270  {
271  return curveDist_;
272  }
273 
274  const labelList& cells() const
275  {
276  return cells_;
277  }
278 
279  const labelList& faces() const
280  {
281  return faces_;
282  }
283 
284  //- Given all sampling points (on all processors) return reference point
285  virtual point getRefPoint(const List<point>&) const = 0;
286 
287  //- Output for debugging
288  Ostream& write(Ostream&) const;
289 };
290 
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 } // End namespace Foam
295 
296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 
298 #endif
299 
300 // ************************ vim: set sw=4 sts=4 et: ************************ //