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

patchDataWave.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 "patchDataWave.H"
00028 #include "MeshWave.H"
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 // Set initial set of changed faces (= all wall faces)
00033 template<class TransferType>
00034 void Foam::patchDataWave<TransferType>::setChangedFaces
00035 (
00036     const labelHashSet& patchIDs,
00037     labelList& changedFaces,
00038     List<TransferType>& faceDist
00039 ) const
00040 {
00041     const polyMesh& mesh = cellDistFuncs::mesh();
00042 
00043     label nChangedFaces = 0;
00044 
00045     forAll(mesh.boundaryMesh(), patchI)
00046     {
00047         if (patchIDs.found(patchI))
00048         {
00049             const polyPatch& patch = mesh.boundaryMesh()[patchI];
00050 
00051             const Field<Type>& patchField = initialPatchValuePtrs_[patchI];
00052 
00053             forAll(patch.faceCentres(), patchFaceI)
00054             {
00055                 label meshFaceI = patch.start() + patchFaceI;
00056 
00057                 changedFaces[nChangedFaces] = meshFaceI;
00058 
00059                 faceDist[nChangedFaces] =
00060                     TransferType
00061                     (
00062                         patch.faceCentres()[patchFaceI],
00063                         patchField[patchFaceI],
00064                         0.0
00065                     );
00066 
00067                 nChangedFaces++;
00068             }
00069         }
00070     }
00071 }
00072 
00073 
00074 // Copy from MeshWave data into *this (distance) and field_ (transported data)
00075 template<class TransferType>
00076 Foam::label Foam::patchDataWave<TransferType>::getValues
00077 (
00078     const MeshWave<TransferType>& waveInfo
00079 )
00080 {
00081     const polyMesh& mesh = cellDistFuncs::mesh();
00082 
00083     const List<TransferType>& cellInfo = waveInfo.allCellInfo();
00084     const List<TransferType>& faceInfo = waveInfo.allFaceInfo();
00085 
00086     label nIllegal = 0;
00087 
00088     // Copy cell values
00089     distance_.setSize(cellInfo.size());
00090 
00091     forAll(cellInfo, cellI)
00092     {
00093         const TransferType & wpn = cellInfo[cellI];
00094 
00095         scalar dist = wpn.distSqr();
00096 
00097         if (cellInfo[cellI].valid())
00098         {
00099             distance_[cellI] = Foam::sqrt(dist);
00100 
00101             cellData_[cellI] = cellInfo[cellI].data();
00102         }
00103         else
00104         {
00105             // Illegal/unset value. What to do with data?
00106 
00107             distance_[cellI] = dist;
00108 
00109             //cellData_[cellI] = wallPoint::greatPoint;
00110             cellData_[cellI] = cellInfo[cellI].data();
00111 
00112             nIllegal++;
00113         }
00114     }
00115 
00116     // Copy boundary values
00117     forAll(patchDistance_, patchI)
00118     {
00119         const polyPatch& patch = mesh.boundaryMesh()[patchI];
00120 
00121         // Allocate storage for patchDistance
00122         scalarField* patchFieldPtr = new scalarField(patch.size());
00123 
00124         patchDistance_.set(patchI, patchFieldPtr);
00125 
00126         scalarField& patchField = *patchFieldPtr;
00127 
00128         // Allocate storage for patchData
00129         Field<Type>* patchDataFieldPtr = new Field<Type>(patch.size());
00130 
00131         patchData_.set(patchI, patchDataFieldPtr);
00132 
00133         Field<Type>& patchDataField = *patchDataFieldPtr;
00134 
00135         // Copy distance and data
00136         forAll(patchField, patchFaceI)
00137         {
00138             label meshFaceI = patch.start() + patchFaceI;
00139 
00140             scalar dist = faceInfo[meshFaceI].distSqr();
00141 
00142             if (faceInfo[meshFaceI].valid())
00143             {
00144                 // Adding SMALL to avoid problems with /0 in the turbulence
00145                 // models
00146                 patchField[patchFaceI] = Foam::sqrt(dist) + SMALL;
00147 
00148                 patchDataField[patchFaceI] = faceInfo[meshFaceI].data();
00149             }
00150             else
00151             {
00152                 // Illegal/unset value. What to do with data?
00153 
00154                 patchField[patchFaceI] = dist;
00155 
00156                 //patchDataField[patchFaceI] = wallPoint::greatPoint;
00157                 patchDataField[patchFaceI] = faceInfo[meshFaceI].data();
00158 
00159                 nIllegal++;
00160             }
00161         }
00162     }
00163 
00164     return nIllegal;
00165 }
00166 
00167 
00168 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00169 
00170 // Construct from components
00171 template<class TransferType>
00172 Foam::patchDataWave<TransferType>::patchDataWave
00173 (
00174     const polyMesh& mesh,
00175     const labelHashSet& patchIDs,
00176     const UPtrList<Field<Type> >& initialPatchValuePtrs,
00177     const bool correctWalls
00178 )
00179 :
00180     cellDistFuncs(mesh),
00181     patchIDs_(patchIDs),
00182     initialPatchValuePtrs_(initialPatchValuePtrs),
00183     correctWalls_(correctWalls),
00184     nUnset_(0),
00185     distance_(mesh.nCells()),
00186     patchDistance_(mesh.boundaryMesh().size()),
00187     cellData_(mesh.nCells()),
00188     patchData_(mesh.boundaryMesh().size())
00189 {
00190     patchDataWave<TransferType>::correct();
00191 }
00192 
00193 
00194 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00195 
00196 template<class TransferType>
00197 Foam::patchDataWave<TransferType>::~patchDataWave()
00198 {}
00199 
00200 
00201 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00202 
00203 // Correct for mesh geom/topo changes
00204 template<class TransferType>
00205 void Foam::patchDataWave<TransferType>::correct()
00206 {
00207     //
00208     // Set initial changed faces: set TransferType for wall faces
00209     // to wall centre.
00210     //
00211 
00212     // Count walls
00213     label nWalls = sumPatchSize(patchIDs_);
00214 
00215     List<TransferType> faceDist(nWalls);
00216     labelList changedFaces(nWalls);
00217 
00218     setChangedFaces(patchIDs_, changedFaces, faceDist);
00219 
00220     //
00221     // Do calculate wall distance by 'growing' from faces.
00222     //
00223 
00224     MeshWave<TransferType> waveInfo
00225     (
00226         mesh(),
00227         changedFaces,
00228         faceDist,
00229         mesh().globalData().nTotalCells() // max iterations
00230     );
00231 
00232 
00233     //
00234     // Copy distance into return field
00235     //
00236 
00237     nUnset_ = getValues(waveInfo);
00238 
00239     //
00240     // Correct wall cells for true distance
00241     //
00242 
00243     if (correctWalls_)
00244     {
00245         Map<label> nearestFace(2 * nWalls);
00246 
00247         // Get distance and indices of nearest face
00248         correctBoundaryFaceCells
00249         (
00250             patchIDs_,
00251             distance_,
00252             nearestFace
00253         );
00254 
00255         correctBoundaryPointCells
00256         (
00257             patchIDs_,
00258             distance_,
00259             nearestFace
00260         );
00261 
00262         // Transfer data from nearest face to cell
00263         const List<TransferType>& faceInfo = waveInfo.allFaceInfo();
00264 
00265         const labelList wallCells(nearestFace.toc());
00266 
00267         forAll(wallCells, wallCellI)
00268         {
00269             label cellI = wallCells[wallCellI];
00270 
00271             label faceI = nearestFace[cellI];
00272 
00273             cellData_[cellI] = faceInfo[faceI].data();
00274         }
00275     }
00276 }
00277 
00278 
00279 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd