primitiveMeshCells.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 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 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 void Foam::primitiveMesh::calcCells
31 (
32  cellList& cellFaceAddr,
33  const labelUList& own,
34  const labelUList& nei,
35  const label inNCells
36 )
37 {
38  label nCells = inNCells;
39 
40  if (nCells == -1)
41  {
42  nCells = -1;
43 
44  forAll(own, faceI)
45  {
46  nCells = max(nCells, own[faceI]);
47  }
48  nCells++;
49  }
50 
51  // 1. Count number of faces per cell
52 
53  labelList ncf(nCells, 0);
54 
55  forAll(own, faceI)
56  {
57  ncf[own[faceI]]++;
58  }
59 
60  forAll(nei, faceI)
61  {
62  if (nei[faceI] >= 0)
63  {
64  ncf[nei[faceI]]++;
65  }
66  }
67 
68  // Create the storage
69  cellFaceAddr.setSize(ncf.size());
70 
71 
72  // 2. Size and fill cellFaceAddr
73 
74  forAll(cellFaceAddr, cellI)
75  {
76  cellFaceAddr[cellI].setSize(ncf[cellI]);
77  }
78  ncf = 0;
79 
80  forAll(own, faceI)
81  {
82  label cellI = own[faceI];
83 
84  cellFaceAddr[cellI][ncf[cellI]++] = faceI;
85  }
86 
87  forAll(nei, faceI)
88  {
89  label cellI = nei[faceI];
90 
91  if (cellI >= 0)
92  {
93  cellFaceAddr[cellI][ncf[cellI]++] = faceI;
94  }
95  }
96 }
97 
98 
99 void Foam::primitiveMesh::calcCells() const
100 {
101  // Loop through faceCells and mark up neighbours
102 
103  if (debug)
104  {
105  Pout<< "primitiveMesh::calcCells() : calculating cells"
106  << endl;
107  }
108 
109  // It is an error to attempt to recalculate cells
110  // if the pointer is already set
111  if (cfPtr_)
112  {
113  FatalErrorIn("primitiveMesh::calcCells() const")
114  << "cells already calculated"
115  << abort(FatalError);
116  }
117  else
118  {
119  // Create the storage
120  cfPtr_ = new cellList(nCells());
121  cellList& cellFaceAddr = *cfPtr_;
122 
123  calcCells
124  (
125  cellFaceAddr,
126  faceOwner(),
127  faceNeighbour(),
128  nCells()
129  );
130  }
131 }
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
137 {
138  if (!cfPtr_)
139  {
140  calcCells();
141  }
142 
143  return *cfPtr_;
144 }
145 
146 
147 // ************************************************************************* //
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
label nCells() const
const cellList & cells() const
void setSize(const label)
Reset size of List.
Definition: List.C:318
List< cell > cellList
list of cells
Definition: cellList.H:42
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define forAll(list, i)
Definition: UList.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
virtual const labelList & faceOwner() const =0
Face face-owner addresing.
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53