meshSurfacePartitionerFunctions.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 "meshSurfacePartitioner.H"
29 #include "helperFunctionsPar.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
39 {
40  const labelList& bPoints = meshSurface_.boundaryPoints();
41  const labelList& bp = meshSurface_.bp();
42  const edgeList& edges = meshSurface_.edges();
43  const VRWGraph& edgeFaces = meshSurface_.edgeFaces();
44  const VRWGraph& pointFaces = meshSurface_.pointFaces();
45 
46  corners_.clear();
48 
49  //- count the number of patches
50  label nPatches(0);
51  # ifdef USE_OMP
52  # pragma omp parallel
53  {
54  label localMax(0);
55 
56  forAll(facePatch_, bfI)
58 
59  # pragma omp critical
61  }
62  # else
63  forAll(facePatch_, bfI)
65  # endif
66  ++nPatches;
67 
68  //- set the size and starting creating addressing
69  patchPatches_.setSize(nPatches);
70 
72  nEdgesAtPoint_.setSize(bPoints.size());
73  nEdgesAtPoint_ = 0;
74 
76 
77  forAll(edgeFaces, edgeI)
78  {
79  if( edgeFaces.sizeOfRow(edgeI) != 2 )
80  continue;
81 
82  const label patch0 = facePatch_[edgeFaces(edgeI, 0)];
83  const label patch1 = facePatch_[edgeFaces(edgeI, 1)];
84 
85  if( patch0 != patch1 )
86  {
87  const edge& e = edges[edgeI];
88  ++nEdgesAtPoint_[bp[e.start()]];
89  ++nEdgesAtPoint_[bp[e.end()]];
90 
91  patchPatches_[patch0].insert(patch1);
92  patchPatches_[patch1].insert(patch0);
93 
94  featureEdges_.insert(edgeI);
95  }
96  }
97 
98  if( Pstream::parRun() )
99  {
100  const Map<label>& otherFaceAtProc = meshSurface_.otherEdgeFaceAtProc();
101 
102  //- find patches on other procs sharing surface edges
103  Map<label> otherFacePatch;
104 
105  const DynList<label>& beNeiProcs = meshSurface_.beNeiProcs();
106  const Map<label>& globalToLocalEdges =
108 
109  std::map<label, labelLongList> exchangeData;
110  forAll(beNeiProcs, i)
111  exchangeData.insert(std::make_pair(beNeiProcs[i], labelLongList()));
112 
113  forAllConstIter(Map<label>, globalToLocalEdges, it)
114  {
115  const label beI = it();
116 
117  if( edgeFaces.sizeOfRow(beI) == 1 )
118  {
119  labelLongList& data = exchangeData[otherFaceAtProc[beI]];
120 
121  data.append(it.key());
122  data.append(facePatch_[edgeFaces(beI, 0)]);
123  }
124  }
125 
126  labelLongList receivedData;
127  help::exchangeMap(exchangeData, receivedData);
128 
129  for(label i=0;i<receivedData.size();)
130  {
131  const label geI = receivedData[i++];
132  const label patchI = receivedData[i++];
133 
134  otherFacePatch.insert(globalToLocalEdges[geI], patchI);
135  }
136 
137  //- take into account feature edges at processor boundaries
138  forAllConstIter(Map<label>, otherFaceAtProc, it)
139  {
140  const label beI = it.key();
141 
142  if( it() <= Pstream::myProcNo() )
143  continue;
144  if( otherFacePatch[beI] != facePatch_[edgeFaces(beI, 0)] )
145  {
146  const edge& e = edges[beI];
147  ++nEdgesAtPoint_[bp[e.start()]];
148  ++nEdgesAtPoint_[bp[e.end()]];
149  }
150  }
151 
152  //- gather data on all processors
153  exchangeData.clear();
154  const DynList<label>& bpNeiProcs = meshSurface_.bpNeiProcs();
155  forAll(bpNeiProcs, i)
156  exchangeData.insert(std::make_pair(bpNeiProcs[i], labelLongList()));
157 
158  const Map<label>& globalToLocal =
160  const VRWGraph& bpAtProcs = meshSurface_.bpAtProcs();
161  forAllConstIter(Map<label>, globalToLocal, it)
162  {
163  const label bpI = it();
164 
165  forAllRow(bpAtProcs, bpI, i)
166  {
167  const label procI = bpAtProcs(bpI, i);
168 
169  if( procI == Pstream::myProcNo() )
170  continue;
171 
172  labelLongList& dts = exchangeData[procI];
173 
174  //- exchange data as follows:
175  //- 1. global point label
176  //- 2. number of feature edges connected to the vertex
177  dts.append(it.key());
178  dts.append(nEdgesAtPoint_[bpI]);
179  }
180  }
181 
182  //- exchange information
183  receivedData.clear();
184  help::exchangeMap(exchangeData, receivedData);
185 
186  //- add the edges from other processors to the points
187  label counter(0);
188  while( counter < receivedData.size() )
189  {
190  const label bpI = globalToLocal[receivedData[counter++]];
191  const label nEdges = receivedData[counter++];
192 
193  nEdgesAtPoint_[bpI] += nEdges;
194  }
195  }
196 
197  //- mark edges and corners
198  forAll(nEdgesAtPoint_, bpI)
199  {
200  if( nEdgesAtPoint_[bpI] > 2 )
201  {
202  corners_.insert(bpI);
203  }
204  else if( nEdgesAtPoint_[bpI] == 2 )
205  {
206  edgePoints_.insert(bpI);
207  }
208  }
209 
210  //- find patches at a surface points
211  pointPatches_.setSize(pointFaces.size());
212  forAll(pointFaces, bpI)
213  {
214  forAllRow(pointFaces, bpI, pfI)
215  pointPatches_.appendIfNotIn(bpI, facePatch_[pointFaces(bpI, pfI)]);
216  }
217 
218  if( Pstream::parRun() )
219  {
220  const Map<label>& globalToLocal =
222  const DynList<label>& bpNeiProcs = meshSurface_.bpNeiProcs();
223  const VRWGraph& bpAtProcs = meshSurface_.bpAtProcs();
224 
225  std::map<label, labelLongList> exchangeData;
226  forAll(bpNeiProcs, i)
227  exchangeData[bpNeiProcs[i]].clear();
228 
229  forAllConstIter(Map<label>, globalToLocal, it)
230  {
231  const label bpI = it();
232 
233  forAllRow(bpAtProcs, bpI, i)
234  {
235  const label neiProc = bpAtProcs(bpI, i);
236 
237  if( neiProc == Pstream::myProcNo() )
238  continue;
239 
240  labelLongList& data = exchangeData[neiProc];
241 
242  data.append(it.key());
243  data.append(pointPatches_.sizeOfRow(bpI));
244  forAllRow(pointPatches_, bpI, i)
245  data.append(pointPatches_(bpI, i));
246  }
247  }
248 
249  //- exchange data with other prcessors
250  labelLongList receivedData;
251  help::exchangeMap(exchangeData, receivedData);
252 
253  label counter(0);
254  while( counter < receivedData.size() )
255  {
256  const label bpI = globalToLocal[receivedData[counter++]];
257  const label size = receivedData[counter++];
258 
259  for(label i=0;i<size;++i)
260  pointPatches_.appendIfNotIn(bpI, receivedData[counter++]);
261  }
262  }
263 
264  label counter = corners_.size();
265  reduce(counter, sumOp<label>());
266  Info << "Found " << counter
267  << " corners at the surface of the volume mesh" << endl;
268  counter = edgePoints_.size();
269  reduce(counter, sumOp<label>());
270  Info << "Found " << counter
271  << " edge points at the surface of the volume mesh" << endl;
272 }
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 } // End namespace Foam
277 
278 // ************************************************************************* //
Foam::meshSurfaceEngine::bpAtProcs
const VRWGraph & bpAtProcs() const
processors which contain the vertex
Definition: meshSurfaceEngineI.H:451
Foam::meshSurfaceEngine::bp
const labelList & bp() const
Definition: meshSurfaceEngineI.H:64
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::meshSurfacePartitioner::facePatch_
const labelList & facePatch_
pointer to face patches
Definition: meshSurfacePartitioner.H:59
Foam::meshSurfacePartitioner::calculateCornersEdgesAndAddressing
void calculateCornersEdgesAndAddressing()
find corners, edge points and addressing
Definition: meshSurfacePartitionerFunctions.C:38
Foam::meshSurfaceEngine::globalToLocalBndEdgeAddressing
const Map< label > & globalToLocalBndEdgeAddressing() const
global boundary edge label to local label. Only for processor edges
Definition: meshSurfaceEngineI.H:510
helperFunctionsPar.H
nPatches
label nPatches
Definition: readKivaGrid.H:402
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::LongList::clear
void clear()
Clear the list, i.e. set next free to zero.
Definition: LongListI.H:230
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::meshSurfaceEngine::bpNeiProcs
const DynList< label > & bpNeiProcs() const
communication matrix for sending point data
Definition: meshSurfaceEngineI.H:470
Foam::meshSurfaceEngine::pointFaces
const VRWGraph & pointFaces() const
Definition: meshSurfaceEngineI.H:162
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::Map< label >
Foam::meshSurfacePartitioner::patchPatches_
List< labelHashSet > patchPatches_
patch-patches addressing
Definition: meshSurfacePartitioner.H:71
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::VRWGraph::appendIfNotIn
void appendIfNotIn(const label rowI, const label)
Append an element to the given row if it does not exist there.
Definition: VRWGraphI.H:346
Foam::meshSurfacePartitioner::pointPatches_
VRWGraph pointPatches_
patches at a surface point
Definition: meshSurfacePartitioner.H:62
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::LongList< label >
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::meshSurfacePartitioner::corners_
labelHashSet corners_
labels of corner points
Definition: meshSurfacePartitioner.H:65
Foam::localMax
LocalMax-mean differencing scheme class.
Definition: localMax.H:54
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::meshSurfacePartitioner::featureEdges_
labelHashSet featureEdges_
labels of feature edges
Definition: meshSurfacePartitioner.H:77
Foam::Info
messageStream Info
Foam::meshSurfaceEngine::otherEdgeFaceAtProc
const Map< label > & otherEdgeFaceAtProc() const
Definition: meshSurfaceEngineI.H:568
Foam::meshSurfaceEngine::beNeiProcs
const DynList< label > & beNeiProcs() const
communication matrix for sending edge data
Definition: meshSurfaceEngineI.H:549
Foam::VRWGraph::size
label size() const
Returns the number of rows.
Definition: VRWGraphI.H:122
Foam::VRWGraph::setSize
void setSize(const label)
Reset the number of rows.
Definition: VRWGraphI.H:132
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
Foam::meshSurfacePartitioner::edgePoints_
labelHashSet edgePoints_
labels of edge points
Definition: meshSurfacePartitioner.H:68
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::meshSurfaceEngine::edgeFaces
const VRWGraph & edgeFaces() const
Definition: meshSurfaceEngineI.H:334
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::DynList< label >
Foam::meshSurfaceEngine::edges
const edgeList & edges() const
Definition: meshSurfaceEngineI.H:296
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::meshSurfacePartitioner::meshSurface_
const meshSurfaceEngine & meshSurface_
reference to mesh surface engine
Definition: meshSurfacePartitioner.H:56
Foam::sumOp
Definition: ops.H:162
Foam::HashTable::clear
void clear()
Clear all entries from table.
Definition: HashTable.C:473
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::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
Foam::help::exchangeMap
void exchangeMap(const std::map< label, ListType > &m, LongList< T > &data, const Pstream::commsTypes commsType)
Definition: helperFunctionsPar.C:129
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::meshSurfacePartitioner::nEdgesAtPoint_
labelList nEdgesAtPoint_
number of edges attached to a surface point
Definition: meshSurfacePartitioner.H:74
Foam::meshSurfaceEngine::boundaryPoints
const labelList & boundaryPoints() const
Definition: meshSurfaceEngineI.H:84
Foam::meshSurfaceEngine::globalToLocalBndPointAddressing
const Map< label > & globalToLocalBndPointAddressing() const
global point label to local label. Only for processors points
Definition: meshSurfaceEngineI.H:431
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::labelLongList
LongList< label > labelLongList
Definition: labelLongList.H:46
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
meshSurfacePartitioner.H