readPoints.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 Foam::label Foam::starMesh::readVtxLabel(IFstream& is)
35 {
36  char lcs[16];
37 
38  for (int i=0; i<15; i++)
39  {
40  is.get(lcs[i]);
41  }
42 
43  lcs[15] = '\0';
44 
45  return atoi(lcs);
46 }
47 
48 
49 Foam::scalar Foam::starMesh::readVtxCmpt(IFstream& is)
50 {
51  char lcs[17];
52 
53  for (int i=0; i<16; i++)
54  {
55  is.get(lcs[i]);
56  }
57 
58  lcs[16] = '\0';
59 
60  return scalar(atof(lcs));
61 }
62 
63 
64 void Foam::starMesh::readToNl(IFstream& is)
65 {
66  char c;
67  do
68  {
69  is.get(c);
70  } while (is && c != '\n');
71 }
72 
73 
74 void Foam::starMesh::readPoints(const scalar scaleFactor)
75 {
76  label nPoints = 0;
77  label maxLabel = -1;
78 
79  fileName pointsFileName(casePrefix_ + ".vrt");
80 
81  {
82  IFstream pointsFile(pointsFileName);
83 
84  // Pass 1: get # points and maximum vertex label
85 
86  if (pointsFile.good())
87  {
88  label pointLabel;
89 
90  maxLabel = -1;
91  while (pointsFile)
92  {
93  pointLabel = readVtxLabel(pointsFile);
94 
95  if (!pointsFile) break;
96 
97  maxLabel = max(maxLabel, pointLabel);
98 
99  readVtxCmpt(pointsFile);
100  readVtxCmpt(pointsFile);
101  readVtxCmpt(pointsFile);
102 
103  readToNl(pointsFile);
104 
105  nPoints++;
106  }
107  }
108  else
109  {
111  << "Cannot read file " << pointsFileName
112  << abort(FatalError);
113  }
114  }
115 
116  Info<< "Number of points = " << nPoints << endl << endl;
117 
118  points_.setSize(nPoints);
119 
120  #ifdef starMesh_H
121  starPointID_.setSize(nPoints);
122 
123  // Reset STAR point ID, just in case
124  starPointID_ = -1;
125  #endif
126 
127  starPointLabelLookup_.setSize(maxLabel+1);
128 
129  // reset point labels to invalid value
130  starPointLabelLookup_ = -1;
131 
132  if (nPoints > 0)
133  {
134  // Pass 2: construct pointlist and conversion table
135  // from Star vertex numbers to Foam pointLabels
136 
137  IFstream pointsFile(pointsFileName);
138  label pointLabel;
139 
140  forAll(points_, p)
141  {
142  pointLabel = readVtxLabel(pointsFile);
143  points_[p].x() = readVtxCmpt(pointsFile);
144  points_[p].y() = readVtxCmpt(pointsFile);
145  points_[p].z() = readVtxCmpt(pointsFile);
146 
147  readToNl(pointsFile);
148 
149  #ifdef starMesh_H
150  starPointID_[p] = pointLabel;
151  #endif
152 
153  starPointLabelLookup_[pointLabel] = p;
154  }
155 
156  if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
157  {
158  points_ *= scaleFactor;
159  }
160  }
161  else
162  {
163  FatalError
164  << "void starMesh::readPoints() : "
165  << "no points in file "
166  << pointsFileName
167  << abort(FatalError);
168  }
169 }
170 
171 
172 // ************************************************************************* //
#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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setSize(const label)
Reset size of List.
Definition: List.C:281
const dimensionedScalar c
Speed of light in a vacuum.
messageStream Info
volScalarField & p