initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / cellDist / patchWave / patchDataWave.C
blobb22a110be625c0a644a7cb0390cd2bbe44c62887
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 "patchDataWave.H"
28 #include "MeshWave.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 // Set initial set of changed faces (= all wall faces)
33 template<class TransferType>
34 void Foam::patchDataWave<TransferType>::setChangedFaces
36     const labelHashSet& patchIDs,
37     labelList& changedFaces,
38     List<TransferType>& 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             const Field<Type>& patchField = initialPatchValuePtrs_[patchI];
53             forAll(patch.faceCentres(), patchFaceI)
54             {
55                 label meshFaceI = patch.start() + patchFaceI;
57                 changedFaces[nChangedFaces] = meshFaceI;
59                 faceDist[nChangedFaces] =
60                     TransferType
61                     (
62                         patch.faceCentres()[patchFaceI],
63                         patchField[patchFaceI],
64                         0.0
65                     );
67                 nChangedFaces++;
68             }
69         }
70     }
74 // Copy from MeshWave data into *this (distance) and field_ (transported data)
75 template<class TransferType>
76 Foam::label Foam::patchDataWave<TransferType>::getValues
78     const MeshWave<TransferType>& waveInfo
81     const polyMesh& mesh = cellDistFuncs::mesh();
83     const List<TransferType>& cellInfo = waveInfo.allCellInfo();
84     const List<TransferType>& faceInfo = waveInfo.allFaceInfo();
86     label nIllegal = 0;
88     // Copy cell values
89     distance_.setSize(cellInfo.size());
91     forAll(cellInfo, cellI)
92     {
93         const TransferType & wpn = cellInfo[cellI];
95         scalar dist = wpn.distSqr();
97         if (cellInfo[cellI].valid())
98         {
99             distance_[cellI] = Foam::sqrt(dist);
101             cellData_[cellI] = cellInfo[cellI].data();
102         }
103         else
104         {
105             // Illegal/unset value. What to do with data?
107             distance_[cellI] = dist;
109             //cellData_[cellI] = wallPoint::greatPoint;
110             cellData_[cellI] = cellInfo[cellI].data();
112             nIllegal++;
113         }
114     }
116     // Copy boundary values
117     forAll(patchDistance_, patchI)
118     {
119         const polyPatch& patch = mesh.boundaryMesh()[patchI];
121         // Allocate storage for patchDistance
122         scalarField* patchFieldPtr = new scalarField(patch.size());
124         patchDistance_.set(patchI, patchFieldPtr);
126         scalarField& patchField = *patchFieldPtr;
128         // Allocate storage for patchData
129         Field<Type>* patchDataFieldPtr = new Field<Type>(patch.size());
131         patchData_.set(patchI, patchDataFieldPtr);
133         Field<Type>& patchDataField = *patchDataFieldPtr;
135         // Copy distance and data
136         forAll(patchField, patchFaceI)
137         {
138             label meshFaceI = patch.start() + patchFaceI;
140             scalar dist = faceInfo[meshFaceI].distSqr();
142             if (faceInfo[meshFaceI].valid())
143             {
144                 // Adding SMALL to avoid problems with /0 in the turbulence
145                 // models
146                 patchField[patchFaceI] = Foam::sqrt(dist) + SMALL;
148                 patchDataField[patchFaceI] = faceInfo[meshFaceI].data();
149             }
150             else
151             {
152                 // Illegal/unset value. What to do with data?
154                 patchField[patchFaceI] = dist;
156                 //patchDataField[patchFaceI] = wallPoint::greatPoint;
157                 patchDataField[patchFaceI] = faceInfo[meshFaceI].data();
159                 nIllegal++;
160             }
161         }
162     }
164     return nIllegal;
168 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
170 // Construct from components
171 template<class TransferType>
172 Foam::patchDataWave<TransferType>::patchDataWave
174     const polyMesh& mesh,
175     const labelHashSet& patchIDs,
176     const UPtrList<Field<Type> >& initialPatchValuePtrs,
177     const bool correctWalls
180     cellDistFuncs(mesh),
181     patchIDs_(patchIDs),
182     initialPatchValuePtrs_(initialPatchValuePtrs),
183     correctWalls_(correctWalls),
184     nUnset_(0),
185     distance_(mesh.nCells()),
186     patchDistance_(mesh.boundaryMesh().size()),
187     cellData_(mesh.nCells()),
188     patchData_(mesh.boundaryMesh().size())
190     patchDataWave<TransferType>::correct();
194 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
196 template<class TransferType>
197 Foam::patchDataWave<TransferType>::~patchDataWave()
201 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
203 // Correct for mesh geom/topo changes
204 template<class TransferType>
205 void Foam::patchDataWave<TransferType>::correct()
207     //
208     // Set initial changed faces: set TransferType for wall faces
209     // to wall centre.
210     //
212     // Count walls
213     label nWalls = sumPatchSize(patchIDs_);
215     List<TransferType> faceDist(nWalls);
216     labelList changedFaces(nWalls);
218     setChangedFaces(patchIDs_, changedFaces, faceDist);
220     //
221     // Do calculate wall distance by 'growing' from faces.
222     //
224     MeshWave<TransferType> waveInfo
225     (
226         mesh(),
227         changedFaces,
228         faceDist,
229         mesh().globalData().nTotalCells() // max iterations
230     );
233     //
234     // Copy distance into return field
235     //
237     nUnset_ = getValues(waveInfo);
239     //
240     // Correct wall cells for true distance
241     //
243     if (correctWalls_)
244     {
245         Map<label> nearestFace(2 * nWalls);
247         // Get distance and indices of nearest face
248         correctBoundaryFaceCells
249         (
250             patchIDs_,
251             distance_,
252             nearestFace
253         );
255         correctBoundaryPointCells
256         (
257             patchIDs_,
258             distance_,
259             nearestFace
260         );
262         // Transfer data from nearest face to cell
263         const List<TransferType>& faceInfo = waveInfo.allFaceInfo();
265         const labelList wallCells(nearestFace.toc());
267         forAll(wallCells, wallCellI)
268         {
269             label cellI = wallCells[wallCellI];
271             label faceI = nearestFace[cellI];
273             cellData_[cellI] = faceInfo[faceI].data();
274         }
275     }
279 // ************************************************************************* //