meshOctreeAddressingIrregularConnections.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 "meshOctreeAddressing.H"
29 #include "meshOctree.H"
30 #include "demandDrivenData.H"
31 #include "helperFunctionsPar.H"
32 
33 #include <map>
34 
35 //#define DEBUGAutoRef
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
45 {
46  Info << "Checking the surface of the selected boxes" << endl;
47 
48  const labelLongList& owner = this->octreeFaceOwner();
49  const labelLongList& neighbour = this->octreeFaceNeighbour();
50  const VRWGraph& faceEdges = this->faceEdges();
51  const VRWGraph& edgeFaces = this->edgeFaces();
52  const VRWGraph& edgeLeaves = this->edgeLeaves();
53  const VRWGraph& pointFaces = this->nodeFaces();
54 
56 
57  boolList boundaryFace(owner.size());
58 
59  label nIrregular;
60  DynList<label> front;
61 
62  do
63  {
64  nIrregular = 0;
65 
66  labelHashSet changedBoxType(100);
67 
68  //- find boundary faces
69  boundaryFace = false;
70 
71  forAll(owner, faceI)
72  {
73  const label own = owner[faceI];
74  const label nei = neighbour[faceI];
75 
76  if( nei < 0 )
77  {
78  continue;
79  }
80  else
81  {
82 
83  if(
84  ((boxType[nei] & BOUNDARY) && (boxType[own] & MESHCELL))
85  || ((boxType[own] & BOUNDARY) && (boxType[nei] & MESHCELL))
86  )
87  boundaryFace[faceI] = true;
88  }
89  }
90 
91  //- remove irregular connections over edges
92  forAll(edgeFaces, edgeI)
93  {
94  label nBoundaryFaces(0);
95  forAllRow(edgeFaces, edgeI, efI)
96  {
97  const label faceI = edgeFaces(edgeI, efI);
98 
99  if( boundaryFace[faceI] )
100  ++nBoundaryFaces;
101  }
102 
103  if( nBoundaryFaces > 2 )
104  {
105  ++nIrregular;
106  forAllRow(edgeLeaves, edgeI, elI)
107  {
108  const label leafI = edgeLeaves(edgeI, elI);
109  boxType[leafI] = BOUNDARY;
110  changedBoxType.insert(leafI);
111  }
112  }
113  }
114 
115  //- check if there exist two or more boundary face groups
116  //- connected to a vertex
117  forAll(pointFaces, pI)
118  {
119  //- find boundary faces connected to the vertex
120  labelHashSet bndFacesAtNode(pointFaces.sizeOfRow(pI));
121  forAllRow(pointFaces, pI, pfI)
122  {
123  const label faceI = pointFaces(pI, pfI);
124  if( boundaryFace[faceI] )
125  bndFacesAtNode.insert(faceI);
126  }
127 
128  //- find the number of face groups at a given vertex
129  label nGroups(0);
130  bool watertightSurface(true);
131  while( bndFacesAtNode.size() != 0 )
132  {
133  front.clear();
134  front.append(bndFacesAtNode.begin().key());
135  bndFacesAtNode.erase(front[0]);
136 
137  while( front.size() != 0 )
138  {
139  const label fLabel = front.removeLastElement();
140 
141  forAllRow(faceEdges, fLabel, feI)
142  {
143  const label eI = faceEdges(fLabel, feI);
144 
145  bool found(false);
146  forAllRow(edgeFaces, eI, efI)
147  {
148  const label fJ = edgeFaces(eI, efI);
149 
150  if( bndFacesAtNode.found(fJ) )
151  {
152  found = true;
153  front.append(fJ);
154  bndFacesAtNode.erase(fJ);
155  }
156  }
157 
158  if( !found )
159  {
160  watertightSurface = false;
161  break;
162  }
163  }
164  }
165 
166  ++nGroups;
167  }
168 
169  if( watertightSurface && (nGroups > 1) )
170  {
171  ++nIrregular;
172 
173  //- this vertex has two groups of faces connected to it
174  forAllRow(pointFaces, pI, pfI)
175  {
176  const label faceI = pointFaces(pI, pfI);
177  if( boundaryFace[faceI] )
178  {
179  //- set BOUNDARY flag to all boxes connected to it
180  if( boxType[owner[faceI]] & MESHCELL )
181  {
182  changedBoxType.insert(owner[faceI]);
183  boxType[owner[faceI]] = BOUNDARY;
184  }
185 
186  if( neighbour[faceI] == -1 )
187  continue;
188 
189  if( boxType[neighbour[faceI]] & MESHCELL )
190  {
191  changedBoxType.insert(neighbour[faceI]);
192  boxType[neighbour[faceI]] = BOUNDARY;
193  }
194  }
195  }
196  }
197  }
198 
199  reduce(nIrregular, sumOp<label>());
200  Info << nIrregular << " surface connections found!" << endl;
201 
202  if( Pstream::parRun() && (nIrregular != 0) )
203  {
205  forAllConstIter(labelHashSet, changedBoxType, it)
206  exchangeData.append(octree_.returnLeaf(it.key()).coordinates());
207 
210  (
211  exchangeData,
212  receivedData
213  );
214 
215  forAll(receivedData, i)
216  {
217  const label leafI =
218  octree_.findLeafLabelForPosition(receivedData[i]);
219  if( leafI < 0 )
220  continue;
221 
222  boxType[leafI] = BOUNDARY;
223  }
224  }
225 
226  } while( nIrregular != 0 );
227 
230  clearAddressing();
231 
232  Info << "Finished checking the surface of the selected boxes" << endl;
233 }
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 } // End namespace Foam
238 
239 // ************************************************************************* //
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
helperFunctionsPar.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshOctreeAddressing::checkAndFixIrregularConnections
void checkAndFixIrregularConnections()
Definition: meshOctreeAddressingIrregularConnections.C:44
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::meshOctreeAddressing::clearAddressing
void clearAddressing()
Definition: meshOctreeAddressing.C:73
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
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::DynList::removeLastElement
T removeLastElement()
Return and remove the last element.
Definition: DynListI.H:384
Foam::meshOctreeAddressing::clearNodeAddressing
void clearNodeAddressing()
Definition: meshOctreeAddressing.C:51
Foam::meshOctreeAddressing::octreeFaceOwner
const labelLongList & octreeFaceOwner() const
return owners of octree faces
Definition: meshOctreeAddressingI.H:110
Foam::meshOctreeCubeBasic::coordinates
const meshOctreeCubeCoordinates & coordinates() const
return coordinates in the octree
Definition: meshOctreeCubeBasicI.H:90
meshOctree.H
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::LongList< label >
Foam::meshOctree::findLeafLabelForPosition
label findLeafLabelForPosition(const meshOctreeCubeCoordinates &) const
return leaf cube for the given position
Definition: meshOctreeNeighbourSearches.C:516
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::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::Info
messageStream Info
Foam::meshOctree::exchangeRequestsWithNeighbourProcessors
void exchangeRequestsWithNeighbourProcessors(const LongList< meshOctreeCubeCoordinates > &dataToSend, LongList< meshOctreeCubeCoordinates > &dataToReceive) const
exchange requests with other processors generating the octree
Definition: meshOctreeParallelCommunication.C:41
Foam::meshOctreeAddressing::boxTypePtr_
List< direction > * boxTypePtr_
identify which boxes should be used as mesh cells
Definition: meshOctreeAddressing.H:84
Foam::HashTable::erase
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
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::meshOctreeAddressing::clearOctreeFaces
void clearOctreeFaces()
Definition: meshOctreeAddressing.C:66
Foam::meshOctreeAddressing::MESHCELL
@ MESHCELL
Definition: meshOctreeAddressing.H:234
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::meshOctreeAddressing::nodeFaces
const VRWGraph & nodeFaces() const
return node-faces addressing
Definition: meshOctreeAddressingI.H:142
Foam::meshOctreeAddressing::edgeLeaves
const VRWGraph & edgeLeaves() const
return edge-leaves addressing
Definition: meshOctreeAddressingI.H:158
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshOctreeAddressing.H
Foam::DynList< label >
Foam::meshOctreeAddressing::faceEdges
const VRWGraph & faceEdges() const
return face-edges addressing
Definition: meshOctreeAddressingI.H:182
Foam::meshOctreeAddressing::octreeFaceNeighbour
const labelLongList & octreeFaceNeighbour() const
return neighbours of octree faces
Definition: meshOctreeAddressingI.H:118
Foam::meshOctreeAddressing::BOUNDARY
@ BOUNDARY
Definition: meshOctreeAddressing.H:235
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::meshOctreeAddressing::boxType
const List< direction > & boxType() const
return which octree boxes are used for mesh creation
Definition: meshOctreeAddressingI.H:68
Foam::HashTable::begin
iterator begin()
Iterator set to the beginning of the HashTable.
Definition: HashTableI.H:417
Foam::sumOp
Definition: ops.H:162
Foam::List< direction >
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::meshOctreeAddressing::octree_
const meshOctree & octree_
reference to the octree
Definition: meshOctreeAddressing.H:63
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::meshOctree::returnLeaf
const meshOctreeCubeBasic & returnLeaf(const label) const
Definition: meshOctreeI.H:60
Foam::DynList::clear
void clear()
Clear the list, i.e. set next free to zero.
Definition: DynListI.H:279
Foam::meshOctreeAddressing::edgeFaces
const VRWGraph & edgeFaces() const
return edge-faces addressing
Definition: meshOctreeAddressingI.H:190
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304