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 -------------------------------------------------------------------------------
11 License
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 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void 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 
102 void 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 size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:600
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
const cellList & cells() const
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
void setSize(const label n)
Alias for resize()
Definition: List.H:325
errorManip< error > abort(error &err)
Definition: errorManip.H:139
int debug
Static debugging option.
label nCells() const noexcept
Number of mesh cells.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127