meshUntanglerCutRegionFaces.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 
31 //#define DEBUGSmooth
32 
33 # ifdef DEBUGSmooth
34 #include "helperFunctions.H"
35 # endif
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
45 {
46  #ifdef DEBUGSmooth
47  Info << "Finding new faces " << endl;
48  #endif
49 
50  bool finished;
51  do
52  {
53  finished = true;
54 
55  const DynList<DynList<label, 8>, 64>& fcs = *facesPtr_;
56  DynList<edge, 128>& cEdges = *cEdgesPtr_;
57 
59  DynList<DynList<label, 8>, 64>& cFaces = *cFacesPtr_;
60 
61  DynList<label, 8> faceInPlane;
62 
63  DynList<label, 64> pointUsage;
64  pointUsage.setSize(cPtsPtr_->size());
65 
66  forAll(fcs, fI)
67  {
68  const DynList<label, 8>& f = fcs[fI];
69 
70  # ifdef DEBUGSmooth
71  Info << "Creating new face from face " << fI
72  << " consisting of edges " << f << endl;
73  # endif
74 
75  pointUsage = 0;
76 
77  DynList<label, 8> newFace;
78 
79  forAll(f, eI)
80  {
81  # ifdef DEBUGSmooth
82  const DynList<edge>& edges = *edgesPtr_;
83  Info << "Vertex types for face edge " << eI << " are "
84  << label(vertexTypes_[edges[f[eI]].start()]) << " and "
85  << label(vertexTypes_[edges[f[eI]].end()]) << endl;
86  # endif
87 
88  const label edgeLabel = newEdgeLabel_[f[eI]];
89 
90  if( edgeLabel != -1 )
91  {
92  # ifdef DEBUGSmooth
93  Info << "Orig edge " << eI << " " << edges[f[eI]]
94  << " is replaced with " << cEdges[edgeLabel] << endl;
95  # endif
96 
97  const edge& e = cEdges[edgeLabel];
98  ++pointUsage[e[0]];
99  ++pointUsage[e[1]];
100  newFace.append(edgeLabel);
101  }
102  }
103 
104  if( newFace.size() > 1 )
105  {
106  DynList<label, 4> newEdge;
107  forAll(pointUsage, pI)
108  if( pointUsage[pI] == 1 )
109  newEdge.append(pI);
110 
111  if( newEdge.size() == 2 )
112  {
113  # ifdef DEBUGSmooth
114  Info << "Storing new edge " << newEdge << endl;
115  # endif
116 
117  newFace.append(cEdges.size());
118  cEdges.append(edge(newEdge[0], newEdge[1]));
119  }
120  else if( newEdge.size() > 2 )
121  {
122  # ifdef DEBUGSmooth
123  Info << "New edge " << newEdge << endl;
124  # endif
125 
126  tieBreak(f);
127  if( !valid_ ) return;
128  finished = false;
129  break;
130 
132  (
133  "void meshUntangler::cutRegion::findNewFaces()"
134  ) << "Edge has more than two nodes!"
135  << abort(FatalError);
136  }
137 
138  cFaces.append(newFace);
139  }
140  }
141 
142  if( !finished ) continue;
143 
144  //- find edges which form the faceInPlane
145  DynList<label, 128> edgeUsage;
146  edgeUsage.setSize(cEdges.size());
147  edgeUsage = 0;
148  forAll(cFaces, fI)
149  {
150  const DynList<label, 8>& f = cFaces[fI];
151 
152  forAll(f, eI)
153  ++edgeUsage[f[eI]];
154  }
155 
156  forAll(edgeUsage, eI)
157  if( edgeUsage[eI] == 1 )
158  faceInPlane.append(eI);
159 
160  if( faceInPlane.size() > 2 )
161  {
162  # ifdef DEBUGSmooth
163  Info << "Adding face in plane " << faceInPlane << endl;
164  Info << "Face in plane consists of edges " << endl;
165  forAll(faceInPlane, eI)
166  Info << "Edge " << eI << " is "
167  << cEdges[faceInPlane[eI]] << endl;
168  # endif
169 
170  cFaces.append(faceInPlane);
171  }
172 
173  # ifdef DEBUGSmooth
174  Info << "cEdges " << cEdges << endl;
175  Info << "Number of faces before cutting " << fcs.size() << endl;
176  Info << "Found " << cFaces.size() << " new faces" << endl;
177  forAll(fcs, fI)
178  {
179  Info << "Old face " << fI << " contains edges " << fcs[fI] << endl;
180  }
181 
182  forAll(cFaces, fI)
183  {
184  Info << "New face " << fI << " contains edges " << cFaces[fI] << endl;
185  }
186 
187  //- test if the region is closed
188  List<DynList<label, 4> > eFaces(cEdges.size());
189  forAll(cFaces, fI)
190  {
191  const DynList<label, 8>& f = cFaces[fI];
192  forAll(f, eI)
193  eFaces[f[eI]].append(fI);
194  }
195 
196  if( eFaces.size() > 5 )
197  forAll(eFaces, fI)
198  if( eFaces[fI].size() != 2 )
199  {
200  Info << "eFaces " << eFaces << endl;
201  Info << "cEdges " << cEdges << endl;
202  Info << "cFaces " << cFaces << endl;
203 
205  (
206  "void meshOptimizer::meshUntangler::"
207  "cutRegion::findNewFaces()"
208  ) << "Cell is not topologically closed!" << abort(FatalError);
209  }
210  # endif
211 
212  } while( !finished );
213 }
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace Foam
218 
219 // ************************************************************************* //
Foam::meshUntangler::cutRegion::vertexTypes_
DynList< direction, 64 > vertexTypes_
Definition: meshUntangler.H:74
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.
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
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::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::List::append
void append(const T &)
Append an element at the end of the list.
Foam::Info
messageStream Info
Foam::meshUntangler::cutRegion::cFacesPtr_
DynList< DynList< label, 8 >, 64 > * cFacesPtr_
Definition: meshUntangler.H:70
Foam::meshUntangler::cutRegion::newEdgeLabel_
DynList< label, 128 > newEdgeLabel_
Definition: meshUntangler.H:75
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::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
Foam::meshUntangler::cutRegion::cPtsPtr_
DynList< point, 64 > * cPtsPtr_
helper data
Definition: meshUntangler.H:68
Foam::meshUntangler::cutRegion::findNewFaces
void findNewFaces()
Definition: meshUntanglerCutRegionFaces.C:44
helperFunctions.H
f
labelList f(nPoints)
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::DynList::setSize
void setSize(const label)
Reset size of List.
Definition: DynListI.H:263
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304