initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / surfMesh / surfaceFormats / starcd / STARCDsurfaceFormatCore.C
blob5777dcb73cfcb1fc72ad24f6e2965dcbcf24c790
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "STARCDsurfaceFormatCore.H"
28 #include "clock.H"
29 #include "IStringStream.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 bool Foam::fileFormats::STARCDsurfaceFormatCore::readHeader
35     IFstream& is,
36     const word& signature
39     if (!is.good())
40     {
41         FatalErrorIn
42         (
43             "fileFormats::STARCDsurfaceFormatCore::readHeader(...)"
44         )
45             << "cannot read " << signature  << "  " << is.name()
46             << abort(FatalError);
47     }
49     word header;
50     label majorVersion;
52     string line;
54     is.getLine(line);
55     IStringStream(line)() >> header;
57     is.getLine(line);
58     IStringStream(line)() >> majorVersion;
60     // add other checks ...
61     if (header != signature)
62     {
63         Info<< "header mismatch " << signature << "  " << is.name()
64             << endl;
65     }
67     return true;
71 void Foam::fileFormats::STARCDsurfaceFormatCore::writeHeader
73     Ostream& os,
74     const char* filetype
77     os  << "PROSTAR_" << filetype << nl
78         << 4000
79         << " " << 0
80         << " " << 0
81         << " " << 0
82         << " " << 0
83         << " " << 0
84         << " " << 0
85         << " " << 0
86         << endl;
90 bool Foam::fileFormats::STARCDsurfaceFormatCore::readPoints
92     IFstream& is,
93     pointField& points,
94     labelList& ids
97     //
98     // read .vrt file
99     // ~~~~~~~~~~~~~~
101     if (!is.good())
102     {
103         FatalErrorIn
104         (
105             "fileFormats::STARCDsurfaceFormatCore::readPoints(...)"
106         )
107             << "Cannot read file " << is.name()
108             << exit(FatalError);
109     }
111     readHeader(is, "PROSTAR_VERTEX");
113     DynamicList<point> dynPoints;
114     // STAR-CD index of points
115     DynamicList<label> dynPointId;
117     label lineLabel;
118     while ((is >> lineLabel).good())
119     {
120         scalar x, y, z;
122         is >> x >> y >> z;
124         dynPoints.append(point(x, y, z));
125         dynPointId.append(lineLabel);
126     }
128     points.transfer(dynPoints);
129     ids.transfer(dynPointId);
131     return true;
136 void Foam::fileFormats::STARCDsurfaceFormatCore::writePoints
138     Ostream& os,
139     const pointField& pointLst
142     writeHeader(os, "VERTEX");
144     // Set the precision of the points data to 10
145     os.precision(10);
147     // force decimal point for Fortran input
148     os.setf(std::ios::showpoint);
150     forAll(pointLst, ptI)
151     {
152         os
153             << ptI + 1 << " "
154             << pointLst[ptI].x() << " "
155             << pointLst[ptI].y() << " "
156             << pointLst[ptI].z() << nl;
157     }
158     os.flush();
162 void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
164     Ostream& os,
165     const pointField& pointLst,
166     const label nFaces,
167     const UList<surfZone>& zoneLst
170     word caseName = os.name().lessExt().name();
172     os  << "! STAR-CD file written " << clock::dateTime().c_str() << nl
173         << "! " << pointLst.size() << " points, " << nFaces << " faces" << nl
174         << "! case " << caseName << nl
175         << "! ------------------------------" << nl;
177     forAll(zoneLst, zoneI)
178     {
179         os  << "ctable " << zoneI + 1 << " shell" << nl
180             << "ctname " << zoneI + 1 << " "
181             << zoneLst[zoneI].name() << nl;
182     }
184     os  << "! ------------------------------" << nl
185         << "*set icvo mxv - 1" << nl
186         << "vread " << caseName << ".vrt icvo,,,coded" << nl
187         << "cread " << caseName << ".cel icvo,,,add,coded" << nl
188         << "*set icvo" << nl
189         << "! end" << nl;
191     os.flush();
195 // ************************************************************************* //