FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/IFstream.H>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 label 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 scalar 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 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 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  scalar x, y, z;
90 
91  maxLabel = -1;
92  while (pointsFile)
93  {
94  pointLabel = readVtxLabel(pointsFile);
95 
96  if (!pointsFile) break;
97 
98  maxLabel = max(maxLabel, pointLabel);
99 
100  x = readVtxCmpt(pointsFile);
101  y = readVtxCmpt(pointsFile);
102  z = readVtxCmpt(pointsFile);
103 
104  readToNl(pointsFile);
105 
106  nPoints++;
107  }
108  }
109  else
110  {
111  FatalErrorIn("starMesh::readPoints()")
112  << "Cannot read file " << pointsFileName
113  << abort(FatalError);
114  }
115  }
116 
117  Info<< "Number of points = " << nPoints << endl << endl;
118 
119  points_.setSize(nPoints);
120 
121 # ifdef starMesh_H
122  starPointID_.setSize(nPoints);
123 
124  // Reset STAR point ID, just in case
125  starPointID_ = -1;
126 # endif
127 
128  starPointLabelLookup_.setSize(maxLabel+1);
129 
130  // reset point labels to invalid value
131  starPointLabelLookup_ = -1;
132 
133  if (nPoints > 0)
134  {
135  // Pass 2: construct pointlist and conversion table
136  // from Star vertex numbers to Foam pointLabels
137 
138  IFstream pointsFile(pointsFileName);
139  label pointLabel;
140 
141  forAll(points_, p)
142  {
143  pointLabel = readVtxLabel(pointsFile);
144  points_[p].x() = readVtxCmpt(pointsFile);
145  points_[p].y() = readVtxCmpt(pointsFile);
146  points_[p].z() = readVtxCmpt(pointsFile);
147 
148  readToNl(pointsFile);
149 
150 # ifdef starMesh_H
151  starPointID_[p] = pointLabel;
152 # endif
153 
154  starPointLabelLookup_[pointLabel] = p;
155  }
156 
157  if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
158  {
159  points_ *= scaleFactor;
160  }
161  }
162  else
163  {
164  FatalError
165  << "void starMesh::readPoints() : "
166  << "no points in file "
167  << pointsFileName
168  << abort(FatalError);
169  }
170 }
171 
172 
173 // ************************ vim: set sw=4 sts=4 et: ************************ //