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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "primitiveMesh.H"
30#include "DynamicList.H"
31#include "ListOps.H"
32
33// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34
35void Foam::primitiveMesh::calcCellEdges() const
36{
37 // Loop through all faces and mark up cells with edges of the face.
38 // Check for duplicates
39
40 if (debug)
41 {
42 Pout<< "primitiveMesh::calcCellEdges() : "
43 << "calculating cellEdges"
44 << endl;
45
46 if (debug == -1)
47 {
48 // For checking calls:abort so we can quickly hunt down
49 // origin of call
51 << abort(FatalError);
52 }
53 }
54
55 // It is an error to attempt to recalculate cellEdges
56 // if the pointer is already set
57 if (cePtr_)
58 {
60 << "cellEdges already calculated"
61 << abort(FatalError);
62 }
63 else
64 {
65 // Set up temporary storage
66 List<DynamicList<label>> ce(nCells());
67
68
69 // Get reference to faceCells and faceEdges
70 const labelList& own = faceOwner();
71 const labelList& nei = faceNeighbour();
72 const labelListList& fe = faceEdges();
73
74 // loop through the list again and add edges; checking for duplicates
75 forAll(own, facei)
76 {
77 DynamicList<label>& curCellEdges = ce[own[facei]];
78
79 const labelList& curEdges = fe[facei];
80
81 for (const label edgei : curEdges)
82 {
83 // Add the edge
84 curCellEdges.appendUniq(edgei);
85 }
86 }
87
88 forAll(nei, facei)
89 {
90 DynamicList<label>& curCellEdges = ce[nei[facei]];
91
92 const labelList& curEdges = fe[facei];
93
94 for (const label edgei : curEdges)
95 {
96 // Add the edge
97 curCellEdges.appendUniq(edgei);
98 }
99 }
100
101 cePtr_ = new labelListList(ce.size());
102 labelListList& cellEdgeAddr = *cePtr_;
103
104 // reset the size
105 forAll(ce, celli)
106 {
107 cellEdgeAddr[celli].transfer(ce[celli]);
108 }
109 }
110}
111
112
113// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114
116{
117 if (!cePtr_)
118 {
119 calcCellEdges();
120 }
121
122 return *cePtr_;
123}
124
125
126// ************************************************************************* //
Various functions to operate on Lists.
label appendUniq(const T &val)
Append an element if not already in the list.
Definition: ListI.H:232
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
const labelListList & cellEdges() const
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
label nCells() const noexcept
Number of mesh cells.
const labelListList & faceEdges() const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
List< label > labelList
A List of labels.
Definition: List.H:66
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333