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

readSeparatedPoints.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 void starMesh::readPoints(const scalar scaleFactor)
00036 {
00037     label nPoints = 0;
00038     label maxLabel = -1;
00039 
00040     fileName pointsFileName(casePrefix_ + ".vrt");
00041 
00042     {
00043         IFstream pointsFile(pointsFileName);
00044 
00045         // Pass 1: get # points and maximum vertex label
00046 
00047         if (pointsFile.good())
00048         {
00049             label pointLabel;
00050             scalar x, y, z;
00051 
00052             maxLabel = -1;
00053             while ((pointsFile >> pointLabel).good())
00054             {
00055                 nPoints++;
00056                 maxLabel = max(maxLabel, pointLabel);
00057                 pointsFile >> x >> y >> z;
00058             }
00059         }
00060         else
00061         {
00062             FatalErrorIn("starMesh::readPoints()")
00063                 << "Cannot read file " << pointsFileName
00064                 << abort(FatalError);
00065         }
00066     }
00067 
00068     Info<< "Number of points = " << nPoints << endl << endl;
00069 
00070     points_.setSize(nPoints);
00071     starPointID_.setSize(nPoints);
00072 
00073     // Reset STAR point ID, just in case
00074     starPointID_ = -1;
00075 
00076     starPointLabelLookup_.setSize(maxLabel+1);
00077 
00078     // reset point labels to invalid value
00079     starPointLabelLookup_ = -1;
00080 
00081     if (nPoints > 0)
00082     {
00083         // Pass 2: construct pointlist and conversion table
00084         // from Star vertex numbers to Foam pointLabels
00085 
00086         IFstream pointsFile(pointsFileName);
00087         label pointLabel;
00088 
00089         forAll(points_, p)
00090         {
00091             pointsFile
00092                 >> pointLabel
00093                 >> points_[p].x()
00094                 >> points_[p].y()
00095                 >> points_[p].z();
00096 
00097             starPointID_[p] = pointLabel;
00098             starPointLabelLookup_[pointLabel] = p;
00099         }
00100 
00101         if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
00102         {
00103             points_ *= scaleFactor;
00104         }
00105     }
00106     else
00107     {
00108         FatalError
00109             << "void starMesh::readPoints() : "
00110             << "no points in file "
00111             << pointsFileName
00112             << abort(FatalError);
00113     }
00114 }
00115 
00116 
00117 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd