meshUntanglerCutRegionTieBreak.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 "sortEdgesIntoChains.H"
31 
32 //#define DEBUGSmooth
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
42 {
43  // There must be only one, singly connected region which is cut off
44  // from the feasible region. This may not be the case if one operates in the
45  // range of computer tolerances. In order to resolve the tie it is necessary
46  // to find a single region which will be cut off from the feasible region.
47  // This will be done by finding the node with the most negative distance,
48  // and then start marking vertices connected to that vertex via an edge.
49 
50  # ifdef DEBUGSmooth
51  Info << "Starting tie break" << endl;
52  # endif
53 
54  //- delete pointer data
58 
59  const DynList<edge, 128>& edges = *edgesPtr_;
60 
61  DynList<edge> faceEdges;
62  forAll(f, eI)
63  faceEdges.append(edges[f[eI]]);
64 
65  const DynList<DynList<label> > fvertices =
66  sortEdgesIntoChains(faceEdges).sortedChains();
67  if( fvertices.size() != 1 )
68  {
69  valid_ = false;
70  return;
71 
72  Info << "Face vertices " << fvertices << endl;
74  (
75  "void meshUntangler::cutRegion::tieBreak(const face& f)"
76  ) << "Number of created faces is not 1 but "
77  << fvertices.size() << abort(FatalError);
78  }
79 
80  const DynList<label>& fv = fvertices[0];
81 
82  DynList<label, 64> vertexRegion;
83  vertexRegion.setSize(fv.size());
84  vertexRegion = 0;
85 
86  label region(1);
87  forAll(fv, vI)
88  if( !vertexTypes_[fv[vI]] && !vertexRegion[vI] )
89  {
90  vertexRegion[vI] = region;
91 
92  label fcI = fv.fcIndex(vI);
93  label rcI = fv.rcIndex(vI);
94  bool found;
95  do
96  {
97  found = false;
98  if( !vertexTypes_[fv[fcI]] )
99  {
100  vertexRegion[fcI] = region;
101  fcI = fv.fcIndex(fcI);
102  found = true;
103  }
104 
105  if( !vertexTypes_[fv[rcI]] )
106  {
107  vertexRegion[rcI] = region;
108  rcI = fv.rcIndex(rcI);
109  found = true;
110  }
111  } while( found );
112 
113  ++region;
114  }
115 
116  # ifdef DEBUGSmooth
117  Info << "Tolerance " << tol_ << endl;
118  Info << "Number of regions " << region-1 << endl;
119  Info << "Vertex regions " << vertexRegion << endl;
120  # endif
121 
122  if( region > 2 )
123  {
124  //- there are more than two regions which need to be cut off
125  # ifdef DEBUGSmooth
126  forAll(fv, vI)
127  Info << "Distance for vertex " << fv[vI] << " is "
128  << vertexDistance_[fv[vI]] << endl;
129  # endif
130 
131  //- there should be only one cut-off region
132  //- there this region will be determined by the most negative
133  //- distance from plane
134  scalar minDist(VGREAT);
135  label minRegion(-1);
136  forAll(fv, vI)
137  if( vertexRegion[vI] && (vertexDistance_[fv[vI]] < minDist) )
138  {
139  minDist = vertexDistance_[fv[vI]];
140  minRegion = vertexRegion[vI];
141  }
142 
143  forAll(vertexRegion, vI)
144  if( vertexRegion[vI] && (vertexRegion[vI] != minRegion) )
145  {
146  vertexTypes_[fv[vI]] |= INPLANE;
147  }
148  }
149  else
150  {
151  forAll(fv, vI)
152  if(
153  (vertexTypes_[fv[vI]] & INPLANE) &&
154  !vertexRegion[fv.rcIndex(vI)] &&
155  !vertexRegion[fv.fcIndex(vI)]
156  )
157  {
158  vertexTypes_[fv[vI]] ^= INPLANE;
159  vertexTypes_[fv[vI]] |= KEEP;
160 
161  # ifdef DEBUGSmooth
162  Info << "Node " << vI << " was INPLANE" << endl;
163  Info << "New type " << label(vertexTypes_[fv[vI]]) << endl;
164  # endif
165  }
166  }
167 
168  # ifdef DEBUGSmooth
169  forAll(fv, vI)
170  Info << "Vertex type for vertex " << fv[vI] << " is "
171  << label(vertexTypes_[fv[vI]]) << endl;
172  # endif
173 
174  //- create new points
177  newVertexLabel_ = -1;
178  origNumVertices_ = 0;
179  forAll(points, pI)
180  if( vertexTypes_[pI] )
181  {
182  cPtsPtr_->append(points[pI]);
184  }
185 
186  //- find new edges and continue creating faces
187  findNewEdges();
188 }
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // ************************************************************************* //
Foam::meshUntangler::cutRegion::vertexTypes_
DynList< direction, 64 > vertexTypes_
Definition: meshUntangler.H:74
Foam::meshUntangler::cutRegion::KEEP
@ KEEP
Definition: meshUntangler.H:99
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::sortEdgesIntoChains::sortedChains
const DynList< DynList< label > > & sortedChains() const
a list of points which have not yet been resolved
Definition: sortEdgesIntoChains.C:264
Foam::meshUntangler::cutRegion::edgesPtr_
DynList< edge, 128 > * edgesPtr_
Definition: meshUntangler.H:64
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::meshUntangler::cutRegion::tieBreak
void tieBreak(const DynList< label, 8 > &f)
Definition: meshUntanglerCutRegionTieBreak.C:41
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::meshUntangler::cutRegion::valid_
bool valid_
Definition: meshUntangler.H:79
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::meshUntangler::cutRegion::cFacesPtr_
DynList< DynList< label, 8 >, 64 > * cFacesPtr_
Definition: meshUntangler.H:70
Foam::meshUntangler::cutRegion::tol_
scalar tol_
Definition: meshUntangler.H:78
sortEdgesIntoChains.H
Foam::FatalError
error FatalError
meshUntangler.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::DynList
Definition: DynList.H:53
Foam::meshUntangler::cutRegion::cEdgesPtr_
DynList< edge, 128 > * cEdgesPtr_
Definition: meshUntangler.H:69
Foam::meshUntangler::cutRegion::cPtsPtr_
DynList< point, 64 > * cPtsPtr_
helper data
Definition: meshUntangler.H:68
found
bool found
Definition: TABSMDCalcMethod2.H:32
fv
labelList fv(nPoints)
Foam::meshUntangler::cutRegion::findNewEdges
void findNewEdges()
Definition: meshUntanglerCutRegionEdges.C:40
Foam::sortEdgesIntoChains
Definition: sortEdgesIntoChains.H:49
f
labelList f(nPoints)
Foam::DynList::setSize
void setSize(const label)
Reset size of List.
Definition: DynListI.H:263
Foam::meshUntangler::cutRegion::INPLANE
@ INPLANE
Definition: meshUntangler.H:100
Foam::meshUntangler::cutRegion::pointsPtr_
DynList< point, 64 > * pointsPtr_
Definition: meshUntangler.H:63
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::meshUntangler::cutRegion::newVertexLabel_
DynList< label, 64 > newVertexLabel_
Definition: meshUntangler.H:72
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::meshUntangler::cutRegion::vertexDistance_
DynList< scalar, 64 > vertexDistance_
Definition: meshUntangler.H:73
Foam::meshUntangler::cutRegion::origNumVertices_
label origNumVertices_
Definition: meshUntangler.H:76
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304