collection_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::searchableSurfaces::collection
26 
27 Description
28  Makes a collection of surface geometries by copying from an existing
29  defined surface geometry. There are no boolean operations, e.g.
30  overlapping surfaces are not intersected.
31 
32 Usage
33  collection requires a surface geometry to be defined
34  initially, e.g. \c buildingA in the example below. The collection then
35  defines copies of buildingA which each can be scaled using the mandatory
36  \c scale parameter and then rotated and translated by the mandatory
37  \c transform. In the example below, two geometries are included named
38  \c buildingB and \c buildingC which are both formed by a translation
39  of \c buildingA according to the \c origin parameter. No rotation is
40  applied (by setting e1 and e2 to the global x and y axis directions,
41  respectively).
42 
43  Example specification in snappyHexMeshDict/geometry:
44 
45  \verbatim
46  buildingA
47  {
48  type searchableBox;
49  min (100 100 0);
50  max (120 120 100);
51  }
52 
53  moreBuildings
54  {
55  type collection;
56 
57  mergeSubRegions true;
58 
59  buildingB
60  {
61  surface buildingA;
62  scale (1 1 1);
63  transform
64  {
65  coordinateSystem
66  {
67  type cartesian;
68  coordinateRotation
69  {
70  type axesRotation;
71  e1 (1 0 0);
72  e2 (0 1 0);
73  }
74  origin (40 40 0);
75  }
76  }
77  }
78 
79  buildingC
80  {
81  $buildingB;
82  transform
83  {
84  coordinateSystem { origin (30 -40 0); }
85  }
86  }
87  }
88  \endverbatim
89 
90 SourceFiles
91  collection_searchableSurface.C
92 
93 \*---------------------------------------------------------------------------*/
94 
95 #ifndef collection_searchableSurface_H
96 #define collection_searchableSurface_H
97 
98 #include "searchableSurface.H"
99 #include "treeBoundBox.H"
100 #include "coordinateSystem.H"
101 #include "UPtrList.H"
102 #include "Switch.H"
103 
104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
105 
106 namespace Foam
107 {
108 namespace searchableSurfaces
109 {
110 
111 /*---------------------------------------------------------------------------*\
112  Class collection Declaration
113 \*---------------------------------------------------------------------------*/
114 
115 class collection
116 :
117  public searchableSurface
118 {
119  // Private Member Data
120 
121  // Per instance data
122 
123  //- Instance name
124  wordList instance_;
125 
126  //- Scaling vector
127  vectorField scale_;
128 
129  //- transformation
130  PtrList<coordinateSystem> transform_;
131 
133 
134  Switch mergeSubRegions_;
135 
136  //- Offsets for indices coming from different surfaces
137  // (sized with size() of each surface)
138  labelList indexOffset_;
139 
140  //- Region names
141  mutable wordList regions_;
142 
143  //- From individual regions to collection regions
144  mutable labelList regionOffset_;
145 
146 
147  // Private Member Functions
148 
149  //- Inherit findNearest from searchableSurface
151 
152  //- Find point nearest to sample. Updates minDistSqr. Sets nearestInfo
153  // and surface index
154  void findNearest
155  (
156  const pointField& samples,
157  scalarField& minDistSqr,
158  List<pointIndexHit>& nearestInfo,
159  labelList& nearestSurf
160  ) const;
161 
162  //- Sort hits into per-surface bins. Misses are rejected.
163  // Maintains map back to position
164  void sortHits
165  (
166  const List<pointIndexHit>& info,
167  List<List<pointIndexHit>>& surfInfo,
168  labelListList& infoMap
169  ) const;
170 
171 
172 public:
173 
174  //- Runtime type information
175  TypeName("collection");
176 
177 
178  // Constructors
179 
180  //- Construct from dictionary (used by searchableSurface)
181  collection
182  (
183  const IOobject& io,
184  const dictionary& dict
185  );
186 
187  //- Disallow default bitwise copy construction
188  collection
189  (
190  const collection&
191  ) = delete;
192 
193 
194  //- Destructor
195  virtual ~collection();
196 
197 
198  // Member Functions
199 
200  //- Scaling vector per subsurface
201  const vectorField& scale() const
202  {
203  return scale_;
204  }
205 
206  //- Scaling vector per subsurface
207  vectorField& scale()
208  {
209  return scale_;
210  }
211 
212  //- Coordinate system per subsurface
213  const PtrList<coordinateSystem>& transform() const
214  {
215  return transform_;
216  }
217 
218  //- Coordinate system per subsurface
220  {
221  return transform_;
222  }
223 
224  virtual const wordList& regions() const;
225 
226  //- Whether supports volume type below
227  virtual bool hasVolumeType() const
228  {
229  return false;
230  }
231 
232  //- Range of local indices that can be returned.
233  virtual label size() const;
234 
235  //- Get representative set of element coordinates
236  // Usually the element centres (should be of length size()).
237  virtual tmp<pointField> coordinates() const;
238 
239  //- Get bounding spheres (centre and radius squared), one per element.
240  // Any point on element is guaranteed to be inside.
241  virtual void boundingSpheres
242  (
243  pointField& centres,
244  scalarField& radiusSqr
245  ) const;
246 
247  //- Get the points that define the surface.
248  virtual tmp<pointField> points() const;
249 
250  //- Does any part of the surface overlap the supplied bound box?
251  virtual bool overlaps(const boundBox& bb) const
252  {
254 
255  return false;
256  }
257 
258 
259  // Multiple point queries.
260 
261  virtual void findNearest
262  (
263  const pointField& sample,
264  const scalarField& nearestDistSqr,
266  ) const;
267 
268  virtual void findLine
269  (
270  const pointField& start,
271  const pointField& end,
273  ) const;
274 
275  virtual void findLineAny
276  (
277  const pointField& start,
278  const pointField& end,
280  ) const;
281 
282  //- Get all intersections in order from start to end.
283  virtual void findLineAll
284  (
285  const pointField& start,
286  const pointField& end,
288  ) const;
289 
290  //- From a set of points and indices get the region
291  virtual void getRegion
292  (
293  const List<pointIndexHit>&,
294  labelList& region
295  ) const;
296 
297  //- From a set of points and indices get the normal
298  virtual void getNormal
299  (
300  const List<pointIndexHit>&,
301  vectorField& normal
302  ) const;
303 
304  //- Determine type (inside/outside/mixed) for point. unknown if
305  // cannot be determined (e.g. non-manifold surface)
306  virtual void getVolumeType
307  (
308  const pointField&,
310  ) const;
311 
312  // Other
313 
314  //- Set bounds of surface. Bounds currently set as list of
315  // bounding boxes. The bounds are hints to the surface as for
316  // the range of queries it can expect. faceMap/pointMap can be
317  // set if the surface has done any redistribution.
318  virtual void distribute
319  (
320  const List<treeBoundBox>&,
321  const bool keepNonLocal,
323  autoPtr<distributionMap>& pointMap
324  );
325 
326  //- WIP. Store element-wise field.
327  virtual void setField(const labelList& values);
328 
329  //- WIP. From a set of hits (points and
330  // indices) get the specified field. Misses do not get set. Return
331  // empty field if not supported.
332  virtual void getField(const List<pointIndexHit>&, labelList&) const;
333 
334  // regIOobject implementation
335 
336  bool writeData(Ostream&) const
337  {
339  return false;
340  }
341 
342 
343  // Member Operators
344 
345  //- Disallow default bitwise assignment
346  void operator=(const collection&) = delete;
347 };
348 
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 } // End of namespace searchableSurfaces
353 } // End namespace Foam
354 
355 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 
357 #endif
358 
359 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:485
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
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
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
Makes a collection of surface geometries by copying from an existing defined surface geometry....
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
void operator=(const collection &)=delete
Disallow default bitwise assignment.
const vectorField & scale() const
Scaling vector per subsurface.
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
bool writeData(Ostream &) const
Pure virtual writaData function.
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
TypeName("collection")
Runtime type information.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual label size() const
Range of local indices that can be returned.
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
const PtrList< coordinateSystem > & transform() const
Coordinate system per subsurface.
virtual void setField(const labelList &values)
WIP. Store element-wise field.
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
collection(const IOobject &io, const dictionary &dict)
Construct from dictionary (used by searchableSurface)
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
virtual const wordList & regions() const
Names of regions.
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
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.
virtual bool hasVolumeType() const
Whether supports volume type below.
virtual tmp< pointField > points() const
Get the points that define the surface.
A class for managing temporary objects.
Definition: tmp.H:55
#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)
dictionary dict
scalarField samples(nIntervals, 0)