1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2010-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 "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 "
62 // All the info for nearest. Construct to miss
63 List<directMappedPatchBase::nearInfo> nearest(probeLocations_.size());
65 const polyPatch& pp = bm[patchI];
69 labelList bndFaces(pp.size());
72 bndFaces[i] = pp.start() + i;
75 treeBoundBox overallBb(pp.points());
76 Random rndGen(123456);
77 overallBb = overallBb.extend(rndGen, 1E-4);
78 overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
79 overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
81 const indexedOctree<treeDataFace> boundaryTree
83 treeDataFace // all information needed to search faces
85 false, // do not cache bb
87 bndFaces // patch faces only
89 overallBb, // overall search domain
96 if (elementList_.empty())
98 elementList_.setSize(probeLocations_.size());
100 // Octree based search engine
101 //meshSearch meshSearchEngine(mesh, false);
103 forAll(probeLocations_, probeI)
105 const point sample = probeLocations_[probeI];
107 scalar span = boundaryTree.bb().mag();
109 pointIndexHit info = boundaryTree.findNearest
117 info = boundaryTree.findNearest
124 label faceI = boundaryTree.shapes().faceLabels()[info.index()];
126 const label patchi = bm.whichPatch(faceI);
128 if (isA<emptyPolyPatch>(bm[patchi]))
132 " Foam::patchProbes::findElements(const fvMesh&)"
134 << " The sample point: " << sample
135 << " belongs to " << patchi
136 << " which is an empty patch. This is not permitted. "
137 << " This sample will not be included "
142 const point& fc = mesh.faceCentres()[faceI];
144 directMappedPatchBase::nearInfo sampleInfo;
146 sampleInfo.first() = pointIndexHit
153 sampleInfo.second().first() = magSqr(fc-sample);
154 sampleInfo.second().second() = Pstream::myProcNo();
156 nearest[probeI]= sampleInfo;
162 Pstream::listCombineGather(nearest, directMappedPatchBase::nearestEqOp());
163 Pstream::listCombineScatter(nearest);
167 Info<< "patchProbes::findElements" << " : " << endl;
168 forAll(nearest, sampleI)
170 label procI = nearest[sampleI].second().second();
171 label localI = nearest[sampleI].first().index();
173 Info<< " " << sampleI << " coord:"<< probeLocations_[sampleI]
174 << " found on processor:" << procI
175 << " in local cell/face:" << localI
176 << " with cc:" << nearest[sampleI].first().rawPoint()
177 << " in patch : "<< pp.name() << endl;
181 // Check if all patchProbes have been found.
182 forAll(probeLocations_, sampleI)
185 if (nearest[sampleI].second().second() == Pstream::myProcNo())
187 localI = nearest[sampleI].first().index();
190 if (elementList_.empty())
192 elementList_.setSize(probeLocations_.size());
195 elementList_[sampleI] = localI;
201 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
203 Foam::patchProbes::patchProbes
206 const objectRegistry& obr,
207 const dictionary& dict,
208 const bool loadFromFiles
211 probes(name, obr, dict, loadFromFiles)
217 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
219 Foam::patchProbes::~patchProbes()
223 void Foam::patchProbes::write()
225 if (probeLocations_.size() && checkFieldTypes())
227 sampleAndWrite(scalarFields_);
228 sampleAndWrite(vectorFields_);
229 sampleAndWrite(sphericalTensorFields_);
230 sampleAndWrite(symmTensorFields_);
231 sampleAndWrite(tensorFields_);
235 void Foam::patchProbes::read(const dictionary& dict)
237 dict.lookup("patchName") >> patchName_;
242 // ************************************************************************* //