Loading...
Searching...
No Matches
patchWave.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "patchWave.H"
30#include "polyMesh.H"
31#include "wallPoint.H"
32#include "globalMeshData.H"
33
34// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35
36void Foam::patchWave::setChangedFaces
37(
38 const labelHashSet& patchIDs,
39 DynamicList<label>& changedFaces,
40 DynamicList<wallPoint>& faceDist
41) const
42{
43 const polyMesh& mesh = cellDistFuncs::mesh();
44
45 forAll(mesh.boundaryMesh(), patchi)
46 {
47 if (patchIDs.found(patchi))
48 {
49 const polyPatch& patch = mesh.boundaryMesh()[patchi];
50
51 const auto areaFraction(patch.areaFraction());
52
53 const auto faceCentres(patch.faceCentres());
54
55 forAll(faceCentres, patchFacei)
56 {
57 if
58 (
59 !areaFraction
60 || (areaFraction()[patchFacei] > 0.5) // mostly wall
61 )
62 {
63 changedFaces.append(patch.start() + patchFacei);
64 faceDist.append(wallPoint(faceCentres[patchFacei], 0.0));
65 }
66 }
67 }
68 }
69
70 for (const label facei : sourceIDs_)
71 {
72 changedFaces.append(facei);
73
74 faceDist.append
75 (
76 wallPoint
77 (
78 mesh.faceCentres()[facei],
79 0.0
80 )
81 );
82 }
83}
84
85
86Foam::label Foam::patchWave::getValues(const MeshWave<wallPoint>& waveInfo)
87{
88 const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
89 const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
90
91 label nIllegal = 0;
92
93 // Copy cell values
94 distance_.setSize(cellInfo.size());
95
96 forAll(cellInfo, celli)
97 {
98 scalar dist = cellInfo[celli].distSqr();
99
100 if (cellInfo[celli].valid(waveInfo.data()))
101 {
102 distance_[celli] = Foam::sqrt(dist);
103 }
104 else
105 {
106 distance_[celli] = dist;
107
108 nIllegal++;
109 }
110 }
111
112 // Copy boundary values
113 forAll(patchDistance_, patchi)
114 {
115 const polyPatch& patch = mesh().boundaryMesh()[patchi];
116
117 // Allocate storage for patchDistance
118 scalarField* patchDistPtr = new scalarField(patch.size());
119
120 patchDistance_.set(patchi, patchDistPtr);
121
122 scalarField& patchField = *patchDistPtr;
123
124 forAll(patchField, patchFacei)
125 {
126 label meshFacei = patch.start() + patchFacei;
127
128 scalar dist = faceInfo[meshFacei].distSqr();
129
130 if (faceInfo[meshFacei].valid(waveInfo.data()))
131 {
132 // Adding SMALL to avoid problems with /0 in the turbulence
133 // models
134 patchField[patchFacei] = Foam::sqrt(dist) + SMALL;
135 }
136 else
137 {
138 patchField[patchFacei] = dist;
139
140 nIllegal++;
141 }
142 }
144 return nIllegal;
145}
146
147
148// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
149
151(
152 const polyMesh& mesh,
153 const labelHashSet& patchIDs,
154 const bool correctWalls,
155 const labelList& sourceIDs
156)
157:
158 cellDistFuncs(mesh),
159 patchIDs_(patchIDs),
160 correctWalls_(correctWalls),
161 nUnset_(0),
162 distance_(mesh.nCells()),
163 patchDistance_(mesh.boundaryMesh().size()),
164 sourceIDs_(sourceIDs)
167}
168
169
170// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
173{}
174
175
176// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
177
179{
180 // Set initial changed faces: set wallPoint for wall faces to wall centre
181
182 label nPatch = sumPatchSize(patchIDs_) + sourceIDs_.size();
183
184 DynamicList<wallPoint> faceDist(nPatch);
185 DynamicList<label> changedFaces(nPatch);
186
187 // Set to faceDist information to facecentre on walls.
188 setChangedFaces(patchIDs_, changedFaces, faceDist);
189
190 // Do calculate wall distance by 'growing' from faces.
191 MeshWave<wallPoint> waveInfo
192 (
193 mesh(),
194 changedFaces,
195 faceDist,
196 mesh().globalData().nTotalCells()+1 // max iterations
197 );
198
199 // Copy distance into return field
200 nUnset_ = getValues(waveInfo);
201
202 // Correct wall cells for true distance
203 if (correctWalls_)
204 {
205 Map<label> nearestFace(2*nPatch);
206
208 {
209 // Correct across multiple patches
210 correctBoundaryCells
211 (
212 patchIDs_.sortedToc(),
213 true, // do point-connected cells as well
214 distance_,
215 nearestFace
216 );
217 }
218 else
219 {
220 // Backwards compatible
221 correctBoundaryFaceCells
222 (
223 patchIDs_,
224 distance_,
225 nearestFace
226 );
227
228 correctBoundaryPointCells
229 (
230 patchIDs_,
231 distance_,
232 nearestFace
233 );
234 }
235 }
236}
237
238
239// ************************************************************************* //
labelList patchIDs
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void setSize(label n)
Alias for resize().
Definition List.H:536
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
FaceCellWave plus data.
Definition MeshWave.H:58
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
label sumPatchSize(const labelHashSet &patchIDs) const
Sum of patch sizes (out of supplied subset of patches).
const polyMesh & mesh() const
Access mesh.
void correctBoundaryFaceCells(const labelHashSet &patchIDs, scalarField &wallDistCorrected, Map< label > &nearestFace) const
Correct all cells connected to boundary (via face). Sets values in.
void correctBoundaryCells(const labelList &patchIDs, const bool doPointCells, scalarField &wallDistCorrected, Map< label > &nearestFace) const
Correct all cells connected to any of the patches in patchIDs. Sets.
void correctBoundaryPointCells(const labelHashSet &patchIDs, scalarField &wallDistCorrected, Map< label > &nearestFace) const
Correct all cells connected to wall (via point). Sets values in.
static bool useCombinedWallPatch
Use combined-wall-patches wall distance v.s. v2406 per-patch distance. Default is true.
Holds information regarding type of cell. Used in inside/outside determination in cellClassification.
Definition cellInfo.H:61
virtual void correct()
Correct for mesh geom/topo changes.
Definition patchWave.C:171
virtual ~patchWave()
Destructor.
Definition patchWave.C:165
patchWave(const polyMesh &mesh, const labelHashSet &patchIDs, bool correctWalls=true, const labelList &sourceFaceIDs=labelList())
Construct from mesh and patches to initialize to 0 and flag.
Definition patchWave.C:144
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition polyMesh.H:609
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
dynamicFvMesh & mesh
const std::string patch
OpenFOAM patch number as a std::string.
List< label > labelList
A List of labels.
Definition List.H:62
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar sqrt(const dimensionedScalar &ds)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299