FreeFOAM The Cross-Platform CFD Toolkit
STARCDsurfaceFormatCore.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 \*---------------------------------------------------------------------------*/
25 
27 #include <OpenFOAM/clock.H>
28 #include <OpenFOAM/IStringStream.H>
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
33 (
34  IFstream& is,
35  const word& signature
36 )
37 {
38  if (!is.good())
39  {
41  (
42  "fileFormats::STARCDsurfaceFormatCore::readHeader(...)"
43  )
44  << "cannot read " << signature << " " << is.name()
45  << abort(FatalError);
46  }
47 
48  word header;
49  label majorVersion;
50 
51  string line;
52 
53  is.getLine(line);
54  IStringStream(line)() >> header;
55 
56  is.getLine(line);
57  IStringStream(line)() >> majorVersion;
58 
59  // add other checks ...
60  if (header != signature)
61  {
62  Info<< "header mismatch " << signature << " " << is.name()
63  << endl;
64  }
65 
66  return true;
67 }
68 
69 
71 (
72  Ostream& os,
73  const char* filetype
74 )
75 {
76  os << "PROSTAR_" << filetype << nl
77  << 4000
78  << " " << 0
79  << " " << 0
80  << " " << 0
81  << " " << 0
82  << " " << 0
83  << " " << 0
84  << " " << 0
85  << endl;
86 }
87 
88 
90 (
91  IFstream& is,
93  labelList& ids
94 )
95 {
96  //
97  // read .vrt file
98  // ~~~~~~~~~~~~~~
99 
100  if (!is.good())
101  {
103  (
104  "fileFormats::STARCDsurfaceFormatCore::readPoints(...)"
105  )
106  << "Cannot read file " << is.name()
107  << exit(FatalError);
108  }
109 
110  readHeader(is, "PROSTAR_VERTEX");
111 
112  DynamicList<point> dynPoints;
113  // STAR-CD index of points
114  DynamicList<label> dynPointId;
115 
116  label lineLabel;
117  while ((is >> lineLabel).good())
118  {
119  scalar x, y, z;
120 
121  is >> x >> y >> z;
122 
123  dynPoints.append(point(x, y, z));
124  dynPointId.append(lineLabel);
125  }
126 
127  points.transfer(dynPoints);
128  ids.transfer(dynPointId);
129 
130  return true;
131 }
132 
133 
134 
136 (
137  Ostream& os,
138  const pointField& pointLst
139 )
140 {
141  writeHeader(os, "VERTEX");
142 
143  // Set the precision of the points data to 10
144  os.precision(10);
145 
146  // force decimal point for Fortran input
147  os.setf(std::ios::showpoint);
148 
149  forAll(pointLst, ptI)
150  {
151  os
152  << ptI + 1 << " "
153  << pointLst[ptI].x() << " "
154  << pointLst[ptI].y() << " "
155  << pointLst[ptI].z() << nl;
156  }
157  os.flush();
158 }
159 
160 
162 (
163  Ostream& os,
164  const pointField& pointLst,
165  const label nFaces,
166  const UList<surfZone>& zoneLst
167 )
168 {
169  word caseName = os.name().lessExt().name();
170 
171  os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
172  << "! " << pointLst.size() << " points, " << nFaces << " faces" << nl
173  << "! case " << caseName << nl
174  << "! ------------------------------" << nl;
175 
176  forAll(zoneLst, zoneI)
177  {
178  os << "ctable " << zoneI + 1 << " shell" << nl
179  << "ctname " << zoneI + 1 << " "
180  << zoneLst[zoneI].name() << nl;
181  }
182 
183  os << "! ------------------------------" << nl
184  << "*set icvo mxv - 1" << nl
185  << "vread " << caseName << ".vrt icvo,,,coded" << nl
186  << "cread " << caseName << ".cel icvo,,,add,coded" << nl
187  << "*set icvo" << nl
188  << "! end" << nl;
189 
190  os.flush();
191 }
192 
193 
194 // ************************ vim: set sw=4 sts=4 et: ************************ //
195