1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "patchCloudSet.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "treeBoundBox.H"
30 #include "treeDataFace.H"
32 #include "meshTools.H"
33 // For 'nearInfo' helper class only
34 #include "directMappedPatchBase.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(patchCloudSet, 0);
41 addToRunTimeSelectionTable(sampledSet, patchCloudSet, word);
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 void Foam::patchCloudSet::calcSamples
49 DynamicList<point>& samplingPts,
50 DynamicList<label>& samplingCells,
51 DynamicList<label>& samplingFaces,
52 DynamicList<label>& samplingSegments,
53 DynamicList<scalar>& samplingCurveDist
58 Info<< "patchCloudSet : sampling on patches :" << endl;
61 // Construct search tree for all patch faces.
63 forAllConstIter(labelHashSet, patchSet_, iter)
65 const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
71 Info<< " " << pp.name() << " size " << pp.size() << endl;
75 labelList patchFaces(sz);
77 treeBoundBox bb(point::max, point::min);
78 forAllConstIter(labelHashSet, patchSet_, iter)
80 const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
84 patchFaces[sz++] = pp.start()+i;
87 // Do not do reduction.
88 const boundBox patchBb(pp.points(), pp.meshPoints(), false);
90 bb.min() = min(bb.min(), patchBb.min());
91 bb.max() = max(bb.max(), patchBb.max());
95 Random rndGen(123456);
96 // Make bb asymetric just to avoid problems on symmetric meshes
97 bb = bb.extend(rndGen, 1E-4);
99 // Make sure bb is 3D.
100 bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
101 bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
104 indexedOctree<treeDataFace> patchTree
106 treeDataFace // all information needed to search faces
108 false, // do not cache bb
110 patchFaces // boundary faces only
112 bb, // overall search domain
118 // Force calculation of face-diagonal decomposition
119 (void)mesh().tetBasePtIs();
122 // All the info for nearest. Construct to miss
123 List<directMappedPatchBase::nearInfo> nearest(sampleCoords_.size());
125 forAll(sampleCoords_, sampleI)
127 const point& sample = sampleCoords_[sampleI];
129 pointIndexHit& nearInfo = nearest[sampleI].first();
131 // Find the nearest locally
132 if (patchFaces.size())
134 nearInfo = patchTree.findNearest(sample, sqr(searchDist_));
142 // Fill in the distance field and the processor field
145 nearest[sampleI].second().first() = Foam::sqr(GREAT);
146 nearest[sampleI].second().second() = Pstream::myProcNo();
150 // Set nearest to mesh face label
151 nearInfo.setIndex(patchFaces[nearInfo.index()]);
153 nearest[sampleI].second().first() = magSqr
158 nearest[sampleI].second().second() = Pstream::myProcNo();
164 Pstream::listCombineGather(nearest, directMappedPatchBase::nearestEqOp());
165 Pstream::listCombineScatter(nearest);
168 if (debug && Pstream::master())
176 Info<< "Dumping mapping as lines from supplied points to"
177 << " nearest patch face to file " << str.name() << endl;
183 if (nearest[i].first().hit())
185 meshTools::writeOBJ(str, sampleCoords_[i]);
187 meshTools::writeOBJ(str, nearest[i].first().hitPoint());
189 str << "l " << vertI-1 << ' ' << vertI << nl;
195 // Store the sampling locations on the nearest processor
196 forAll(nearest, sampleI)
198 const pointIndexHit& nearInfo = nearest[sampleI].first();
202 if (nearest[sampleI].second().second() == Pstream::myProcNo())
204 label faceI = nearInfo.index();
206 samplingPts.append(nearInfo.hitPoint());
207 samplingCells.append(mesh().faceOwner()[faceI]);
208 samplingFaces.append(faceI);
209 samplingSegments.append(0);
210 samplingCurveDist.append(1.0 * sampleI);
215 // No processor found point near enough. Mark with special value
216 // which is intercepted when interpolating
217 if (Pstream::master())
219 samplingPts.append(sampleCoords_[sampleI]);
220 samplingCells.append(-1);
221 samplingFaces.append(-1);
222 samplingSegments.append(0);
223 samplingCurveDist.append(1.0 * sampleI);
230 void Foam::patchCloudSet::genSamples()
232 // Storage for sample points
233 DynamicList<point> samplingPts;
234 DynamicList<label> samplingCells;
235 DynamicList<label> samplingFaces;
236 DynamicList<label> samplingSegments;
237 DynamicList<scalar> samplingCurveDist;
248 samplingPts.shrink();
249 samplingCells.shrink();
250 samplingFaces.shrink();
251 samplingSegments.shrink();
252 samplingCurveDist.shrink();
265 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
267 Foam::patchCloudSet::patchCloudSet
270 const polyMesh& mesh,
271 meshSearch& searchEngine,
273 const List<point>& sampleCoords,
274 const labelHashSet& patchSet,
275 const scalar searchDist
278 sampledSet(name, mesh, searchEngine, axis),
279 sampleCoords_(sampleCoords),
281 searchDist_(searchDist)
292 Foam::patchCloudSet::patchCloudSet
295 const polyMesh& mesh,
296 meshSearch& searchEngine,
297 const dictionary& dict
300 sampledSet(name, mesh, searchEngine, dict),
301 sampleCoords_(dict.lookup("points")),
304 mesh.boundaryMesh().patchSet
306 wordReList(dict.lookup("patches"))
309 searchDist_(readScalar(dict.lookup("maxDistance")))
320 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
322 Foam::patchCloudSet::~patchCloudSet()
326 // ************************************************************************* //