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

readBoundary.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 "Time.H"
00032 #include "wallPolyPatch.H"
00033 #include "cyclicPolyPatch.H"
00034 #include "symmetryPolyPatch.H"
00035 #include "preservePatchTypes.H"
00036 #include "IFstream.H"
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 void starMesh::readBoundary()
00041 {
00042     label nPatches=0, nFaces=0;
00043     labelList nPatchFaces(1000);
00044 
00045     label lineIndex, starLabel;
00046     label starRegion, configNumber;
00047 
00048     labelList pointLabels(4);
00049     labelList pointLabelsTri(3);
00050 
00051     labelList patchLabels(1000, -1);
00052 
00053     word patchType;
00054     patchTypes_.setSize(1000);
00055     patchNames_.setSize(1000);
00056 
00057     fileName boundaryFileName(casePrefix_ + ".bnd");
00058 
00059     {
00060         IFstream boundaryFile(boundaryFileName);
00061 
00062         // Collect no. of faces (nFaces),
00063         // no. of patches (nPatches)
00064         // and for each of these patches the number of faces
00065         // (nPatchFaces[patchLabel])
00066         // and a conversion table from Star regions to (Foam) patchLabels
00067 
00068         if (boundaryFile.good())
00069         {
00070             forAll(nPatchFaces, faceLabel)
00071             {
00072                 nPatchFaces[faceLabel] = 0;
00073             }
00074 
00075             while ((boundaryFile >> lineIndex).good())
00076             {
00077                 nFaces++;
00078 
00079                 // Skip point numbers
00080                 for (int i=0; i<4; i++)
00081                 {
00082                     boundaryFile >> starLabel;
00083                 }
00084 
00085                 boundaryFile >> starRegion;
00086                 boundaryFile >> configNumber;
00087                 boundaryFile >> patchType;
00088 
00089                 // Build translation table to convert star patch to foam patch
00090                 label patchLabel = patchLabels[starRegion];
00091                 if (patchLabel == -1)
00092                 {
00093                     patchLabel = nPatches;
00094                     patchLabels[starRegion] = patchLabel;
00095                     patchTypes_[patchLabel] = patchType;
00096                     patchNames_[patchLabel] = patchType + name(starRegion);
00097 
00098                     nPatches++;
00099 
00100                     Info<< "Star region " << starRegion
00101                         << " with type " << patchType
00102                         << " is now Foam patch " << patchLabel << endl;
00103 
00104                 }
00105 
00106                 nPatchFaces[patchLabel]++;
00107             }
00108 
00109 
00110             Info<< nl
00111                 << "Setting size of boundary to " << nPatches
00112                 << nl << endl;
00113 
00114             nPatchFaces.setSize(nPatches);
00115         }
00116         else
00117         {
00118             FatalErrorIn("starMesh::readBoundary()")
00119                 << "Cannot read file "
00120                 << boundaryFileName
00121                 << abort(FatalError);
00122         }
00123     }
00124 
00125     if (nPatches > 0)
00126     {
00127         boundary_.setSize(nPatchFaces.size());
00128         patchTypes_.setSize(nPatchFaces.size());
00129         patchNames_.setSize(nPatchFaces.size());
00130 
00131         // size the lists and reset the counters to be used again
00132         forAll(boundary_, patchLabel)
00133         {
00134             boundary_[patchLabel].setSize(nPatchFaces[patchLabel]);
00135 
00136             nPatchFaces[patchLabel] = 0;
00137         }
00138 
00139         IFstream boundaryFile(boundaryFileName);
00140 
00141         for (label faceI=0; faceI<nFaces; faceI++)
00142         {
00143             boundaryFile >> lineIndex;
00144 
00145             for (int i = 0; i < 4; i++)
00146             {
00147                 boundaryFile >> starLabel;
00148 
00149                 // convert Star label to Foam point label
00150                 // through lookup-list starPointLabelLookup_
00151                 pointLabels[i] = starPointLabelLookup_[starLabel];
00152 
00153                 if (pointLabels[i] < 0)
00154                 {
00155                     Info<< "Boundary file not consistent with vertex file\n"
00156                         << "Star vertex number " << starLabel
00157                         << " does not exist\n";
00158                 }
00159 
00160             }
00161 
00162             boundaryFile >> starRegion;
00163             label patchLabel = patchLabels[starRegion];
00164 
00165             boundaryFile >> configNumber;
00166             boundaryFile >> patchType;
00167 
00168             if   // Triangle
00169             (
00170                 pointLabels[2] == pointLabels[3]
00171             )
00172             {
00173                 //Info<< "Converting collapsed quad into triangle"
00174                 //    << " for face " << faceI
00175                 //    << " in Star boundary " << lineIndex << endl;
00176 
00177                 pointLabelsTri[0] = pointLabels[0];
00178                 pointLabelsTri[1] = pointLabels[1];
00179                 pointLabelsTri[2] = pointLabels[2];
00180 
00181                 boundary_[patchLabel][nPatchFaces[patchLabel]]
00182                     = face(pointLabelsTri);
00183             }
00184             else
00185             {
00186                 boundary_[patchLabel][nPatchFaces[patchLabel]]
00187                     = face(pointLabels);
00188             }
00189             
00190             // increment counter of faces in current patch
00191             nPatchFaces[patchLabel]++;
00192         }
00193 
00194         forAll(boundary_, patchLabel)
00195         {
00196             word patchType = patchTypes_[patchLabel];
00197 
00198             if (patchType == "SYMP")
00199             {
00200                 patchTypes_[patchLabel] = symmetryPolyPatch::typeName;
00201             }
00202             else if (patchType == "WALL")
00203             {
00204                 patchTypes_[patchLabel] = wallPolyPatch::typeName;
00205             }
00206             else if (patchType == "CYCL")
00207             {
00208                 // incorrect. should be cyclicPatch but this
00209                 // requires info on connected faces.
00210                 patchTypes_[patchLabel] = cyclicPolyPatch::typeName;
00211             }
00212             else
00213             {
00214                 patchTypes_[patchLabel] = polyPatch::typeName;
00215             }
00216 
00217             Info<< "Foam patch " << patchLabel
00218                 << " is of type " << patchTypes_[patchLabel]
00219                 << " with name " << patchNames_[patchLabel] << endl;
00220         }
00221     }
00222     else
00223     {
00224         WarningIn("void starMesh::readBoundary()")
00225             << "no boundary faces in file "
00226             << boundaryFileName
00227             << endl;
00228     }
00229 
00230     patchPhysicalTypes_.setSize(patchTypes_.size());
00231 
00232     preservePatchTypes
00233     (
00234         runTime_,
00235         runTime_.constant(),
00236         polyMesh::defaultRegion,
00237         patchNames_,
00238         patchTypes_,
00239         defaultFacesName_,
00240         defaultFacesType_,
00241         patchPhysicalTypes_
00242     );
00243 }
00244 
00245 
00246 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd