checkCellConnectionsOverFaces.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 
29 #include "labelLongList.H"
30 #include "labelledPair.H"
31 
32 # ifdef USE_OMP
33 #include <omp.h>
34 # endif
35 
36 #include <set>
37 #include <map>
38 
39 #include "helperFunctions.H"
40 
41 //#define DEBUGCheck
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // * * * * * * * * * * Private member functions * * * * * * * * * * * * * * * //
49 
50 namespace meshConnectionsHelper
51 {
52 
54 {
56 
57 public:
58 
60  :
61  mesh_(mesh)
62  {}
63 
64  label size() const
65  {
66  return mesh_.cells().size();
67  }
68 
69  void operator()(const label cellI, DynList<label>& neighbourCells) const
70  {
71  neighbourCells.clear();
72 
73  const labelList& owner = mesh_.owner();
74  const labelList& neighbour = mesh_.neighbour();
75 
76  const cell& c = mesh_.cells()[cellI];
77 
78  forAll(c, fI)
79  {
80  label nei = owner[c[fI]];
81 
82  if( nei == cellI )
83  nei = neighbour[c[fI]];
84 
85  if( nei >= 0 )
86  neighbourCells.append(nei);
87  }
88  }
89 
90  template<class labelListType>
91  void collectGroups
92  (
93  std::map<label, DynList<label> >& neiGroups,
94  const labelListType& elementInGroup,
95  const DynList<label>& localGroupLabel
96  ) const
97  {
98  const PtrList<processorBoundaryPatch>& procBoundaries =
100  const labelList& owner = mesh_.owner();
101 
102  //- send the data to other processors
103  forAll(procBoundaries, patchI)
104  {
105  const label start = procBoundaries[patchI].patchStart();
106  const label size = procBoundaries[patchI].patchSize();
107 
108  labelList groupOwner(procBoundaries[patchI].patchSize());
109  for(label faceI=0;faceI<size;++faceI)
110  {
111  const label groupI = elementInGroup[owner[start+faceI]];
112 
113  if( groupI < 0 )
114  {
115  groupOwner[faceI] = -1;
116  continue;
117  }
118 
119  groupOwner[faceI] = localGroupLabel[groupI];
120  }
121 
122  OPstream toOtherProc
123  (
125  procBoundaries[patchI].neiProcNo(),
126  groupOwner.byteSize()
127  );
128 
129  toOtherProc << groupOwner;
130  }
131 
132  //- receive data from other processors
133  forAll(procBoundaries, patchI)
134  {
135  const label start = procBoundaries[patchI].patchStart();
136 
137  labelList receivedData;
138 
139  IPstream fromOtherProc
140  (
142  procBoundaries[patchI].neiProcNo()
143  );
144 
145  fromOtherProc >> receivedData;
146 
147  forAll(receivedData, faceI)
148  {
149  if( receivedData[faceI] < 0 )
150  continue;
151 
152  const label groupI = elementInGroup[owner[start+faceI]];
153 
154  if( groupI < 0 )
155  continue;
156 
157  DynList<label>& ng = neiGroups[localGroupLabel[groupI]];
158 
159  //- store the connection over the inter-processor boundary
160  ng.appendIfNotIn(receivedData[faceI]);
161  }
162  }
163  }
164 };
165 
167 {
168 
169 public:
170 
172  {}
173 
174  bool operator()(const label /*cellI*/) const
175  {
176  return true;
177  }
178 };
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace meshConnectionsHelper
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
187 {
188  Info << "Checking cell connections" << endl;
189 
190  mesh_.owner();
191  nGroups_ =
193  (
194  cellGroup_,
197  );
198 
199  Info << "Finished checking cell connections" << endl;
200 }
201 
202 // * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * //
203 // Constructors
204 
206 :
207  mesh_(mesh),
208  cellGroup_(mesh.cells().size(), -1),
209  nGroups_(0)
210 {
211  findCellGroups();
212 }
213 
214 // * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * * * * //
215 
217 {}
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
222 {
223  if( nGroups_ == 1 )
224  return false;
225 
226  Warning << "Mesh has " << nGroups_ << " unconnected regions" << endl;
227 
228  labelList nCellsInGroup(nGroups_, 0);
229 
230  forAll(cellGroup_, cI)
231  ++nCellsInGroup[cellGroup_[cI]];
232 
233  if( Pstream::parRun() )
234  {
235  forAll(nCellsInGroup, groupI)
236  reduce(nCellsInGroup[groupI], sumOp<label>());
237  }
238 
239  //- find groups which has most cells this group will be kept
240  label maxGroup(-1);
241  forAll(nCellsInGroup, groupI)
242  if( nCellsInGroup[groupI] > maxGroup )
243  {
244  maxGroup = nCellsInGroup[groupI];
245  nGroups_ = groupI;
246  }
247 
248  //- remove cells which are not in the group which has max num of cells
249  boolList removeCell(mesh_.cells().size(), false);
250  forAll(cellGroup_, cellI)
251  if( cellGroup_[cellI] != nGroups_ )
252  removeCell[cellI] = true;
253 
255 
256  return true;
257 }
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 } // End namespace Foam
262 
263 // ************************************************************************* //
Foam::polyMeshGenFaces::neighbour
const labelList & neighbour() const
Definition: polyMeshGenFacesI.H:86
Foam::polyMeshGenFaces::owner
const labelList & owner() const
owner and neighbour cells for faces
Definition: polyMeshGenFacesI.H:67
Foam::checkCellConnectionsOverFaces::cellGroup_
labelList cellGroup_
Definition: checkCellConnectionsOverFaces.H:57
Foam::checkCellConnectionsOverFaces::checkCellGroups
bool checkCellGroups()
Definition: checkCellConnectionsOverFaces.C:221
Foam::checkCellConnectionsOverFaces::mesh_
polyMeshGen & mesh_
Reference to polyMeshGen.
Definition: checkCellConnectionsOverFaces.H:52
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:50
Foam::meshConnectionsHelper::meshConnectionsSelectorOperator
Definition: checkCellConnectionsOverFaces.C:166
Foam::Warning
messageStream Warning
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::meshConnectionsHelper::meshConnectionsSelectorOperator::meshConnectionsSelectorOperator
meshConnectionsSelectorOperator()
Definition: checkCellConnectionsOverFaces.C:171
Foam::meshConnectionsHelper::meshConnectionsNeighbourOperator::meshConnectionsNeighbourOperator
meshConnectionsNeighbourOperator(const polyMeshGen &mesh)
Definition: checkCellConnectionsOverFaces.C:59
Foam::checkCellConnectionsOverFaces::checkCellConnectionsOverFaces
checkCellConnectionsOverFaces(const checkCellConnectionsOverFaces &)
Disallow default bitwise copy construct.
Foam::meshConnectionsHelper::meshConnectionsNeighbourOperator::operator()
void operator()(const label cellI, DynList< label > &neighbourCells) const
Definition: checkCellConnectionsOverFaces.C:69
Foam::checkCellConnectionsOverFaces::nGroups_
label nGroups_
number of groups
Definition: checkCellConnectionsOverFaces.H:60
Foam::UPstream::blocking
@ blocking
Definition: UPstream.H:66
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
labelledPair.H
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::help::groupMarking
label groupMarking(labelListType &elementInGroup, const neiOp &neighbourCalculator, const filterOp &selector)
Definition: helperFunctionsFrontalMarking.C:155
Foam::Info
messageStream Info
Foam::polyMeshGenCells::cells
const cellListPMG & cells() const
access to cells
Definition: polyMeshGenCellsI.H:39
Foam::DynList::appendIfNotIn
void appendIfNotIn(const T &e)
Definition: DynListI.H:324
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::meshConnectionsHelper::meshConnectionsNeighbourOperator::size
label size() const
Definition: checkCellConnectionsOverFaces.C:64
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynList< label >
Foam::polyMeshGenModifier
Definition: polyMeshGenModifier.H:52
Foam::sumOp
Definition: ops.H:162
helperFunctions.H
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::meshConnectionsHelper::meshConnectionsNeighbourOperator::mesh_
const polyMeshGen & mesh_
Definition: checkCellConnectionsOverFaces.C:55
Foam::polyMeshGenFaces::procBoundaries
const PtrList< processorBoundaryPatch > & procBoundaries() const
inter-processor boundaries
Definition: polyMeshGenFacesI.H:106
Foam::meshConnectionsHelper::meshConnectionsNeighbourOperator::collectGroups
void collectGroups(std::map< label, DynList< label > > &neiGroups, const labelListType &elementInGroup, const DynList< label > &localGroupLabel) const
Definition: checkCellConnectionsOverFaces.C:92
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:50
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::meshConnectionsHelper::meshConnectionsNeighbourOperator
Definition: checkCellConnectionsOverFaces.C:53
Foam::meshConnectionsHelper::meshConnectionsSelectorOperator::operator()
bool operator()(const label) const
Definition: checkCellConnectionsOverFaces.C:174
checkCellConnectionsOverFaces.H
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::checkCellConnectionsOverFaces::~checkCellConnectionsOverFaces
~checkCellConnectionsOverFaces()
Definition: checkCellConnectionsOverFaces.C:216
Foam::DynList::clear
void clear()
Clear the list, i.e. set next free to zero.
Definition: DynListI.H:279
Foam::cellListPMG::size
label size() const
return the number of used elements
Definition: cellListPMGI.H:56
Foam::polyMeshGenModifier::removeCells
void removeCells(const boolList &removeCell, const bool removeProcFaces=true)
remove cells
Definition: polyMeshGenModifierRemoveCells.C:41
Foam::checkCellConnectionsOverFaces::findCellGroups
void findCellGroups()
decompose marked cells
Definition: checkCellConnectionsOverFaces.C:186
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304