meshUntanglerCutRegionPoints.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 "demandDrivenData.H"
29 #include "meshUntangler.H"
30 #include "plane.H"
31 #include "primitiveMesh.H"
32 #include "polyMeshGenModifier.H"
33 #include "helperFunctions.H"
34 
35 //#define DEBUGSmooth
36 
37 #ifdef DEBUGSmooth
38 #include "Time.H"
39 #include "objectRegistry.H"
40 #endif
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
50 (
51  const plane& plane
52 )
53 {
54  #ifdef DEBUGSmooth
55  Info << "Finding new vertices" << endl;
56  #endif
57 
58  const DynList<point, 64>& points = *pointsPtr_;
59 
60  newVertexLabel_.setSize(points.size());
61  newVertexLabel_ = -1;
62 
63  vertexDistance_.setSize(points.size());
64 
65  vertexTypes_.setSize(points.size());
66  vertexTypes_ = direction(NONE);
67 
68  origNumVertices_ = 0;
69 
70  cPtsPtr_ = new DynList<point, 64>();
71 
72  const point& rp = plane.refPoint();
73  const vector& n = plane.normal();
74  forAll(points, pI)
75  {
76  const point& p = points[pI];
77  vertexDistance_[pI] = ((p - rp) & n);
78 
79  if( vertexDistance_[pI] > tol_ )
80  {
81  cPtsPtr_->append(p);
82  newVertexLabel_[pI] = origNumVertices_++;
83  vertexTypes_[pI] |= KEEP;
84  }
85  else if( vertexDistance_[pI] >= -tol_ )
86  {
87  cPtsPtr_->append(p);
88  newVertexLabel_[pI] = origNumVertices_++;
89  vertexTypes_[pI] |= INPLANE;
90  vertexDistance_[pI] = 0.0;
91  }
92  }
93 
94  #ifdef DEBUGSmooth
95  Info << "tolerance " << tol_ << endl;
96  Info << "New number of vertices is " << origNumVertices_ << endl;
97  forAll(points, pI)
98  Info << "Original vertex " << pI << " is " << points[pI]
99  << ". Vertex distance from plane is " << vertexDistance_[pI]
100  << " and its new label is " << newVertexLabel_[pI] << endl;
101  #endif
102 
103  if( origNumVertices_ < points.size() )
104  {
105  return true;
106  }
107  else
108  {
109  deleteDemandDrivenData(cPtsPtr_);
110 
111  return false;
112  }
113 }
114 
116 {
118  DynList<edge, 128>& edges = *edgesPtr_;
119  DynList<label, 64> newLabelForPoint;
120  newLabelForPoint.setSize(points.size());
121  newLabelForPoint = -1;
122 
123  bool found(false);
124  forAll(points, pI)
125  {
126  if( newLabelForPoint[pI] != -1 ) continue;
127  for(label pJ=pI+1;pJ<points.size();++pJ)
128  if( mag(points[pJ] - points[pI]) < tol_ )
129  {
130  # ifdef DEBUGSmooth
131  Info << "Vertices " << pI << " and " << pJ
132  << " are too close" << endl;
133  # endif
134 
135  newLabelForPoint[pJ] = pI;
136  found = true;
137  }
138  }
139 
140  if( !found )
141  return;
142 
143  forAll(edges, eI)
144  {
145  edge& e = edges[eI];
146  if( newLabelForPoint[e.start()] != -1 )
147  e.start() = newLabelForPoint[e.start()];
148  if( newLabelForPoint[e.end()] != -1 )
149  e.end() = newLabelForPoint[e.end()];
150  }
151 
152  //- remove edges which contain the same vertex
153  newEdgeLabel_ = -1;
154  label edgeLabel(0);
155 
157  forAll(edges, eI)
158  if( edges[eI].start() != edges[eI].end() )
159  {
160  cEdgesPtr_->append(edges[eI]);
161  newEdgeLabel_[eI] = edgeLabel++;
162  }
163 
166  cEdgesPtr_ = NULL;
167 
168  //- renumber faces
169  const DynList<DynList<label, 8>, 64>& faces = *facesPtr_;
171  forAll(faces, fI)
172  {
173  const DynList<label, 8>& f = faces[fI];
174 
176 
177  forAll(f, eI)
178  if( newEdgeLabel_[f[eI]] != -1 )
179  nf.append(newEdgeLabel_[f[eI]]);
180 
181  if( nf.size() > 2 )
182  {
183  cFacesPtr_->append(nf);
184  }
185  }
186 
189  cFacesPtr_ = NULL;
190 }
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 } // End namespace Foam
195 
196 // ************************************************************************* //
Foam::plane::normal
const vector & normal() const
Return plane normal.
Definition: plane.C:248
p
p
Definition: pEqn.H:62
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshUntangler::cutRegion::facesPtr_
DynList< DynList< label, 8 >, 64 > * facesPtr_
Definition: meshUntangler.H:65
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
polyMeshGenModifier.H
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::meshUntangler::cutRegion::edgesPtr_
DynList< edge, 128 > * edgesPtr_
Definition: meshUntangler.H:64
objectRegistry.H
Foam::meshUntangler::cutRegion::points
const DynList< point, 64 > & points() const
return the vertices of the feasible region
Definition: meshUntangler.H:115
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::meshUntangler::cutRegion::removeCoincidentVertices
void removeCoincidentVertices()
remove coincident vertices to improve tie breaking
Definition: meshUntanglerCutRegionPoints.C:115
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
n
label n
Definition: TABSMDCalcMethod2.H:31
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
plane.H
Foam::Info
messageStream Info
Foam::meshUntangler::cutRegion::cFacesPtr_
DynList< DynList< label, 8 >, 64 > * cFacesPtr_
Definition: meshUntangler.H:70
Foam::meshUntangler::cutRegion::tol_
scalar tol_
Definition: meshUntangler.H:78
Foam::meshUntangler::cutRegion::newEdgeLabel_
DynList< label, 128 > newEdgeLabel_
Definition: meshUntangler.H:75
meshUntangler.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::DynList
Definition: DynList.H:53
Foam::meshUntangler::cutRegion::cEdgesPtr_
DynList< edge, 128 > * cEdgesPtr_
Definition: meshUntangler.H:69
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::meshUntangler::cutRegion::findNewVertices
bool findNewVertices(const plane &plane)
Definition: meshUntanglerCutRegionPoints.C:50
helperFunctions.H
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::DynList::setSize
void setSize(const label)
Reset size of List.
Definition: DynListI.H:263
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::plane::refPoint
const point & refPoint() const
Return or return plane base point.
Definition: plane.C:255
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::meshUntangler::cutRegion::pointsPtr_
DynList< point, 64 > * pointsPtr_
Definition: meshUntangler.H:63
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304