triSurfacePartitionerCreateAddressing.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 | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
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 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "triSurfacePartitioner.H"
29 #include "demandDrivenData.H"
30 #include "labelLongList.H"
31 #include "boolList.H"
32 
33 # ifdef USE_OMP
34 #include <omp.h>
35 # endif
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
45 {
47 
49 
51 
53 
55 }
56 
58 {
59  const VRWGraph& pointFaces = surface_.pointFacets();
60  const edgeLongList& edges = surface_.edges();
61  const VRWGraph& edgeFaces = surface_.edgeFacets();
62 
63  //- find the number of feature edges connected to each surface node
64  labelList nEdgesAtNode(surface_.points().size(), 0);
65  forAll(edgeFaces, eI)
66  {
67  if( edgeFaces.sizeOfRow(eI) != 2 )
68  continue;
69 
70  const label sPatch = surface_[edgeFaces(eI, 0)].region();
71  const label ePatch = surface_[edgeFaces(eI, 1)].region();
72 
73  if( sPatch != ePatch )
74  {
75  const edge& e = edges[eI];
76  ++nEdgesAtNode[e.start()];
77  ++nEdgesAtNode[e.end()];
78  }
79  }
80 
81  //- count the number of feature edges connected to each surface point
82  //- corners must have 3 or more edges attached to them
83  label nCorners(0);
84  forAll(nEdgesAtNode, pI)
85  {
86  if( nEdgesAtNode[pI] < 3 )
87  continue;
88 
89  ++nCorners;
90  }
91 
92  corners_.setSize(nCorners);
93  cornerPatches_.setSize(nCorners);
94  nCorners = 0;
95 
96  //- store corner data
98  forAll(pointFaces, pointI)
99  {
100  if( nEdgesAtNode[pointI] < 3 )
101  continue;
102 
103  patches.clear();
104  forAllRow(pointFaces, pointI, pfI)
105  patches.appendIfNotIn(surface_[pointFaces(pointI, pfI)].region());
106 
107  corners_[nCorners] = pointI;
108  cornerPatches_[nCorners] = patches;
109  ++nCorners;
110  }
111 }
112 
114 {
115  const VRWGraph& edgeFaces = surface_.edgeFacets();
116 
117  forAll(edgeFaces, eI)
118  {
119  if( edgeFaces.sizeOfRow(eI) != 2 )
120  continue;
121 
122  const label sPatch = surface_[edgeFaces(eI, 0)].region();
123  const label ePatch = surface_[edgeFaces(eI, 1)].region();
124 
125  if( sPatch != ePatch )
126  {
127  patchPatches_[sPatch].insert(ePatch);
128  patchPatches_[ePatch].insert(sPatch);
129  }
130  }
131 }
132 
134 {
135  const edgeLongList& edges = surface_.edges();
136  const VRWGraph& edgeFaces = surface_.edgeFacets();
137  const VRWGraph& pointEdges = surface_.pointEdges();
138 
139 
140  //- make all feature edges
141  boolList featureEdge(edgeFaces.size(), false);
142 
143  # ifdef USE_OMP
144  # pragma omp parallel for schedule(dynamic, 40)
145  # endif
146  forAll(edgeFaces, eI)
147  {
149  forAllRow(edgeFaces, eI, efI)
150  patches.appendIfNotIn(surface_[edgeFaces(eI, efI)].region());
151 
152  if( patches.size() > 1 )
153  featureEdge[eI] = true;
154  }
155 
156  //- create a set containing corners for fast searching
158  forAll(corners_, i)
159  corners.insert(corners_[i]);
160 
161  edgeGroups_.setSize(edgeFaces.size());
162  edgeGroups_ = -1;
163 
164  label nGroups(0);
165  forAll(featureEdge, eI)
166  {
167  if( !featureEdge[eI] )
168  continue;
169  if( edgeGroups_[eI] != -1 )
170  continue;
171 
172  labelLongList front;
173  front.append(eI);
174  edgeGroups_[eI] = nGroups;
175  featureEdge[eI] = false;
176 
177  while( front.size() )
178  {
179  const label eLabel = front.removeLastElement();
180  const edge& e = edges[eLabel];
181 
182  for(label pI=0;pI<2;++pI)
183  {
184  const label pointI = e[pI];
185 
186  if( corners.found(pointI) )
187  continue;
188 
189  forAllRow(pointEdges, pointI, peI)
190  {
191  const label eJ = pointEdges(pointI, peI);
192 
193  if( featureEdge[eJ] && (edgeGroups_[eJ] == -1) )
194  {
195  edgeGroups_[eJ] = nGroups;
196  featureEdge[eJ] = false;
197  front.append(eJ);
198  }
199  }
200  }
201  }
202 
203  ++nGroups;
204  }
205 
206  Info << nGroups << " edge groups found!" << endl;
207 
208  edgeGroupEdgeGroups_.clear();
209  edgeGroupEdgeGroups_.setSize(nGroups);
210 }
211 
213 {
214  const VRWGraph& edgeFaces = surface_.edgeFacets();
215 
216  forAll(edgeFaces, eI)
217  {
218  if( edgeGroups_[eI] < 0 )
219  continue;
220 
222  forAllRow(edgeFaces, eI, efI)
223  patches.appendIfNotIn(surface_[edgeFaces(eI, efI)].region());
224 
225  forAll(patches, i)
226  {
227  const label patchI = patches[i];
228 
229  for(label j=i+1;j<patches.size();++j)
230  {
231  const label patchJ = patches[j];
232 
233  const std::pair<label, label> pp
234  (
235  Foam::min(patchI, patchJ),
236  Foam::max(patchI, patchJ)
237  );
238 
239  patchesEdgeGroups_[pp].insert(edgeGroups_[eI]);
240  }
241  }
242  }
243 }
244 
246 {
247  const VRWGraph& pointEdges = surface_.pointEdges();
248 
249  forAll(corners_, cornerI)
250  {
251  DynList<label> edgeGroupsAtCorner;
252  const label pointI = corners_[cornerI];
253 
254  forAllRow(pointEdges, pointI, peI)
255  edgeGroupsAtCorner.appendIfNotIn
256  (
257  edgeGroups_[pointEdges(pointI, peI)]
258  );
259 
260  forAll(edgeGroupsAtCorner, i)
261  {
262  const label epI = edgeGroupsAtCorner[i];
263  if( epI < 0 )
264  continue;
265  for(label j=i+1;j<edgeGroupsAtCorner.size();++j)
266  {
267  const label epJ = edgeGroupsAtCorner[j];
268  if( epJ < 0 )
269  continue;
270 
271  std::pair<label, label> ep
272  (
273  Foam::min(epI, epJ),
274  Foam::max(epI, epJ)
275  );
276 
277  //- create edgepartition - edge partitions addressing
278  edgeGroupEdgeGroups_[ep.first].insert(ep.second);
279  edgeGroupEdgeGroups_[ep.second].insert(ep.first);
280 
281  edgeGroupsCorners_[ep].insert(cornerI);
282  }
283  }
284  }
285 }
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 } // End namespace Foam
290 
291 // ************************************************************************* //
Foam::triSurfacePartitioner::calculatePatchPatches
void calculatePatchPatches()
calculate patch-patches addressing
Definition: triSurfacePartitionerCreateAddressing.C:113
Foam::triSurfacePartitioner::patchesEdgeGroups_
std::map< std::pair< label, label >, labelHashSet > patchesEdgeGroups_
edge groups between surface patches
Definition: triSurfacePartitioner.H:74
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
boolList.H
Foam::triSurfacePartitioner::edgeGroups_
labelList edgeGroups_
edge partitions
Definition: triSurfacePartitioner.H:67
Foam::triSurfacePartitioner::corners_
labelList corners_
corner nodes
Definition: triSurfacePartitioner.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
triSurfacePartitioner.H
Foam::triSurfacePartitioner::patchPatches_
List< labelHashSet > patchPatches_
information which partitions share an edge with a given partition
Definition: triSurfacePartitioner.H:64
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::triSurfPoints::points
const pointField & points() const
access to points
Definition: triSurfPointsI.H:44
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::HashSet< label, Hash< label > >
Foam::triSurfacePartitioner::calculateCornersAndAddressing
void calculateCornersAndAddressing()
find surface corners
Definition: triSurfacePartitionerCreateAddressing.C:57
Foam::triSurfacePartitioner::calculatePatchToEdgeGroups
void calculatePatchToEdgeGroups()
calculate surface patch to edge groups addressing
Definition: triSurfacePartitionerCreateAddressing.C:212
Foam::LongList< edge >
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::triSurfacePartitioner::cornerPatches_
List< DynList< label > > cornerPatches_
Definition: triSurfacePartitioner.H:61
Foam::Info
messageStream Info
Foam::VRWGraph::size
label size() const
Returns the number of rows.
Definition: VRWGraphI.H:122
Foam::DynList::appendIfNotIn
void appendIfNotIn(const T &e)
Definition: DynListI.H:324
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::triSurfAddressing::pointFacets
const VRWGraph & pointFacets() const
return point-facets addressing
Definition: triSurfAddressingI.H:43
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
Foam::triSurfacePartitioner::calculatePatchAddressing
void calculatePatchAddressing()
calculate patch addressing
Definition: triSurfacePartitionerCreateAddressing.C:44
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::DynList< label >
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::triSurfacePartitioner::edgeGroupsCorners_
std::map< std::pair< label, label >, labelHashSet > edgeGroupsCorners_
corners shared by edge groups
Definition: triSurfacePartitioner.H:77
Foam::triSurfacePartitioner::calculateEdgeGroups
void calculateEdgeGroups()
calculate edge groups
Definition: triSurfacePartitionerCreateAddressing.C:133
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
labelLongList.H
Foam::triSurfAddressing::edges
const LongList< edge > & edges() const
return edges
Definition: triSurfAddressingI.H:61
Foam::triSurfacePartitioner::corners
const labelList & corners() const
return corner nodes
Definition: triSurfacePartitioner.C:64
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::triSurfacePartitioner::edgeGroupEdgeGroups_
List< labelHashSet > edgeGroupEdgeGroups_
Definition: triSurfacePartitioner.H:71
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::triSurfacePartitioner::surface_
const triSurf & surface_
reference to triSurf
Definition: triSurfacePartitioner.H:57
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::triSurfacePartitioner::calculateEdgeGroupsToCorners
void calculateEdgeGroupsToCorners()
calculate edge groups to corner addressing
Definition: triSurfacePartitionerCreateAddressing.C:245
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::LongList::removeLastElement
T removeLastElement()
Definition: LongListI.H:323
Foam::triSurfAddressing::edgeFacets
const VRWGraph & edgeFacets() const
return edge-facets addressing
Definition: triSurfAddressingI.H:97
Foam::triSurfAddressing::pointEdges
const VRWGraph & pointEdges() const
return point-edges addressing
Definition: triSurfAddressingI.H:115