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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "primitiveMesh.H"
29 #include "ListOps.H"
30 
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
35 {
36  if (!ecPtr_)
37  {
38  if (debug)
39  {
40  Pout<< "primitiveMesh::edgeCells() : calculating edgeCells" << 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  // Invert cellEdges
51  ecPtr_ = new labelListList(nEdges());
52  invertManyToMany(nEdges(), cellEdges(), *ecPtr_);
53  }
54 
55  return *ecPtr_;
56 }
57 
58 
60 (
61  const label edgeI,
62  DynamicList<label>& storage
63 ) const
64 {
65  if (hasEdgeCells())
66  {
67  return edgeCells()[edgeI];
68  }
69  else
70  {
71  const labelList& own = faceOwner();
72  const labelList& nei = faceNeighbour();
73 
74  // Construct edgeFaces
75  DynamicList<label> eFacesStorage;
76  const labelList& eFaces = edgeFaces(edgeI, eFacesStorage);
77 
78  storage.clear();
79 
80  // Do quadratic insertion.
81  forAll(eFaces, i)
82  {
83  label facei = eFaces[i];
84 
85  {
86  label ownCelli = own[facei];
87 
88  // Check if not already in storage
89  forAll(storage, j)
90  {
91  if (storage[j] == ownCelli)
92  {
93  ownCelli = -1;
94  break;
95  }
96  }
97 
98  if (ownCelli != -1)
99  {
100  storage.append(ownCelli);
101  }
102  }
103 
104  if (isInternalFace(facei))
105  {
106  label neiCelli = nei[facei];
107 
108  forAll(storage, j)
109  {
110  if (storage[j] == neiCelli)
111  {
112  neiCelli = -1;
113  break;
114  }
115  }
116 
117  if (neiCelli != -1)
118  {
119  storage.append(neiCelli);
120  }
121  }
122  }
123 
124  return storage;
125  }
126 }
127 
128 
129 const Foam::labelList& Foam::primitiveMesh::edgeCells(const label edgeI) const
130 {
131  return edgeCells(edgeI, labels_);
132 }
133 
134 
135 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::DynamicList< label >
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
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::invertManyToMany
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
Definition: ListOpsTemplates.C:720
Foam::primitiveMesh::cellEdges
const labelListList & cellEdges() const
Definition: primitiveMeshCellEdges.C:115
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::edgeCells
const labelListList & edgeCells() const
Definition: primitiveMeshEdgeCells.C:34
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
Foam::List< labelList >
ListOps.H
Various functions to operate on Lists.