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

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