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