ENH: RASModel.C: clipping input to log
[OpenFOAM-1.7.x.git] / src / sampling / probes / patchProbes.C
bloba545911b84cc49a004c4da231a0175c058daae0e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2010-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "IOmanip.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 * * * * * * * * * * * * * //
37 namespace Foam
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_);
51     if (patchI == -1)
52     {
53         FatalErrorIn
54         (
55             " Foam::patchProbes::findElements(const fvMesh&)"
56         )   << " Unknown patch name "
57             << patchName_ << endl
58             << exit(FatalError);
59     }
62     // All the info for nearest. Construct to miss
63     List<directMappedPatchBase::nearInfo> nearest(probeLocations_.size());
65     const polyPatch& pp = bm[patchI];
67     if (pp.size() > 0)
68     {
69         labelList bndFaces(pp.size());
70         forAll(bndFaces, i)
71         {
72             bndFaces[i] =  pp.start() + i;
73         }
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
82         (
83             treeDataFace    // all information needed to search faces
84             (
85                 false,                      // do not cache bb
86                 mesh,
87                 bndFaces                    // patch faces only
88             ),
89             overallBb,                      // overall search domain
90             8,                              // maxLevel
91             10,                             // leafsize
92             3.0                             // duplicity
93         );
96         if (elementList_.empty())
97         {
98             elementList_.setSize(probeLocations_.size());
100             // Octree based search engine
101             //meshSearch meshSearchEngine(mesh, false);
103             forAll(probeLocations_, probeI)
104             {
105                 const point sample = probeLocations_[probeI];
107                 scalar span = boundaryTree.bb().mag();
109                 pointIndexHit info = boundaryTree.findNearest
110                 (
111                     sample,
112                     Foam::sqr(span)
113                 );
115                 if (!info.hit())
116                 {
117                     info = boundaryTree.findNearest
118                     (
119                         sample,
120                         Foam::sqr(GREAT)
121                     );
122                 }
124                 label faceI = boundaryTree.shapes().faceLabels()[info.index()];
126                 const label patchi = bm.whichPatch(faceI);
128                 if (isA<emptyPolyPatch>(bm[patchi]))
129                 {
130                     WarningIn
131                     (
132                         " Foam::patchProbes::findElements(const fvMesh&)"
133                     )
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 "
138                     << endl;
139                 }
140                 else
141                 {
142                     const point& fc = mesh.faceCentres()[faceI];
144                     directMappedPatchBase::nearInfo sampleInfo;
146                     sampleInfo.first() = pointIndexHit
147                     (
148                         true,
149                         fc,
150                         faceI
151                     );
153                     sampleInfo.second().first() = magSqr(fc-sample);
154                     sampleInfo.second().second() = Pstream::myProcNo();
156                     nearest[probeI]= sampleInfo;
157                 }
158             }
159         }
160     }
161     // Find nearest.
162     Pstream::listCombineGather(nearest, directMappedPatchBase::nearestEqOp());
163     Pstream::listCombineScatter(nearest);
165     if (debug)
166     {
167         Info<< "patchProbes::findElements" << " : " << endl;
168         forAll(nearest, sampleI)
169         {
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;
178         }
179     }
181     // Check if all patchProbes have been found.
182     forAll(probeLocations_, sampleI)
183     {
184         label localI = -1;
185         if (nearest[sampleI].second().second() == Pstream::myProcNo())
186         {
187             localI = nearest[sampleI].first().index();
188         }
190         if (elementList_.empty())
191         {
192              elementList_.setSize(probeLocations_.size());
193         }
195         elementList_[sampleI] = localI;
196     }
201 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
203 Foam::patchProbes::patchProbes
205     const word& name,
206     const objectRegistry& obr,
207     const dictionary& dict,
208     const bool loadFromFiles
211     probes(name, obr, dict, loadFromFiles)
213     read(dict);
217 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
219 Foam::patchProbes::~patchProbes()
223 void Foam::patchProbes::write()
225     if (probeLocations_.size() && checkFieldTypes())
226     {
227         sampleAndWrite(scalarFields_);
228         sampleAndWrite(vectorFields_);
229         sampleAndWrite(sphericalTensorFields_);
230         sampleAndWrite(symmTensorFields_);
231         sampleAndWrite(tensorFields_);
232     }
235 void Foam::patchProbes::read(const dictionary& dict)
237     dict.lookup("patchName") >> patchName_;
238     probes::read(dict);
242 // ************************************************************************* //