primitiveMeshPointCells.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#include "cell.H"
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33void Foam::primitiveMesh::calcPointCells() const
34{
35 // Loop through cells and mark up points
36
37 if (debug)
38 {
39 Pout<< "primitiveMesh::calcPointCells() : "
40 << "calculating pointCells"
41 << endl;
42
43 if (debug == -1)
44 {
45 // For checking calls:abort so we can quickly hunt down
46 // origin of call
48 << abort(FatalError);
49 }
50 }
51
52 // It is an error to attempt to recalculate pointCells
53 // if the pointer is already set
54 if (pcPtr_)
55 {
57 << "pointCells already calculated"
58 << abort(FatalError);
59 }
60 else
61 {
62 const cellList& cf = cells();
63
64 // Count number of cells per point
65
66 labelList npc(nPoints(), Zero);
67
68 forAll(cf, celli)
69 {
70 const labelList curPoints = cf[celli].labels(faces());
71
72 forAll(curPoints, pointi)
73 {
74 label ptI = curPoints[pointi];
75
76 npc[ptI]++;
77 }
78 }
79
80
81 // Size and fill cells per point
82
83 pcPtr_ = new labelListList(npc.size());
84 labelListList& pointCellAddr = *pcPtr_;
85
86 forAll(pointCellAddr, pointi)
87 {
88 pointCellAddr[pointi].setSize(npc[pointi]);
89 }
90 npc = 0;
91
92
93 forAll(cf, celli)
94 {
95 const labelList curPoints = cf[celli].labels(faces());
96
97 forAll(curPoints, pointi)
98 {
99 label ptI = curPoints[pointi];
100
101 pointCellAddr[ptI][npc[ptI]++] = celli;
102 }
103 }
104 }
105}
106
107
108// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109
111{
112 if (!pcPtr_)
113 {
114 calcPointCells();
115 }
116
117 return *pcPtr_;
118}
119
120
122(
123 const label pointi,
124 DynamicList<label>& storage
125) const
126{
127 if (hasPointCells())
128 {
129 return pointCells()[pointi];
130 }
131 else
132 {
133 const labelList& own = faceOwner();
134 const labelList& nei = faceNeighbour();
135 const labelList& pFaces = pointFaces()[pointi];
136
137 storage.clear();
138
139 forAll(pFaces, i)
140 {
141 const label facei = pFaces[i];
142
143 // Append owner
144 storage.append(own[facei]);
145
146 // Append neighbour
147 if (facei < nInternalFaces())
148 {
149 storage.append(nei[facei]);
150 }
151 }
152
153 // Filter duplicates
154 if (storage.size() > 1)
155 {
156 sort(storage);
157
158 label n = 1;
159 for (label i = 1; i < storage.size(); i++)
160 {
161 if (storage[i-1] != storage[i])
162 {
163 storage[n++] = storage[i];
164 }
165 }
166
167 // truncate addressed list
168 storage.setSize(n);
169 }
170
171 return storage;
172 }
173}
174
175
176const Foam::labelList& Foam::primitiveMesh::pointCells(const label pointi) const
177{
178 return pointCells(pointi, labels_);
179}
180
181
182// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183
184// ************************************************************************* //
label n
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
void setSize(const label n)
Same as resize()
Definition: DynamicList.H:221
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Smooth ATC in cells having a point to a set of patches supplied by type.
Definition: pointCells.H:59
const labelListList & pointCells() const
virtual const faceList & faces() const =0
Return faces.
label nPoints() const noexcept
Number of mesh points.
const cellList & cells() const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
List< label > labelList
A List of labels.
Definition: List.H:66
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:342
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.
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=cellModel::ref(cellModel::HEX);labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells].reset(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
Definition: readKivaGrid.H:235
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333