primitiveMeshEdgeFaces.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-2015 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "primitiveMesh.H"
30 #include "ListOps.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
35 {
36  if (!efPtr_)
37  {
38  if (debug)
39  {
40  Pout<< "primitiveMesh::edgeFaces() : calculating edgeFaces" << endl;
41 
42  if (debug == -1)
43  {
44  // For checking calls:abort so we can quickly hunt down
45  // origin of call
47  << abort(FatalError);
48  }
49  }
50 
51  // Invert faceEdges
52  efPtr_ = new labelListList(nEdges());
53  invertManyToMany(nEdges(), faceEdges(), *efPtr_);
54  }
55 
56  return *efPtr_;
57 }
58 
59 
61 (
62  const label edgeI,
63  DynamicList<label>& storage
64 ) const
65 {
66  if (hasEdgeFaces())
67  {
68  return edgeFaces()[edgeI];
69  }
70  else
71  {
72  // Use the fact that pointFaces are sorted in incrementing edge order
73  // (since they get constructed by inverting the faces which walks
74  // in increasing face order)
75  const edge& e = edges()[edgeI];
76  const labelList& pFaces0 = pointFaces()[e[0]];
77  const labelList& pFaces1 = pointFaces()[e[1]];
78 
79  label i0 = 0;
80  label i1 = 0;
81 
82  storage.clear();
83 
84  while (i0 < pFaces0.size() && i1 < pFaces1.size())
85  {
86  const label f0 = pFaces0[i0];
87  const label f1 = pFaces1[i1];
88 
89  if (f0 < f1)
90  {
91  ++i0;
92  }
93  else if (f0 > f1)
94  {
95  ++i1;
96  }
97  else
98  {
99  // Equal face. Check if indeed on consecutive vertices on both
100  // faces since it could be that there is an 'ear' where one
101  // side is a triangle and the other side is part of a bigger
102  // face (e.g. quad). Now all vertex-vertex pairs on the
103  // triangle are edges but there is no cross connection on the
104  // bigger face.
105  const face& f = faces()[f0];
106  const label fp0 = f.find(e[0]);
107 
108  if (f[f.fcIndex(fp0)] == e[1] || f[f.rcIndex(fp0)] == e[1])
109  {
110  storage.append(f0);
111  ++i0;
112  ++i1;
113  }
114  else
115  {
116  ++i1;
117  }
118  }
119  }
120 
121  return storage;
122  }
123 }
124 
125 
126 const Foam::labelList& Foam::primitiveMesh::edgeFaces(const label edgeI) const
127 {
128  return edgeFaces(edgeI, labels_);
129 }
130 
131 
132 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::DynamicList< label >
Foam::primitiveMesh::edgeFaces
const labelListList & edgeFaces() const
Definition: primitiveMeshEdgeFaces.C:34
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::primitiveMesh::nEdges
label nEdges() const
Number of mesh edges.
Definition: primitiveMeshI.H:67
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::DynamicList::clear
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
Foam::invertManyToMany
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
Definition: ListOpsTemplates.C:720
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::primitiveMesh::faceEdges
const labelListList & faceEdges() const
Definition: primitiveMeshEdges.C:528
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
f
labelList f(nPoints)
Foam::List< labelList >
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
ListOps.H
Various functions to operate on Lists.