calcPointCells.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 | Copyright (C) 2011-2016 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 Description
25  Create intermediate mesh files from PROSTAR files
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "starMesh.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 void Foam::starMesh::calcPointCells() const
34 {
35  static const label UNIT_POINT_CELLS = 12;
36 
37  if (pointCellsPtr_)
38  {
40  << "pointCells already calculated"
41  << abort(FatalError);
42  }
43 
44 
45  pointCellsPtr_ = new labelListList(points_.size());
46 
47  labelListList& pc = *pointCellsPtr_;
48 
49  forAll(pc, i)
50  {
51  pc[i].setSize(UNIT_POINT_CELLS);
52  }
53 
54  // Initialise the list of labels which will hold the count the
55  // actual number of cells per point during the analysis
56  labelList cellCount(points_.size());
57 
58  forAll(cellCount, i)
59  {
60  cellCount[i] = 0;
61  }
62 
63  // Note. Unlike the standard point-cell algorithm, which asks the cell for
64  // the supporting point labels, we need to work based on the cell faces.
65  // This is because some of the faces for meshes with arbitrary interfaces
66  // do not come from the cell shape, but from the slaves of the coupled
67  // match. It is also adventageous to remove the duplicates from the
68  // point-cell addressing, because this removes a lot of waste later.
69  //
70 
71  // For each cell
72  forAll(cellShapes_, celli)
73  {
74  const faceList& faces = cellFaces_[celli];
75 
76  forAll(faces, i)
77  {
78  // For each vertex
79  const labelList& labels = faces[i];
80 
81  forAll(labels, j)
82  {
83  // Set working point label
84  label curPoint = labels[j];
85  labelList& curPointCells = pc[curPoint];
86  label curCount = cellCount[curPoint];
87 
88  // check if the cell has been added before
89  bool found = false;
90 
91  for (label f = 0; f < curCount; f++)
92  {
93  if (curPointCells[f] == celli)
94  {
95  found = true;
96 
97  break;
98  }
99  }
100 
101  if (!found)
102  {
103 
104  // If the list of pointCells is not big enough, double it
105  if (curPointCells.size() <= curCount)
106  {
107  curPointCells.setSize(curPointCells.size()*2);
108  }
109 
110  // Enter the cell label in the point's cell list
111  curPointCells[curCount] = celli;
112 
113  // Increment the cell count for the point addressed
114  cellCount[curPoint]++;
115  }
116  }
117  }
118  }
119 
120  // Finally, truncate the lists made to their active size
121  forAll(pc, i)
122  {
123  pc[i].setSize(cellCount[i]);
124  }
125 }
126 
127 
128 const Foam::labelListList& Foam::starMesh::pointCells() const
129 {
130  if (!pointCellsPtr_)
131  {
132  calcPointCells();
133  }
134 
135  return *pointCellsPtr_;
136 }
137 
138 
139 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
List< face > faceList
Definition: faceListFwd.H:43
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
labelList f(nPoints)