1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "patchWave.H"
29 #include "wallPoint.H"
31 #include "globalMeshData.H"
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 void Foam::patchWave::setChangedFaces
37 const labelHashSet& patchIDs,
38 labelList& changedFaces,
39 List<wallPoint>& faceDist
42 const polyMesh& mesh = cellDistFuncs::mesh();
44 label nChangedFaces = 0;
46 forAll(mesh.boundaryMesh(), patchI)
48 if (patchIDs.found(patchI))
50 const polyPatch& patch = mesh.boundaryMesh()[patchI];
52 forAll(patch.faceCentres(), patchFaceI)
54 label meshFaceI = patch.start() + patchFaceI;
56 changedFaces[nChangedFaces] = meshFaceI;
58 faceDist[nChangedFaces] =
61 patch.faceCentres()[patchFaceI],
72 Foam::label Foam::patchWave::getValues(const MeshWave<wallPoint>& waveInfo)
74 const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
75 const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
80 distance_.setSize(cellInfo.size());
82 forAll(cellInfo, cellI)
84 scalar dist = cellInfo[cellI].distSqr();
86 if (cellInfo[cellI].valid())
88 distance_[cellI] = Foam::sqrt(dist);
92 distance_[cellI] = dist;
98 // Copy boundary values
99 forAll(patchDistance_, patchI)
101 const polyPatch& patch = mesh().boundaryMesh()[patchI];
103 // Allocate storage for patchDistance
104 scalarField* patchDistPtr = new scalarField(patch.size());
106 patchDistance_.set(patchI, patchDistPtr);
108 scalarField& patchField = *patchDistPtr;
110 forAll(patchField, patchFaceI)
112 label meshFaceI = patch.start() + patchFaceI;
114 scalar dist = faceInfo[meshFaceI].distSqr();
116 if (faceInfo[meshFaceI].valid())
118 // Adding SMALL to avoid problems with /0 in the turbulence
120 patchField[patchFaceI] = Foam::sqrt(dist) + SMALL;
124 patchField[patchFaceI] = dist;
134 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
136 // Construct from components
137 Foam::patchWave::patchWave
139 const polyMesh& mesh,
140 const labelHashSet& patchIDs,
141 const bool correctWalls
146 correctWalls_(correctWalls),
148 distance_(mesh.nCells()),
149 patchDistance_(mesh.boundaryMesh().size())
151 patchWave::correct();
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
157 Foam::patchWave::~patchWave()
161 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 // Correct for mesh geom/topo changes. Might be more intelligent in the
164 // future (if only small topology change)
165 void Foam::patchWave::correct()
168 // Set initial changed faces: set wallPoint for wall faces to wall centre
172 label nWalls = sumPatchSize(patchIDs_);
174 List<wallPoint> faceDist(nWalls);
175 labelList changedFaces(nWalls);
177 // Set to faceDist information to facecentre on walls.
178 setChangedFaces(patchIDs_, changedFaces, faceDist);
182 // Do calculate wall distance by 'growing' from faces.
185 MeshWave<wallPoint> waveInfo
190 mesh().globalData().nTotalCells() // max iterations
195 // Copy distance into return field
198 nUnset_ = getValues(waveInfo);
201 // Correct wall cells for true distance
206 Map<label> nearestFace(2 * nWalls);
208 correctBoundaryFaceCells
215 correctBoundaryPointCells
225 // ************************************************************************* //