Moving cfMesh into place. Updated contibutors list
[foam-extend-3.2.git] / src / mesh / cfMesh / meshLibrary / utilities / meshes / polyMeshGenAddressing / polyMeshGenAddressingCellPoints.C
blob45ccbadabcdec3c8e158edd082d19efb2134cd89
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.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "polyMeshGenAddressing.H"
27 #include "VRWGraphSMPModifier.H"
29 # ifdef USE_OMP
30 #include <omp.h>
31 # endif
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
40 void polyMeshGenAddressing::calcCellPoints() const
42     if( cpPtr_ )
43     {
44         FatalErrorIn("polyMeshGenAddressing::calcCellPoints() const")
45             << "cellPoints already calculated"
46             << abort(FatalError);
47     }
48     else
49     {
50         const cellListPMG& cells = mesh_.cells();
51         const faceListPMG& faces = mesh_.faces();
53         //- create the storage
54         cpPtr_ = new VRWGraph(cells.size());
55         VRWGraph& cellPointsAddr = *cpPtr_;
57         labelList nPoints(cells.size());
59         # ifdef USE_OMP
60         const label nThreads = 3 * omp_get_num_procs();
61         # pragma omp parallel num_threads(nThreads) if( cells.size() > 10000 )
62         # endif
63         {
64             # ifdef USE_OMP
65             # pragma omp for schedule(static)
66             # endif
67             forAll(nPoints, i)
68                 nPoints[i] = i;
70             # ifdef USE_OMP
71             # pragma omp for schedule(static)
72             # endif
73             forAll(cells, cellI)
74             {
75                 const cell& c = cells[cellI];
77                 DynList<label, 32> cPoints;
78                 forAll(c, fI)
79                 {
80                     const face& f = faces[c[fI]];
82                     forAll(f, pI)
83                         cPoints.appendIfNotIn(f[pI]);
84                 }
86                 nPoints[cellI] = cPoints.size();
87             }
89             # ifdef USE_OMP
90             # pragma omp barrier
92             # pragma omp master
93             # endif
94             VRWGraphSMPModifier(cellPointsAddr).setSizeAndRowSize(nPoints);
96             # ifdef USE_OMP
97             # pragma omp barrier
99             # pragma omp for schedule(static)
100             # endif
101             forAll(cells, cellI)
102             {
103                 const cell& c = cells[cellI];
105                 DynList<label, 32> cPoints;
106                 forAll(c, fI)
107                 {
108                     const face& f = faces[c[fI]];
110                     forAll(f, pI)
111                         cPoints.appendIfNotIn(f[pI]);
112                 }
114                 cellPointsAddr.setRow(cellI, cPoints);
115             }
116         }
117     }
120 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
122 const VRWGraph& polyMeshGenAddressing::cellPoints() const
124     if( !cpPtr_ )
125     {
126         # ifdef USE_OMP
127         if( omp_in_parallel() )
128             FatalErrorIn
129             (
130                 "const VRWGraph& polyMeshGenAddressing::cellPoints() const"
131             ) << "Calculating addressing inside a parallel region."
132                 << " This is not thread safe" << exit(FatalError);
133         # endif
135         calcCellPoints();
136     }
138     return *cpPtr_;
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 } // End namespace Foam
145 // ************************************************************************* //