1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
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 #include "wordReList.H"
34 // For 'nearInfo' helper class only
35 #include "directMappedPatchBase.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(patchCloudSet, 0);
42 addToRunTimeSelectionTable(sampledSet, patchCloudSet, word);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 void Foam::patchCloudSet::calcSamples
50 DynamicList<point>& samplingPts,
51 DynamicList<label>& samplingCells,
52 DynamicList<label>& samplingFaces,
53 DynamicList<label>& samplingSegments,
54 DynamicList<scalar>& samplingCurveDist
59 Info<< "patchCloudSet : sampling on patches :" << endl;
62 // Construct search tree for all patch faces.
64 forAllConstIter(labelHashSet, patchSet_, iter)
66 const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
72 Info<< " " << pp.name() << " size " << pp.size() << endl;
76 labelList patchFaces(sz);
78 treeBoundBox bb(point::max, point::min);
79 forAllConstIter(labelHashSet, patchSet_, iter)
81 const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
85 patchFaces[sz++] = pp.start()+i;
88 // Do not do reduction.
89 const boundBox patchBb(pp.localPoints(), false);
91 bb.min() = min(bb.min(), patchBb.min());
92 bb.max() = max(bb.max(), patchBb.max());
96 Random rndGen(123456);
97 // Make bb asymetric just to avoid problems on symmetric meshes
98 bb = bb.extend(rndGen, 1E-4);
100 // Make sure bb is 3D.
101 bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
102 bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
105 indexedOctree<treeDataFace> patchTree
107 treeDataFace // all information needed to search faces
109 false, // do not cache bb
111 patchFaces // boundary faces only
113 bb, // overall search domain
121 // All the info for nearest. Construct to miss
122 List<directMappedPatchBase::nearInfo> nearest(sampleCoords_.size());
124 forAll(sampleCoords_, sampleI)
126 const point& sample = sampleCoords_[sampleI];
128 pointIndexHit& nearInfo = nearest[sampleI].first();
130 // Find the nearest locally
131 if (patchFaces.size())
133 nearInfo = patchTree.findNearest(sample, sqr(searchDist_));
141 // Fill in the distance field and the processor field
144 nearest[sampleI].second().first() = Foam::sqr(GREAT);
145 nearest[sampleI].second().second() = Pstream::myProcNo();
149 // Set nearest to mesh face label
150 nearInfo.setIndex(patchFaces[nearInfo.index()]);
152 nearest[sampleI].second().first() = magSqr
157 nearest[sampleI].second().second() = Pstream::myProcNo();
163 Pstream::listCombineGather(nearest, directMappedPatchBase::nearestEqOp());
164 Pstream::listCombineScatter(nearest);
167 if (debug && Pstream::master())
175 Info<< "Dumping mapping as lines from supplied points to"
176 << " nearest patch face to file " << str.name() << endl;
182 if (nearest[i].first().hit())
184 meshTools::writeOBJ(str, sampleCoords_[i]);
186 meshTools::writeOBJ(str, nearest[i].first().hitPoint());
188 str << "l " << vertI-1 << ' ' << vertI << nl;
194 // Store the sampling locations on the nearest processor
195 forAll(nearest, sampleI)
197 const pointIndexHit& nearInfo = nearest[sampleI].first();
201 if (nearest[sampleI].second().second() == Pstream::myProcNo())
203 label faceI = nearInfo.index();
205 samplingPts.append(nearInfo.hitPoint());
206 samplingCells.append(mesh().faceOwner()[faceI]);
207 samplingFaces.append(faceI);
208 samplingSegments.append(0);
209 samplingCurveDist.append(1.0 * sampleI);
214 // No processor found point near enough. Mark with special value
215 // which is intercepted when interpolating
216 if (Pstream::master())
218 samplingPts.append(sampleCoords_[sampleI]);
219 samplingCells.append(-1);
220 samplingFaces.append(-1);
221 samplingSegments.append(0);
222 samplingCurveDist.append(1.0 * sampleI);
229 void Foam::patchCloudSet::genSamples()
231 // Storage for sample points
232 DynamicList<point> samplingPts;
233 DynamicList<label> samplingCells;
234 DynamicList<label> samplingFaces;
235 DynamicList<label> samplingSegments;
236 DynamicList<scalar> samplingCurveDist;
247 samplingPts.shrink();
248 samplingCells.shrink();
249 samplingFaces.shrink();
250 samplingSegments.shrink();
251 samplingCurveDist.shrink();
264 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
266 Foam::patchCloudSet::patchCloudSet
269 const polyMesh& mesh,
270 meshSearch& searchEngine,
272 const List<point>& sampleCoords,
273 const labelHashSet& patchSet,
274 const scalar searchDist
277 sampledSet(name, mesh, searchEngine, axis),
278 sampleCoords_(sampleCoords),
280 searchDist_(searchDist)
291 Foam::patchCloudSet::patchCloudSet
294 const polyMesh& mesh,
295 meshSearch& searchEngine,
296 const dictionary& dict
299 sampledSet(name, mesh, searchEngine, dict),
300 sampleCoords_(dict.lookup("points")),
303 mesh.boundaryMesh().patchSet
305 wordList(dict.lookup("patches"))
308 searchDist_(readScalar(dict.lookup("maxDistance")))
319 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
321 Foam::patchCloudSet::~patchCloudSet()
325 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
327 Foam::point Foam::patchCloudSet::getRefPoint(const List<point>& pts) const
331 // Use first samplePt as starting point
341 // ************************************************************************* //