meshOctreeAddressingGluedMesh.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 "IOdictionary.H"
30 #include "meshOctree.H"
31 #include "demandDrivenData.H"
32 
33 //#define DEBUGAutoRef
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
43 {
44  if( !useDATABoxes_ )
45  return;
46 
47  if( meshDict_.found("checkForGluedMesh") )
48  {
49  if( !readBool(meshDict_.lookup("checkForGluedMesh")) )
50  return;
51  }
52  else
53  {
54  return;
55  }
56 
57  Info << "Removing glued regions" << endl;
58  const List<direction>& boxType = this->boxType();
59  const VRWGraph& nodeLabels = this->nodeLabels();
60  const List<direction>& nodeType = this->nodeType();
61 
62  const VRWGraph& edgeLeaves = this->edgeLeaves();
63  const VRWGraph& leafEdges = this->leafEdges();
64  const FRWGraph<label, 8>& nodeLeaves = this->nodeLeaves();
65  const LongList<edge>& edges = this->octreeEdges();
66 
67  DynList<label> neighbours;
68  labelLongList removeBox;
69  forAll(boxType, leafI)
70  {
71  if(
73  (boxType[leafI] & MESHCELL)
74  )
75  {
76  //- mark the initial INNERNODE
77  labelHashSet innerNodes;
78  forAllRow(nodeLabels, leafI, nodeI)
79  if( nodeType[nodeLabels(leafI, nodeI)] & INNERNODE )
80  {
81  innerNodes.insert(nodeLabels(leafI, nodeI));
82  break;
83  }
84 
85  //- mark all INNERNODEs for which it is possible to walk along
86  //- cubes edges without crossing any boundary
87  bool finished;
88  do
89  {
90  finished = true;
91 
92  forAllRow(leafEdges, leafI, leI)
93  {
94  const label edgeI = leafEdges(leafI, leI);
95  const edge& edg = edges[edgeI];
96  const label s = edg[0];
97  const label e = edg[1];
98 
99  if(
100  (nodeType[s] & INNERNODE) && (nodeType[e] & INNERNODE)
101  && (innerNodes.found(s) ^ innerNodes.found(e))
102  )
103  {
104  bool foundInside(false);
105  forAllRow(edgeLeaves, edgeI, elI)
106  {
107  const label ecLabel = edgeLeaves(edgeI, elI);
108  if( ecLabel < 0 )
109  continue;
110  if( octree_.hasContainedTriangles(ecLabel) )
111  continue;
112  if(
113  !(
114  octree_.returnLeaf(ecLabel).cubeType() &
116  )
117  )
118  continue;
119 
120  foundInside = true;
121  break;
122  }
123 
124  if( foundInside )
125  {
126  innerNodes.insert(s);
127  innerNodes.insert(e);
128  finished = false;
129  }
130  }
131  }
132 
133  } while( !finished );
134 
135  labelHashSet permissibleNeighbours;
136  forAllConstIter(labelHashSet, innerNodes, it)
137  {
138  const label nodeI = it.key();
139  forAllRow(nodeLeaves, nodeI, nlI)
140  permissibleNeighbours.insert(nodeLeaves(nodeI, nlI));
141  }
142 
143  if( permissibleNeighbours.size() )
144  {
145  for(label i=0;i<6;++i)
146  {
147  neighbours.clear();
148  octree_.findNeighboursInDirection(leafI, i, neighbours);
149 
150  forAll(neighbours, neiI)
151  {
152  const label nei = neighbours[neiI];
153  if( nei < 0 )
154  continue;
155  if( !(boxType[nei] & MESHCELL) )
156  continue;
157  if( !permissibleNeighbours.found(nei) )
158  {
159  removeBox.append(leafI);
160  break;
161  }
162  }
163  }
164  }
165  else
166  {
167  removeBox.append(leafI);
168  }
169  }
170  }
171 
172  forAll(removeBox, i)
173  (*boxTypePtr_)[removeBox[i]] = BOUNDARY;
174 
175  if( Pstream::parRun() )
176  {
178  forAll(removeBox, i)
179  {
180  const meshOctreeCubeBasic& oc = octree_.returnLeaf(removeBox[i]);
181  checkBoundary.append(oc.coordinates());
182  }
183 
184  LongList<meshOctreeCubeCoordinates> receivedBoundary;
186  (
187  checkBoundary,
188  receivedBoundary
189  );
190 
191  forAll(receivedBoundary, i)
192  {
193  const label cLabel =
194  octree_.findLeafLabelForPosition(receivedBoundary[i]);
195  if( cLabel < 0 )
196  continue;
197  (*boxTypePtr_)[cLabel] = BOUNDARY;
198  }
199  }
200 
201  Info << "Finished removing glued regions" << endl;
202 }
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 } // End namespace Foam
207 
208 // ************************************************************************* //
Foam::meshOctreeAddressing::checkGluedRegions
void checkGluedRegions()
check if distinct parts are glued together
Definition: meshOctreeAddressingGluedMesh.C:42
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::meshOctreeAddressing::nodeType
const List< direction > & nodeType() const
return type of node (INNERNODE,or OUTERNODE)
Definition: meshOctreeAddressingI.H:94
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshOctreeAddressing::useDATABoxes_
bool useDATABoxes_
use DATA boxes
Definition: meshOctreeAddressing.H:69
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::meshOctreeAddressing::nodeLabels
const VRWGraph & nodeLabels() const
return nodeLabels
Definition: meshOctreeAddressingI.H:52
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
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::meshOctreeCubeBasic::cubeType
direction cubeType() const
return type
Definition: meshOctreeCubeBasicI.H:75
Foam::HashSet< label, Hash< label > >
Foam::meshOctreeCubeBasic::coordinates
const meshOctreeCubeCoordinates & coordinates() const
return coordinates in the octree
Definition: meshOctreeCubeBasicI.H:90
meshOctree.H
Foam::meshOctree::findNeighboursInDirection
void findNeighboursInDirection(const meshOctreeCubeCoordinates &, const label dir, DynList< label > &neighbourLeaves) const
find neighbours over a leaf cube face in the given direction
Definition: meshOctreeNeighbourSearches.C:262
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::meshOctreeAddressing::meshDict_
const dictionary & meshDict_
reference to the dictionary
Definition: meshOctreeAddressing.H:66
Foam::LongList< edge >
Foam::meshOctree::findLeafLabelForPosition
label findLeafLabelForPosition(const meshOctreeCubeCoordinates &) const
return leaf cube for the given position
Definition: meshOctreeNeighbourSearches.C:516
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::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
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
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
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::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::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::DynList< label >
Foam::meshOctreeCubeBasic::INSIDE
@ INSIDE
Definition: meshOctreeCubeBasic.H:91
Foam::meshOctreeAddressing::BOUNDARY
@ BOUNDARY
Definition: meshOctreeAddressing.H:235
IOdictionary.H
Foam::meshOctreeAddressing::INNERNODE
@ INNERNODE
Definition: meshOctreeAddressing.H:237
Foam::meshOctreeAddressing::boxType
const List< direction > & boxType() const
return which octree boxes are used for mesh creation
Definition: meshOctreeAddressingI.H:68
Foam::List< direction >
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::meshOctreeAddressing::octreeEdges
const LongList< edge > & octreeEdges() const
return octree edges, created for MESHCELL boxes
Definition: meshOctreeAddressingI.H:150
Foam::meshOctree::hasContainedTriangles
bool hasContainedTriangles(const label) const
Definition: meshOctreeI.H:72
Foam::meshOctreeAddressing::nodeLeaves
const FRWGraph< label, 8 > & nodeLeaves() const
return nodeLeaves
Definition: meshOctreeAddressingI.H:60
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
Foam::meshOctreeAddressing::octree_
const meshOctree & octree_
reference to the octree
Definition: meshOctreeAddressing.H:63
Foam::meshOctreeAddressing::leafEdges
const VRWGraph & leafEdges() const
return leaf-edges addressing
Definition: meshOctreeAddressingI.H:166
Foam::FRWGraph< label, 8 >
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::meshOctreeCubeBasic
Definition: meshOctreeCubeBasic.H:49