1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Copyright held by the original author
7 -------------------------------------------------------------------------------
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
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"
28 #include "helperFunctions.H"
29 #include "demandDrivenData.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 void polyMeshGenAddressing::calcEdges() const
46 FatalErrorIn("polyMeshGenAddressing::calcEdges() const")
47 << "edges already calculated"
52 const faceListPMG& faces = mesh_.faces();
53 const VRWGraph& pointFaces = this->pointFaces();
55 edgesPtr_ = new edgeList();
57 labelList nfe(faces.size());
60 const label nThreads = 3 * omp_get_num_procs();
61 labelList nEdgesForThread(nThreads);
63 labelList nEdgesForThread(1);
67 # pragma omp parallel num_threads(nThreads) if( faces.size() > 1000 )
70 LongList<edge> edgesHelper;
73 # pragma omp for schedule(static)
77 const face& f = faces[faceI];
81 const edge fe = f.faceEdge(pI);
82 const label s = fe.start();
83 const label e = fe.end();
85 DynList<label> edgeFaces;
89 //- find all faces attached to this edge
90 //- store the edge in case the face faceI is the face
91 //- with the smallest label
92 forAllRow(pointFaces, s, pfI)
94 const label ofI = pointFaces(s, pfI);
95 const face& of = faces[ofI];
105 edgeFaces.append(ofI);
109 edgesHelper.append(fe);
113 //- this enables other threads to see the number of edges
114 //- generated by each thread
116 nEdgesForThread[omp_get_thread_num()] = edgesHelper.size();
118 nEdgesForThread[0] = edgesHelper.size();
122 # pragma omp critical
124 nEdges += edgesHelper.size();
131 edgesPtr_->setSize(nEdges);
137 //- find the starting position of the edges generated by this thread
138 //- in the global list of edges
141 const label threadI = omp_get_thread_num();
143 const label threadI = 0;
145 for(label i=0;i<threadI;++i)
146 localStart += nEdgesForThread[i];
148 //- store edges into the global list
149 forAll(edgesHelper, i)
150 edgesPtr_->operator[](localStart+i) = edgesHelper[i];
155 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
157 const edgeList& polyMeshGenAddressing::edges() const
162 if( omp_in_parallel() )
165 "const edgeList& polyMeshGenAddressing::edges() const"
166 ) << "Calculating addressing inside a parallel region."
167 << " This is not thread safe" << exit(FatalError);
176 void polyMeshGenAddressing::clearOutEdges()
178 deleteDemandDrivenData(edgesPtr_);
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 } // End namespace Foam
186 // ************************************************************************* //