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

patchWave.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 "patchWave.H"
00028 #include "polyMesh.H"
00029 #include "wallPoint.H"
00030 #include "MeshWave.H"
00031 #include "globalMeshData.H"
00032 
00033 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00034 
00035 void Foam::patchWave::setChangedFaces
00036 (
00037     const labelHashSet& patchIDs,
00038     labelList& changedFaces,
00039     List<wallPoint>& faceDist
00040 ) const
00041 {
00042     const polyMesh& mesh = cellDistFuncs::mesh();
00043 
00044     label nChangedFaces = 0;
00045 
00046     forAll(mesh.boundaryMesh(), patchI)
00047     {
00048         if (patchIDs.found(patchI))
00049         {
00050             const polyPatch& patch = mesh.boundaryMesh()[patchI];
00051 
00052             forAll(patch.faceCentres(), patchFaceI)
00053             {
00054                 label meshFaceI = patch.start() + patchFaceI;
00055 
00056                 changedFaces[nChangedFaces] = meshFaceI;
00057 
00058                 faceDist[nChangedFaces] =
00059                     wallPoint
00060                     (
00061                         patch.faceCentres()[patchFaceI],
00062                         0.0
00063                     );
00064 
00065                 nChangedFaces++;
00066             }
00067         }
00068     }
00069 }
00070 
00071 
00072 Foam::label Foam::patchWave::getValues(const MeshWave<wallPoint>& waveInfo)
00073 {
00074     const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
00075     const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
00076 
00077     label nIllegal = 0;
00078 
00079     // Copy cell values
00080     distance_.setSize(cellInfo.size());
00081 
00082     forAll(cellInfo, cellI)
00083     {
00084         scalar dist = cellInfo[cellI].distSqr();
00085 
00086         if (cellInfo[cellI].valid())
00087         {
00088             distance_[cellI] = Foam::sqrt(dist);
00089         }
00090         else
00091         {
00092             distance_[cellI] = dist;
00093 
00094             nIllegal++;
00095         }
00096     }
00097 
00098     // Copy boundary values
00099     forAll(patchDistance_, patchI)
00100     {
00101         const polyPatch& patch = mesh().boundaryMesh()[patchI];
00102 
00103         // Allocate storage for patchDistance
00104         scalarField* patchDistPtr = new scalarField(patch.size());
00105 
00106         patchDistance_.set(patchI, patchDistPtr);
00107 
00108         scalarField& patchField = *patchDistPtr;
00109 
00110         forAll(patchField, patchFaceI)
00111         {
00112             label meshFaceI = patch.start() + patchFaceI;
00113 
00114             scalar dist = faceInfo[meshFaceI].distSqr();
00115 
00116             if (faceInfo[meshFaceI].valid())
00117             {
00118                 // Adding SMALL to avoid problems with /0 in the turbulence
00119                 // models
00120                 patchField[patchFaceI] = Foam::sqrt(dist) + SMALL;
00121             }
00122             else
00123             {
00124                 patchField[patchFaceI] = dist;
00125 
00126                 nIllegal++;
00127             }
00128         }
00129     }
00130     return nIllegal;
00131 }
00132 
00133 
00134 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00135 
00136 // Construct from components
00137 Foam::patchWave::patchWave
00138 (
00139     const polyMesh& mesh,
00140     const labelHashSet& patchIDs,
00141     const bool correctWalls
00142 )
00143 :
00144     cellDistFuncs(mesh),
00145     patchIDs_(patchIDs),
00146     correctWalls_(correctWalls),
00147     nUnset_(0),
00148     distance_(mesh.nCells()),
00149     patchDistance_(mesh.boundaryMesh().size())
00150 {
00151     patchWave::correct();
00152 }
00153 
00154 
00155 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00156 
00157 Foam::patchWave::~patchWave()
00158 {}
00159 
00160 
00161 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00162 
00163 // Correct for mesh geom/topo changes. Might be more intelligent in the
00164 // future (if only small topology change)
00165 void Foam::patchWave::correct()
00166 {
00167     //
00168     // Set initial changed faces: set wallPoint for wall faces to wall centre
00169     //
00170 
00171     // Count walls
00172     label nWalls = sumPatchSize(patchIDs_);
00173 
00174     List<wallPoint> faceDist(nWalls);
00175     labelList changedFaces(nWalls);
00176 
00177     // Set to faceDist information to facecentre on walls.
00178     setChangedFaces(patchIDs_, changedFaces, faceDist);
00179 
00180 
00181     //
00182     // Do calculate wall distance by 'growing' from faces.
00183     //
00184 
00185     MeshWave<wallPoint> waveInfo
00186     (
00187         mesh(),
00188         changedFaces,
00189         faceDist,
00190         mesh().globalData().nTotalCells()   // max iterations
00191     );
00192 
00193 
00194     //
00195     // Copy distance into return field
00196     //
00197 
00198     nUnset_ = getValues(waveInfo);
00199 
00200     //
00201     // Correct wall cells for true distance
00202     //
00203 
00204     if (correctWalls_)
00205     {
00206         Map<label> nearestFace(2 * nWalls);
00207 
00208         correctBoundaryFaceCells
00209         (
00210             patchIDs_,
00211             distance_,
00212             nearestFace
00213         );
00214 
00215         correctBoundaryPointCells
00216         (
00217             patchIDs_,
00218             distance_,
00219             nearestFace
00220         );
00221     }
00222 }
00223 
00224 
00225 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd