oppositeCellFace.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 Description
25  Given the cell and a face label, return the opposite face label
26  and the face oriented in the same sense as the original face.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "cell.H"
31 #include "oppositeFace.H"
32 #include "boolList.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 
37 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 
40 (
41  const label masterFaceLabel,
42  const faceUList& meshFaces
43 ) const
44 {
45  // Go through all the faces of the cell and find the one which
46  // does not share a single vertex with the master face
47  //
48  // If there are no such faces (e.g., a tetrahedron), return -1
49  //
50  // If there are more than one such faces (e.g., a hex with split faces),
51  // return -2
52 
53  const face& masterFace = meshFaces[masterFaceLabel];
54 
55  const labelList& curFaceLabels = *this;
56 
57  label oppositeFaceLabel = -1;
58 
59  forAll(curFaceLabels, facei)
60  {
61  // Compare the face with the master
62  const face& curFace = meshFaces[curFaceLabels[facei]];
63 
64  // Skip the master face
65  if
66  (
67  curFaceLabels[facei] != masterFaceLabel
68  && curFace.size() == masterFace.size()
69  )
70  {
71  bool sharedPoint = false;
72 
73  // Compare every vertex of the current face against the
74  // vertices of the master face
75  forAll(curFace, pointi)
76  {
77  const label l = curFace[pointi];
78 
79  forAll(masterFace, masterPointi)
80  {
81  if (masterFace[masterPointi] == l)
82  {
83  sharedPoint = true;
84  break;
85  }
86  }
87 
88  if (sharedPoint) break;
89  }
90 
91  // If no points are shared, this is the opposite face
92  if (!sharedPoint)
93  {
94  if (oppositeFaceLabel == -1)
95  {
96  // Found opposite face
97  oppositeFaceLabel = curFaceLabels[facei];
98  }
99  else
100  {
101  // There has already been a face with no shared points.
102  // This cell is not prismatic.
103  return -2;
104  }
105  }
106  }
107  }
108 
109  return oppositeFaceLabel;
110 }
111 
112 
114 (
115  const label masterFaceLabel,
116  const faceUList& meshFaces
117 ) const
118 {
119  // Get the label of the opposite face
120  label oppFaceLabel = opposingFaceLabel(masterFaceLabel, meshFaces);
121 
122  // If the opposing face is not found, return a failure
123  if (oppFaceLabel < 0)
124  {
125  return oppositeFace(face(0), masterFaceLabel, oppFaceLabel);
126  }
127  else
128  {
129  // This is a prismatic cell. Go through all the vertices of the master
130  // face and find an edge going from the master face vertex to a slave
131  // face vertex. If all is OK, there should be only one such
132  // edge for every master vertex and will provide te
133  // master-to-slave vertex mapping. Assemble the opposite face
134  // in the same manner as the master.
135 
136  // Get reference to faces and prepare the return
137  const face& masterFace = meshFaces[masterFaceLabel];
138  const face& slaveFace = meshFaces[oppFaceLabel];
139 
140  // Get cell edges
141  const edgeList e = edges(meshFaces);
142  boolList usedEdges(e.size(), false);
143 
144  oppositeFace oppFace
145  (
146  face(masterFace.size()),
147  masterFaceLabel,
148  oppFaceLabel
149  );
150 
151  forAll(masterFace, pointi)
152  {
153  // Go through the list of edges and find the edge from this vertex
154  // to the slave face
155  forAll(e, edgeI)
156  {
157  if (!usedEdges[edgeI])
158  {
159  // Get the other vertex
160  label otherVertex =
161  e[edgeI].otherVertex(masterFace[pointi]);
162 
163  if (otherVertex != -1)
164  {
165  // Found an edge coming from this vertex.
166  // Check all vertices of the slave to find out
167  // if it exists.
168  forAll(slaveFace, slavePointi)
169  {
170  if (slaveFace[slavePointi] == otherVertex)
171  {
172  usedEdges[edgeI] = true;
173  oppFace[pointi] = otherVertex;
174 
175  break;
176  }
177  }
178  }
179  }
180  }
181  }
182 
183  return oppFace;
184  }
185 }
186 
187 
188 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Class containing opposite face for a prismatic cell with addressing and a possibility of failure...
Definition: oppositeFace.H:49
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
oppositeFace opposingFace(const label masterFaceLabel, const faceUList &meshFaces) const
Return opposite face oriented the same way as the master face.
label opposingFaceLabel(const label masterFaceLabel, const faceUList &meshFaces) const
Return index of opposite face.
const dimensionedScalar e
Elementary charge.
Definition: doubleScalar.H:105