oppositeCellFace.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 Description
27  Given the cell and a face label, return the opposite face label
28  and the face oriented in the same sense as the original face.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "cell.H"
33 #include "oppositeFace.H"
34 #include "bitSet.H"
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
39 (
40  const label masterFaceLabel,
41  const faceUList& meshFaces
42 ) const
43 {
44  // Algorithm:
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. If there
47  // are two or more such faces, return the first one and issue a
48  // warning; if there is no opposite face, return -1;
49 
50  const face& masterFace = meshFaces[masterFaceLabel];
51 
52  label oppositeFaceLabel = -1;
53 
54  for (const label facei : *this)
55  {
56  // Compare the face with the master
57  const face& f = meshFaces[facei];
58 
59  // Skip the master face
60  if
61  (
62  facei != masterFaceLabel
63  && f.size() == masterFace.size()
64  && !f.connected(masterFace)
65  )
66  {
67  // Not connected : this is an opposite face
68  if (oppositeFaceLabel == -1)
69  {
70  // Not previously found
71  oppositeFaceLabel = facei;
72  }
73  else
74  {
75  // There has already been an opposite face.
76  // Non-prismatic cell
77  Info<< "Multiple faces not sharing vertex: "
78  << oppositeFaceLabel << " and "
79  << facei << endl;
80  return -1;
81  }
82  }
83  }
84 
85  return oppositeFaceLabel;
86 }
87 
88 
90 (
91  const label masterFaceLabel,
92  const faceUList& meshFaces
93 ) const
94 {
95  // Get the label of the opposite face
96  label oppFaceLabel = opposingFaceLabel(masterFaceLabel, meshFaces);
97 
98  // If the opposing face is not found, return a failure
99  if (oppFaceLabel < 0)
100  {
101  return oppositeFace(face(0), masterFaceLabel, oppFaceLabel);
102  }
103 
104  // This is a prismatic cell. Go through all the vertices of the master
105  // face and find an edge going from the master face vertex to a slave
106  // face vertex. If all is OK, there should be only one such
107  // edge for every master vertex and will provide the
108  // master-to-slave vertex mapping. Assemble the opposite face
109  // in the same manner as the master.
110 
111  // Get reference to faces and prepare the return
112  const face& masterFace = meshFaces[masterFaceLabel];
113  const face& slaveFace = meshFaces[oppFaceLabel];
114 
115  // Get cell edges
116  const edgeList e = edges(meshFaces);
117  bitSet usedEdges(e.size());
118 
119  oppositeFace oppFace
120  (
121  face(masterFace.size()),
122  masterFaceLabel,
123  oppFaceLabel
124  );
125 
126  forAll(masterFace, pointi)
127  {
128  // Go through the list of edges and find the edge from this vertex
129  // to the slave face
130  forAll(e, edgeI)
131  {
132  if (!usedEdges.test(edgeI))
133  {
134  // Get the other vertex
135  label otherVertex = e[edgeI].otherVertex(masterFace[pointi]);
136 
137  if (otherVertex != -1)
138  {
139  // Found an edge coming from this vertex.
140  // Check all vertices of the slave to find out
141  // if it exists.
142  forAll(slaveFace, slavePointi)
143  {
144  if (slaveFace[slavePointi] == otherVertex)
145  {
146  usedEdges.set(edgeI);
147  oppFace[pointi] = otherVertex;
148 
149  break;
150  }
151  }
152  }
153  }
154  }
155  }
156 
157  return oppFace;
158 }
159 
160 
161 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
Class containing opposite face for a prismatic cell with addressing and a possibility of failure...
Definition: oppositeFace.H:42
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
List< edge > edgeList
List of edge.
Definition: edgeList.H:32
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
oppositeFace opposingFace(const label masterFaceLabel, const faceUList &meshFaces) const
Return opposite face oriented the same way as the master face.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
label opposingFaceLabel(const label masterFaceLabel, const faceUList &meshFaces) const
Return index of opposite face.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
labelList f(nPoints)
messageStream Info
Information stream (stdout output on master, null elsewhere)