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

createPolyBoundary.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 #include "polyPatch.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 void starMesh::createPolyBoundary()
00036 {
00037     label nBoundaryFacesFound = 0;
00038 
00039     polyBoundaryPatchStartIndices_.setSize(boundary_.size());
00040 
00041     label nCreatedFaces = nInternalFaces_;
00042 
00043     const labelListList& PointCells = pointCells();
00044 
00045     forAll (boundary_, patchI)
00046     {
00047         const faceList& curShapePatch = boundary_[patchI];
00048 
00049         polyBoundaryPatchStartIndices_[patchI] = nCreatedFaces;
00050 
00051         forAll (curShapePatch, faceI)
00052         {
00053             bool found = false;
00054 
00055             const face& curFace = curShapePatch[faceI];
00056 
00057             meshFaces_[nCreatedFaces] = curFace;
00058 
00059             // Must find which cell this face belongs to in order to
00060             // mark it in the cellPolys_
00061             const labelList& facePoints = curFace;
00062 
00063             forAll(facePoints, pointI)
00064             {
00065                 const labelList& facePointCells =
00066                     PointCells[facePoints[pointI]];
00067 
00068                 forAll(facePointCells, cellI)
00069                 {
00070                     const faceList& curCellFaces =
00071                         cellFaces_[facePointCells[cellI]];
00072 
00073                     forAll(curCellFaces, cellFaceI)
00074                     {
00075                         if (curCellFaces[cellFaceI] == curFace)
00076                         {
00077                             // Found the cell face corresponding to this face
00078                             found = true;
00079 
00080                             // Debugging
00081                             if
00082                             (
00083                                 cellPolys_[facePointCells[cellI]][cellFaceI]
00084                              != -1
00085                             )
00086                             {
00087                                 if
00088                                 (
00089                                     cellPolys_[facePointCells[cellI]][cellFaceI]
00090                                   > nInternalFaces_
00091                                 )
00092                                 {
00093                                     Info
00094                                         << "void starMesh::createPolyBoundary()"
00095                                         << ": Problem with face: " << curFace
00096                                         << "\nProbably multiple definitions "
00097                                         << "of a single boundary face. " << endl
00098                                         << "Other boundary face: "
00099                                         << curCellFaces[cellFaceI]
00100                                         << endl;
00101 
00102                                     Info << "PROSTAR Command: vset,news,vlis";
00103                                     forAll (curCellFaces[cellFaceI], spI)
00104                                     {
00105                                         // check if the point is given by STAR
00106                                         // or created locally
00107                                         if
00108                                         (
00109                                             curCellFaces[cellFaceI][spI] > -1
00110                                          && curCellFaces[cellFaceI][spI]
00111                                                 < starPointID_.size()
00112                                         )
00113                                         {
00114                                             Info
00115                                                 << ","
00116                                                 << starPointID_
00117                                                  [curCellFaces[cellFaceI][spI]];
00118                                         }
00119                                         else
00120                                         {
00121                                             Info << ",???";
00122                                         }
00123                                     }
00124                                     Info << " $ bset,add,vset,all" << endl;
00125                                 }
00126                                 else
00127                                 {
00128                                     Info
00129                                         << "void starMesh::createPolyBoundary()"
00130                                         << ": Problem with face: " << curFace
00131                                         << "\nProbably trying to define a "
00132                                         << "boundary face on a previously "
00133                                         << "matched internal face. " << endl
00134                                         << "Internal face: "
00135                                         << curCellFaces[cellFaceI]
00136                                         << endl;
00137 
00138                                     Info << "PROSTAR Command: vset,news,vlis";
00139                                     forAll (curCellFaces[cellFaceI], spI)
00140                                     {
00141                                         // check if the point is given by STAR
00142                                         // or created locally
00143                                         if
00144                                         (
00145                                             curCellFaces[cellFaceI][spI] > -1
00146                                          && curCellFaces[cellFaceI][spI]
00147                                                 < starPointID_.size()
00148                                         )
00149                                         {
00150                                             Info
00151                                                 << ","
00152                                                 << starPointID_
00153                                                  [curCellFaces[cellFaceI][spI]];
00154                                         }
00155                                         else
00156                                         {
00157                                             Info << ",???";
00158                                         }
00159                                     }
00160                                     Info << " $ bset,add,vset,all" << endl;
00161 
00162                                 }
00163                             }
00164 
00165                             cellPolys_[facePointCells[cellI]][cellFaceI] =
00166                                 nCreatedFaces;
00167 
00168                             nBoundaryFacesFound++;
00169                         }
00170                         if (found) break;
00171                     }
00172                     if (found) break;
00173                 }
00174                 if (found) break;
00175             }
00176 
00177             nCreatedFaces++;
00178         }
00179     }
00180 
00181     // check all cellPolys_ to see if there are any missing faces
00182     label nMissingFaceFound = 0;
00183 
00184     forAll (cellPolys_, cellI)
00185     {
00186         const labelList& curFaces = cellPolys_[cellI];
00187 
00188         forAll (curFaces, faceI)
00189         {
00190             if (curFaces[faceI] < 0)
00191             {
00192                 const face& missingFace = cellFaces_[cellI][faceI];
00193 
00194                 Info << "starMesh::createPolyBoundary() : "
00195                     << "missing face found in cell " << cellI
00196                     << ".\nType: " << cellShapes_[cellI].model().name()
00197                     << ". STAR cell number: " << starCellID_[cellI]
00198                     << ". Face: " << missingFace << endl;
00199 
00200                 nMissingFaceFound++;
00201 
00202                 Info << "PROSTAR Command: vset,news,vlis";
00203                 forAll (missingFace, spI)
00204                 {
00205                     // check if the point is given by STAR or created locally
00206                     if
00207                     (
00208                         missingFace[spI] > -1
00209                      && missingFace[spI] < starPointID_.size()
00210                     )
00211                     {
00212                         Info << "," << starPointID_[missingFace[spI]];
00213                     }
00214                     else
00215                     {
00216                         Info << ",???";
00217                     }
00218                 }
00219                 Info << " $ bset,add,vset,all" << endl;
00220             }
00221         }
00222     }
00223 
00224     if (nMissingFaceFound > 0)
00225     {
00226         Info << "Number of unmatched faces: " << nMissingFaceFound << endl;
00227     }
00228 
00229     // reset the size of the face list
00230     meshFaces_.setSize(nCreatedFaces);
00231 
00232     // check the mesh for face mismatch
00233     // (faces addressed once or more than twice)
00234     labelList markupFaces(meshFaces_.size(), 0);
00235 
00236     forAll (cellPolys_, cellI)
00237     {
00238         const labelList& curFaces = cellPolys_[cellI];
00239 
00240         forAll (curFaces, faceI)
00241         {
00242             markupFaces[curFaces[faceI]]++;
00243         }
00244     }
00245 
00246     for (label i = nInternalFaces_; i < markupFaces.size(); i++)
00247     {
00248         markupFaces[i]++;
00249     }
00250 
00251     label nProblemFacesFound = 0;
00252 
00253     forAll (markupFaces, faceI)
00254     {
00255         if (markupFaces[faceI] != 2)
00256         {
00257             const face& problemFace = meshFaces_[faceI];
00258 
00259             Info << "starMesh::createPolyBoundary() : "
00260                 << "problem with face " << faceI << ": addressed "
00261                 << markupFaces[faceI] << " times (should be 2!). Face: "
00262                 << problemFace << endl;
00263 
00264             nProblemFacesFound++;
00265 
00266             Info << "PROSTAR Command: vset,news,vlis";
00267             forAll (problemFace, spI)
00268             {
00269                 // check if the point is given by STAR or created locally
00270                 if
00271                 (
00272                     problemFace[spI] > -1
00273                  && problemFace[spI] < starPointID_.size()
00274                 )
00275                 {
00276                     Info << "," << starPointID_[problemFace[spI]];
00277                 }
00278                 else
00279                 {
00280                     Info << ",???";
00281                 }
00282             }
00283             Info << " $ bset,add,vset,all" << endl;
00284         }
00285     }
00286 
00287     if (nProblemFacesFound > 0)
00288     {
00289         Info << "Number of incorrectly matched faces: "
00290             << nProblemFacesFound << endl;
00291     }
00292 
00293     Info << "Number of boundary faces: " << nBoundaryFacesFound << endl;
00294     Info << "Total number of faces: " << nCreatedFaces << endl;
00295 }
00296 
00297 
00298 List<polyPatch*> starMesh::polyBoundaryPatches(const polyMesh& pMesh)
00299 {
00300     List<polyPatch*> p(boundary_.size());
00301 
00302     forAll (boundary_, patchI)
00303     {
00304         p[patchI] = polyPatch::New
00305         (
00306             patchTypes_[patchI],
00307             patchNames_[patchI],
00308             boundary_[patchI].size(),
00309             polyBoundaryPatchStartIndices_[patchI],
00310             patchI,
00311             pMesh.boundaryMesh()
00312         ).ptr();
00313     }
00314 
00315     return p;
00316 }
00317 
00318 
00319 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd