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

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