STARCDCore.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 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 \*---------------------------------------------------------------------------*/
25 
26 #include "STARCDCore.H"
27 #include "ListOps.H"
28 #include "clock.H"
29 #include "PackedBoolList.H"
30 #include "IStringStream.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 {}
36 
37 
38 // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
39 
41 (
42  IFstream& is,
43  const word& signature
44 )
45 {
46  if (!is.good())
47  {
49  (
50  "fileFormats::STARCDCore::readHeader(...)"
51  )
52  << "cannot read " << signature << " " << is.name()
53  << abort(FatalError);
54  }
55 
56  word header;
57  label majorVersion;
58 
59  string line;
60 
61  is.getLine(line);
62  IStringStream(line)() >> header;
63 
64  is.getLine(line);
65  IStringStream(line)() >> majorVersion;
66 
67  // add other checks ...
68  if (header != signature)
69  {
70  Info<< "header mismatch " << signature << " " << is.name()
71  << endl;
72  }
73 
74  return true;
75 }
76 
77 
79 (
80  Ostream& os,
81  const word& filetype
82 )
83 {
84  os << "PROSTAR_" << filetype << nl
85  << 4000
86  << " " << 0
87  << " " << 0
88  << " " << 0
89  << " " << 0
90  << " " << 0
91  << " " << 0
92  << " " << 0
93  << endl;
94 }
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 (
101  IFstream& is,
102  pointField& points,
103  labelList& ids
104 )
105 {
106  if (!is.good())
107  {
109  (
110  "fileFormats::STARCDedgeFormat::readPoints(...)"
111  )
112  << "Cannot read file " << is.name()
113  << exit(FatalError);
114  }
115 
116  readHeader(is, "PROSTAR_VERTEX");
117 
118 
119  // reuse memory if possible
120  DynamicList<point> dynPoints(points.xfer());
121  DynamicList<label> dynPointId(ids.xfer()); // STAR-CD index of points
122 
123  dynPoints.clear();
124  dynPointId.clear();
125 
126  label lineLabel;
127  while ((is >> lineLabel).good())
128  {
129  scalar x, y, z;
130 
131  is >> x >> y >> z;
132 
133  dynPoints.append(point(x, y, z));
134  dynPointId.append(lineLabel);
135  }
136 
137  points.transfer(dynPoints);
138  ids.transfer(dynPointId);
139 
140  return true;
141 }
142 
143 
145 (
146  Ostream& os,
147  const pointField& pointLst
148 )
149 {
150  writeHeader(os, "VERTEX");
151 
152  // Set the precision of the points data to 10
153  os.precision(10);
154 
155  // force decimal point for Fortran input
156  os.setf(std::ios::showpoint);
157 
158  forAll(pointLst, ptI)
159  {
160  os
161  << ptI + 1 << " "
162  << pointLst[ptI].x() << " "
163  << pointLst[ptI].y() << " "
164  << pointLst[ptI].z() << nl;
165  }
166  os.flush();
167 }
168 
169 
170 
171 
172 // ************************************************************************* //
Input from memory buffer stream.
Definition: IStringStream.H:49
static void writePoints(Ostream &, const pointField &)
Write header and points to (.vrt) file.
Definition: STARCDCore.C:145
const fileName & name() const
Return the name of the stream.
Definition: IFstream.H:116
vector point
Point is a vector.
Definition: point.H:41
STARCDCore()
Construct null.
Definition: STARCDCore.C:34
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
Definition: ListI.H:90
static bool readPoints(IFstream &, pointField &, labelList &ids)
Read points from a (.vrt) file.
Definition: STARCDCore.C:100
static void writeHeader(Ostream &, const word &fileType)
Write header for fileType (CELL|VERTEX|BOUNDARY)
Definition: STARCDCore.C:79
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:242
A class for handling words, derived from string.
Definition: word.H:59
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Various functions to operate on Lists.
static bool readHeader(IFstream &, const word &fileSignature)
Read header.
Definition: STARCDCore.C:41
messageStream Info
Input from file stream.
Definition: IFstream.H:81
A line primitive.
Definition: line.H:56
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
errorManip< error > abort(error &err)
Definition: errorManip.H:131
ISstream & getLine(string &)
Raw, low-level getline into a string function.
Definition: ISstreamI.H:77
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
virtual int precision() const =0
Get precision of output field.
virtual void flush()=0
Flush stream.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
error FatalError
scalar y
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:496
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53