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