STARCDCore.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 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  << abort(FatalError);
50  }
51 
52  word header;
53  label majorVersion;
54 
55  string line;
56 
57  is.getLine(line);
58  (IStringStream(line)()) >> header;
59 
60  is.getLine(line);
61  (IStringStream(line)()) >> majorVersion;
62 
63  // add other checks ...
64  if (header != signature)
65  {
66  Info<< "header mismatch " << signature << " " << is.name()
67  << endl;
68  }
69 
70  return true;
71 }
72 
73 
75 (
76  Ostream& os,
77  const word& filetype
78 )
79 {
80  os << "PROSTAR_" << filetype << nl
81  << 4000
82  << " " << 0
83  << " " << 0
84  << " " << 0
85  << " " << 0
86  << " " << 0
87  << " " << 0
88  << " " << 0
89  << endl;
90 }
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 (
97  IFstream& is,
98  pointField& points,
99  labelList& ids
100 )
101 {
102  if (!is.good())
103  {
105  << "Cannot read file " << is.name()
106  << exit(FatalError);
107  }
108 
109  readHeader(is, "PROSTAR_VERTEX");
110 
111 
112  // reuse memory if possible
113  DynamicList<point> dynPoints(move(points));
114  DynamicList<label> dynPointId(move(ids)); // STAR-CD index of points
115 
116  dynPoints.clear();
117  dynPointId.clear();
118 
119  label lineLabel;
120  while ((is >> lineLabel).good())
121  {
122  scalar x, y, z;
123 
124  is >> x >> y >> z;
125 
126  dynPoints.append(point(x, y, z));
127  dynPointId.append(lineLabel);
128  }
129 
130  points.transfer(dynPoints);
131  ids.transfer(dynPointId);
132 
133  return true;
134 }
135 
136 
138 (
139  Ostream& os,
140  const pointField& pointLst
141 )
142 {
143  writeHeader(os, "VERTEX");
144 
145  // Set the precision of the points data to 10
146  os.precision(10);
147 
148  // force decimal point for Fortran input
149  os.setf(std::ios::showpoint);
150 
151  forAll(pointLst, ptI)
152  {
153  os
154  << ptI + 1 << " "
155  << pointLst[ptI].x() << " "
156  << pointLst[ptI].y() << " "
157  << pointLst[ptI].z() << nl;
158  }
159  os.flush();
160 }
161 
162 
163 
164 
165 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A line primitive.
Definition: line.H:56
virtual void flush()=0
Flush stream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:493
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static void writeHeader(Ostream &, const word &fileType)
Write header for fileType (CELL|VERTEX|BOUNDARY)
Definition: STARCDCore.C:75
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
Various functions to operate on Lists.
static bool readHeader(IFstream &, const word &fileSignature)
Read header.
Definition: STARCDCore.C:41
STARCDCore()
Construct null.
Definition: STARCDCore.C:34
static void writePoints(Ostream &, const pointField &)
Write header and points to (.vrt) file.
Definition: STARCDCore.C:138
scalar y
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
A class for handling words, derived from string.
Definition: word.H:59
const fileName & name() const
Return the name of the stream.
Definition: IFstream.H:116
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
errorManip< error > abort(error &err)
Definition: errorManip.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
Input from file stream.
Definition: IFstream.H:81
ISstream & getLine(string &, const bool continuation=true)
Read line into a string.
Definition: ISstream.C:692
vector point
Point is a vector.
Definition: point.H:41
Input from memory buffer stream.
Definition: IStringStream.H:49
static bool readPoints(IFstream &, pointField &, labelList &ids)
Read points from a (.vrt) file.
Definition: STARCDCore.C:96
messageStream Info
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:236
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
virtual int precision() const =0
Get precision of output field.