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

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