FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
25 
26 #include "primitiveMesh.H"
27 #include <OpenFOAM/ListOps.H>
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
32 {
33  if (!efPtr_)
34  {
35  if (debug)
36  {
37  Pout<< "primitiveMesh::edgeFaces() : calculating edgeFaces" << endl;
38 
39  if (debug == -1)
40  {
41  // For checking calls:abort so we can quickly hunt down
42  // origin of call
43  FatalErrorIn("primitiveMesh::edgeFaces()")
44  << abort(FatalError);
45  }
46  }
47 
48  // Invert faceEdges
49  efPtr_ = new labelListList(nEdges());
50  invertManyToMany(nEdges(), faceEdges(), *efPtr_);
51  }
52 
53  return *efPtr_;
54 }
55 
56 
58 (
59  const label edgeI,
60  DynamicList<label>& storage
61 ) const
62 {
63  if (hasEdgeFaces())
64  {
65  return edgeFaces()[edgeI];
66  }
67  else
68  {
69  // Use the fact that pointEdges are sorted in incrementing edge order
70  const edge& e = edges()[edgeI];
71  const labelList& pFaces0 = pointFaces()[e[0]];
72  const labelList& pFaces1 = pointFaces()[e[1]];
73 
74  label i0 = 0;
75  label i1 = 0;
76 
77  storage.clear();
78 
79  while (i0 < pFaces0.size() && i1 < pFaces1.size())
80  {
81  if (pFaces0[i0] < pFaces1[i1])
82  {
83  ++i0;
84  }
85  else if (pFaces0[i0] > pFaces1[i1])
86  {
87  ++i1;
88  }
89  else
90  {
91  // Equal. Append.
92  storage.append(pFaces0[i0]);
93  ++i0;
94  ++i1;
95  }
96  }
97 
98  return storage;
99  }
100 }
101 
102 
103 const Foam::labelList& Foam::primitiveMesh::edgeFaces(const label edgeI) const
104 {
105  return edgeFaces(edgeI, labels_);
106 }
107 
108 
109 // ************************ vim: set sw=4 sts=4 et: ************************ //