primitiveMeshCells.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// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31
32void Foam::primitiveMesh::calcCells
33(
34 cellList& cellFaceAddr,
35 const labelUList& own,
36 const labelUList& nei,
37 const label inNCells
38)
39{
40 label nCells = inNCells;
41
42 if (nCells == -1)
43 {
44 nCells = -1;
45
46 forAll(own, facei)
47 {
48 nCells = max(nCells, own[facei]);
49 }
50 nCells++;
51 }
52
53 // 1. Count number of faces per cell
54
55 labelList ncf(nCells, Zero);
56
57 forAll(own, facei)
58 {
59 ncf[own[facei]]++;
60 }
61
62 forAll(nei, facei)
63 {
64 if (nei[facei] >= 0)
65 {
66 ncf[nei[facei]]++;
67 }
68 }
69
70 // Create the storage
71 cellFaceAddr.setSize(ncf.size());
72
73
74 // 2. Size and fill cellFaceAddr
75
76 forAll(cellFaceAddr, celli)
77 {
78 cellFaceAddr[celli].setSize(ncf[celli]);
79 }
80 ncf = 0;
81
82 forAll(own, facei)
83 {
84 label celli = own[facei];
85
86 cellFaceAddr[celli][ncf[celli]++] = facei;
87 }
88
89 forAll(nei, facei)
90 {
91 label celli = nei[facei];
92
93 if (celli >= 0)
94 {
95 cellFaceAddr[celli][ncf[celli]++] = facei;
96 }
97 }
98}
99
100
101void Foam::primitiveMesh::calcCells() const
102{
103 // Loop through faceCells and mark up neighbours
104
105 if (debug)
106 {
107 Pout<< "primitiveMesh::calcCells() : calculating cells"
108 << endl;
109 }
110
111 // It is an error to attempt to recalculate cells
112 // if the pointer is already set
113 if (cfPtr_)
114 {
116 << "cells already calculated"
117 << abort(FatalError);
118 }
119 else
120 {
121 // Create the storage
122 cfPtr_ = new cellList(nCells());
123 cellList& cellFaceAddr = *cfPtr_;
124
125 calcCells
126 (
127 cellFaceAddr,
128 faceOwner(),
129 faceNeighbour(),
130 nCells()
131 );
132 }
133}
134
135
136// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137
139{
140 if (!cfPtr_)
141 {
142 calcCells();
143 }
144
145 return *cfPtr_;
146}
147
148
149// ************************************************************************* //
void setSize(const label n)
Alias for resize()
Definition: List.H:218
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
label nCells() const noexcept
Number of mesh cells.
const cellList & cells() const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
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