polyMeshGenAddressingCellCells.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Copyright held by the original author
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh 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  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "polyMeshGenAddressing.H"
27 #include "VRWGraphSMPModifier.H"
28 
29 # ifdef USE_OMP
30 #include <omp.h>
31 # endif
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
41 {
42  if( ccPtr_ )
43  {
44  FatalErrorIn("polyMeshGenAddressing::calcCellCells() const")
45  << "cellCells already calculated"
46  << abort(FatalError);
47  }
48  else
49  {
50  const cellListPMG& cells = mesh_.cells();
51 
52  const labelList& own = mesh_.owner();
53  const labelList& nei = mesh_.neighbour();
54 
55  //- create the storage
56  ccPtr_ = new VRWGraph();
57  VRWGraph& cellCellAddr = *ccPtr_;
58 
59  labelList nNei(cells.size());
60 
61  # ifdef USE_OMP
62  const label nThreads = 3 * omp_get_num_procs();
63  # endif
64 
65  # ifdef USE_OMP
66  # pragma omp parallel num_threads(nThreads)
67  # endif
68  {
69  # ifdef USE_OMP
70  # pragma omp for schedule(static)
71  # endif
72  forAll(nNei, i)
73  nNei[i] = 0;
74 
75  # ifdef USE_OMP
76  # pragma omp for schedule(static)
77  # endif
78  forAll(cells, cellI)
79  {
80  const cell& c = cells[cellI];
81 
82  DynList<label> neiCells;
83 
84  forAll(c, fI)
85  {
86  label neiCell = own[c[fI]];
87  if( (neiCell == cellI) && (nei[c[fI]] != -1) )
88  neiCell = nei[c[fI]];
89 
90  if( neiCell != cellI )
91  neiCells.appendIfNotIn(neiCell);
92  }
93 
94  nNei[cellI] = neiCells.size();
95  }
96 
97  # ifdef USE_OMP
98  # pragma omp barrier
99 
100  # pragma omp master
101  # endif
102  VRWGraphSMPModifier(cellCellAddr).setSizeAndRowSize(nNei);
103 
104  # ifdef USE_OMP
105  # pragma omp barrier
106 
107  //- fill the graph with data
108  # pragma omp for schedule(static)
109  # endif
110  forAll(cells, cellI)
111  {
112  const cell& c = cells[cellI];
113 
114  DynList<label> neiCells;
115 
116  forAll(c, fI)
117  {
118  label neiCell = own[c[fI]];
119  if( (neiCell == cellI) && (nei[c[fI]] != -1) )
120  neiCell = nei[c[fI]];
121 
122  if( neiCell != cellI )
123  neiCells.appendIfNotIn(neiCell);
124  }
125 
126  cellCellAddr.setRow(cellI, neiCells);
127  }
128  }
129  }
130 }
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
135 {
136  if( !ccPtr_ )
137  {
138  # ifdef USE_OMP
139  if( omp_in_parallel() )
141  (
142  "const VRWGraph& polyMeshGenAddressing::cellCells() const"
143  ) << "Calculating addressing inside a parallel region."
144  << " This is not thread safe" << exit(FatalError);
145  # endif
146 
147  calcCellCells();
148  }
149 
150  return *ccPtr_;
151 }
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace Foam
156 
157 // ************************************************************************* //
Foam::polyMeshGenFaces::neighbour
const labelList & neighbour() const
Definition: polyMeshGenFacesI.H:86
Foam::polyMeshGenFaces::owner
const labelList & owner() const
owner and neighbour cells for faces
Definition: polyMeshGenFacesI.H:67
Foam::VRWGraph::setRow
void setRow(const label rowI, const ListType &l)
Set row with the list.
Definition: VRWGraphI.H:354
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::polyMeshGenAddressing::mesh_
const polyMeshGenCells & mesh_
reference to the mesh
Definition: polyMeshGenAddressing.H:74
Foam::polyMeshGenAddressing::calcCellCells
void calcCellCells() const
Calculate cell-cell addressing.
Definition: polyMeshGenAddressingCellCells.C:40
Foam::cellListPMG
Definition: cellListPMG.H:49
VRWGraphSMPModifier.H
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::polyMeshGenAddressing::ccPtr_
VRWGraph * ccPtr_
Cell-cells.
Definition: polyMeshGenAddressing.H:85
Foam::polyMeshGenCells::cells
const cellListPMG & cells() const
access to cells
Definition: polyMeshGenCellsI.H:39
Foam::DynList::appendIfNotIn
void appendIfNotIn(const T &e)
Definition: DynListI.H:324
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::DynList< label >
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::DynList::size
label size() const
Definition: DynListI.H:235
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::VRWGraphSMPModifier
Definition: VRWGraphSMPModifier.H:50
Foam::VRWGraph
Definition: VRWGraph.H:101
polyMeshGenAddressing.H
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::polyMeshGenAddressing::cellCells
const VRWGraph & cellCells() const
Definition: polyMeshGenAddressingCellCells.C:134
Foam::VRWGraphSMPModifier::setSizeAndRowSize
void setSizeAndRowSize(const ListType &)
set the size and row sizes
Definition: VRWGraphSMPModifierTemplates.C:41