1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "patchWave.H"
28 #include "wallPoint.H"
29 #include "globalMeshData.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 void Foam::patchWave::setChangedFaces
36 const labelHashSet& patchIDs,
37 labelList& changedFaces,
38 List<wallPoint>& faceDist
41 const polyMesh& mesh = cellDistFuncs::mesh();
43 label nChangedFaces = 0;
45 forAll(mesh.boundaryMesh(), patchI)
47 if (patchIDs.found(patchI))
49 const polyPatch& patch = mesh.boundaryMesh()[patchI];
51 forAll(patch.faceCentres(), patchFaceI)
53 label meshFaceI = patch.start() + patchFaceI;
55 changedFaces[nChangedFaces] = meshFaceI;
57 faceDist[nChangedFaces] =
60 patch.faceCentres()[patchFaceI],
71 Foam::label Foam::patchWave::getValues(const MeshWave<wallPoint>& waveInfo)
73 const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
74 const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
79 distance_.setSize(cellInfo.size());
81 forAll(cellInfo, cellI)
83 scalar dist = cellInfo[cellI].distSqr();
85 if (cellInfo[cellI].valid(waveInfo.data()))
87 distance_[cellI] = Foam::sqrt(dist);
91 distance_[cellI] = dist;
97 // Copy boundary values
98 forAll(patchDistance_, patchI)
100 const polyPatch& patch = mesh().boundaryMesh()[patchI];
102 // Allocate storage for patchDistance
103 scalarField* patchDistPtr = new scalarField(patch.size());
105 patchDistance_.set(patchI, patchDistPtr);
107 scalarField& patchField = *patchDistPtr;
109 forAll(patchField, patchFaceI)
111 label meshFaceI = patch.start() + patchFaceI;
113 scalar dist = faceInfo[meshFaceI].distSqr();
115 if (faceInfo[meshFaceI].valid(waveInfo.data()))
117 // Adding SMALL to avoid problems with /0 in the turbulence
119 patchField[patchFaceI] = Foam::sqrt(dist) + SMALL;
123 patchField[patchFaceI] = dist;
133 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
135 // Construct from components
136 Foam::patchWave::patchWave
138 const polyMesh& mesh,
139 const labelHashSet& patchIDs,
140 const bool correctWalls
145 correctWalls_(correctWalls),
147 distance_(mesh.nCells()),
148 patchDistance_(mesh.boundaryMesh().size())
150 patchWave::correct();
154 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 Foam::patchWave::~patchWave()
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
162 // Correct for mesh geom/topo changes. Might be more intelligent in the
163 // future (if only small topology change)
164 void Foam::patchWave::correct()
167 // Set initial changed faces: set wallPoint for wall faces to wall centre
171 label nWalls = sumPatchSize(patchIDs_);
173 List<wallPoint> faceDist(nWalls);
174 labelList changedFaces(nWalls);
176 // Set to faceDist information to facecentre on walls.
177 setChangedFaces(patchIDs_, changedFaces, faceDist);
181 // Do calculate wall distance by 'growing' from faces.
184 MeshWave<wallPoint> waveInfo
189 mesh().globalData().nTotalCells()+1 // max iterations
194 // Copy distance into return field
197 nUnset_ = getValues(waveInfo);
200 // Correct wall cells for true distance
205 Map<label> nearestFace(2 * nWalls);
207 correctBoundaryFaceCells
214 correctBoundaryPointCells
224 // ************************************************************************* //