OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

thresholdCellFaces.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) 1991-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "thresholdCellFaces.H"
00028 
00029 #include "polyMesh.H"
00030 #include "DynamicList.H"
00031 
00032 #include "emptyPolyPatch.H"
00033 #include "processorPolyPatch.H"
00034 
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 defineTypeNameAndDebug(Foam::thresholdCellFaces, 0);
00039 
00040 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00041 
00042 void Foam::thresholdCellFaces::calculate
00043 (
00044     const scalarField& field,
00045     const scalar lowerThreshold,
00046     const scalar upperThreshold,
00047     const bool triangulate
00048 )
00049 {
00050     const labelList& own = mesh_.faceOwner();
00051     const labelList& nei = mesh_.faceNeighbour();
00052 
00053     const faceList& origFaces = mesh_.faces();
00054     const pointField& origPoints = mesh_.points();
00055 
00056     const polyBoundaryMesh& bMesh = mesh_.boundaryMesh();
00057 
00058 
00059     surfZoneList surfZones(bMesh.size()+1);
00060 
00061     surfZones[0] = surfZone
00062     (
00063         "internalMesh",
00064         0,  // size
00065         0,  // start
00066         0   // index
00067     );
00068 
00069     forAll(bMesh, patchI)
00070     {
00071         surfZones[patchI+1] = surfZone
00072         (
00073             bMesh[patchI].name(),
00074             0,        // size
00075             0,        // start
00076             patchI+1  // index
00077         );
00078     }
00079 
00080 
00081     label nFaces = 0;
00082     label nPoints = 0;
00083 
00084 
00085     meshCells_.clear();
00086 
00087     DynamicList<face>  surfFaces(0.5 * mesh_.nFaces());
00088     DynamicList<label> surfCells(surfFaces.size());
00089 
00090     labelList oldToNewPoints(origPoints.size(), -1);
00091 
00092 
00093     // internal faces only
00094     for (label faceI = 0; faceI < mesh_.nInternalFaces(); ++faceI)
00095     {
00096         int side = 0;
00097 
00098         // check lowerThreshold
00099         if (field[own[faceI]] > lowerThreshold)
00100         {
00101             if (field[nei[faceI]] < lowerThreshold)
00102             {
00103                 side = +1;
00104             }
00105         }
00106         else if (field[nei[faceI]] > lowerThreshold)
00107         {
00108             side = -1;
00109         }
00110 
00111         // check upperThreshold
00112         if (field[own[faceI]] < upperThreshold)
00113         {
00114             if (field[nei[faceI]] > upperThreshold)
00115             {
00116                 side = +1;
00117             }
00118         }
00119         else if (field[nei[faceI]] < upperThreshold)
00120         {
00121             side = -1;
00122         }
00123 
00124 
00125         if (side)
00126         {
00127             const face& f = origFaces[faceI];
00128 
00129             forAll(f, fp)
00130             {
00131                 if (oldToNewPoints[f[fp]] == -1)
00132                 {
00133                     oldToNewPoints[f[fp]] = nPoints++;
00134                 }
00135             }
00136 
00137 
00138             label cellId;
00139             face  surfFace;
00140 
00141             if (side > 0)
00142             {
00143                 surfFace = f;
00144                 cellId = own[faceI];
00145             }
00146             else
00147             {
00148                 surfFace = f.reverseFace();
00149                 cellId = nei[faceI];
00150             }
00151 
00152 
00153             if (triangulate)
00154             {
00155                 label count = surfFace.triangles(origPoints, surfFaces);
00156                 while (count-- > 0)
00157                 {
00158                     surfCells.append(cellId);
00159                 }
00160             }
00161             else
00162             {
00163                 surfFaces.append(surfFace);
00164                 surfCells.append(cellId);
00165             }
00166         }
00167     }
00168 
00169     surfZones[0].size() = surfFaces.size();
00170 
00171 
00172     // nothing special for processor patches?
00173     forAll(bMesh, patchI)
00174     {
00175         const polyPatch& p = bMesh[patchI];
00176         surfZone& zone = surfZones[patchI+1];
00177 
00178         zone.start() = nFaces;
00179 
00180         if
00181         (
00182             isType<emptyPolyPatch>(p)
00183          || (Pstream::parRun() && isType<processorPolyPatch>(p))
00184         )
00185         {
00186             continue;
00187         }
00188 
00189         label faceI = p.start();
00190 
00191         // patch faces
00192         forAll(p, localFaceI)
00193         {
00194             if
00195             (
00196                 field[own[faceI]] > lowerThreshold
00197              && field[own[faceI]] < upperThreshold
00198             )
00199             {
00200                 const face& f = origFaces[faceI];
00201                 forAll(f, fp)
00202                 {
00203                     if (oldToNewPoints[f[fp]] == -1)
00204                     {
00205                         oldToNewPoints[f[fp]] = nPoints++;
00206                     }
00207                 }
00208 
00209                 label cellId = own[faceI];
00210 
00211                 if (triangulate)
00212                 {
00213                     label count = f.triangles(origPoints, surfFaces);
00214                     while (count-- > 0)
00215                     {
00216                         surfCells.append(cellId);
00217                     }
00218                 }
00219                 else
00220                 {
00221                     surfFaces.append(f);
00222                     surfCells.append(cellId);
00223                 }
00224             }
00225 
00226             ++faceI;
00227         }
00228 
00229         zone.size() = surfFaces.size() - zone.start();
00230     }
00231 
00232 
00233     surfFaces.shrink();
00234     surfCells.shrink();
00235 
00236     // renumber
00237     forAll(surfFaces, faceI)
00238     {
00239         inplaceRenumber(oldToNewPoints, surfFaces[faceI]);
00240     }
00241 
00242 
00243     pointField surfPoints(nPoints);
00244     nPoints = 0;
00245     forAll(oldToNewPoints, pointI)
00246     {
00247         if (oldToNewPoints[pointI] >= 0)
00248         {
00249             surfPoints[oldToNewPoints[pointI]] = origPoints[pointI];
00250             nPoints++;
00251         }
00252     }
00253     surfPoints.setSize(nPoints);
00254 
00255     this->storedPoints().transfer(surfPoints);
00256     this->storedFaces().transfer(surfFaces);
00257     this->storedZones().transfer(surfZones);
00258 
00259     meshCells_.transfer(surfCells);
00260 }
00261 
00262 
00263 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00264 
00265 Foam::thresholdCellFaces::thresholdCellFaces
00266 (
00267     const polyMesh& mesh,
00268     const scalarField& field,
00269     const scalar lowerThreshold,
00270     const scalar upperThreshold,
00271     const bool triangulate
00272 )
00273 :
00274     mesh_(mesh)
00275 {
00276 
00277     if (lowerThreshold > upperThreshold)
00278     {
00279         WarningIn("thresholdCellFaces::thresholdCellFaces(...)")
00280             << "lower > upper limit!  "
00281             << lowerThreshold << " > " << upperThreshold << endl;
00282     }
00283 
00284     calculate(field, lowerThreshold, upperThreshold, triangulate);
00285 }
00286 
00287 
00288 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd