Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / mesh / conversion / sammToFoam / fixCollapsedEdges.C
blob194984fb924be46adc0a6b2775cfdae4a0ae5813
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     Create intermediate mesh files from SAMM files
27 \*---------------------------------------------------------------------------*/
29 #include "sammMesh.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 void sammMesh::fixCollapsedEdges()
35     cellFaces_.setSize(cellShapes_.size());
37     forAll (cellShapes_, cellI)
38     {
39         cellFaces_[cellI] = cellShapes_[cellI].faces();
40     }
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
45     forAll (cellFaces_, cellI)
46     {
47         faceList& curFaces = cellFaces_[cellI];
49         forAll (curFaces, faceI)
50         {
51             face& vertexLabels = curFaces[faceI];
53             bool duplicatesFound = false;
55             forAll (vertexLabels, vI)
56             {
57                 label curLabel = vertexLabels[vI];
59                 label nFound = 0;
61                 forAll (vertexLabels, searchI)
62                 {
63                     if (vertexLabels[searchI] == curLabel)
64                     {
65                         nFound++;
66                     }
67                 }
69                 if (nFound > 1)
70                 {
71                     duplicatesFound = true;
73                     break;
74                 }
75             }
77             if (duplicatesFound)
78             {
79                 // this mesh cannot be described as a shapeMesh
80                 isShapeMesh_ = false;
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                 //
88                 // create a new face without duplicates and replace original
89                 face newFace(vertexLabels.size());
91                 label nNewVertices = 0;
93                 forAll (vertexLabels, vI)
94                 {
95                     // In order for a face to be a valid entity, duplicate
96                     // vertices can only be consecutive (othervise, the
97                     // collapse creates an invalid face). We shall use this
98                     // property in the creation of the collapsed face
100                     label curLabel = vertexLabels[vI];
102                     bool found = false;
104                     // search through all vertices from the new face. If the
105                     // current label has not been added, add it to the end.
106                     for (label searchI = 0; searchI < nNewVertices; searchI++)
107                     {
108                         if (newFace[searchI] == curLabel)
109                         {
110                             found = true;
112                             break;
113                         }
114                     }
116                     if (!found)
117                     {
118                         newFace[nNewVertices] = curLabel;
119                         nNewVertices++;
120                     }
121                 }
123                 newFace.setSize(nNewVertices);
125                 // If the number of non-duplicate labels in the face is less
126                 // than three, the face has been collapsed in an invalid
127                 // manner. Error.
129                 if (nNewVertices < 3)
130                 {
131                     FatalErrorIn("void sammMesh::fixCollapsedEdges()")
132                         << "face " << faceI << " of cell " << cellI
133                         << " is colapsed down to a point or edge, which is "
134                         << "not permitted" << endl
135                         << "original face: " << vertexLabels << endl
136                         << "purged face: " << newFace << endl
137                         << abort(FatalError);
138                 }
139                 else
140                 {
141                     vertexLabels = newFace;
142                 }
143             }
144         }
145     }
149 // ************************************************************************* //