primitiveMeshCellCells.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "primitiveMesh.H"
29 
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::primitiveMesh::calcCellCells() const
34 {
35  // Loop through faceCells and mark up neighbours
36 
37  if (debug)
38  {
39  Pout<< "primitiveMesh::calcCellCells() : calculating cellCells"
40  << endl;
41 
42  if (debug == -1)
43  {
44  // For checking calls:abort so we can quickly hunt down
45  // origin of call
47  << abort(FatalError);
48  }
49  }
50 
51  // It is an error to attempt to recalculate cellCells
52  // if the pointer is already set
53  if (ccPtr_)
54  {
56  << "cellCells already calculated"
57  << abort(FatalError);
58  }
59  else
60  {
61  // 1. Count number of internal faces per cell
62 
63  labelList ncc(nCells(), Zero);
64 
65  const labelList& own = faceOwner();
66  const labelList& nei = faceNeighbour();
67 
68  forAll(nei, facei)
69  {
70  ncc[own[facei]]++;
71  ncc[nei[facei]]++;
72  }
73 
74  // Create the storage
75  ccPtr_ = new labelListList(ncc.size());
76  labelListList& cellCellAddr = *ccPtr_;
77 
78 
79 
80  // 2. Size and fill cellFaceAddr
81 
82  forAll(cellCellAddr, celli)
83  {
84  cellCellAddr[celli].setSize(ncc[celli]);
85  }
86  ncc = 0;
87 
88  forAll(nei, facei)
89  {
90  label ownCelli = own[facei];
91  label neiCelli = nei[facei];
92 
93  cellCellAddr[ownCelli][ncc[ownCelli]++] = neiCelli;
94  cellCellAddr[neiCelli][ncc[neiCelli]++] = ownCelli;
95  }
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 {
104  if (!ccPtr_)
105  {
106  calcCellCells();
107  }
108 
109  return *ccPtr_;
110 }
111 
112 
114 (
115  const label celli,
116  DynamicList<label>& storage
117 ) const
118 {
119  if (hasCellCells())
120  {
121  return cellCells()[celli];
122  }
123  else
124  {
125  const labelList& own = faceOwner();
126  const labelList& nei = faceNeighbour();
127  const cell& cFaces = cells()[celli];
128 
129  storage.clear();
130 
131  forAll(cFaces, i)
132  {
133  label facei = cFaces[i];
134 
135  if (facei < nInternalFaces())
136  {
137  if (own[facei] == celli)
138  {
139  storage.append(nei[facei]);
140  }
141  else
142  {
143  storage.append(own[facei]);
144  }
145  }
146  }
147 
148  return storage;
149  }
150 }
151 
152 
153 const Foam::labelList& Foam::primitiveMesh::cellCells(const label celli) const
154 {
155  return cellCells(celli, labels_);
156 }
157 
158 
159 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::DynamicList< label >
Foam::primitiveMesh::faceOwner
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::DynamicList::clear
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
Foam::primitiveMesh::faceNeighbour
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::primitiveMesh::cellCells
const labelListList & cellCells() const
Definition: primitiveMeshCellCells.C:102
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::List< labelList >
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54