triSurfaceRegionSearch.C
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) 2015-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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\*---------------------------------------------------------------------------*/
28
30#include "indexedOctree.H"
31#include "triSurface.H"
32#include "PatchTools.H"
33
34// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35
37:
38 triSurfaceSearch(surface),
39 indirectRegionPatches_(),
40 treeByRegion_()
41{}
42
43
45(
46 const triSurface& surface,
47 const dictionary& dict
48)
49:
50 triSurfaceSearch(surface, dict),
51 indirectRegionPatches_(),
52 treeByRegion_()
53{}
54
55
56// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
57
59{
60 clearOut();
61}
62
63
65{
67 treeByRegion_.clear();
68}
69
70
71// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72
75{
76 if (treeByRegion_.empty())
77 {
78 label maxRegion = -1;
79 forAll(surface(), fI)
80 {
81 const label regionI = surface()[fI].region();
82 maxRegion = max(maxRegion, regionI);
83 }
84 const label nRegions = maxRegion+1;
85
86 labelList nFacesInRegions(nRegions, 0);
87 forAll(surface(), fI)
88 {
89 const label regionI = surface()[fI].region();
90 nFacesInRegions[regionI]++;
91 }
92
93 indirectRegionPatches_.setSize(nRegions);
94 treeByRegion_.setSize(nRegions);
95
96 labelListList regionsAddressing(nRegions);
97
98 forAll(regionsAddressing, regionI)
99 {
100 regionsAddressing[regionI].setSize(nFacesInRegions[regionI]);
101 }
102 nFacesInRegions = Zero;
103 forAll(surface(), fI)
104 {
105 const label regionI = surface()[fI].region();
106 regionsAddressing[regionI][nFacesInRegions[regionI]++] = fI;
107 }
108
109 forAll(regionsAddressing, regionI)
110 {
111 scalar oldTol = treeType::perturbTol();
112 treeType::perturbTol() = tolerance();
113
114 indirectRegionPatches_.set
115 (
116 regionI,
118 (
120 (
121 surface(),
122 regionsAddressing[regionI]
123 ),
124 surface().points()
125 )
126 );
127
128 // Calculate bb without constructing local point numbering.
130
131 if (indirectRegionPatches_[regionI].size())
132 {
133 label nPoints;
134 PatchTools::calcBounds
135 (
136 indirectRegionPatches_[regionI],
137 bb,
138 nPoints
139 );
140
141 // if (nPoints != surface().points().size())
142 // {
143 // WarningInFunction
144 // << "Surface does not have compact point numbering. "
145 // << "Of " << surface().points().size()
146 // << " only " << nPoints
147 // << " are used."
148 // << " This might give problems in some routines."
149 // << endl;
150 // }
151
152 // Random number generator. Bit dodgy since not exactly
153 // random ;-)
154 Random rndGen(65431);
155
156 // Slightly extended bb. Slightly off-centred just so
157 // on symmetric geometry there are fewer face/edge
158 // aligned items.
159 bb = bb.extend(rndGen, 1e-4);
160 bb.min() -= point::uniform(ROOTVSMALL);
161 bb.max() += point::uniform(ROOTVSMALL);
162 }
163
164 treeByRegion_.set
165 (
166 regionI,
167 new treeType
168 (
170 (
171 false, //true,
172 indirectRegionPatches_[regionI],
173 tolerance()
174 ),
175 bb,
176 maxTreeDepth(), // maxLevel
177 10, // leafsize
178 3.0 // duplicity
179 )
180 );
181
182 treeType::perturbTol() = oldTol;
183 }
184 }
185
186 return treeByRegion_;
187}
188
189
191(
192 const pointField& samples,
193 const scalarField& nearestDistSqr,
194 const labelList& regionIndices,
196) const
197{
198 if (regionIndices.empty())
199 {
200 triSurfaceSearch::findNearest(samples, nearestDistSqr, info);
201 }
202 else
203 {
204 scalar oldTol = treeType::perturbTol();
205 treeType::perturbTol() = tolerance();
206
207 const PtrList<treeType>& octrees = treeByRegion();
208
209 info.setSize(samples.size());
210
211 forAll(octrees, treeI)
212 {
213 if (!regionIndices.found(treeI))
214 {
215 continue;
216 }
217
218 const treeType& octree = octrees[treeI];
220
221 forAll(samples, i)
222 {
223// if (!octree.bb().contains(samples[i]))
224// {
225// continue;
226// }
227
228 pointIndexHit currentRegionHit = octree.findNearest
229 (
230 samples[i],
231 nearestDistSqr[i],
232 nearOp
233 );
234
235 if
236 (
237 currentRegionHit.hit()
238 &&
239 (
240 !info[i].hit()
241 ||
242 (
243 magSqr(currentRegionHit.hitPoint() - samples[i])
244 < magSqr(info[i].hitPoint() - samples[i])
245 )
246 )
247 )
248 {
249 info[i] = currentRegionHit;
250 }
251 }
252 }
253
254 treeType::perturbTol() = oldTol;
255 }
256}
257
258
259// ************************************************************************* //
A List with indirect addressing.
Definition: IndirectList.H:119
void setSize(const label n)
Alias for resize()
Definition: List.H:218
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:66
bool hit() const noexcept
Is there a hit?
const point_type & hitPoint() const
Return hit point. Fatal if not hit.
A list of faces which address into the list of points.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
Random number generator.
Definition: Random.H:60
bool found(const T &val, label pos=0) const
True if the value if found in the list.
Definition: UListI.H:265
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:91
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Particle-size distribution model wherein random samples are drawn from the doubly-truncated uniform p...
Definition: uniform.H:164
Non-pointer based hierarchical recursive searching.
Definition: indexedOctree.H:74
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:89
treeBoundBox extend(Random &rndGen, const scalar s) const
Return slightly wider bounding box.
Encapsulation of data needed to search on PrimitivePatches.
Helper class to search on triSurface. Creates an octree for each region of the surface and only searc...
void findNearest(const pointField &samples, const scalarField &nearestDistSqr, const labelList &regionIndices, List< pointIndexHit > &info) const
Find the nearest point on the surface out of the regions.
const PtrList< treeType > & treeByRegion() const
Demand driven construction of octree for each region.
Helper class to search on triSurface.
void clearOut()
Clear storage.
void findNearest(const pointField &samples, const scalarField &nearestDistSqr, List< pointIndexHit > &info) const
Triangulated surface description with patch information.
Definition: triSurface.H:79
const pointField & points
label nPoints
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dictionary dict
volScalarField & e
Definition: createFields.H:11
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
scalarField samples(nIntervals, Zero)
Random rndGen
Definition: createFields.H:23