OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

STARCDsurfaceFormatCore.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "STARCDsurfaceFormatCore.H"
00028 #include "clock.H"
00029 #include "IStringStream.H"
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 bool Foam::fileFormats::STARCDsurfaceFormatCore::readHeader
00034 (
00035     IFstream& is,
00036     const word& signature
00037 )
00038 {
00039     if (!is.good())
00040     {
00041         FatalErrorIn
00042         (
00043             "fileFormats::STARCDsurfaceFormatCore::readHeader(...)"
00044         )
00045             << "cannot read " << signature  << "  " << is.name()
00046             << abort(FatalError);
00047     }
00048 
00049     word header;
00050     label majorVersion;
00051 
00052     string line;
00053 
00054     is.getLine(line);
00055     IStringStream(line)() >> header;
00056 
00057     is.getLine(line);
00058     IStringStream(line)() >> majorVersion;
00059 
00060     // add other checks ...
00061     if (header != signature)
00062     {
00063         Info<< "header mismatch " << signature << "  " << is.name()
00064             << endl;
00065     }
00066 
00067     return true;
00068 }
00069 
00070 
00071 void Foam::fileFormats::STARCDsurfaceFormatCore::writeHeader
00072 (
00073     Ostream& os,
00074     const char* filetype
00075 )
00076 {
00077     os  << "PROSTAR_" << filetype << nl
00078         << 4000
00079         << " " << 0
00080         << " " << 0
00081         << " " << 0
00082         << " " << 0
00083         << " " << 0
00084         << " " << 0
00085         << " " << 0
00086         << endl;
00087 }
00088 
00089 
00090 bool Foam::fileFormats::STARCDsurfaceFormatCore::readPoints
00091 (
00092     IFstream& is,
00093     pointField& points,
00094     labelList& ids
00095 )
00096 {
00097     //
00098     // read .vrt file
00099     // ~~~~~~~~~~~~~~
00100 
00101     if (!is.good())
00102     {
00103         FatalErrorIn
00104         (
00105             "fileFormats::STARCDsurfaceFormatCore::readPoints(...)"
00106         )
00107             << "Cannot read file " << is.name()
00108             << exit(FatalError);
00109     }
00110 
00111     readHeader(is, "PROSTAR_VERTEX");
00112 
00113     DynamicList<point> dynPoints;
00114     // STAR-CD index of points
00115     DynamicList<label> dynPointId;
00116 
00117     label lineLabel;
00118     while ((is >> lineLabel).good())
00119     {
00120         scalar x, y, z;
00121 
00122         is >> x >> y >> z;
00123 
00124         dynPoints.append(point(x, y, z));
00125         dynPointId.append(lineLabel);
00126     }
00127 
00128     points.transfer(dynPoints);
00129     ids.transfer(dynPointId);
00130 
00131     return true;
00132 }
00133 
00134 
00135 
00136 void Foam::fileFormats::STARCDsurfaceFormatCore::writePoints
00137 (
00138     Ostream& os,
00139     const pointField& pointLst
00140 )
00141 {
00142     writeHeader(os, "VERTEX");
00143 
00144     // Set the precision of the points data to 10
00145     os.precision(10);
00146 
00147     // force decimal point for Fortran input
00148     os.setf(std::ios::showpoint);
00149 
00150     forAll(pointLst, ptI)
00151     {
00152         os
00153             << ptI + 1 << " "
00154             << pointLst[ptI].x() << " "
00155             << pointLst[ptI].y() << " "
00156             << pointLst[ptI].z() << nl;
00157     }
00158     os.flush();
00159 }
00160 
00161 
00162 void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
00163 (
00164     Ostream& os,
00165     const pointField& pointLst,
00166     const label nFaces,
00167     const UList<surfZone>& zoneLst
00168 )
00169 {
00170     word caseName = os.name().lessExt().name();
00171 
00172     os  << "! STAR-CD file written " << clock::dateTime().c_str() << nl
00173         << "! " << pointLst.size() << " points, " << nFaces << " faces" << nl
00174         << "! case " << caseName << nl
00175         << "! ------------------------------" << nl;
00176 
00177     forAll(zoneLst, zoneI)
00178     {
00179         os  << "ctable " << zoneI + 1 << " shell" << nl
00180             << "ctname " << zoneI + 1 << " "
00181             << zoneLst[zoneI].name() << nl;
00182     }
00183 
00184     os  << "! ------------------------------" << nl
00185         << "*set icvo mxv - 1" << nl
00186         << "vread " << caseName << ".vrt icvo,,,coded" << nl
00187         << "cread " << caseName << ".cel icvo,,,add,coded" << nl
00188         << "*set icvo" << nl
00189         << "! end" << nl;
00190 
00191     os.flush();
00192 }
00193 
00194 
00195 // ************************************************************************* //
00196 
Copyright © 2000-2009 OpenCFD Ltd