Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / meshTools / cellDist / patchWave / patchWave.C
blob2570db5f63feb006d22a434bb8557773bdef7d52
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "patchWave.H"
27 #include "polyMesh.H"
28 #include "wallPoint.H"
29 #include "MeshWave.H"
30 #include "globalMeshData.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())
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())
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     }
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().globalData().nTotalCells()   // 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 // ************************************************************************* //