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-2023 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 #include "WallInfo.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
34 (
35  const polyMesh& mesh,
36  const labelHashSet& patchIDs
37 )
38 {
39  label nChangedFaces = 0;
40  forAllConstIter(labelHashSet, patchIDs, iter)
41  {
42  nChangedFaces += mesh.boundaryMesh()[iter.key()].size();
43  }
44 
45  labelList changedFaces(nChangedFaces);
46  label changedFacei = 0;
47 
48  forAllConstIter(labelHashSet, patchIDs, iter)
49  {
50  const label patchi = iter.key();
51 
52  const polyPatch& patch = mesh.boundaryMesh()[patchi];
53 
54  forAll(patch.faceCentres(), patchFacei)
55  {
56  const label meshFacei = patch.start() + patchFacei;
57 
58  changedFaces[changedFacei] = meshFacei;
59 
60  changedFacei++;
61  }
62  }
63 
64  return changedFaces;
65 }
66 
67 
69 (
70  const polyMesh& mesh,
71  const labelList& changedFaces,
72  scalarField& cellDistance
73 )
74 {
75  // Initialise changedFacesInfo to face centres on patches
76  List<WallInfo<wallPoint>> changedFacesInfo(changedFaces.size());
77  forAll(changedFaces, changedFacei)
78  {
79  const label facei = changedFaces[changedFacei];
80 
81  changedFacesInfo[changedFacei] =
82  WallInfo<wallPoint>(mesh.faceCentres()[facei], scalar(0));
83  }
84 
85  // Do calculate patch distance by 'growing' from faces.
86  List<WallInfo<wallPoint>> faceInfo(mesh.nFaces()), cellInfo(mesh.nCells());
87  FaceCellWave<WallInfo<wallPoint>> wave
88  (
89  mesh,
90  changedFaces,
91  changedFacesInfo,
92  faceInfo,
93  cellInfo,
94  mesh.globalData().nTotalCells() + 1 // max iterations
95  );
96 
97  // Copy distances into field
98  label nUnset = 0;
99  forAll(cellInfo, celli)
100  {
101  nUnset += !cellInfo[celli].valid(wave.data());
102 
103  cellDistance[celli] = cellInfo[celli].dist(wave.data());
104  }
105 
106  return nUnset;
107 }
108 
109 
111 (
112  const polyMesh& mesh,
113  const labelHashSet& patchIDs,
114  scalarField& cellDistance
115 )
116 {
117  return wave(mesh, getChangedFaces(mesh, patchIDs), cellDistance);
118 }
119 
120 
121 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
label patchi
label wave(const fvMesh &mesh, const List< labelPair > &changedPatchAndFaces, const label nCorrections, GeometricField< scalar, PatchField, GeoMesh > &distance, TrackingData &td, GeometricField< DataType, PatchField, GeoMesh > &... data)
Wave distance (and maybe additional) data from faces. If nCorrections is.
label calculate(const polyMesh &mesh, const labelHashSet &patchIDs, scalarField &cellDistance)
Calculate distance data from patches.
label wave(const polyMesh &mesh, const labelList &changedFaces, scalarField &cellDistance)
Wave distance data from faces.
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
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:211