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 SAMM files
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "sammMesh.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 sammMesh::readBoundary()
00041 {
00042     label nPatches=0, nFaces=0;
00043     labelList nPatchFaces(1000);
00044 
00045     label lineIndex, sammLabel;
00046     label sammRegion, 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 Samm 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 >> sammLabel;
00083                 }
00084 
00085                 boundaryFile >> sammRegion;
00086                 boundaryFile >> configNumber;
00087                 boundaryFile >> patchType;
00088 
00089                 // Build translation table to convert samm patch to foam patch
00090                 label patchLabel = patchLabels[sammRegion];
00091                 if (patchLabel == -1)
00092                 {
00093                     patchLabel = nPatches;
00094                     patchLabels[sammRegion] = patchLabel;
00095                     patchTypes_[patchLabel] = patchType;
00096                     patchNames_[patchLabel] = patchType + name(sammRegion);
00097 
00098                     nPatches++;
00099 
00100                     Info<< "Samm region " << sammRegion
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 shapePatchList to " << nPatches
00112                 << nl << endl;
00113 
00114             nPatchFaces.setSize(nPatches);
00115             patchTypes_.setSize(nPatches);
00116             patchNames_.setSize(nPatches);
00117         }
00118         else
00119         {
00120             FatalErrorIn("void sammMesh::readBoundary()")
00121                 << "Cannot read file "
00122                 << boundaryFileName
00123                 << abort(FatalError);
00124         }
00125     }
00126 
00127     if (nPatches > 0)
00128     {
00129         boundary_.setSize(nPatchFaces.size());
00130         patchTypes_.setSize(nPatchFaces.size());
00131         patchNames_.setSize(nPatchFaces.size());
00132 
00133         // size the lists and reset the counters to be used again
00134         forAll(boundary_, patchLabel)
00135         {
00136             boundary_[patchLabel].setSize(nPatchFaces[patchLabel]);
00137 
00138             nPatchFaces[patchLabel] = 0;
00139         }
00140 
00141         IFstream boundaryFile(boundaryFileName);
00142 
00143         for (label faceI=0; faceI<nFaces; faceI++)
00144         {
00145             boundaryFile >> lineIndex;
00146 
00147             for (int i = 0; i < 4; i++)
00148             {
00149                 boundaryFile >> sammLabel;
00150 
00151                 // convert Samm label to Foam point label
00152                 // through lookup-list starPointLabelLookup_
00153                 pointLabels[i] = starPointLabelLookup_[sammLabel];
00154 
00155                 if (pointLabels[i] < 0)
00156                 {
00157                     Info<< "Boundary file not consistent with vertex file\n"
00158                         << "Samm vertex number " << sammLabel
00159                         << " does not exist\n";
00160                 }
00161 
00162             }
00163 
00164             boundaryFile >> sammRegion;
00165             label patchLabel = patchLabels[sammRegion];
00166 
00167             boundaryFile >> configNumber;
00168             boundaryFile >> patchType;
00169 
00170             if   // Triangle
00171             (
00172                 pointLabels[2] == pointLabels[3]
00173             )
00174             {
00175                 //Info<< "Converting collapsed quad into triangle"
00176                 //    << " for face " << faceI
00177                 //    << " in Samm boundary " << lineIndex << endl;
00178 
00179                 pointLabelsTri[0] = pointLabels[0];
00180                 pointLabelsTri[1] = pointLabels[1];
00181                 pointLabelsTri[2] = pointLabels[2];
00182 
00183                 boundary_[patchLabel][nPatchFaces[patchLabel]]
00184                     = face(pointLabelsTri);
00185             }
00186             else
00187             {
00188                 boundary_[patchLabel][nPatchFaces[patchLabel]]
00189                     = face(pointLabels);
00190             }
00191             
00192             // increment counter of faces in current patch
00193             nPatchFaces[patchLabel]++;
00194         }
00195 
00196         forAll(boundary_, patchLabel)
00197         {
00198             word patchType = patchTypes_[patchLabel];
00199 
00200             if (patchType == "SYMP")
00201             {
00202                 patchTypes_[patchLabel] = symmetryPolyPatch::typeName;
00203             }
00204             else if (patchType == "WALL")
00205             {
00206                 patchTypes_[patchLabel] = wallPolyPatch::typeName;
00207             }
00208             else if (patchType == "CYCL")
00209             {
00210                 // incorrect. should be cyclicPatch but this
00211                 // requires info on connected faces.
00212                 patchTypes_[patchLabel] = cyclicPolyPatch::typeName;
00213             }
00214             else
00215             {
00216                 patchTypes_[patchLabel] = polyPatch::typeName;
00217             }
00218 
00219             Info<< "Foam patch " << patchLabel
00220                 << " is of type " << patchTypes_[patchLabel]
00221                 << " with name " << patchNames_[patchLabel] << endl;
00222         }
00223     }
00224     else
00225     {
00226         FatalErrorIn("sammMesh::readBoundary()")
00227             << "No boundary faces in file "
00228             << boundaryFileName
00229             << endl;
00230     }
00231 
00232     patchPhysicalTypes_.setSize(patchTypes_.size());
00233 
00234     preservePatchTypes
00235     (
00236         runTime_,
00237         runTime_.constant(),
00238         polyMesh::defaultRegion,
00239         patchNames_,
00240         patchTypes_,
00241         defaultFacesName_,
00242         defaultFacesType_,
00243         patchPhysicalTypes_
00244     );
00245 }
00246 
00247 
00248 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd