primitiveMeshEdgeCells.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 "ListOps.H"
28 
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
33 {
34  if (!ecPtr_)
35  {
36  if (debug)
37  {
38  Pout<< "primitiveMesh::edgeCells() : calculating edgeCells" << endl;
39 
40  if (debug == -1)
41  {
42  // For checking calls:abort so we can quickly hunt down
43  // origin of call
45  << abort(FatalError);
46  }
47  }
48  // Invert cellEdges
49  ecPtr_ = new labelListList(nEdges());
50  invertManyToMany(nEdges(), cellEdges(), *ecPtr_);
51  }
52 
53  return *ecPtr_;
54 }
55 
56 
58 (
59  const label edgeI,
60  DynamicList<label>& storage
61 ) const
62 {
63  if (hasEdgeCells())
64  {
65  return edgeCells()[edgeI];
66  }
67  else
68  {
69  const labelList& own = faceOwner();
70  const labelList& nei = faceNeighbour();
71 
72  // Construct edgeFaces
73  DynamicList<label> eFacesStorage;
74  const labelList& eFaces = edgeFaces(edgeI, eFacesStorage);
75 
76  storage.clear();
77 
78  // Do quadratic insertion.
79  forAll(eFaces, i)
80  {
81  label facei = eFaces[i];
82 
83  {
84  label ownCelli = own[facei];
85 
86  // Check if not already in storage
87  forAll(storage, j)
88  {
89  if (storage[j] == ownCelli)
90  {
91  ownCelli = -1;
92  break;
93  }
94  }
95 
96  if (ownCelli != -1)
97  {
98  storage.append(ownCelli);
99  }
100  }
101 
102  if (isInternalFace(facei))
103  {
104  label neiCelli = nei[facei];
105 
106  forAll(storage, j)
107  {
108  if (storage[j] == neiCelli)
109  {
110  neiCelli = -1;
111  break;
112  }
113  }
114 
115  if (neiCelli != -1)
116  {
117  storage.append(neiCelli);
118  }
119  }
120  }
121 
122  return storage;
123  }
124 }
125 
126 
128 {
129  return edgeCells(edgeI, labels_);
130 }
131 
132 
133 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
const labelListList & cellEdges() const
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Various functions to operate on Lists.
const labelListList & edgeCells() const
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
label nEdges() const
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
bool hasEdgeCells() const
void invertManyToMany(const label len, const UList< InList > &, List< OutList > &)
Invert many-to-many.
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:236
const labelListList & edgeFaces() const