primitiveMeshEdgeCells.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) 2011 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
44  FatalErrorIn("primitiveMesh::edgeCells()")
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 // ************************************************************************* //
void invertManyToMany(const label len, const UList< InList > &, List< OutList > &)
Invert many-to-many.
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:242
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
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:310
Various functions to operate on Lists.
label nEdges() const
const labelListList & cellEdges() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
bool hasEdgeCells() const
const labelListList & edgeFaces() const
const labelListList & edgeCells() const
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
virtual const labelList & faceOwner() const =0
Face face-owner addresing.
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.