initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / mesh / conversion / sammToFoam / fixCollapsedEdges.C
blob4260650355bfe5021b0431b613ace65eaed4583b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Create intermediate mesh files from SAMM files
28 \*---------------------------------------------------------------------------*/
30 #include "sammMesh.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 void sammMesh::fixCollapsedEdges()
36     cellFaces_.setSize(cellShapes_.size());
38     forAll (cellShapes_, cellI)
39     {
40         cellFaces_[cellI] = cellShapes_[cellI].faces();
41     }
43     // go through the faces and find if there exist faces with duplicate
44     // vertices. If so, purge the duplicates and mark the mesh as a polyMesh
46     forAll (cellFaces_, cellI)
47     {
48         faceList& curFaces = cellFaces_[cellI];
50         forAll (curFaces, faceI)
51         {
52             face& vertexLabels = curFaces[faceI];
54             bool duplicatesFound = false;
56             forAll (vertexLabels, vI)
57             {
58                 label curLabel = vertexLabels[vI];
60                 label nFound = 0;
62                 forAll (vertexLabels, searchI)
63                 {
64                     if (vertexLabels[searchI] == curLabel)
65                     {
66                         nFound++;
67                     }
68                 }
70                 if (nFound > 1)
71                 {
72                     duplicatesFound = true;
74                     break;
75                 }
76             }
78             if (duplicatesFound)
79             {
80                 // this mesh cannot be described as a shapeMesh
81                 isShapeMesh_ = false;
83                 // I am not allowed to reset the shape pointer to unknown
84                 // here as the shape is still needed to determine which face
85                 // of the shape is used in potential couple matches.  This
86                 // will be done in the end using the purgeShapes()
87                 // 
89                 // create a new face without duplicates and replace original
90                 face newFace(vertexLabels.size());
92                 label nNewVertices = 0;
94                 forAll (vertexLabels, vI)
95                 {
96                     // In order for a face to be a valid entity, duplicate
97                     // vertices can only be consecutive (othervise, the
98                     // collapse creates an invalid face). We shall use this
99                     // property in the creation of the collapsed face
101                     label curLabel = vertexLabels[vI];
103                     bool found = false;
105                     // search through all vertices from the new face. If the
106                     // current label has not been added, add it to the end.
107                     for (label searchI = 0; searchI < nNewVertices; searchI++)
108                     {
109                         if (newFace[searchI] == curLabel)
110                         {
111                             found = true;
113                             break;
114                         }
115                     }
117                     if (!found)
118                     {
119                         newFace[nNewVertices] = curLabel;
120                         nNewVertices++;
121                     }
122                 }
124                 newFace.setSize(nNewVertices);
126                 // If the number of non-duplicate labels in the face is less
127                 // than three, the face has been collapsed in an invalid
128                 // manner. Error.
130                 if (nNewVertices < 3)
131                 {
132                     FatalErrorIn("void sammMesh::fixCollapsedEdges()")
133                         << "face " << faceI << " of cell " << cellI
134                         << " is colapsed down to a point or edge, which is "
135                         << "not permitted" << endl
136                         << "original face: " << vertexLabels << endl
137                         << "purged face: " << newFace << endl
138                         << abort(FatalError);
139                 }
140                 else
141                 {
142                     vertexLabels = newFace;
143                 }
144             }
145         }
146     }
150 // ************************************************************************* //