Loading...
Searching...
No Matches
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-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/>.
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
37void 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_ = std::make_unique<labelListList>(nCells());
65 invertManyToMany(nCells(), pointCells(), *cpPtr_);
66 }
67 else
68 {
69 // Calculate cell-point topology
70
71 cpPtr_ = std::make_unique<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
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
159const Foam::labelList& Foam::primitiveMesh::cellPoints(const label celli) const
160{
161 return cellPoints(celli, labelSet_, labels_);
162}
163
164
165// ************************************************************************* //
Various functions to operate on Lists.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
void push_back(const T &val)
Copy append an element to the end of this list.
label capacity() const noexcept
Size of the underlying storage.
void setCapacity(const label len)
Alter the size of the underlying storage.
bool hasPointCells() const noexcept
const labelListList & pointCells() const
virtual const faceList & faces() const =0
Return faces.
label nPoints() const noexcept
Number of mesh points.
const labelListList & cellPoints() const
label nCells() const noexcept
Number of mesh cells.
bool hasCellPoints() const noexcept
const cellList & cells() const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const cellShapeList & cells
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign 'true').
Definition BitOps.C:35
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
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:41
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
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.