initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / cellDist / patchWave / patchWave.C
blobf365927c1cab65ebd13c818f583f2ee695c0b1fc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "polyMesh.H"
29 #include "wallPoint.H"
30 #include "MeshWave.H"
33 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
35 void Foam::patchWave::setChangedFaces
37     const labelHashSet& patchIDs,
38     labelList& changedFaces,
39     List<wallPoint>& faceDist
40 ) const
42     const polyMesh& mesh = cellDistFuncs::mesh();
44     label nChangedFaces = 0;
46     forAll(mesh.boundaryMesh(), patchI)
47     {
48         if (patchIDs.found(patchI))
49         {
50             const polyPatch& patch = mesh.boundaryMesh()[patchI];
52             forAll(patch.faceCentres(), patchFaceI)
53             {
54                 label meshFaceI = patch.start() + patchFaceI;
56                 changedFaces[nChangedFaces] = meshFaceI;
58                 faceDist[nChangedFaces] =
59                     wallPoint
60                     (
61                         patch.faceCentres()[patchFaceI],
62                         0.0
63                     );
65                 nChangedFaces++;
66             }
67         }
68     }
72 Foam::label Foam::patchWave::getValues(const MeshWave<wallPoint>& waveInfo)
74     const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
75     const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
77     label nIllegal = 0;
79     // Copy cell values
80     distance_.setSize(cellInfo.size());
82     forAll(cellInfo, cellI)
83     {
84         scalar dist = cellInfo[cellI].distSqr();
86         if (cellInfo[cellI].valid())
87         {
88             distance_[cellI] = Foam::sqrt(dist);
89         }
90         else
91         {
92             distance_[cellI] = dist;
94             nIllegal++;
95         }
96     }
98     // Copy boundary values
99     forAll(patchDistance_, patchI)
100     {
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)
111         {
112             label meshFaceI = patch.start() + patchFaceI;
114             scalar dist = faceInfo[meshFaceI].distSqr();
116             if (faceInfo[meshFaceI].valid())
117             {
118                 // Adding SMALL to avoid problems with /0 in the turbulence
119                 // models
120                 patchField[patchFaceI] = Foam::sqrt(dist) + SMALL;
121             }
122             else
123             {
124                 patchField[patchFaceI] = dist;
126                 nIllegal++;
127             }
128         }
129     }
130     return nIllegal;
134 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
136 // Construct from components
137 Foam::patchWave::patchWave
139     const polyMesh& mesh,
140     const labelHashSet& patchIDs,
141     const bool correctWalls
144     cellDistFuncs(mesh),
145     patchIDs_(patchIDs),
146     correctWalls_(correctWalls),
147     nUnset_(0),
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()
167     //
168     // Set initial changed faces: set wallPoint for wall faces to wall centre
169     //
171     // Count walls
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);
181     //
182     // Do calculate wall distance by 'growing' from faces.
183     //
185     MeshWave<wallPoint> waveInfo
186     (
187         mesh(),
188         changedFaces,
189         faceDist,
190         mesh().nCells() // max iterations
191     );
194     //
195     // Copy distance into return field
196     //
198     nUnset_ = getValues(waveInfo);
200     //
201     // Correct wall cells for true distance
202     //
204     if (correctWalls_)
205     {
206         Map<label> nearestFace(2 * nWalls);
208         correctBoundaryFaceCells
209         (
210             patchIDs_,
211             distance_,
212             nearestFace
213         );
215         correctBoundaryPointCells
216         (
217             patchIDs_,
218             distance_,
219             nearestFace
220         );
221     }
225 // ************************************************************************* //