Moving cfMesh into place. Updated contibutors list
[foam-extend-3.2.git] / src / mesh / cfMesh / meshLibrary / utilities / meshes / polyMeshGenAddressing / polyMeshGenAddressingPointPoints.C
blob0ab46397b07badb24ce30f2471ad8001812769a0
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::calcPointPoints() const
42     if( ppPtr_ )
43     {
44         FatalErrorIn("polyMeshGenAddressing::calcPointPoints() const")
45             << "pointPoints already calculated"
46             << abort(FatalError);
47     }
48     else
49     {
50         ppPtr_ = new VRWGraph();
51         VRWGraph& pp = *ppPtr_;
53         const faceListPMG& faces = mesh_.faces();
54         const VRWGraph& pointFaces = this->pointFaces();
56         labelList nPoints(pointFaces.size());
58         # ifdef USE_OMP
59         const label nThreads = 3 * omp_get_num_procs();
60         # pragma omp parallel num_threads(nThreads) if( nPoints.size() > 10000 )
61         # endif
62         {
63             # ifdef USE_OMP
64             # pragma omp for schedule(static)
65             # endif
66             forAll(nPoints, i)
67                 nPoints[i] = 0;
69             # ifdef USE_OMP
70             # pragma omp for schedule(static)
71             # endif
72             forAll(pointFaces, pointI)
73             {
74                 DynList<label, 32> helper;
76                 forAllRow(pointFaces, pointI, pfI)
77                 {
78                     const face& f = faces[pointFaces(pointI, pfI)];
80                     const label pos = f.which(pointI);
81                     helper.appendIfNotIn(f.prevLabel(pos));
82                     helper.appendIfNotIn(f.nextLabel(pos));
83                 }
85                 nPoints[pointI] = helper.size();
86             }
88             # ifdef USE_OMP
89             # pragma omp barrier
91             # pragma omp master
92             # endif
93             VRWGraphSMPModifier(pp).setSizeAndRowSize(nPoints);
95             # ifdef USE_OMP
96             # pragma omp barrier
98             # pragma omp for schedule(static)
99             # endif
100             forAll(pointFaces, pointI)
101             {
102                 DynList<label, 32> helper;
104                 forAllRow(pointFaces, pointI, pfI)
105                 {
106                     const face& f = faces[pointFaces(pointI, pfI)];
108                     const label pos = f.which(pointI);
109                     const label pLabel = f.prevLabel(pos);
110                     const label nLabel = f.nextLabel(pos);
112                     helper.appendIfNotIn(nLabel);
113                     helper.appendIfNotIn(pLabel);
114                 }
116                 pp.setRow(pointI, helper);
117             }
118         }
119     }
122 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
124 const VRWGraph& polyMeshGenAddressing::pointPoints() const
126     if( !ppPtr_ )
127     {
128         # ifdef USE_OMP
129         if( omp_in_parallel() )
130             FatalErrorIn
131             (
132                 "const VRWGraph& polyMeshGenAddressing::pointPoints() const"
133             ) << "Calculating addressing inside a parallel region."
134                 << " This is not thread safe" << exit(FatalError);
135         # endif
137         calcPointPoints();
138     }
140     return *ppPtr_;
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 } // End namespace Foam
147 // ************************************************************************* //