OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Create intermediate mesh files from PROSTAR files
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "starMesh.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 void starMesh::fixCollapsedEdges()
00035 {
00036     cellFaces_.setSize(cellShapes_.size());
00037 
00038     forAll (cellShapes_, cellI)
00039     {
00040         cellFaces_[cellI] = cellShapes_[cellI].faces();
00041     }
00042 
00043     // go through the faces and find if there exist faces with duplicate
00044     // vertices. If so, purge the duplicates and mark the mesh as a polyMesh
00045 
00046     forAll (cellFaces_, cellI)
00047     {
00048         faceList& curFaces = cellFaces_[cellI];
00049 
00050         forAll (curFaces, faceI)
00051         {
00052             face& vertexLabels = curFaces[faceI];
00053 
00054             bool duplicatesFound = false;
00055 
00056             forAll (vertexLabels, vI)
00057             {
00058                 label curLabel = vertexLabels[vI];
00059 
00060                 label nFound = 0;
00061 
00062                 forAll (vertexLabels, searchI)
00063                 {
00064                     if (vertexLabels[searchI] == curLabel)
00065                     {
00066                         nFound++;
00067                     }
00068                 }
00069 
00070                 if (nFound > 1)
00071                 {
00072                     duplicatesFound = true;
00073 
00074                     break;
00075                 }
00076             }
00077 
00078             if (duplicatesFound)
00079             {
00080                 // this mesh cannot be described as a shapeMesh
00081                 isShapeMesh_ = false;
00082 
00083                 // I am not allowed to reset the shape pointer to unknown
00084                 // here as the shape is still needed to determine which face
00085                 // of the shape is used in potential couple matches.  This
00086                 // will be done in the end using the purgeShapes()
00087                 // 
00088 
00089                 // create a new face without duplicates and replace original
00090                 face newFace(vertexLabels.size());
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("starMesh::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 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd