Loading...
Searching...
No Matches
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-2024 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 if (!curCellEdges.contains(edgei))
85 {
86 curCellEdges.push_back(edgei);
87 }
88 }
89 }
90
91 forAll(nei, facei)
92 {
93 DynamicList<label>& curCellEdges = ce[nei[facei]];
94
95 const labelList& curEdges = fe[facei];
96
97 for (const label edgei : curEdges)
98 {
99 // Add the edge
100 if (!curCellEdges.contains(edgei))
101 {
102 curCellEdges.push_back(edgei);
103 }
104 }
105 }
106
107 cePtr_ = std::make_unique<labelListList>(ce.size());
108 auto& cellEdgeAddr = *cePtr_;
109
110 // reset the size
111 forAll(ce, celli)
112 {
113 cellEdgeAddr[celli].transfer(ce[celli]);
115 }
116}
117
118
119// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120
122{
123 if (!cePtr_)
124 {
125 calcCellEdges();
126 }
127
128 return *cePtr_;
129}
130
131
132// ************************************************************************* //
Various functions to operate on Lists.
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:600
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299