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-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 \*---------------------------------------------------------------------------*/
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  {
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 // ************************************************************************* //
#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
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const cellList & cells() const
label nCells() const
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53
void setSize(const label)
Reset size of List.
Definition: List.C:295
virtual const labelList & faceOwner() const =0
Face face-owner addresing.
List< cell > cellList
list of cells
Definition: cellList.H:42