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-2018 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  // Algorithm:
46  // Go through all the faces of the cell and find the one which
47  // does not share a single vertex with the master face. If there
48  // are two or more such faces, return the first one and issue a
49  // warning; if there is no opposite face, return -1;
50 
51  const face& masterFace = meshFaces[masterFaceLabel];
52 
53  const labelList& curFaceLabels = *this;
54 
55  label oppositeFaceLabel = -1;
56 
57  forAll(curFaceLabels, facei)
58  {
59  // Compare the face with the master
60  const face& curFace = meshFaces[curFaceLabels[facei]];
61 
62  // Skip the master face
63  if
64  (
65  curFaceLabels[facei] != masterFaceLabel
66  && curFace.size() == masterFace.size()
67  )
68  {
69  bool sharedPoint = false;
70 
71  // Compare every vertex of the current face against the
72  // vertices of the master face
73  forAll(curFace, pointi)
74  {
75  const label l = curFace[pointi];
76 
77  forAll(masterFace, masterPointi)
78  {
79  if (masterFace[masterPointi] == l)
80  {
81  sharedPoint = true;
82  break;
83  }
84  }
85 
86  if (sharedPoint) break;
87  }
88 
89  // If no points are shared, this is the opposite face
90  if (!sharedPoint)
91  {
92  if (oppositeFaceLabel == -1)
93  {
94  // Found opposite face
95  oppositeFaceLabel = curFaceLabels[facei];
96  }
97  else
98  {
99  // There has already been an opposite face.
100  // Non-prismatic cell
101  Info<< "Multiple faces not sharing vertex: "
102  << oppositeFaceLabel << " and "
103  << curFaceLabels[facei] << endl;
104  return -1;
105  }
106  }
107  }
108  }
109 
110  return oppositeFaceLabel;
111 }
112 
113 
115 (
116  const label masterFaceLabel,
117  const faceUList& meshFaces
118 ) const
119 {
120  // Get the label of the opposite face
121  label oppFaceLabel = opposingFaceLabel(masterFaceLabel, meshFaces);
122 
123  // If the opposing face is not found, return a failure
124  if (oppFaceLabel < 0)
125  {
126  return oppositeFace(face(0), masterFaceLabel, oppFaceLabel);
127  }
128  else
129  {
130  // This is a prismatic cell. Go through all the vertices of the master
131  // face and find an edge going from the master face vertex to a slave
132  // face vertex. If all is OK, there should be only one such
133  // edge for every master vertex and will provide te
134  // master-to-slave vertex mapping. Assemble the opposite face
135  // in the same manner as the master.
136 
137  // Get reference to faces and prepare the return
138  const face& masterFace = meshFaces[masterFaceLabel];
139  const face& slaveFace = meshFaces[oppFaceLabel];
140 
141  // Get cell edges
142  const edgeList e = edges(meshFaces);
143  boolList usedEdges(e.size(), false);
144 
145  oppositeFace oppFace
146  (
147  face(masterFace.size()),
148  masterFaceLabel,
149  oppFaceLabel
150  );
151 
152  forAll(masterFace, pointi)
153  {
154  // Go through the list of edges and find the edge from this vertex
155  // to the slave face
156  forAll(e, edgeI)
157  {
158  if (!usedEdges[edgeI])
159  {
160  // Get the other vertex
161  label otherVertex =
162  e[edgeI].otherVertex(masterFace[pointi]);
163 
164  if (otherVertex != -1)
165  {
166  // Found an edge coming from this vertex.
167  // Check all vertices of the slave to find out
168  // if it exists.
169  forAll(slaveFace, slavePointi)
170  {
171  if (slaveFace[slavePointi] == otherVertex)
172  {
173  usedEdges[edgeI] = true;
174  oppFace[pointi] = otherVertex;
175 
176  break;
177  }
178  }
179  }
180  }
181  }
182  }
183 
184  return oppFace;
185  }
186 }
187 
188 
189 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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.
messageStream Info
const dimensionedScalar e
Elementary charge.
Definition: doubleScalar.H:105