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 "patchProbes.H"
27 #include "volFields.H"
29 // For 'nearInfo' helper class only
30 #include "directMappedPatchBase.H"
31 //#include "meshSearch.H"
32 #include "treeBoundBox.H"
33 #include "treeDataFace.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(patchProbes, 0);
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 void Foam::patchProbes::findElements(const fvMesh& mesh)
47 const polyBoundaryMesh& bm = mesh.boundaryMesh();
49 label patchI = bm.findPatchID(patchName_);
55 " Foam::patchProbes::findElements(const fvMesh&)"
56 ) << " Unknown patch name "
61 // All the info for nearest. Construct to miss
62 List<directMappedPatchBase::nearInfo> nearest(this->size());
64 const polyPatch& pp = bm[patchI];
68 labelList bndFaces(pp.size());
71 bndFaces[i] = pp.start() + i;
74 treeBoundBox overallBb(pp.points());
75 Random rndGen(123456);
76 overallBb = overallBb.extend(rndGen, 1E-4);
77 overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
78 overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
80 const indexedOctree<treeDataFace> boundaryTree
82 treeDataFace // all information needed to search faces
84 false, // do not cache bb
86 bndFaces // patch faces only
88 overallBb, // overall search domain
95 forAll(probeLocations(), probeI)
97 const point sample = probeLocations()[probeI];
99 scalar span = boundaryTree.bb().mag();
101 pointIndexHit info = boundaryTree.findNearest
109 info = boundaryTree.findNearest
116 label faceI = boundaryTree.shapes().faceLabels()[info.index()];
118 const label patchi = bm.whichPatch(faceI);
120 if (isA<emptyPolyPatch>(bm[patchi]))
124 " Foam::patchProbes::findElements(const fvMesh&)"
126 << " The sample point: " << sample
127 << " belongs to " << patchi
128 << " which is an empty patch. This is not permitted. "
129 << " This sample will not be included "
134 const point& fc = mesh.faceCentres()[faceI];
136 directMappedPatchBase::nearInfo sampleInfo;
138 sampleInfo.first() = pointIndexHit
145 sampleInfo.second().first() = magSqr(fc-sample);
146 sampleInfo.second().second() = Pstream::myProcNo();
148 nearest[probeI]= sampleInfo;
155 Pstream::listCombineGather(nearest, directMappedPatchBase::nearestEqOp());
156 Pstream::listCombineScatter(nearest);
160 Info<< "patchProbes::findElements" << " : " << endl;
161 forAll(nearest, sampleI)
163 label procI = nearest[sampleI].second().second();
164 label localI = nearest[sampleI].first().index();
166 Info<< " " << sampleI << " coord:"<< operator[](sampleI)
167 << " found on processor:" << procI
168 << " in local cell/face:" << localI
169 << " with fc:" << nearest[sampleI].first().rawPoint() << endl;
174 // Extract any local faces to sample
175 elementList_.setSize(nearest.size(), -1);
177 forAll(nearest, sampleI)
179 if (nearest[sampleI].second().second() == Pstream::myProcNo())
181 // Store the face to sample
182 elementList_[sampleI] = nearest[sampleI].first().index();
188 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
190 Foam::patchProbes::patchProbes
193 const objectRegistry& obr,
194 const dictionary& dict,
195 const bool loadFromFiles
198 probes(name, obr, dict, loadFromFiles)
200 // When constructing probes above it will have called the
201 // probes::findElements (since the virtual mechanism not yet operating).
202 // Not easy to workaround (apart from feeding through flag into constructor)
203 // so clear out any cells found for now.
204 elementList_.clear();
210 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
212 Foam::patchProbes::~patchProbes()
216 void Foam::patchProbes::write()
218 if (this->size() && prepare())
220 sampleAndWrite(scalarFields_);
221 sampleAndWrite(vectorFields_);
222 sampleAndWrite(sphericalTensorFields_);
223 sampleAndWrite(symmTensorFields_);
224 sampleAndWrite(tensorFields_);
228 void Foam::patchProbes::read(const dictionary& dict)
230 dict.lookup("patchName") >> patchName_;
235 // ************************************************************************* //