searchableSurface.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
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::searchableSurface
26 
27 Description
28  Base class of (analytical or triangulated) surface.
29  Encapsulates all the search routines. WIP.
30 
31  Information returned is usually a pointIndexHit:
32  - bool : was intersection/nearest found?
33  - point : intersection point or nearest point
34  - index : unique index on surface (e.g. triangle for triSurface)
35 
36 SourceFiles
37  searchableSurface.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef searchableSurface_H
42 #define searchableSurface_H
43 
44 #include "pointField.H"
45 #include "boundBox.H"
46 #include "typeInfo.H"
47 #include "runTimeSelectionTables.H"
48 #include "pointIndexHit.H"
49 #include "linePointRef.H"
50 #include "objectRegistry.H"
51 #include "volumeType.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 // Forward declaration of classes
59 class objectRegistry;
60 class distributionMap;
61 class treeBoundBox;
62 
63 /*---------------------------------------------------------------------------*\
64  Class searchableSurface Declaration
65 \*---------------------------------------------------------------------------*/
66 
68 :
69  public regIOobject
70 {
71  // Private Data
72 
73  const word name_;
74 
75  boundBox bounds_;
76 
77 
78 public:
79 
80  //- Runtime type information
81  TypeName("searchableSurface");
82 
83 
84  // Static data
85 
86  //- Name of the directory for the geometry files
87  // Defaults to "geometry"
88  static word geometryDir_;
89 
90 
91  // Declare run-time constructor selection table
92 
93  // For the dictionary constructor
95  (
96  autoPtr,
98  dictionary,
99  (
100  const IOobject& io,
101  const dictionary& dict
102  ),
103  (io, dict)
104  );
105 
106 
107  //- Class used for the read-construction of
108  // PtrLists of searchableSurface.
109  class iNew
110  {
111  IOobject& io_;
112 
113  public:
114 
115  iNew(IOobject& io)
116  :
117  io_(io)
118  {}
119 
121  {
122  word surfaceType(is);
123  word readName(is);
124  dictionary dict(is);
125 
126  autoPtr<IOobject> namedIO(io_.clone());
127  namedIO().rename(readName);
128  return searchableSurface::New(surfaceType, namedIO(), dict);
129  }
130  };
131 
132 
133  // Constructors
134 
135  searchableSurface(const IOobject& io);
136 
137  //- Disallow default bitwise copy construction
138  searchableSurface(const searchableSurface&) = delete;
139 
140  //- Clone
141  virtual autoPtr<searchableSurface> clone() const
142  {
144  return autoPtr<searchableSurface>(nullptr);
145  }
146 
147 
148  // Selectors
149 
150  //- Return a reference to the selected searchableSurface
152  (
153  const word& surfaceType,
154  const IOobject& io,
155  const dictionary& dict
156  );
157 
158 
159  //- Destructor
160  virtual ~searchableSurface();
161 
162 
163  // Member Functions
164 
165  //- Return the geometry directory name
166  static const word& geometryDir();
167 
168  //- Check that the geometry directory exists and return
169  // if not return "triSurface" for backward compatibility
170  static const word& geometryDir(const Time& time);
171 
172  //- Return const reference to boundBox
173  const boundBox& bounds() const
174  {
175  return bounds_;
176  }
177 
178  //- Return non-const access to the boundBox to allow it to be set.
179  boundBox& bounds()
180  {
181  return bounds_;
182  }
183 
184  //- Names of regions
185  virtual const wordList& regions() const = 0;
186 
187  //- Whether supports volume type below
188  virtual bool hasVolumeType() const = 0;
189 
190  //- Range of local indices that can be returned
191  virtual label size() const = 0;
192 
193  //- Range of global indices that can be returned
194  virtual label globalSize() const
195  {
196  return size();
197  }
198 
199  //- Get representative set of element coordinates
200  // Usually the element centres (should be of length size()).
201  virtual tmp<pointField> coordinates() const = 0;
202 
203  //- Get bounding spheres (centre and radius squared), one per element.
204  // Any point on element is guaranteed to be inside.
205  virtual void boundingSpheres
206  (
207  pointField& centres,
208  scalarField& radiusSqr
209  ) const = 0;
210 
211  //- Get the points that define the surface.
212  virtual tmp<pointField> points() const = 0;
213 
214  //- Does any part of the surface overlap the supplied bound box?
215  virtual bool overlaps(const boundBox& bb) const = 0;
216 
217 
218  // Multiple point queries. When surface is distributed the index
219  // should be a global index. Not done yet.
220 
221  virtual void findNearest
222  (
223  const pointField& sample,
224  const scalarField& nearestDistSqr,
226  ) const = 0;
227 
228  //- Find the nearest locations for the supplied points to a
229  // particular region in the searchable surface.
230  virtual void findNearest
231  (
232  const pointField& samples,
233  const scalarField& nearestDistSqr,
234  const labelList& regionIndices,
236  ) const
237  {
238  findNearest(samples, nearestDistSqr, info);
239  }
240 
241  //- Find first intersection on segment from start to end.
242  // Note: searchableSurfacesQueries expects no
243  // intersection to be found if start==end. Is problem?
244  virtual void findLine
245  (
246  const pointField& start,
247  const pointField& end,
249  ) const = 0;
250 
251  //- Return any intersection on segment from start to end.
252  virtual void findLineAny
253  (
254  const pointField& start,
255  const pointField& end,
257  ) const = 0;
258 
259  //- Get all intersections in order from start to end.
260  virtual void findLineAll
261  (
262  const pointField& start,
263  const pointField& end,
265  ) const = 0;
266 
267  //- From a set of points and indices get the region
268  virtual void getRegion
269  (
270  const List<pointIndexHit>&,
271  labelList& region
272  ) const = 0;
273 
274  //- From a set of points and indices get the normal
275  virtual void getNormal
276  (
277  const List<pointIndexHit>&,
278  vectorField& normal
279  ) const = 0;
280 
281  //- Determine type (inside/outside) for point. unknown if
282  // cannot be determined (e.g. non-manifold surface)
283  virtual void getVolumeType
284  (
285  const pointField&,
287  ) const = 0;
288 
289  //- Find nearest, normal and region. Can be overridden with
290  // optimised implementation
291  virtual void findNearest
292  (
293  const pointField& sample,
294  const scalarField& nearestDistSqr,
296  vectorField& normal,
297  labelList& region
298  ) const;
299 
300 
301  // Other
302 
303  //- Set bounds of surface. Bounds currently set as list of
304  // bounding boxes. The bounds are hints to the surface as for
305  // the range of queries it can expect. faceMap/pointMap can be
306  // set if the surface has done any redistribution.
307  virtual void distribute
308  (
309  const List<treeBoundBox>&,
310  const bool keepNonLocal,
312  autoPtr<distributionMap>& pointMap
313  )
314  {}
315 
316  //- WIP. Store element-wise field.
317  virtual void setField(const labelList& values)
318  {}
319 
320  //- WIP. From a set of hits (points and
321  // indices) get the specified field. Misses do not get set. Return
322  // empty field if not supported.
323  virtual void getField(const List<pointIndexHit>&, labelList& values)
324  const
325  {
326  values.clear();
327  }
328 
329 
330  // Member Operators
331 
332  //- Disallow default bitwise assignment
333  void operator=(const searchableSurface&) = delete;
334 };
335 
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 } // End namespace Foam
340 
341 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
342 
343 #endif
344 
345 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const Time & time() const
Return time.
Definition: IOobject.C:315
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:280
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:485
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
Class used for the read-construction of.
autoPtr< searchableSurface > operator()(Istream &is) const
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const =0
From a set of points and indices get the region.
static word geometryDir_
Name of the directory for the geometry files.
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const =0
Find first intersection on segment from start to end.
virtual void getVolumeType(const pointField &, List< volumeType > &) const =0
Determine type (inside/outside) for point. unknown if.
virtual tmp< pointField > points() const =0
Get the points that define the surface.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
declareRunTimeSelectionTable(autoPtr, searchableSurface, dictionary,(const IOobject &io, const dictionary &dict),(io, dict))
virtual void setField(const labelList &values)
WIP. Store element-wise field.
virtual tmp< pointField > coordinates() const =0
Get representative set of element coordinates.
virtual bool hasVolumeType() const =0
Whether supports volume type below.
virtual autoPtr< searchableSurface > clone() const
Clone.
virtual void getField(const List< pointIndexHit > &, labelList &values) const
WIP. From a set of hits (points and.
virtual const wordList & regions() const =0
Names of regions.
virtual bool overlaps(const boundBox &bb) const =0
Does any part of the surface overlap the supplied bound box?
searchableSurface(const IOobject &io)
TypeName("searchableSurface")
Runtime type information.
virtual ~searchableSurface()
Destructor.
virtual void distribute(const List< treeBoundBox > &, const bool keepNonLocal, autoPtr< distributionMap > &faceMap, autoPtr< distributionMap > &pointMap)
Set bounds of surface. Bounds currently set as list of.
static const word & geometryDir()
Return the geometry directory name.
static autoPtr< searchableSurface > New(const word &surfaceType, const IOobject &io, const dictionary &dict)
Return a reference to the selected searchableSurface.
virtual label size() const =0
Range of local indices that can be returned.
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const =0
Get all intersections in order from start to end.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const =0
Return any intersection on segment from start to end.
void operator=(const searchableSurface &)=delete
Disallow default bitwise assignment.
virtual label globalSize() const
Range of global indices that can be returned.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const =0
From a set of points and indices get the normal.
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const =0
Get bounding spheres (centre and radius squared), one per element.
const boundBox & bounds() const
Return const reference to boundBox.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Macros to ease declaration of run-time selection tables.
dictionary dict
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...
scalarField samples(nIntervals, 0)