fixCollapsedEdges.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Create intermediate mesh files from PROSTAR files
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "starMesh.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 void Foam::starMesh::fixCollapsedEdges()
34 {
35  cellFaces_.setSize(cellShapes_.size());
36 
37  forAll(cellShapes_, celli)
38  {
39  cellFaces_[celli] = cellShapes_[celli].faces();
40  }
41 
42  // go through the faces and find if there exist faces with duplicate
43  // vertices. If so, purge the duplicates and mark the mesh as a polyMesh
44 
45  forAll(cellFaces_, celli)
46  {
47  faceList& curFaces = cellFaces_[celli];
48 
49  forAll(curFaces, facei)
50  {
51  face& vertexLabels = curFaces[facei];
52 
53  bool duplicatesFound = false;
54 
55  forAll(vertexLabels, vI)
56  {
57  label curLabel = vertexLabels[vI];
58 
59  label nFound = 0;
60 
61  forAll(vertexLabels, searchI)
62  {
63  if (vertexLabels[searchI] == curLabel)
64  {
65  nFound++;
66  }
67  }
68 
69  if (nFound > 1)
70  {
71  duplicatesFound = true;
72 
73  break;
74  }
75  }
76 
77  if (duplicatesFound)
78  {
79  // this mesh cannot be described as a shapeMesh
80  isShapeMesh_ = false;
81 
82  // I am not allowed to reset the shape pointer to unknown
83  // here as the shape is still needed to determine which face
84  // of the shape is used in potential couple matches. This
85  // will be done in the end using the purgeShapes()
86  //
87 
88  // create a new face without duplicates and replace original
89  face newFace(vertexLabels.size());
90  label nNewVertices = 0;
91 
92  forAll(vertexLabels, vI)
93  {
94  // In order for a face to be a valid entity, duplicate
95  // vertices can only be consecutive (othervise, the
96  // collapse creates an invalid face). We shall use this
97  // property in the creation of the collapsed face
98 
99  label curLabel = vertexLabels[vI];
100 
101  bool found = false;
102 
103  // search through all vertices from the new face. If the
104  // current label has not been added, add it to the end.
105  for (label searchI = 0; searchI < nNewVertices; searchI++)
106  {
107  if (newFace[searchI] == curLabel)
108  {
109  found = true;
110 
111  break;
112  }
113  }
114 
115  if (!found)
116  {
117  newFace[nNewVertices] = curLabel;
118  nNewVertices++;
119  }
120  }
121 
122  newFace.setSize(nNewVertices);
123 
124  // If the number of non-duplicate labels in the face is less
125  // than three, the face has been collapsed in an invalid
126  // manner. Error.
127 
128  if (nNewVertices < 3)
129  {
131  << "Face " << facei << " of cell " << celli
132  << " is colapsed down to a point or edge, which is "
133  << "not permitted" << endl
134  << "original face: " << vertexLabels << endl
135  << "purged face: " << newFace << endl
136  << abort(FatalError);
137  }
138  else
139  {
140  vertexLabels = newFace;
141  }
142  }
143  }
144  }
145 }
146 
147 
148 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setSize(const label)
Reset size of List.
Definition: List.C:295