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

readPoints.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 from PROSTAR files
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "starMesh.H"
00030 #include <OpenFOAM/IFstream.H>
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 label starMesh::readVtxLabel(IFstream& is)
00035 {
00036     char lcs[16];
00037 
00038     for (int i=0; i<15; i++)
00039     {
00040         is.get(lcs[i]);
00041     }
00042 
00043     lcs[15] = '\0';
00044 
00045     return atoi(lcs);
00046 }
00047 
00048 
00049 scalar starMesh::readVtxCmpt(IFstream& is)
00050 {
00051     char lcs[17];
00052 
00053     for (int i=0; i<16; i++)
00054     {
00055         is.get(lcs[i]);
00056     }
00057 
00058     lcs[16] = '\0';
00059 
00060     return scalar(atof(lcs));
00061 }
00062 
00063 
00064 void starMesh::readToNl(IFstream& is)
00065 {
00066     char c;
00067     do
00068     {
00069         is.get(c);
00070     } while (is && c != '\n');
00071 }
00072 
00073 
00074 void starMesh::readPoints(const scalar scaleFactor)
00075 {
00076     label nPoints = 0;
00077     label maxLabel = -1;
00078 
00079     fileName pointsFileName(casePrefix_ + ".vrt");
00080 
00081     {
00082         IFstream pointsFile(pointsFileName);
00083 
00084         // Pass 1: get # points and maximum vertex label
00085 
00086         if (pointsFile.good())
00087         {
00088             label pointLabel;
00089             scalar x, y, z;
00090 
00091             maxLabel = -1;
00092             while (pointsFile)
00093             {
00094                 pointLabel = readVtxLabel(pointsFile);
00095 
00096                 if (!pointsFile) break;
00097                 
00098                 maxLabel = max(maxLabel, pointLabel);
00099 
00100                 x = readVtxCmpt(pointsFile);
00101                 y = readVtxCmpt(pointsFile);
00102                 z = readVtxCmpt(pointsFile);
00103 
00104                 readToNl(pointsFile);
00105 
00106                 nPoints++;
00107             }
00108         }
00109         else
00110         {
00111             FatalErrorIn("starMesh::readPoints()")
00112                 << "Cannot read file " << pointsFileName
00113                 << abort(FatalError);
00114         }
00115     }
00116 
00117     Info<< "Number of points = " << nPoints << endl << endl;
00118 
00119     points_.setSize(nPoints);
00120 
00121 #   ifdef starMesh_H
00122     starPointID_.setSize(nPoints);
00123 
00124     // Reset STAR point ID, just in case
00125     starPointID_ = -1;
00126 #   endif
00127 
00128     starPointLabelLookup_.setSize(maxLabel+1);
00129 
00130     // reset point labels to invalid value
00131     starPointLabelLookup_ = -1;
00132 
00133     if (nPoints > 0)
00134     {
00135         // Pass 2: construct pointlist and conversion table
00136         // from Star vertex numbers to Foam pointLabels
00137 
00138         IFstream pointsFile(pointsFileName);
00139         label pointLabel;
00140 
00141         forAll(points_, p)
00142         {
00143             pointLabel = readVtxLabel(pointsFile);
00144             points_[p].x() = readVtxCmpt(pointsFile);
00145             points_[p].y() = readVtxCmpt(pointsFile);
00146             points_[p].z() = readVtxCmpt(pointsFile);
00147 
00148             readToNl(pointsFile);
00149 
00150 #           ifdef starMesh_H
00151             starPointID_[p] = pointLabel;
00152 #           endif
00153 
00154             starPointLabelLookup_[pointLabel] = p;
00155         }
00156 
00157         if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
00158         {
00159             points_ *= scaleFactor;
00160         }
00161     }
00162     else
00163     {
00164         FatalError
00165             << "void starMesh::readPoints() : "
00166             << "no points in file "
00167             << pointsFileName
00168             << abort(FatalError);
00169     }
00170 }
00171 
00172 
00173 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines