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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::sampledSet
29 
30 Group
31  grpUtilitiesFunctionObjects
32 
33 Description
34  Holds list of sampling points which is filled at construction time.
35  Various implementations of this base class to e.g. get sampling points
36  at uniform distance along a line (uniformSet) or directly specified
37  (cloudSet)
38 
39  Each 'sampledSet' has a name and a specifier of how the axis should be
40  write (x/y/z component or all 3 components)
41 
42  For a dictionary specification:
43  \table
44  Property | Description | Required | Default
45  axis | x, y, z, xyz, distance | yes |
46  \endtable
47 
48 SourceFiles
49  sampledSet.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef Foam_sampledSet_H
54 #define Foam_sampledSet_H
55 
56 #include "coordSet.H"
57 #include "autoPtr.H"
58 #include "typeInfo.H"
59 #include "runTimeSelectionTables.H"
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 namespace Foam
64 {
65 
66 // Forward Declarations
67 class polyMesh;
68 class meshSearch;
69 
70 /*---------------------------------------------------------------------------*\
71  Class sampledSet Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 class sampledSet
75 :
76  public coordSet
77 {
78  // Private Data
79 
80  //- Reference to mesh
81  const polyMesh& mesh_;
82 
83  //- Reference to mesh searching class
84  const meshSearch& searchEngine_;
85 
86 
87 protected:
88 
89  // Protected Data
90 
91  //- Segment numbers
93 
94  //- Cell numbers
96 
97  //- Face numbers (-1 if not known)
99 
100 
101  // Protected Member Functions
102 
103  //- Check for consistent sizing
104  void checkDimensions() const;
105 
106  //- Returns cell next to boundary face
107  label getBoundaryCell(const label) const;
109  //- Returns the neighbour cell or the owner if face in on the boundary
110  label getNeighbourCell(const label) const;
111 
112  //- Return the cell in which the point on the sample line
113  // resides if found otherwise return -1
114  label pointInCell(const point& p, const label samplei) const;
115 
116  //- Calculates inproduct of face normal and vector sample-face centre
117  // <0 if sample inside.
118  scalar calcSign(const label facei, const point& sample) const;
119 
120  //- Returns face label (or -1) of face which is close to sample
121  label findNearFace
122  (
123  const label celli,
124  const point& sample,
125  const scalar smallDist
126  ) const;
127 
128  //- Moves sample in direction of -n to it is 'inside' of facei
129  point pushIn
130  (
131  const point& sample,
132  const label facei
133  ) const;
134 
135  //- Calculates start of tracking given samplePt and first boundary
136  // intersection
137  // (bPoint, bFacei) (bFacei == -1 if no boundary intersection)
138  // Returns true if trackPt is valid sampling point. Sets trackPt,
139  // trackFacei, trackCelli (-1 if no tracking point found)
140  bool getTrackingPoint
141  (
142  const point& samplePt,
143  const point& bPoint,
144  const label bFacei,
145  const scalar smallDist,
146 
147  point& trackPt,
148  label& trackCelli,
149  label& trackFacei
150  ) const;
151 
152  //- Set sample data. Copy list contents.
153  void setSamples
154  (
155  const List<point>& samplingPts,
156  const labelList& samplingCells,
157  const labelList& samplingFaces,
158  const labelList& samplingSegments,
159  const scalarList& samplingDistance
160  );
161 
162  //- Set sample data. Move list contents.
163  void setSamples
164  (
165  List<point>&& samplingPts,
166  labelList&& samplingCells,
167  labelList&& samplingFaces,
168  labelList&& samplingSegments,
169  scalarList&& samplingDistance
170  );
171 
172 public:
173 
174  //- Runtime type information
175  TypeName("sampledSet");
176 
177 
178  // Declare run-time constructor selection table
179 
181  (
182  autoPtr,
183  sampledSet,
184  word,
185  (
186  const word& name,
187  const polyMesh& mesh,
188  const meshSearch& searchEngine,
189  const dictionary& dict
190  ),
192  );
193 
194 
195  //- Class used for the read-construction of
196  // PtrLists of sampledSet
197  class iNew
198  {
199  //- Reference to the volume mesh
200  const polyMesh& mesh_;
201  const meshSearch& search_;
202 
203  public:
204 
205  iNew(const polyMesh& mesh, const meshSearch& searchEngine)
206  :
207  mesh_(mesh),
208  search_(searchEngine)
209  {}
210 
212  {
213  word name(is);
214  dictionary dict(is);
215  return sampledSet::New(name, mesh_, search_, dict);
216  }
217  };
218 
219 
220  //- PtrList read-construction helper that captures dictionaries used
221  //- during creation.
222  class iNewCapture
223  {
224  //- Reference to the volume mesh
225  const polyMesh& mesh_;
226  const meshSearch& search_;
227 
228  //- Captured (recorded) dictionaries
229  DynamicList<dictionary>& capture_;
230 
231  public:
232 
234  (
235  const polyMesh& mesh,
236  const meshSearch& searchEngine,
237  DynamicList<dictionary>& capture
238  )
239  :
240  mesh_(mesh),
241  search_(searchEngine),
242  capture_(capture)
243  {}
244 
246  {
247  word name(is);
248  dictionary& dict = capture_.emplace_back(is);
249 
250  return sampledSet::New(name, mesh_, search_, dict);
251  }
252  };
253 
254 
255  // Constructors
257  //- Construct from components
258  sampledSet
259  (
260  const word& name,
261  const polyMesh& mesh,
262  const meshSearch& searchEngine,
263  const coordSet::coordFormat axisType
264  );
265 
266  //- Construct from components
267  sampledSet
268  (
269  const word& name,
270  const polyMesh& mesh,
271  const meshSearch& searchEngine,
272  const word& axis
273  );
274 
275  //- Construct from dictionary
276  sampledSet
277  (
278  const word& name,
279  const polyMesh& mesh,
280  const meshSearch& searchEngine,
281  const dictionary& dict
282  );
283 
284  //- Clone
286  {
288  return nullptr;
289  }
290 
291 
292  // Selectors
293 
294  //- Return a reference to the selected sampledSet
295  static autoPtr<sampledSet> New
296  (
297  const word& name,
298  const polyMesh& mesh,
299  const meshSearch& searchEngine,
300  const dictionary& dict
301  );
302 
303 
304  //- Destructor
305  virtual ~sampledSet() = default;
306 
307 
308  // Member Functions
309 
310  const polyMesh& mesh() const noexcept
311  {
312  return mesh_;
313  }
314 
315  const meshSearch& searchEngine() const noexcept
316  {
317  return searchEngine_;
318  }
319 
320  const labelList& segments() const noexcept
321  {
322  return segments_;
323  }
324 
325  const labelList& cells() const noexcept
326  {
327  return cells_;
328  }
329 
330  const labelList& faces() const noexcept
331  {
332  return faces_;
333  }
334 
335  //- Output for debugging
336  Ostream& write(Ostream&) const;
337 
338 
339  // Other
340 
348 };
349 
350 
351 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 
353 } // End namespace Foam
354 
355 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 
357 #endif
358 
359 // ************************************************************************* //
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:56
dictionary dict
void checkDimensions() const
Check for consistent sizing.
Definition: sampledSet.C:40
iNew(const polyMesh &mesh, const meshSearch &searchEngine)
Definition: sampledSet.H:250
const word & axis() const
The sort axis name.
Definition: coordSet.H:160
label findNearFace(const label celli, const point &sample, const scalar smallDist) const
Returns face label (or -1) of face which is close to sample.
Definition: sampledSet.C:176
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static autoPtr< sampledSet > New(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Return a reference to the selected sampledSet.
Definition: sampledSet.C:477
label getNeighbourCell(const label) const
Returns the neighbour cell or the owner if face in on the boundary.
Definition: sampledSet.C:68
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
autoPtr< sampledSet > operator()(Istream &is) const
Definition: sampledSet.H:296
const labelList & faces() const noexcept
Definition: sampledSet.H:393
point pushIn(const point &sample, const label facei) const
Moves sample in direction of -n to it is &#39;inside&#39; of facei.
Definition: sampledSet.C:202
virtual ~sampledSet()=default
Destructor.
sampledSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const coordSet::coordFormat axisType)
Construct from components.
Definition: sampledSet.C:405
Ostream & write(Ostream &) const
Output for debugging.
Definition: sampledSet.C:512
autoPtr< sampledSet > operator()(Istream &is) const
Definition: sampledSet.H:256
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:79
A class for handling words, derived from Foam::string.
Definition: word.H:63
coordFormat
Enumeration defining the output format for coordinates.
Definition: coordSet.H:60
const word & name() const noexcept
The coord-set name.
Definition: coordSet.H:152
TypeName("sampledSet")
Runtime type information.
const direction noexcept
Definition: Scalar.H:258
Class used for the read-construction of.
Definition: sampledSet.H:240
labelList segments_
Segment numbers.
Definition: sampledSet.H:103
const labelList & segments() const noexcept
Definition: sampledSet.H:383
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
declareRunTimeSelectionTable(autoPtr, sampledSet, word,(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict),(name, mesh, searchEngine, dict))
const polyMesh & mesh() const noexcept
Definition: sampledSet.H:373
label getBoundaryCell(const label) const
Returns cell next to boundary face.
Definition: sampledSet.C:62
iNewCapture(const polyMesh &mesh, const meshSearch &searchEngine, DynamicList< dictionary > &capture)
Definition: sampledSet.H:285
label pointInCell(const point &p, const label samplei) const
Return the cell in which the point on the sample line.
Definition: sampledSet.C:80
scalar calcSign(const label facei, const point &sample) const
Calculates inproduct of face normal and vector sample-face centre.
Definition: sampledSet.C:152
const meshSearch & searchEngine() const noexcept
Definition: sampledSet.H:378
autoPtr< sampledSet > clone() const
Clone.
Definition: sampledSet.H:344
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
void setSamples(const List< point > &samplingPts, const labelList &samplingCells, const labelList &samplingFaces, const labelList &samplingSegments, const scalarList &samplingDistance)
Set sample data. Copy list contents.
Definition: sampledSet.C:363
labelList cells_
Cell numbers.
Definition: sampledSet.H:108
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Macros to ease declaration of run-time selection tables.
List< label > labelList
A List of labels.
Definition: List.H:62
const labelList & cells() const noexcept
Definition: sampledSet.H:388
volScalarField & p
bool getTrackingPoint(const point &samplePt, const point &bPoint, const label bFacei, const scalar smallDist, point &trackPt, label &trackCelli, label &trackFacei) const
Calculates start of tracking given samplePt and first boundary.
Definition: sampledSet.C:267
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
labelList faces_
Face numbers (-1 if not known)
Definition: sampledSet.H:113
Namespace for OpenFOAM.