primitiveMeshCellPoints.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) 2018-2023 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 #include "cell.H"
31 #include "bitSet.H"
32 #include "DynamicList.H"
33 #include "ListOps.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 void Foam::primitiveMesh::calcCellPoints() const
38 {
39  if (debug)
40  {
41  Pout<< "primitiveMesh::cellCellPoints() : "
42  << "calculating cellPoints" << endl;
43 
44  if (debug == -1)
45  {
46  // For checking calls:abort so we can quickly hunt down
47  // origin of call
49  << abort(FatalError);
50  }
51  }
52 
53  // It is an error to attempt to recalculate cellPoints
54  // if the pointer is already set
55  if (cpPtr_)
56  {
58  << "cellPoints already calculated"
59  << abort(FatalError);
60  }
61  else if (hasPointCells())
62  {
63  // Invert pointCells
64  cpPtr_ = new labelListList(nCells());
65  invertManyToMany(nCells(), pointCells(), *cpPtr_);
66  }
67  else
68  {
69  // Calculate cell-point topology
70 
71  cpPtr_ = new labelListList(nCells());
72  auto& cellPointAddr = *cpPtr_;
73 
74  const cellList& cellLst = cells();
75  const faceList& faceLst = faces();
76 
77  // Tracking (only use each point id once)
78  bitSet usedPoints(nPoints());
79 
80  // Vertex labels for the current cell
81  DynamicList<label> currPoints(256);
82 
83  const label loopLen = nCells();
84 
85  for (label celli = 0; celli < loopLen; ++celli)
86  {
87  // Clear any previous contents
88  usedPoints.unset(currPoints);
89  currPoints.clear();
90 
91  for (const label facei : cellLst[celli])
92  {
93  for (const label pointi : faceLst[facei])
94  {
95  // Only once for each point id
96  if (usedPoints.set(pointi))
97  {
98  currPoints.push_back(pointi);
99  }
100  }
101  }
102 
103  cellPointAddr[celli] = currPoints; // NB: unsorted
104  }
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
112 {
113  if (!cpPtr_)
114  {
115  calcCellPoints();
116  }
117 
118  return *cpPtr_;
119 }
120 
121 
123 (
124  const label celli,
125  labelHashSet& set,
126  DynamicList<label>& storage
127 ) const
128 {
129  if (hasCellPoints())
130  {
131  return cellPoints()[celli];
132  }
133 
134  const faceList& fcs = faces();
135  const labelList& cFaces = cells()[celli];
136 
137  set.clear();
138 
139  for (const label facei : cFaces)
140  {
141  set.insert(fcs[facei]);
142  }
143 
144  storage.clear();
145  if (storage.capacity() < set.size())
146  {
147  storage.setCapacity(set.size());
148  }
149 
150  for (const label pointi : set)
151  {
152  storage.push_back(pointi);
153  }
154 
155  return storage;
156 }
157 
158 
159 const Foam::labelList& Foam::primitiveMesh::cellPoints(const label celli) const
160 {
161  return cellPoints(celli, labelSet_, labels_);
162 }
163 
164 
165 // ************************************************************************* //
List< cell > cellList
List of cell.
Definition: cellListFwd.H:39
label nPoints() const noexcept
Number of mesh points.
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:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
const cellList & cells() const
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
Various functions to operate on Lists.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
const cellShapeList & cells
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
errorManip< error > abort(error &err)
Definition: errorManip.H:139
const labelListList & pointCells() const
int debug
Static debugging option.
bool hasPointCells() const noexcept
label nCells() const noexcept
Number of mesh cells.
virtual const faceList & faces() const =0
Return faces.
List< label > labelList
A List of labels.
Definition: List.H:62
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
const labelListList & cellPoints() const