voronoiMeshExtractorAddressing.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 "voronoiMeshExtractor.H"
29 #include "demandDrivenData.H"
30 
31 # ifdef USE_OMP
32 #include <omp.h>
33 # endif
34 
35 //#define DEBUGVoronoi
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
45 {
47  return;
48 
51 
52  edgeTetsPtr_ = new VRWGraph();
54 
55  boundaryEdgePtr_ = new boolList();
56  boolList& boundaryEdges = *boundaryEdgePtr_;
57 
58  edgesPtr_ = new LongList<edge>();
60 
61  //- create edges and edgeTets
62  const LongList<partTet>& tets = tetCreator_.tets();
63 
64  VRWGraph pointTets;
65  pointTets.reverseAddressing(tets);
66 
67  forAll(tets, tetI)
68  {
69  const FixedList<edge, 6> tetEdges = tets[tetI].edges();
70 
71  forAll(tetEdges, eI)
72  {
73  const edge& e = tetEdges[eI];
74  const label start = e.start();
75 
76  const row endTets = pointTets[e.end()];
77 
78  bool store(true);
79 
80  DynList<label> eTets;
81  forAllRow(pointTets, start, ptI)
82  {
83  const label tetJ = pointTets(start, ptI);
84 
85  if( !endTets.contains(tetJ) )
86  continue;
87 
88  if( tetJ < tetI )
89  {
90  store = false;
91  break;
92  }
93 
94  eTets.append(tetJ);
95  }
96 
97  if( store )
98  {
99  edgeTets.appendList(eTets);
100 
101  edges.append(e);
102  }
103  }
104  }
105 
106  # ifdef DEBUGVoronoi
107  Info << "Edge tets " << edgeTets << endl;
108  # endif
109 
110  //- calculate point-edges addressing
112 
113  //- sort edge-tets in circular order
114  boundaryEdges.setSize(edgeTets.size());
115  boundaryEdges = false;
116 
117  # ifdef USE_OMP
118  # pragma omp parallel for schedule(dynamic, 100)
119  # endif
120  forAll(edgeTets, edgeI)
121  {
122  const edge& e = edges[edgeI];
123  row eTets = edgeTets[edgeI];
124 
125  # ifdef DEBUGVoronoi
126  Info << "Edge " << edgeI << " has points " << e << endl;
127  # endif
128 
129  forAll(eTets, tetI)
130  {
131  const partTet& pt = tets[eTets[tetI]];
132 
133  # ifdef DEBUGVoronoi
134  Info << "Checking tet " << eTets[tetI] << " points " << pt << endl;
135  # endif
136 
137  //- find the face shared with the neighbour
138  const FixedList<edge, 6> tetEdges = pt.edges();
139 
140  label searchPoint(-1);
141  forAll(tetEdges, eI)
142  {
143  if( tetEdges[eI] == e )
144  {
145  if( tetEdges[eI].start() == e.start() )
146  {
147  searchPoint = pt[sameOrientation_[eI]];
148  }
149  else
150  {
151  searchPoint = pt[oppositeOrientation_[eI]];
152  }
153 
154  break;
155  }
156  }
157 
158  if( searchPoint < 0 )
160  (
161  "void voronoiMeshExtractor::createAddressing() const"
162  ) << " invalid search point " << abort(FatalError);
163 
164  bool found(false);
165  forAll(eTets, i)
166  {
167  if( tetI == i )
168  continue;
169 
170  const partTet& ptNei = tets[eTets[i]];
171 
172  const label pos = ptNei.whichPosition(searchPoint);
173 
174  if( pos < 0 )
175  continue;
176 
177  if( tetI < eTets.size()-1 )
178  {
179  const label add = eTets[tetI+1];
180  eTets[tetI+1] = eTets[i];
181  eTets[i] = add;
182  }
183  found = true;
184  break;
185  }
186 
187  if( !found )
188  boundaryEdges[edgeI] = true;
189  }
190  }
191 }
192 
194 {
195  if( !pointEdgesPtr_ )
197 
198  return *pointEdgesPtr_;
199 }
200 
202 {
203  if( !edgesPtr_ )
205 
206  return *edgesPtr_;
207 }
208 
210 {
211  if( !edgeTetsPtr_ )
213 
214  return *edgeTetsPtr_;
215 }
216 
218 {
219  if( !boundaryEdgePtr_ )
221 
222  return *boundaryEdgePtr_;
223 }
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace Foam
228 
229 // ************************************************************************* //
Foam::voronoiMeshExtractor::sameOrientation_
static label sameOrientation_[6]
positive orientation
Definition: voronoiMeshExtractor.H:99
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::voronoiMeshExtractor::createAddressing
void createAddressing() const
create and return addressing
Definition: voronoiMeshExtractorAddressing.C:44
voronoiMeshExtractor.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::voronoiMeshExtractor::edgesPtr_
LongList< edge > * edgesPtr_
edges of the tetrahedrization
Definition: voronoiMeshExtractor.H:64
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
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::partTet
Definition: partTet.H:53
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::voronoiMeshExtractor::pointEdges
const VRWGraph & pointEdges() const
Definition: voronoiMeshExtractorAddressing.C:193
Foam::LongList< edge >
Foam::voronoiMeshExtractor::edgeTetsPtr_
VRWGraph * edgeTetsPtr_
tets around each edge
Definition: voronoiMeshExtractor.H:67
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::VRWGraph::size
label size() const
Returns the number of rows.
Definition: VRWGraphI.H:122
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::voronoiMeshExtractor::oppositeOrientation_
static label oppositeOrientation_[6]
opposite orientation
Definition: voronoiMeshExtractor.H:102
Foam::FatalError
error FatalError
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:870
Foam::tetCreatorOctree::tetPoints
const LongList< point > & tetPoints() const
Definition: tetCreatorOctree.H:144
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::partTet::edges
FixedList< edge, 6 > edges() const
Return edges.
Definition: partTetI.H:207
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::boolList
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
Foam::DynList< label >
Foam::graphRow
Definition: graphRow.H:48
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::voronoiMeshExtractor::tetCreator_
tetCreatorOctree tetCreator_
create tets
Definition: voronoiMeshExtractor.H:55
Foam::VRWGraph::reverseAddressing
void reverseAddressing(const label nRows, const GraphType &origGraph)
Definition: VRWGraphI.H:406
Foam::voronoiMeshExtractor::pointEdgesPtr_
VRWGraph * pointEdgesPtr_
edges connected to a vertex in the tet mesh
Definition: voronoiMeshExtractor.H:61
Foam::VRWGraph::appendList
void appendList(const ListType &l)
Append a list as a row at the end of the graph.
Definition: VRWGraphI.H:286
Foam::partTet::whichPosition
label whichPosition(const label) const
find position of the node in the partTet
Definition: partTetI.H:88
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::voronoiMeshExtractor::edges
const LongList< edge > & edges() const
Definition: voronoiMeshExtractorAddressing.C:201
Foam::FixedList
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Foam::voronoiMeshExtractor::boundaryEdge
const boolList & boundaryEdge() const
Definition: voronoiMeshExtractorAddressing.C:217
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::voronoiMeshExtractor::edgeTets
const VRWGraph & edgeTets() const
Definition: voronoiMeshExtractorAddressing.C:209
Foam::graphRow::contains
bool contains(const label e) const
check if the element is in the given row (takes linear time)
Definition: graphRowI.H:104
Foam::tetCreatorOctree::tets
const LongList< partTet > & tets() const
Definition: tetCreatorOctree.H:155
Foam::voronoiMeshExtractor::boundaryEdgePtr_
boolList * boundaryEdgePtr_
is edge at the boundary
Definition: voronoiMeshExtractor.H:70
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:190