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  const labelList& curFaceLabels = *this;
53 
54  label oppositeFaceLabel = -1;
55 
56  forAll(curFaceLabels, facei)
57  {
58  // Compare the face with the master
59  const face& curFace = meshFaces[curFaceLabels[facei]];
60 
61  // Skip the master face
62  if
63  (
64  curFaceLabels[facei] != masterFaceLabel
65  && curFace.size() == masterFace.size()
66  )
67  {
68  bool sharedPoint = false;
69 
70  // Compare every vertex of the current face against the
71  // vertices of the master face
72  forAll(curFace, pointi)
73  {
74  const label l = curFace[pointi];
75 
76  forAll(masterFace, masterPointi)
77  {
78  if (masterFace[masterPointi] == l)
79  {
80  sharedPoint = true;
81  break;
82  }
83  }
84 
85  if (sharedPoint) break;
86  }
87 
88  // If no points are shared, this is the opposite face
89  if (!sharedPoint)
90  {
91  if (oppositeFaceLabel == -1)
92  {
93  // Found opposite face
94  oppositeFaceLabel = curFaceLabels[facei];
95  }
96  else
97  {
98  // There has already been an opposite face.
99  // Non-prismatic cell
100  Info<< "Multiple faces not sharing vertex: "
101  << oppositeFaceLabel << " and "
102  << curFaceLabels[facei] << endl;
103  return -1;
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 
128  // This is a prismatic cell. Go through all the vertices of the master
129  // face and find an edge going from the master face vertex to a slave
130  // face vertex. If all is OK, there should be only one such
131  // edge for every master vertex and will provide the
132  // master-to-slave vertex mapping. Assemble the opposite face
133  // in the same manner as the master.
134 
135  // Get reference to faces and prepare the return
136  const face& masterFace = meshFaces[masterFaceLabel];
137  const face& slaveFace = meshFaces[oppFaceLabel];
138 
139  // Get cell edges
140  const edgeList e = edges(meshFaces);
141  bitSet usedEdges(e.size());
142 
143  oppositeFace oppFace
144  (
145  face(masterFace.size()),
146  masterFaceLabel,
147  oppFaceLabel
148  );
149 
150  forAll(masterFace, pointi)
151  {
152  // Go through the list of edges and find the edge from this vertex
153  // to the slave face
154  forAll(e, edgeI)
155  {
156  if (!usedEdges.test(edgeI))
157  {
158  // Get the other vertex
159  label otherVertex = e[edgeI].otherVertex(masterFace[pointi]);
160 
161  if (otherVertex != -1)
162  {
163  // Found an edge coming from this vertex.
164  // Check all vertices of the slave to find out
165  // if it exists.
166  forAll(slaveFace, slavePointi)
167  {
168  if (slaveFace[slavePointi] == otherVertex)
169  {
170  usedEdges.set(edgeI);
171  oppFace[pointi] = otherVertex;
172 
173  break;
174  }
175  }
176  }
177  }
178  }
179  }
180 
181  return oppFace;
182 }
183 
184 
185 // ************************************************************************* //
cell.H
oppositeFace.H
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::oppositeFace
Class containing opposite face for a prismatic cell with addressing and a possibility of failure.
Definition: oppositeFace.H:51
bitSet.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::cell::opposingFace
oppositeFace opposingFace(const label masterFaceLabel, const faceUList &meshFaces) const
Return opposite face oriented the same way as the master face.
Definition: oppositeCellFace.C:114
Foam::cell::opposingFaceLabel
label opposingFaceLabel(const label masterFaceLabel, const faceUList &meshFaces) const
Return index of opposite face.
Definition: oppositeCellFace.C:39
Foam::List< label >
Foam::UList< face >
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72