1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 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
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"
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
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 const Field<Type>& patchField = initialPatchValuePtrs_[patchI];
53 forAll(patch.faceCentres(), patchFaceI)
55 label meshFaceI = patch.start() + patchFaceI;
57 changedFaces[nChangedFaces] = meshFaceI;
59 faceDist[nChangedFaces] =
62 patch.faceCentres()[patchFaceI],
63 patchField[patchFaceI],
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();
89 distance_.setSize(cellInfo.size());
91 forAll(cellInfo, cellI)
93 const TransferType & wpn = cellInfo[cellI];
95 scalar dist = wpn.distSqr();
97 if (cellInfo[cellI].valid())
99 distance_[cellI] = Foam::sqrt(dist);
101 cellData_[cellI] = cellInfo[cellI].data();
105 // Illegal/unset value. What to do with data?
107 distance_[cellI] = dist;
109 //cellData_[cellI] = wallPoint::greatPoint;
110 cellData_[cellI] = cellInfo[cellI].data();
116 // Copy boundary values
117 forAll(patchDistance_, patchI)
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)
138 label meshFaceI = patch.start() + patchFaceI;
140 scalar dist = faceInfo[meshFaceI].distSqr();
142 if (faceInfo[meshFaceI].valid())
144 // Adding SMALL to avoid problems with /0 in the turbulence
146 patchField[patchFaceI] = Foam::sqrt(dist) + SMALL;
148 patchDataField[patchFaceI] = faceInfo[meshFaceI].data();
152 // Illegal/unset value. What to do with data?
154 patchField[patchFaceI] = dist;
156 //patchDataField[patchFaceI] = wallPoint::greatPoint;
157 patchDataField[patchFaceI] = faceInfo[meshFaceI].data();
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
182 initialPatchValuePtrs_(initialPatchValuePtrs),
183 correctWalls_(correctWalls),
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()
208 // Set initial changed faces: set TransferType for wall faces
213 label nWalls = sumPatchSize(patchIDs_);
215 List<TransferType> faceDist(nWalls);
216 labelList changedFaces(nWalls);
218 setChangedFaces(patchIDs_, changedFaces, faceDist);
221 // Do calculate wall distance by 'growing' from faces.
224 MeshWave<TransferType> waveInfo
229 mesh().globalData().nTotalCells() // max iterations
234 // Copy distance into return field
237 nUnset_ = getValues(waveInfo);
240 // Correct wall cells for true distance
245 Map<label> nearestFace(2 * nWalls);
247 // Get distance and indices of nearest face
248 correctBoundaryFaceCells
255 correctBoundaryPointCells
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)
269 label cellI = wallCells[wallCellI];
271 label faceI = nearestFace[cellI];
273 cellData_[cellI] = faceInfo[faceI].data();
279 // ************************************************************************* //