PrimitivePatchMeshEdges.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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "PrimitivePatch.H"
29 
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template
34 <
35  class Face,
36  template<class> class FaceList,
37  class PointField,
38  class PointType
39 >
43 (
44  const edgeList& allEdges,
45  const labelListList& cellEdges,
46  const labelList& faceCells
47 ) const
48 {
49  if (debug)
50  {
51  Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
52  << "::meshEdges() : "
53  << "calculating labels of patch edges in mesh edge list"
54  << endl;
55  }
56 
57  // get reference to the list of edges on the patch
58  const edgeList& PatchEdges = edges();
59 
60  const labelListList& EdgeFaces = edgeFaces();
61 
62  // create the storage
63  labelList meshEdges(PatchEdges.size());
64 
65  bool found = false;
66 
67  // get reference to the points on the patch
68  const labelList& pp = meshPoints();
69 
70  // WARNING: Remember that local edges address into local point list;
71  // local-to-global point label translation is necessary
72  forAll(PatchEdges, edgeI)
73  {
74  const edge curEdge
75  (pp[PatchEdges[edgeI].start()], pp[PatchEdges[edgeI].end()]);
76 
77  found = false;
78 
79  // get the patch faces sharing the edge
80  const labelList& curFaces = EdgeFaces[edgeI];
81 
82  forAll(curFaces, facei)
83  {
84  // get the cell next to the face
85  label curCell = faceCells[curFaces[facei]];
86 
87  // get reference to edges on the cell
88  const labelList& ce = cellEdges[curCell];
89 
90  forAll(ce, cellEdgeI)
91  {
92  if (allEdges[ce[cellEdgeI]] == curEdge)
93  {
94  found = true;
95 
96  meshEdges[edgeI] = ce[cellEdgeI];
97 
98  break;
99  }
100  }
101 
102  if (found) break;
103  }
104  }
105 
106  return meshEdges;
107 }
108 
109 
110 template
111 <
112  class Face,
113  template<class> class FaceList,
114  class PointField,
115  class PointType
116 >
119 meshEdges
120 (
121  const edgeList& allEdges,
122  const labelListList& pointEdges
123 ) const
124 {
125  if (debug)
126  {
127  Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
128  << "::meshEdges() : "
129  << "calculating labels of patch edges in mesh edge list"
130  << endl;
131  }
132 
133  // get reference to the list of edges on the patch
134  const edgeList& PatchEdges = edges();
135 
136  // create the storage
137  labelList meshEdges(PatchEdges.size());
138 
139  // get reference to the points on the patch
140  const labelList& pp = meshPoints();
141 
142  // WARNING: Remember that local edges address into local point list;
143  // local-to-global point label translation is necessary
144  forAll(PatchEdges, edgeI)
145  {
146  const label globalPointi = pp[PatchEdges[edgeI].start()];
147  const edge curEdge(globalPointi, pp[PatchEdges[edgeI].end()]);
148 
149  const labelList& pe = pointEdges[globalPointi];
150 
151  forAll(pe, i)
152  {
153  if (allEdges[pe[i]] == curEdge)
154  {
155  meshEdges[edgeI] = pe[i];
156  break;
157  }
158  }
159  }
160 
161  return meshEdges;
162 }
163 
164 
165 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
166 
167 template
168 <
169  class Face,
170  template<class> class FaceList,
171  class PointField,
172  class PointType
173 >
176 whichEdge
177 (
178  const edge& e
179 ) const
180 {
181  // Get pointEdges from the starting point and search all the candidates
182  const edgeList& Edges = edges();
183 
184  if (e.start() > -1 && e.start() < nPoints())
185  {
186  const labelList& pe = pointEdges()[e.start()];
187 
188  forAll(pe, peI)
189  {
190  if (e == Edges[pe[peI]])
191  {
192  return pe[peI];
193  }
194  }
195  }
196 
197  // Edge not found. Return -1
198  return -1;
199 }
200 
201 
202 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::PrimitivePatch::meshEdges
labelList meshEdges(const edgeList &allEdges, const labelListList &cellEdges, const labelList &faceCells) const
Definition: PrimitivePatchMeshEdges.C:43
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::label
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:62
PrimitivePatch.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:115
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::List< label >
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::PrimitivePatch::whichEdge
label whichEdge(const edge &) const
Definition: PrimitivePatchMeshEdges.C:177
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56