primitiveMeshCells.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation, either version 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "primitiveMesh.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
31 (
32  cellList& cellFaceAddr,
33  const unallocLabelList& own,
34  const unallocLabelList& 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 
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 // ************************************************************************* //
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::primitiveMesh::faceOwner
virtual const labelList & faceOwner() const =0
Face face-owner addresing.
Foam::primitiveMesh::calcCells
void calcCells() const
Calculate cell-face addressing.
Definition: primitiveMeshCells.C:99
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::primitiveMesh::faceNeighbour
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
Foam::label
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
primitiveMesh.H
Foam::cellList
List< cell > cellList
list of cells
Definition: cellList.H:42
Foam::primitiveMesh::cfPtr_
cellList * cfPtr_
Cell-faces.
Definition: primitiveMesh.H:125
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::UList
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
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.