primitiveMeshCellCells.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 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
32 {
33  // Loop through faceCells and mark up neighbours
34 
35  if (debug)
36  {
37  Pout<< "primitiveMesh::calcCellCells() : calculating cellCells"
38  << endl;
39 
40  if (debug == -1)
41  {
42  // For checking calls:abort so we can quickly hunt down
43  // origin of call
44  FatalErrorIn("primitiveMesh::calcCellCells()")
45  << abort(FatalError);
46  }
47  }
48 
49  // It is an error to attempt to recalculate cellCells
50  // if the pointer is already set
51  if (ccPtr_)
52  {
53  FatalErrorIn("primitiveMesh::calcCellCells() const")
54  << "cellCells already calculated"
55  << abort(FatalError);
56  }
57  else
58  {
59  // 1. Count number of internal faces per cell
60 
61  labelList ncc(nCells(), 0);
62 
63  const labelList& own = faceOwner();
64  const labelList& nei = faceNeighbour();
65 
66  forAll (nei, faceI)
67  {
68  ncc[own[faceI]]++;
69  ncc[nei[faceI]]++;
70  }
71 
72  // Create the storage
73  ccPtr_ = new labelListList(ncc.size());
74  labelListList& cellCellAddr = *ccPtr_;
75 
76 
77 
78  // 2. Size and fill cellCellAddr
79 
80  forAll (cellCellAddr, cellI)
81  {
82  cellCellAddr[cellI].setSize(ncc[cellI]);
83  }
84  ncc = 0;
85 
86  forAll (nei, faceI)
87  {
88  label ownCellI = own[faceI];
89  label neiCellI = nei[faceI];
90 
91  cellCellAddr[ownCellI][ncc[ownCellI]++] = neiCellI;
92  cellCellAddr[neiCellI][ncc[neiCellI]++] = ownCellI;
93  }
94  }
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 {
102  if (!ccPtr_)
103  {
104  calcCellCells();
105  }
106 
107  return *ccPtr_;
108 }
109 
110 
112 (
113  const label cellI,
114  dynamicLabelList& storage
115 ) const
116 {
117  if (hasCellCells())
118  {
119  return cellCells()[cellI];
120  }
121  else
122  {
123  const labelList& own = faceOwner();
124  const labelList& nei = faceNeighbour();
125  const cell& cFaces = cells()[cellI];
126 
127  storage.clear();
128 
129  forAll(cFaces, i)
130  {
131  label faceI = cFaces[i];
132 
133  if (faceI < nInternalFaces())
134  {
135  if (own[faceI] == cellI)
136  {
137  storage.append(nei[faceI]);
138  }
139  else
140  {
141  storage.append(own[faceI]);
142  }
143  }
144  }
145 
146  return storage;
147  }
148 }
149 
150 
152 {
153  return cellCells(cellI, labels_);
154 }
155 
156 
157 // ************************************************************************* //
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::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::primitiveMesh::calcCellCells
void calcCellCells() const
Calculate cell-cell addressing.
Definition: primitiveMeshCellCells.C:31
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
Foam::List::append
void append(const T &)
Append an element at the end of the list.
primitiveMesh.H
Foam::primitiveMesh::cellCells
const labelListList & cellCells() const
Definition: primitiveMeshCellCells.C:100
Foam::FatalError
error FatalError
Foam::primitiveMesh::ccPtr_
labelListList * ccPtr_
Cell-cells.
Definition: primitiveMesh.H:116
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
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::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56