Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / meshTools / searchableSurface / searchableSurfaceWithGaps.H
blob25f2c6d7f05b37e440356f33b22b203fc2acbf57
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::searchableSurfaceWithGaps
27 Description
28     searchableSurface using multiple slightly shifted underlying surfaces
29     to make sure pierces don't go through gaps:
30     - shift test vector with two small vectors (of size gap_) perpendicular
31       to the original.
32       Test with + and - this vector. Only if both register a hit is it seen
33       as one.
34     - extend the test vector slightly (with SMALL) to account for numerical
35       inaccuracies.
37 SourceFiles
38     searchableSurfaceWithGaps.C
40 \*---------------------------------------------------------------------------*/
42 #ifndef searchableSurfaceWithGaps_H
43 #define searchableSurfaceWithGaps_H
45 #include "searchableSurface.H"
46 #include "UPtrList.H"
47 #include "Pair.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 namespace Foam
54 // Forward declaration of classes
56 /*---------------------------------------------------------------------------*\
57                            Class searchableSurfaceWithGaps Declaration
58 \*---------------------------------------------------------------------------*/
60 class searchableSurfaceWithGaps
62     public searchableSurface
64 private:
66     // Private Member Data
68         //- Gap size in meter
69         const scalar gap_;
71         //- Underlying geometry (size 1)
72         UPtrList<searchableSurface> subGeom_;
75     // Private Member Functions
77         Pair<vector> offsetVecs(const point&, const point&) const;
79         void offsetVecs
80         (
81             const pointField& start,
82             const pointField& end,
83             pointField& offset0,
84             pointField& offset1
85         ) const;
87         static label countMisses
88         (
89             const List<pointIndexHit>& info,
90             labelList& missMap
91         );
93         static label countMisses
94         (
95             const List<pointIndexHit>& plusInfo,
96             const List<pointIndexHit>& minInfo,
97             labelList& missMap
98         );
101         //- Disallow default bitwise copy construct
102         searchableSurfaceWithGaps(const searchableSurfaceWithGaps&);
104         //- Disallow default bitwise assignment
105         void operator=(const searchableSurfaceWithGaps&);
108 public:
110     //- Runtime type information
111     TypeName("searchableSurfaceWithGaps");
114     // Constructors
116         //- Construct from dictionary (used by searchableSurface)
117         searchableSurfaceWithGaps
118         (
119             const IOobject& io,
120             const dictionary& dict
121         );
123     // Destructor
125         virtual ~searchableSurfaceWithGaps();
128     // Member Functions
130         const searchableSurface& surface() const
131         {
132             return subGeom_[0];
133         }
136         virtual const wordList& regions() const
137         {
138             return surface().regions();
139         }
141         //- Whether supports volume type below
142         virtual bool hasVolumeType() const
143         {
144             return surface().hasVolumeType();
145         }
147         //- Range of local indices that can be returned.
148         virtual label size() const
149         {
150             return surface().size();
151         }
153         //- Get representative set of element coordinates
154         //  Usually the element centres (should be of length size()).
155         virtual pointField coordinates() const
156         {
157             return surface().coordinates();
158         }
161         // Multiple point queries.
163             //- Find nearest on original surface. Note:does not use perturbation
164             //  and hence might be inconsistent with intersections.
165             virtual void findNearest
166             (
167                 const pointField& sample,
168                 const scalarField& nearestDistSqr,
169                 List<pointIndexHit>& info
170             ) const
171             {
172                 surface().findNearest
173                 (
174                     sample,
175                     nearestDistSqr,
176                     info
177                 );
178             }
180             virtual void findLine
181             (
182                 const pointField& start,
183                 const pointField& end,
184                 List<pointIndexHit>&
185             ) const;
187             virtual void findLineAny
188             (
189                 const pointField& start,
190                 const pointField& end,
191                 List<pointIndexHit>&
192             ) const;
194             //- Get all intersections in order from start to end.
195             virtual void findLineAll
196             (
197                 const pointField& start,
198                 const pointField& end,
199                 List<List<pointIndexHit> >&
200             ) const;
202             //- From a set of points and indices get the region
203             virtual void getRegion
204             (
205                 const List<pointIndexHit>& info,
206                 labelList& region
207             ) const
208             {
209                 surface().getRegion(info, region);
210             }
212             //- From a set of points and indices get the normal
213             virtual void getNormal
214             (
215                 const List<pointIndexHit>& info,
216                 vectorField& normal
217             ) const
218             {
219                 surface().getNormal(info, normal);
220             }
222             //- Determine type (inside/outside/mixed) for point. unknown if
223             //  cannot be determined (e.g. non-manifold surface)
224             virtual void getVolumeType
225             (
226                 const pointField& samples,
227                 List<volumeType>& info
228             ) const
229             {
230                 surface().getVolumeType(samples, info);
231             }
234         // Other
236             //- Set bounds of surface. Bounds currently set as list of
237             //  bounding boxes. The bounds are hints to the surface as for
238             //  the range of queries it can expect. faceMap/pointMap can be
239             //  set if the surface has done any redistribution.
240             virtual void distribute
241             (
242                 const List<treeBoundBox>& bbs,
243                 const bool keepNonLocal,
244                 autoPtr<mapDistribute>& faceMap,
245                 autoPtr<mapDistribute>& pointMap
246             )
247             {
248                 subGeom_[0].distribute(bbs, keepNonLocal, faceMap, pointMap);
249             }
251             //- WIP. Store element-wise field.
252             virtual void setField(const labelList& values)
253             {
254                 subGeom_[0].setField(values);
255             }
257             //- WIP. From a set of hits (points and
258             //  indices) get the specified field. Misses do not get set. Return
259             //  empty field if not supported.
260             virtual void getField
261             (
262                 const List<pointIndexHit>& info,
263                 labelList& values
264             ) const
265             {
266                 surface().getField(info, values);
267             }
269         // regIOobject implementation
271             bool writeData(Ostream& os) const
272             {
273                 return surface().writeData(os);
274             }
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 } // End namespace Foam
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 #endif
287 // ************************************************************************* //