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 PROSTAR files
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "starMesh.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 void starMesh::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                 label nNewVertices = 0;
00091 
00092                 forAll (vertexLabels, vI)
00093                 {
00094                     // In order for a face to be a valid entity, duplicate
00095                     // vertices can only be consecutive (othervise, the
00096                     // collapse creates an invalid face). We shall use this
00097                     // property in the creation of the collapsed face
00098 
00099                     label curLabel = vertexLabels[vI];
00100 
00101                     bool found = false;
00102 
00103                     // search through all vertices from the new face. If the
00104                     // current label has not been added, add it to the end.
00105                     for (label searchI = 0; searchI < nNewVertices; searchI++)
00106                     {
00107                         if (newFace[searchI] == curLabel)
00108                         {
00109                             found = true;
00110 
00111                             break;
00112                         }
00113                     }
00114 
00115                     if (!found)
00116                     {
00117                         newFace[nNewVertices] = curLabel;
00118                         nNewVertices++;
00119                     }
00120                 }
00121 
00122                 newFace.setSize(nNewVertices);
00123 
00124                 // If the number of non-duplicate labels in the face is less
00125                 // than three, the face has been collapsed in an invalid
00126                 // manner. Error.
00127 
00128                 if (nNewVertices < 3)
00129                 {
00130                     FatalErrorIn("starMesh::fixCollapsedEdges()")
00131                         << "Face " << faceI << " of cell " << cellI
00132                         << " is colapsed down to a point or edge, which is "
00133                         << "not permitted" << endl
00134                         << "original face: " << vertexLabels << endl
00135                         << "purged face: " << newFace << endl
00136                         << abort(FatalError);
00137                 }
00138                 else
00139                 {
00140                     vertexLabels = newFace;
00141                 }
00142             }
00143         }
00144     }
00145 }
00146 
00147 
00148 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines