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-2018 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 sampledSet_H
54 #define sampledSet_H
55 
56 #include "coordSet.H"
57 #include "typeInfo.H"
58 #include "runTimeSelectionTables.H"
59 #include "autoPtr.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  //- Segment numbers
91 
92  //- Cell numbers
94 
95  //- Face numbers (-1 if not known)
97 
98 
99  // Protected Member Functions
100 
101  //- Check for consistent sizing
102  void checkDimensions() const;
103 
104  //- Returns cell next to boundary face
105  label getBoundaryCell(const label) const;
106 
107  //- Returns the neighbour cell or the owner if face in on the boundary
108  label getNeighbourCell(const label) const;
109 
110  //- Return the cell in which the point on the sample line
111  // resides if found otherwise return -1
112  label pointInCell(const point& p, const label samplei) const;
113 
114  //- Calculates inproduct of face normal and vector sample-face centre
115  // <0 if sample inside.
116  scalar calcSign(const label facei, const point& sample) const;
117 
118  //- Returns face label (or -1) of face which is close to sample
119  label findNearFace
120  (
121  const label celli,
122  const point& sample,
123  const scalar smallDist
124  ) const;
125 
126  //- Moves sample in direction of -n to it is 'inside' of facei
127  point pushIn
128  (
129  const point& sample,
130  const label facei
131  ) const;
132 
133  //- Calculates start of tracking given samplePt and first boundary
134  // intersection
135  // (bPoint, bFacei) (bFacei == -1 if no boundary intersection)
136  // Returns true if trackPt is valid sampling point. Sets trackPt,
137  // trackFacei, trackCelli (-1 if no tracking point found)
138  bool getTrackingPoint
139  (
140  const point& samplePt,
141  const point& bPoint,
142  const label bFacei,
143  const scalar smallDist,
144 
145  point& trackPt,
146  label& trackCelli,
147  label& trackFacei
148  ) const;
149 
150  //- Set sample data. Copy list contents.
151  void setSamples
152  (
153  const List<point>& samplingPts,
154  const labelList& samplingCells,
155  const labelList& samplingFaces,
156  const labelList& samplingSegments,
157  const scalarList& samplingCurveDist
158  );
159 
160  //- Set sample data. Move list contents.
161  void setSamples
162  (
163  List<point>&& samplingPts,
164  labelList&& samplingCells,
165  labelList&& samplingFaces,
166  labelList&& samplingSegments,
167  scalarList&& samplingCurveDist
168  );
169 
170 public:
171 
172  //- Runtime type information
173  TypeName("sampledSet");
174 
175 
176  // Declare run-time constructor selection table
177 
179  (
180  autoPtr,
181  sampledSet,
182  word,
183  (
184  const word& name,
185  const polyMesh& mesh,
186  const meshSearch& searchEngine,
187  const dictionary& dict
188  ),
190  );
191 
192 
193  //- Class used for the read-construction of
194  // PtrLists of sampledSet
195  class iNew
196  {
197  const polyMesh& mesh_;
198  const meshSearch& searchEngine_;
199 
200  public:
201 
202  iNew(const polyMesh& mesh, const meshSearch& searchEngine)
203  :
204  mesh_(mesh),
205  searchEngine_(searchEngine)
206  {}
207 
209  {
210  word name(is);
212  return sampledSet::New(name, mesh_, searchEngine_, dict);
213  }
214  };
215 
216 
217  // Constructors
218 
219  //- Construct from components
220  sampledSet
221  (
222  const word& name,
223  const polyMesh& mesh,
224  const meshSearch& searchEngine,
225  const coordSet::coordFormat axisType
226  );
227 
228  //- Construct from components
229  sampledSet
230  (
231  const word& name,
232  const polyMesh& mesh,
233  const meshSearch& searchEngine,
234  const word& axis
235  );
236 
237  //- Construct from dictionary
238  sampledSet
239  (
240  const word& name,
241  const polyMesh& mesh,
242  const meshSearch& searchEngine,
243  const dictionary& dict
244  );
245 
246  //- Clone
247  autoPtr<sampledSet> clone() const
248  {
250  return nullptr;
251  }
252 
253 
254  // Selectors
255 
256  //- Return a reference to the selected sampledSet
257  static autoPtr<sampledSet> New
258  (
259  const word& name,
260  const polyMesh& mesh,
261  const meshSearch& searchEngine,
262  const dictionary& dict
263  );
264 
265 
266  //- Destructor
267  virtual ~sampledSet() = default;
268 
269 
270  // Member Functions
271 
272  const polyMesh& mesh() const
273  {
274  return mesh_;
275  }
276 
277  const meshSearch& searchEngine() const
278  {
279  return searchEngine_;
280  }
281 
282  const labelList& segments() const
283  {
284  return segments_;
285  }
286 
287  const labelList& cells() const
288  {
289  return cells_;
290  }
291 
292  const labelList& faces() const
293  {
294  return faces_;
295  }
296 
297  //- Output for debugging
298  Ostream& write(Ostream&) const;
299 
300  //- Helper: gather onto master and sort.
301  // \return (on master) gathered set and overall sort order
303  (
304  labelList& indexSet,
305  labelList& allSegments
306  ) const;
307 };
308 
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
312 } // End namespace Foam
313 
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315 
316 #endif
317 
318 // ************************************************************************* //
Foam::sampledSet
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:83
Foam::sampledSet::New
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:519
Foam::sampledSet::~sampledSet
virtual ~sampledSet()=default
Destructor.
Foam::coordSet::name
const word & name() const
Definition: coordSet.H:125
Foam::sampledSet::checkDimensions
void checkDimensions() const
Check for consistent sizing.
Definition: sampledSet.C:48
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::sampledSet::iNew::operator()
autoPtr< sampledSet > operator()(Istream &is) const
Definition: sampledSet.H:217
Foam::sampledSet::write
Ostream & write(Ostream &) const
Output for debugging.
Definition: sampledSet.C:554
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::meshSearch
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:60
Foam::sampledSet::gather
autoPtr< coordSet > gather(labelList &indexSet, labelList &allSegments) const
Helper: gather onto master and sort.
Definition: sampledSet.C:422
typeInfo.H
Foam::sampledSet::getNeighbourCell
label getNeighbourCell(const label) const
Returns the neighbour cell or the owner if face in on the boundary.
Definition: sampledSet.C:76
Foam::sampledSet::searchEngine
const meshSearch & searchEngine() const
Definition: sampledSet.H:286
coordSet.H
Foam::sampledSet::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, sampledSet, word,(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict),(name, mesh, searchEngine, dict))
Foam::coordSet::coordFormat
coordFormat
Enumeration defining the output format for coordinates.
Definition: coordSet.H:62
Foam::sampledSet::calcSign
scalar calcSign(const label facei, const point &sample) const
Calculates inproduct of face normal and vector sample-face centre.
Definition: sampledSet.C:162
Foam::sampledSet::cells
const labelList & cells() const
Definition: sampledSet.H:296
Foam::sampledSet::TypeName
TypeName("sampledSet")
Runtime type information.
Foam::sampledSet::findNearFace
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:186
Foam::sampledSet::sampledSet
sampledSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const coordSet::coordFormat axisType)
Construct from components.
Definition: sampledSet.C:466
Foam::coordSet::axis
word axis() const
Definition: coordSet.H:130
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::sampledSet::iNew::iNew
iNew(const polyMesh &mesh, const meshSearch &searchEngine)
Definition: sampledSet.H:211
Foam::sampledSet::segments_
labelList segments_
Segment numbers.
Definition: sampledSet.H:99
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::sampledSet::segments
const labelList & segments() const
Definition: sampledSet.H:291
Foam::sampledSet::clone
autoPtr< sampledSet > clone() const
Clone.
Definition: sampledSet.H:256
Foam::sampledSet::faces
const labelList & faces() const
Definition: sampledSet.H:301
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:53
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::sampledSet::getBoundaryCell
label getBoundaryCell(const label) const
Returns cell next to boundary face.
Definition: sampledSet.C:70
Foam::sampledSet::pushIn
point pushIn(const point &sample, const label facei) const
Moves sample in direction of -n to it is 'inside' of facei.
Definition: sampledSet.C:221
Foam::sampledSet::cells_
labelList cells_
Cell numbers.
Definition: sampledSet.H:102
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::sampledSet::mesh
const polyMesh & mesh() const
Definition: sampledSet.H:281
Foam::sampledSet::setSamples
void setSamples(const List< point > &samplingPts, const labelList &samplingCells, const labelList &samplingFaces, const labelList &samplingSegments, const scalarList &samplingCurveDist)
Set sample data. Copy list contents.
Definition: sampledSet.C:382
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::Vector< scalar >
Foam::List< label >
Foam::sampledSet::getTrackingPoint
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:286
Foam::sampledSet::faces_
labelList faces_
Face numbers (-1 if not known)
Definition: sampledSet.H:105
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::sampledSet::pointInCell
label pointInCell(const point &p, const label samplei) const
Return the cell in which the point on the sample line.
Definition: sampledSet.C:90
Foam::sampledSet::iNew
Class used for the read-construction of.
Definition: sampledSet.H:204
sample
Minimal example by using system/controlDict.functions:
autoPtr.H