primitiveMeshPointCells.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "primitiveMesh.H"
27 #include "cell.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 void Foam::primitiveMesh::calcPointCells() const
32 {
33  // Loop through cells and mark up points
34 
35  if (debug)
36  {
37  Pout<< "primitiveMesh::calcPointCells() : "
38  << "calculating pointCells"
39  << endl;
40 
41  if (debug == -1)
42  {
43  // For checking calls:abort so we can quickly hunt down
44  // origin of call
46  << abort(FatalError);
47  }
48  }
49 
50  // It is an error to attempt to recalculate pointCells
51  // if the pointer is already set
52  if (pcPtr_)
53  {
55  << "pointCells already calculated"
56  << abort(FatalError);
57  }
58  else
59  {
60  const cellList& cf = cells();
61 
62  // Count number of cells per point
63 
64  labelList npc(nPoints(), 0);
65 
66  forAll(cf, celli)
67  {
68  const labelList curPoints = cf[celli].labels(faces());
69 
70  forAll(curPoints, pointi)
71  {
72  label ptI = curPoints[pointi];
73 
74  npc[ptI]++;
75  }
76  }
77 
78 
79  // Size and fill cells per point
80 
81  pcPtr_ = new labelListList(npc.size());
82  labelListList& pointCellAddr = *pcPtr_;
83 
84  forAll(pointCellAddr, pointi)
85  {
86  pointCellAddr[pointi].setSize(npc[pointi]);
87  }
88  npc = 0;
89 
90 
91  forAll(cf, celli)
92  {
93  const labelList curPoints = cf[celli].labels(faces());
94 
95  forAll(curPoints, pointi)
96  {
97  label ptI = curPoints[pointi];
98 
99  pointCellAddr[ptI][npc[ptI]++] = celli;
100  }
101  }
102  }
103 }
104 
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 
109 {
110  if (!pcPtr_)
111  {
112  calcPointCells();
113  }
114 
115  return *pcPtr_;
116 }
117 
118 
120 (
121  const label pointi,
122  DynamicList<label>& storage
123 ) const
124 {
125  if (hasPointCells())
126  {
127  return pointCells()[pointi];
128  }
129  else
130  {
131  const labelList& own = faceOwner();
132  const labelList& nei = faceNeighbour();
133  const labelList& pFaces = pointFaces()[pointi];
134 
135  storage.clear();
136 
137  forAll(pFaces, i)
138  {
139  const label facei = pFaces[i];
140 
141  // Append owner
142  storage.append(own[facei]);
143 
144  // Append neighbour
145  if (facei < nInternalFaces())
146  {
147  storage.append(nei[facei]);
148  }
149  }
150 
151  // Filter duplicates
152  if (storage.size() > 1)
153  {
154  sort(storage);
155 
156  label n = 1;
157  for (label i = 1; i < storage.size(); i++)
158  {
159  if (storage[i-1] != storage[i])
160  {
161  storage[n++] = storage[i];
162  }
163  }
164 
165  // truncate addressed list
166  storage.setSize(n);
167  }
168 
169  return storage;
170  }
171 }
172 
173 
175 {
176  return pointCells(pointi, labels_);
177 }
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
label nInternalFaces() const
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const cellList & cells() const
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
void setSize(const label)
Alter the addressed list size.
Definition: DynamicListI.H:175
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
void sort(UList< T > &)
Definition: UList.C:115
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const labelListList & pointCells() const
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=*(cellModeller::lookup("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]=cellShape(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, &mergedCyclicPolyPatch::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
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
virtual const faceList & faces() const =0
Return faces.
const labelListList & pointFaces() const
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
label n
label nPoints() const
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:236
List< cell > cellList
list of cells
Definition: cellList.H:42
bool hasPointCells() const