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

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