readSeparatedPoints.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Create intermediate mesh from PROSTAR files
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "starMesh.H"
30 #include "IFstream.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 void Foam::starMesh::readPoints(const scalar scaleFactor)
35 {
36  label nPoints = 0;
37  label maxLabel = -1;
38 
39  fileName pointsFileName(casePrefix_ + ".vrt");
40 
41  {
42  IFstream pointsFile(pointsFileName);
43 
44  // Pass 1: get # points and maximum vertex label
45 
46  if (pointsFile.good())
47  {
48  label pointLabel;
49  scalar x, y, z;
50 
51  maxLabel = -1;
52  while ((pointsFile >> pointLabel).good())
53  {
54  nPoints++;
55  maxLabel = max(maxLabel, pointLabel);
56  pointsFile >> x >> y >> z;
57  }
58  }
59  else
60  {
62  << "Cannot read file " << pointsFileName
63  << abort(FatalError);
64  }
65  }
66 
67  Info<< "Number of points = " << nPoints << endl << endl;
68 
69  points_.setSize(nPoints);
70  starPointID_.setSize(nPoints);
71 
72  // Reset STAR point ID, just in case
73  starPointID_ = -1;
74 
75  starPointLabelLookup_.setSize(maxLabel+1);
76 
77  // reset point labels to invalid value
78  starPointLabelLookup_ = -1;
79 
80  if (nPoints > 0)
81  {
82  // Pass 2: construct pointlist and conversion table
83  // from Star vertex numbers to Foam pointLabels
84 
85  IFstream pointsFile(pointsFileName);
86  label pointLabel;
87 
88  forAll(points_, p)
89  {
90  pointsFile
91  >> pointLabel
92  >> points_[p].x()
93  >> points_[p].y()
94  >> points_[p].z();
95 
96  starPointID_[p] = pointLabel;
97  starPointLabelLookup_[pointLabel] = p;
98  }
99 
100  if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
101  {
102  points_ *= scaleFactor;
103  }
104  }
105  else
106  {
107  FatalError
108  << "void starMesh::readPoints() : "
109  << "no points in file "
110  << pointsFileName
111  << abort(FatalError);
112  }
113 }
114 
115 
116 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
scalar y
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setSize(const label)
Reset size of List.
Definition: List.C:295
messageStream Info
volScalarField & p