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