ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / meshTools / cellDist / patchWave / patchWave.C
blob92d0b5c96c78236d3141a83c416642ef696eeccf
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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"
27 #include "polyMesh.H"
28 #include "wallPoint.H"
29 #include "globalMeshData.H"
30 #include "SubField.H"
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 void Foam::patchWave::setChangedFaces
36     const labelHashSet& patchIDs,
37     labelList& changedFaces,
38     List<wallPoint>& faceDist
39 ) const
41     const polyMesh& mesh = cellDistFuncs::mesh();
43     label nChangedFaces = 0;
45     forAll(mesh.boundaryMesh(), patchI)
46     {
47         if (patchIDs.found(patchI))
48         {
49             const polyPatch& patch = mesh.boundaryMesh()[patchI];
51             forAll(patch.faceCentres(), patchFaceI)
52             {
53                 label meshFaceI = patch.start() + patchFaceI;
55                 changedFaces[nChangedFaces] = meshFaceI;
57                 faceDist[nChangedFaces] =
58                     wallPoint
59                     (
60                         patch.faceCentres()[patchFaceI],
61                         0.0
62                     );
64                 nChangedFaces++;
65             }
66         }
67     }
71 Foam::label Foam::patchWave::getValues(const MeshWave<wallPoint>& waveInfo)
73     const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
74     const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
76     label nIllegal = 0;
78     // Copy cell values
79     distance_.setSize(cellInfo.size());
81     forAll(cellInfo, cellI)
82     {
83         scalar dist = cellInfo[cellI].distSqr();
85         if (cellInfo[cellI].valid(waveInfo.data()))
86         {
87             distance_[cellI] = Foam::sqrt(dist);
88         }
89         else
90         {
91             distance_[cellI] = dist;
93             nIllegal++;
94         }
95     }
97     // Copy boundary values
98     forAll(patchDistance_, patchI)
99     {
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)
110         {
111             label meshFaceI = patch.start() + patchFaceI;
113             scalar dist = faceInfo[meshFaceI].distSqr();
115             if (faceInfo[meshFaceI].valid(waveInfo.data()))
116             {
117                 // Adding SMALL to avoid problems with /0 in the turbulence
118                 // models
119                 patchField[patchFaceI] = Foam::sqrt(dist) + SMALL;
120             }
121             else
122             {
123                 patchField[patchFaceI] = dist;
125                 nIllegal++;
126             }
127         }
128     }
129     return nIllegal;
133 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
135 // Construct from components
136 Foam::patchWave::patchWave
138     const polyMesh& mesh,
139     const labelHashSet& patchIDs,
140     const bool correctWalls
143     cellDistFuncs(mesh),
144     patchIDs_(patchIDs),
145     correctWalls_(correctWalls),
146     nUnset_(0),
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()
166     //
167     // Set initial changed faces: set wallPoint for wall faces to wall centre
168     //
170     // Count walls
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);
180     //
181     // Do calculate wall distance by 'growing' from faces.
182     //
184     MeshWave<wallPoint> waveInfo
185     (
186         mesh(),
187         changedFaces,
188         faceDist,
189         mesh().globalData().nTotalCells()+1 // max iterations
190     );
193     //
194     // Copy distance into return field
195     //
197     nUnset_ = getValues(waveInfo);
199     //
200     // Correct wall cells for true distance
201     //
203     if (correctWalls_)
204     {
205         Map<label> nearestFace(2 * nWalls);
207         correctBoundaryFaceCells
208         (
209             patchIDs_,
210             distance_,
211             nearestFace
212         );
214         correctBoundaryPointCells
215         (
216             patchIDs_,
217             distance_,
218             nearestFace
219         );
220     }
224 // ************************************************************************* //