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

createBoundaryFaces.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 // Specialist version of face comparison to deal with
00035 // PROSTAR boundary format idiosyncracies
00036 bool starMesh::starEqualFace
00037 (
00038     const face& boundaryFace,
00039     const face& cellFace
00040 ) const
00041 {
00042     // A PROSTAR boundary face is defined by 4 vertices irrespective
00043     // of its topology.
00044     // In order to deal with all possibilities, cell face is
00045     // considered equal if three of the vertices are the same.
00046     bool cellFaceHappy = false;
00047 
00048     label nEqual = 0;
00049 
00050     forAll (cellFace, cellFaceLabelI)
00051     {
00052         const label curCellFaceLabel = cellFace[cellFaceLabelI];
00053 
00054         forAll (boundaryFace, bouFaceLabelI)
00055         {
00056             if (boundaryFace[bouFaceLabelI] == curCellFaceLabel)
00057             {
00058                 nEqual++;
00059 
00060                 break;
00061             }
00062         }
00063     }
00064 
00065     if (nEqual >= 3)
00066     {
00067         cellFaceHappy = true;
00068     }
00069 
00070     // Boundary face is happy if all of its vertices are recognised
00071     bool boundaryFaceHappy = true;
00072 
00073     forAll (boundaryFace, bouFaceLabelI)
00074     {
00075         const label curBouFaceLabel = boundaryFace[bouFaceLabelI];
00076 
00077         bool found = false;
00078 
00079         forAll (cellFace, cellFaceLabelI)
00080         {
00081             if (curBouFaceLabel == cellFace[cellFaceLabelI])
00082             {
00083                 found = true;
00084                 break;
00085             }
00086         }
00087 
00088         boundaryFaceHappy = boundaryFaceHappy && found;
00089     }
00090 
00091     return (cellFaceHappy && boundaryFaceHappy);
00092 }
00093 
00094 
00095 void starMesh::markBoundaryFaces()
00096 {
00097     // set size of mark lists for the boundary
00098     boundaryCellIDs_.setSize(boundary_.size());
00099     boundaryCellFaceIDs_.setSize(boundary_.size());
00100 
00101     forAll(boundary_, patchI)
00102     {
00103         const faceList& patchFaces = boundary_[patchI];
00104 
00105         // set size of patch lists
00106         labelList& curBoundaryCellIDs = boundaryCellIDs_[patchI];
00107         labelList& curBoundaryCellFaceIDs = boundaryCellFaceIDs_[patchI];
00108 
00109         curBoundaryCellIDs.setSize(patchFaces.size());
00110         curBoundaryCellFaceIDs.setSize(patchFaces.size());
00111 
00112         const labelListList& PointCells = pointCells();
00113 
00114         forAll(patchFaces, faceI)
00115         {
00116             bool found = false;
00117 
00118             const face& curFace = patchFaces[faceI];
00119             const labelList& facePoints = curFace;
00120 
00121             forAll(facePoints, pointI)
00122             {
00123                 const labelList& facePointCells =
00124                     PointCells[facePoints[pointI]];
00125 
00126                 forAll(facePointCells, cellI)
00127                 {
00128                     const label curCellIndex = facePointCells[cellI];
00129 
00130                     const faceList& curCellFaces = 
00131                         cellFaces_[curCellIndex];
00132 
00133                     forAll(curCellFaces, cellFaceI)
00134                     {
00135                         if (starEqualFace(curFace, curCellFaces[cellFaceI]))
00136                         {
00137                             // Found the cell face corresponding to this face
00138                             found = true;
00139 
00140                             // Set boundary face to the corresponding cell face
00141                             curBoundaryCellIDs[faceI] = curCellIndex;
00142                             curBoundaryCellFaceIDs[faceI] = cellFaceI;
00143                         }
00144                         if (found) break;
00145                     }
00146                     if (found) break;
00147                 }
00148                 if (found) break;
00149             }
00150             if (!found)
00151             {
00152                 FatalErrorIn("starMesh::markBoundaryFaces()")
00153                     << "Face " << faceI
00154                     << " does not have neighbour cell."
00155                     << " Face : " << endl << curFace << endl
00156                     << "PROSTAR Command: vset,news,vlis";
00157 
00158                 forAll (curFace, spI)
00159                 {
00160                     if (curFace[spI] > -1 && curFace[spI] < starPointID_.size())
00161                     {
00162                         Info << "," << starPointID_[curFace[spI]];
00163                     }
00164                     else
00165                     {
00166                         Info << ",???";
00167                     }
00168                 }
00169 
00170                 FatalError << " $ bset,add,vset,all" << abort(FatalError);
00171             }
00172         }
00173     }
00174 }
00175 
00176 
00177 void starMesh::collectBoundaryFaces()
00178 {
00179     Info << "Collecting boundary faces" << endl;
00180     forAll(boundary_, patchI)
00181     {
00182         faceList& patchFaces = boundary_[patchI];
00183 
00184         // set size of patch lists
00185         const labelList& curBoundaryCellIDs = boundaryCellIDs_[patchI];
00186         const labelList& curBoundaryCellFaceIDs = boundaryCellFaceIDs_[patchI];
00187 
00188         forAll (curBoundaryCellIDs, faceI)
00189         {
00190             patchFaces[faceI] =
00191                 cellFaces_[curBoundaryCellIDs[faceI]]
00192                     [curBoundaryCellFaceIDs[faceI]];
00193         }
00194     }
00195 
00196     Info << "Finished collecting boundary faces" << endl;
00197 }
00198 
00199 
00200 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd