patchDistWave.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "patchDistWave.H"
27 #include "FaceCellWave.H"
28 #include "wallPoint.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
33 (
34  const polyMesh& mesh,
35  const labelHashSet& patchIDs
36 )
37 {
38  label nChangedFaces = 0;
39  forAllConstIter(labelHashSet, patchIDs, iter)
40  {
41  nChangedFaces += mesh.boundaryMesh()[iter.key()].size();
42  }
43 
44  labelList changedFaces(nChangedFaces);
45  label changedFacei = 0;
46 
47  forAllConstIter(labelHashSet, patchIDs, iter)
48  {
49  const label patchi = iter.key();
50 
51  const polyPatch& patch = mesh.boundaryMesh()[patchi];
52 
53  forAll(patch.faceCentres(), patchFacei)
54  {
55  const label meshFacei = patch.start() + patchFacei;
56 
57  changedFaces[changedFacei] = meshFacei;
58 
59  changedFacei++;
60  }
61  }
62 
63  return changedFaces;
64 }
65 
66 
68 (
69  const polyMesh& mesh,
70  const labelList& changedFaces,
71  scalarField& cellDistance
72 )
73 {
74  // Initialise changedFacesInfo to face centres on patches
75  List<wallPoint> changedFacesInfo(changedFaces.size());
76  forAll(changedFaces, changedFacei)
77  {
78  const label facei = changedFaces[changedFacei];
79 
80  changedFacesInfo[changedFacei] =
81  wallPoint(mesh.faceCentres()[facei], scalar(0));
82  }
83 
84  // Do calculate patch distance by 'growing' from faces.
85  List<wallPoint> faceInfo(mesh.nFaces()), cellInfo(mesh.nCells());
86  FaceCellWave<wallPoint> wave
87  (
88  mesh,
89  changedFaces,
90  changedFacesInfo,
91  faceInfo,
92  cellInfo,
93  mesh.globalData().nTotalCells() + 1 // max iterations
94  );
95 
96  // Copy distances into field
97  label nUnset = 0;
98  forAll(cellInfo, celli)
99  {
100  nUnset += !cellInfo[celli].valid(wave.data());
101 
102  cellDistance[celli] = cellInfo[celli].dist(wave.data());
103  }
104 
105  return nUnset;
106 }
107 
108 
110 (
111  const polyMesh& mesh,
112  const labelHashSet& patchIDs,
113  scalarField& cellDistance
114 )
115 {
116  return wave(mesh, getChangedFaces(mesh, patchIDs), cellDistance);
117 }
118 
119 
120 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
const Type & data() const
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:211
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
labelList getChangedFaces(const polyMesh &mesh, const labelHashSet &patchIDs)
Get initial set of changed faces.
List< label > labelList
A List of labels.
Definition: labelList.H:56
label calculate(const polyMesh &mesh, const labelHashSet &patchIDs, scalarField &cellDistance)
Calculate distance data from patches.
label patchi
label wave(const polyMesh &mesh, const labelList &changedFaces, scalarField &cellDistance)
Wave distance data from faces.