primitiveMeshCellCells.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-------------------------------------------------------------------------------
10License
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
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33void Foam::primitiveMesh::calcCellCells() const
34{
35 // Loop through faceCells and mark up neighbours
36
37 if (debug)
38 {
39 Pout<< "primitiveMesh::calcCellCells() : calculating cellCells"
40 << 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
51 // It is an error to attempt to recalculate cellCells
52 // if the pointer is already set
53 if (ccPtr_)
54 {
56 << "cellCells already calculated"
57 << abort(FatalError);
58 }
59 else
60 {
61 // 1. Count number of internal faces per cell
62
63 labelList ncc(nCells(), Zero);
64
65 const labelList& own = faceOwner();
66 const labelList& nei = faceNeighbour();
67
68 forAll(nei, facei)
69 {
70 ncc[own[facei]]++;
71 ncc[nei[facei]]++;
72 }
73
74 // Create the storage
75 ccPtr_ = new labelListList(ncc.size());
76 labelListList& cellCellAddr = *ccPtr_;
77
78
79
80 // 2. Size and fill cellFaceAddr
81
82 forAll(cellCellAddr, celli)
83 {
84 cellCellAddr[celli].setSize(ncc[celli]);
85 }
86 ncc = 0;
87
88 forAll(nei, facei)
89 {
90 label ownCelli = own[facei];
91 label neiCelli = nei[facei];
92
93 cellCellAddr[ownCelli][ncc[ownCelli]++] = neiCelli;
94 cellCellAddr[neiCelli][ncc[neiCelli]++] = ownCelli;
95 }
96 }
97}
98
99
100// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101
103{
104 if (!ccPtr_)
105 {
106 calcCellCells();
107 }
108
109 return *ccPtr_;
110}
111
112
114(
115 const label celli,
116 DynamicList<label>& storage
117) const
118{
119 if (hasCellCells())
120 {
121 return cellCells()[celli];
122 }
123 else
124 {
125 const labelList& own = faceOwner();
126 const labelList& nei = faceNeighbour();
127 const cell& cFaces = cells()[celli];
128
129 storage.clear();
130
131 forAll(cFaces, i)
132 {
133 label facei = cFaces[i];
134
135 if (facei < nInternalFaces())
136 {
137 if (own[facei] == celli)
138 {
139 storage.append(nei[facei]);
140 }
141 else
142 {
143 storage.append(own[facei]);
144 }
145 }
146 }
147
148 return storage;
149 }
150}
151
152
153const Foam::labelList& Foam::primitiveMesh::cellCells(const label celli) const
154{
155 return cellCells(celli, labels_);
156}
157
158
159// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:57
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
const labelListList & cellCells() const
label nCells() const noexcept
Number of mesh cells.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const cellShapeList & cells
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
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
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