FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

patchProbes.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2010-2011 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "patchProbes.H"
00027 #include <finiteVolume/volFields.H>
00028 #include <OpenFOAM/IOmanip.H>
00029 // For 'nearInfo' helper class only
00030 #include <meshTools/directMappedPatchBase.H>
00031 #include <meshTools/meshSearch.H>
00032 #include <meshTools/treeBoundBox.H>
00033 #include <meshTools/treeDataFace.H>
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039     defineTypeNameAndDebug(patchProbes, 0);
00040 }
00041 
00042 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00043 
00044 void Foam::patchProbes::findElements(const fvMesh& mesh)
00045 {
00046 
00047     const polyBoundaryMesh& bm = mesh.boundaryMesh();
00048 
00049     label patchI = bm.findPatchID(patchName_);
00050 
00051     if (patchI == -1)
00052     {
00053         FatalErrorIn
00054         (
00055             " Foam::patchProbes::findElements(const fvMesh&)"
00056         )   << " Unknown patch name "
00057             << patchName_ << endl
00058             << exit(FatalError);
00059     }
00060 
00061 
00062     // All the info for nearest. Construct to miss
00063     List<directMappedPatchBase::nearInfo> nearest(probeLocations_.size());
00064 
00065     const polyPatch& pp = bm[patchI];
00066 
00067     if (pp.size() > 0)
00068     {
00069         labelList bndFaces(pp.size());
00070         forAll(bndFaces, i)
00071         {
00072             bndFaces[i] =  pp.start() + i;
00073         }
00074 
00075         treeBoundBox overallBb(pp.points());
00076         Random rndGen(123456);
00077         overallBb = overallBb.extend(rndGen, 1E-4);
00078         overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
00079         overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
00080 
00081         const indexedOctree<treeDataFace> boundaryTree
00082         (
00083             treeDataFace    // all information needed to search faces
00084             (
00085                 false,                      // do not cache bb
00086                 mesh,
00087                 bndFaces                    // patch faces only
00088             ),
00089             overallBb,                      // overall search domain
00090             8,                              // maxLevel
00091             10,                             // leafsize
00092             3.0                             // duplicity
00093         );
00094 
00095 
00096         if (elementList_.empty())
00097         {
00098             elementList_.setSize(probeLocations_.size());
00099 
00100             // Octree based search engine
00101             //meshSearch meshSearchEngine(mesh, false);
00102 
00103             forAll(probeLocations_, probeI)
00104             {
00105                 const point sample = probeLocations_[probeI];
00106 
00107                 scalar span = boundaryTree.bb().mag();
00108 
00109                 pointIndexHit info = boundaryTree.findNearest
00110                 (
00111                     sample,
00112                     Foam::sqr(span)
00113                 );
00114 
00115                 if (!info.hit())
00116                 {
00117                     info = boundaryTree.findNearest
00118                     (
00119                         sample,
00120                         Foam::sqr(GREAT)
00121                     );
00122                 }
00123 
00124                 label faceI = boundaryTree.shapes().faceLabels()[info.index()];
00125 
00126                 const label patchi = bm.whichPatch(faceI);
00127 
00128                 if (isA<emptyPolyPatch>(bm[patchi]))
00129                 {
00130                     WarningIn
00131                     (
00132                         " Foam::patchProbes::findElements(const fvMesh&)"
00133                     )
00134                     << " The sample point: " << sample
00135                     << " belongs to " << patchi
00136                     << " which is an empty patch. This is not permitted. "
00137                     << " This sample will not be included "
00138                     << endl;
00139                 }
00140                 else
00141                 {
00142                     const point& fc = mesh.faceCentres()[faceI];
00143 
00144                     directMappedPatchBase::nearInfo sampleInfo;
00145 
00146                     sampleInfo.first() = pointIndexHit
00147                     (
00148                         true,
00149                         fc,
00150                         faceI
00151                     );
00152 
00153                     sampleInfo.second().first() = magSqr(fc-sample);
00154                     sampleInfo.second().second() = Pstream::myProcNo();
00155 
00156                     nearest[probeI]= sampleInfo;
00157                 }
00158             }
00159         }
00160     }
00161     // Find nearest.
00162     Pstream::listCombineGather(nearest, directMappedPatchBase::nearestEqOp());
00163     Pstream::listCombineScatter(nearest);
00164 
00165     if (debug)
00166     {
00167         Info<< "patchProbes::findElements" << " : " << endl;
00168         forAll(nearest, sampleI)
00169         {
00170             label procI = nearest[sampleI].second().second();
00171             label localI = nearest[sampleI].first().index();
00172 
00173             Info<< "    " << sampleI << " coord:"<< probeLocations_[sampleI]
00174                 << " found on processor:" << procI
00175                 << " in local cell/face:" << localI
00176                 << " with cc:" << nearest[sampleI].first().rawPoint()
00177                 << " in patch : "<< pp.name() << endl;
00178         }
00179     }
00180 
00181     // Check if all patchProbes have been found.
00182     forAll(probeLocations_, sampleI)
00183     {
00184         label localI = -1;
00185         if (nearest[sampleI].second().second() == Pstream::myProcNo())
00186         {
00187             localI = nearest[sampleI].first().index();
00188         }
00189 
00190         if (elementList_.empty())
00191         {
00192              elementList_.setSize(probeLocations_.size());
00193         }
00194 
00195         elementList_[sampleI] = localI;
00196     }
00197 }
00198 
00199 
00200 
00201 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00202 
00203 Foam::patchProbes::patchProbes
00204 (
00205     const word& name,
00206     const objectRegistry& obr,
00207     const dictionary& dict,
00208     const bool loadFromFiles
00209 )
00210 :
00211     probes(name, obr, dict, loadFromFiles)
00212 {
00213     read(dict);
00214 }
00215 
00216 
00217 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00218 
00219 Foam::patchProbes::~patchProbes()
00220 {}
00221 
00222 
00223 void Foam::patchProbes::write()
00224 {
00225     if (probeLocations_.size() && checkFieldTypes())
00226     {
00227         sampleAndWrite(scalarFields_);
00228         sampleAndWrite(vectorFields_);
00229         sampleAndWrite(sphericalTensorFields_);
00230         sampleAndWrite(symmTensorFields_);
00231         sampleAndWrite(tensorFields_);
00232     }
00233 }
00234 
00235 void Foam::patchProbes::read(const dictionary& dict)
00236 {
00237     dict.lookup("patchName") >> patchName_;
00238     probes::read(dict);
00239 }
00240 
00241 
00242 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines