primitiveMeshCellEdges.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-2016 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 "DynamicList.H"
28 #include "ListOps.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::primitiveMesh::calcCellEdges() const
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
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  {
57  << "cellEdges already calculated"
58  << abort(FatalError);
59  }
60  else
61  {
62  // Set up temporary storage
63  List<DynamicList<label, edgesPerCell_>> ce(nCells());
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 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:253
label nCells() const
Various functions to operate on Lists.
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53
const labelListList & cellEdges() const
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
virtual const labelList & faceOwner() const =0
Face face-owner addresing.
const labelListList & faceEdges() const