patchPatchDist.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 "patchPatchDist.H"
27 #include "PatchEdgeFaceWave.H"
28 #include "syncTools.H"
29 #include "polyMesh.H"
30 #include "patchEdgeFacePoint.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 (
36  const polyPatch& patch,
37  const labelHashSet& nbrPatchIDs
38 )
39 :
40  patch_(patch),
41  nbrPatchIndices_(nbrPatchIDs),
42  nUnset_(0)
43 {
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
49 
51 {}
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
57 {
58  // Mark all edge connected to a nbrPatch.
59  label nBnd = 0;
60  forAllConstIter(labelHashSet, nbrPatchIndices_, iter)
61  {
62  label nbrPatchi = iter.key();
63  const polyPatch& nbrPatch = patch_.boundaryMesh()[nbrPatchi];
64  nBnd += nbrPatch.nEdges()-nbrPatch.nInternalEdges();
65  }
66 
67  // Mark all edges. Note: should use HashSet but have no syncTools
68  // functionality for these.
69  EdgeMap<label> nbrEdges(2*nBnd);
70 
71  forAllConstIter(labelHashSet, nbrPatchIndices_, iter)
72  {
73  label nbrPatchi = iter.key();
74  const polyPatch& nbrPatch = patch_.boundaryMesh()[nbrPatchi];
75  const labelList& nbrMp = nbrPatch.meshPoints();
76 
77  for
78  (
79  label edgei = nbrPatch.nInternalEdges();
80  edgei < nbrPatch.nEdges();
81  edgei++
82  )
83  {
84  const edge& e = nbrPatch.edges()[edgei];
85  const edge meshE = edge(nbrMp[e[0]], nbrMp[e[1]]);
86  nbrEdges.insert(meshE, nbrPatchi);
87  }
88  }
89 
90 
91  // Make sure these boundary edges are marked everywhere.
93  (
94  patch_.boundaryMesh().mesh(),
95  nbrEdges,
97  );
98 
99 
100  // Data on all edges and faces
101  List<patchEdgeFacePoint> allEdgeInfo(patch_.nEdges());
102  List<patchEdgeFacePoint> allFaceInfo(patch_.size());
103 
104  // Initial seed
105  label nBndEdges = patch_.nEdges() - patch_.nInternalEdges();
106  DynamicList<label> initialEdges(2*nBndEdges);
107  DynamicList<patchEdgeFacePoint> initialEdgesInfo(2*nBndEdges);
108 
109 
110  // Seed all my edges that are also nbrEdges
111 
112  const labelList& mp = patch_.meshPoints();
113 
114  for
115  (
116  label edgei = patch_.nInternalEdges();
117  edgei < patch_.nEdges();
118  edgei++
119  )
120  {
121  const edge& e = patch_.edges()[edgei];
122  const edge meshE = edge(mp[e[0]], mp[e[1]]);
123  EdgeMap<label>::const_iterator edgeFnd = nbrEdges.find(meshE);
124  if (edgeFnd != nbrEdges.end())
125  {
126  initialEdges.append(edgei);
127  initialEdgesInfo.append
128  (
130  (
131  e.centre(patch_.localPoints()),
132  0.0
133  )
134  );
135  }
136  }
137 
138 
139  // Walk
141  (
142  patch_.boundaryMesh().mesh(),
143  patch_,
144  initialEdges,
145  initialEdgesInfo,
146  allEdgeInfo,
147  allFaceInfo,
148  returnReduce(patch_.nEdges(), sumOp<label>())
149  );
150 
151 
152  // Extract into *this
153  setSize(patch_.size());
154  nUnset_ = 0;
155  forAll(allFaceInfo, facei)
156  {
157  if (allFaceInfo[facei].valid(calc.data()))
158  {
159  operator[](facei) = Foam::sqrt(allFaceInfo[facei].distSqr());
160  }
161  else
162  {
163  nUnset_++;
164  }
165  }
166 }
167 
168 
169 // ************************************************************************* //
#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
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:167
Wave propagation of information along patch. Every iteration information goes through one layer of fa...
const TrackingData & data() const
Additional data to be passed into container.
label nEdges() const
Return number of edges in patch.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
label nInternalEdges() const
Number of internal edges.
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
Transport of nearest point location for use in PatchEdgeFaceWave.
virtual void correct()
Correct for mesh geom/topo changes.
virtual ~patchPatchDist()
Destructor.
patchPatchDist(const polyPatch &pp, const labelHashSet &nbrPatchIDs)
Construct from patch and neighbour patches.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:270
static void syncEdgeMap(const polyMesh &, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronise values on selected edges.
bool valid(const PtrList< ModelType > &l)
const dimensionedScalar mp
Proton mass.
const doubleScalar e
Definition: doubleScalar.H:106
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
dimensionedScalar sqrt(const dimensionedScalar &ds)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
points setSize(newPointi)
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112