FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

fixCollapsedEdges.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     Create intermediate mesh files from SAMM files
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "sammMesh.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 void sammMesh::fixCollapsedEdges()
00034 {
00035     cellFaces_.setSize(cellShapes_.size());
00036 
00037     forAll (cellShapes_, cellI)
00038     {
00039         cellFaces_[cellI] = cellShapes_[cellI].faces();
00040     }
00041 
00042     // go through the faces and find if there exist faces with duplicate
00043     // vertices. If so, purge the duplicates and mark the mesh as a polyMesh
00044 
00045     forAll (cellFaces_, cellI)
00046     {
00047         faceList& curFaces = cellFaces_[cellI];
00048 
00049         forAll (curFaces, faceI)
00050         {
00051             face& vertexLabels = curFaces[faceI];
00052 
00053             bool duplicatesFound = false;
00054 
00055             forAll (vertexLabels, vI)
00056             {
00057                 label curLabel = vertexLabels[vI];
00058 
00059                 label nFound = 0;
00060 
00061                 forAll (vertexLabels, searchI)
00062                 {
00063                     if (vertexLabels[searchI] == curLabel)
00064                     {
00065                         nFound++;
00066                     }
00067                 }
00068 
00069                 if (nFound > 1)
00070                 {
00071                     duplicatesFound = true;
00072 
00073                     break;
00074                 }
00075             }
00076 
00077             if (duplicatesFound)
00078             {
00079                 // this mesh cannot be described as a shapeMesh
00080                 isShapeMesh_ = false;
00081 
00082                 // I am not allowed to reset the shape pointer to unknown
00083                 // here as the shape is still needed to determine which face
00084                 // of the shape is used in potential couple matches.  This
00085                 // will be done in the end using the purgeShapes()
00086                 // 
00087 
00088                 // create a new face without duplicates and replace original
00089                 face newFace(vertexLabels.size());
00090 
00091                 label nNewVertices = 0;
00092 
00093                 forAll (vertexLabels, vI)
00094                 {
00095                     // In order for a face to be a valid entity, duplicate
00096                     // vertices can only be consecutive (othervise, the
00097                     // collapse creates an invalid face). We shall use this
00098                     // property in the creation of the collapsed face
00099 
00100                     label curLabel = vertexLabels[vI];
00101 
00102                     bool found = false;
00103 
00104                     // search through all vertices from the new face. If the
00105                     // current label has not been added, add it to the end.
00106                     for (label searchI = 0; searchI < nNewVertices; searchI++)
00107                     {
00108                         if (newFace[searchI] == curLabel)
00109                         {
00110                             found = true;
00111 
00112                             break;
00113                         }
00114                     }
00115 
00116                     if (!found)
00117                     {
00118                         newFace[nNewVertices] = curLabel;
00119                         nNewVertices++;
00120                     }
00121                 }
00122 
00123                 newFace.setSize(nNewVertices);
00124 
00125                 // If the number of non-duplicate labels in the face is less
00126                 // than three, the face has been collapsed in an invalid
00127                 // manner. Error.
00128 
00129                 if (nNewVertices < 3)
00130                 {
00131                     FatalErrorIn("void sammMesh::fixCollapsedEdges()")
00132                         << "face " << faceI << " of cell " << cellI
00133                         << " is colapsed down to a point or edge, which is "
00134                         << "not permitted" << endl
00135                         << "original face: " << vertexLabels << endl
00136                         << "purged face: " << newFace << endl
00137                         << abort(FatalError);
00138                 }
00139                 else
00140                 {
00141                     vertexLabels = newFace;
00142                 }
00143             }
00144         }
00145     }
00146 }
00147 
00148 
00149 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines