primitiveMeshCellEdges.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation, either version 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "primitiveMesh.H"
27 #include "DynamicList.H"
28 #include "ListOps.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
33 {
34  // Loop through all faces and mark up cells with edges of the face.
35  // Check for duplicates
36 
37  if (debug)
38  {
39  Pout<< "primitiveMesh::calcCellEdges() : "
40  << "calculating cellEdges"
41  << endl;
42 
43  if (debug == -1)
44  {
45  // For checking calls:abort so we can quickly hunt down
46  // origin of call
47  FatalErrorIn("primitiveMesh::calcCellEdges()")
48  << abort(FatalError);
49  }
50  }
51 
52  // It is an error to attempt to recalculate cellEdges
53  // if the pointer is already set
54  if (cePtr_)
55  {
56  FatalErrorIn("primitiveMesh::calcCellEdges() const")
57  << "cellEdges already calculated"
58  << abort(FatalError);
59  }
60  else
61  {
62  // Set up temporary storage
64 
65 
66  // Get reference to faceCells and faceEdges
67  const labelList& own = faceOwner();
68  const labelList& nei = faceNeighbour();
69  const labelListList& fe = faceEdges();
70 
71  // loop through the list again and add edges; checking for duplicates
72  forAll (own, faceI)
73  {
74  DynamicList<label, edgesPerCell_>& curCellEdges = ce[own[faceI]];
75 
76  const labelList& curEdges = fe[faceI];
77 
78  forAll (curEdges, edgeI)
79  {
80  if (findIndex(curCellEdges, curEdges[edgeI]) == -1)
81  {
82  // Add the edge
83  curCellEdges.append(curEdges[edgeI]);
84  }
85  }
86  }
87 
88  forAll (nei, faceI)
89  {
90  DynamicList<label, edgesPerCell_>& curCellEdges = ce[nei[faceI]];
91 
92  const labelList& curEdges = fe[faceI];
93 
94  forAll (curEdges, edgeI)
95  {
96  if (findIndex(curCellEdges, curEdges[edgeI]) == -1)
97  {
98  // add the edge
99  curCellEdges.append(curEdges[edgeI]);
100  }
101  }
102  }
103 
104  cePtr_ = new labelListList(ce.size());
105  labelListList& cellEdgeAddr = *cePtr_;
106 
107  // reset the size
108  forAll (ce, cellI)
109  {
110  cellEdgeAddr[cellI].transfer(ce[cellI]);
111  }
112  }
113 }
114 
115 
116 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117 
119 {
120  if (!cePtr_)
121  {
122  calcCellEdges();
123  }
124 
125  return *cePtr_;
126 }
127 
128 
129 // ************************************************************************* //
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::findIndex
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::primitiveMesh::faceOwner
virtual const labelList & faceOwner() const =0
Face face-owner addresing.
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::primitiveMesh::faceNeighbour
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
Foam::primitiveMesh::calcCellEdges
void calcCellEdges() const
Calculate edge list.
Definition: primitiveMeshCellEdges.C:32
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
Foam::primitiveMesh::cellEdges
const labelListList & cellEdges() const
Definition: primitiveMeshCellEdges.C:118
primitiveMesh.H
Foam::primitiveMesh::faceEdges
const labelListList & faceEdges() const
Definition: primitiveMeshEdges.C:366
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::primitiveMesh::cePtr_
labelListList * cePtr_
Cell-edges.
Definition: primitiveMesh.H:134
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
DynamicList.H
ListOps.H
Various functions to operate on Lists.
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.