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 // ************************************************************************* //
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
const labelListList & faceEdges() const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
Various functions to operate on Lists.
label fcIndex(const label i) const noexcept
The forward circular index. The next index in the list which returns to the first at the end of the l...
Definition: UListI.H:97
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
errorManip< error > abort(error &err)
Definition: errorManip.H:139
label nEdges() const
Number of mesh edges.
label find(const T &val) const
Find index of the first occurrence of the value.
Definition: UList.C:173
int debug
Static debugging option.
labelList f(nPoints)
List< label > labelList
A List of labels.
Definition: List.H:62
label rcIndex(const label i) const noexcept
The reverse circular index. The previous index in the list which returns to the last at the beginning...
Definition: UListI.H:104
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
const labelListList & edgeFaces() const