FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "STARCDsurfaceFormatCore.H"
00027 #include <OpenFOAM/clock.H>
00028 #include <OpenFOAM/IStringStream.H>
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 bool Foam::fileFormats::STARCDsurfaceFormatCore::readHeader
00033 (
00034     IFstream& is,
00035     const word& signature
00036 )
00037 {
00038     if (!is.good())
00039     {
00040         FatalErrorIn
00041         (
00042             "fileFormats::STARCDsurfaceFormatCore::readHeader(...)"
00043         )
00044             << "cannot read " << signature  << "  " << is.name()
00045             << abort(FatalError);
00046     }
00047 
00048     word header;
00049     label majorVersion;
00050 
00051     string line;
00052 
00053     is.getLine(line);
00054     IStringStream(line)() >> header;
00055 
00056     is.getLine(line);
00057     IStringStream(line)() >> majorVersion;
00058 
00059     // add other checks ...
00060     if (header != signature)
00061     {
00062         Info<< "header mismatch " << signature << "  " << is.name()
00063             << endl;
00064     }
00065 
00066     return true;
00067 }
00068 
00069 
00070 void Foam::fileFormats::STARCDsurfaceFormatCore::writeHeader
00071 (
00072     Ostream& os,
00073     const char* filetype
00074 )
00075 {
00076     os  << "PROSTAR_" << filetype << nl
00077         << 4000
00078         << " " << 0
00079         << " " << 0
00080         << " " << 0
00081         << " " << 0
00082         << " " << 0
00083         << " " << 0
00084         << " " << 0
00085         << endl;
00086 }
00087 
00088 
00089 bool Foam::fileFormats::STARCDsurfaceFormatCore::readPoints
00090 (
00091     IFstream& is,
00092     pointField& points,
00093     labelList& ids
00094 )
00095 {
00096     //
00097     // read .vrt file
00098     // ~~~~~~~~~~~~~~
00099 
00100     if (!is.good())
00101     {
00102         FatalErrorIn
00103         (
00104             "fileFormats::STARCDsurfaceFormatCore::readPoints(...)"
00105         )
00106             << "Cannot read file " << is.name()
00107             << exit(FatalError);
00108     }
00109 
00110     readHeader(is, "PROSTAR_VERTEX");
00111 
00112     DynamicList<point> dynPoints;
00113     // STAR-CD index of points
00114     DynamicList<label> dynPointId;
00115 
00116     label lineLabel;
00117     while ((is >> lineLabel).good())
00118     {
00119         scalar x, y, z;
00120 
00121         is >> x >> y >> z;
00122 
00123         dynPoints.append(point(x, y, z));
00124         dynPointId.append(lineLabel);
00125     }
00126 
00127     points.transfer(dynPoints);
00128     ids.transfer(dynPointId);
00129 
00130     return true;
00131 }
00132 
00133 
00134 
00135 void Foam::fileFormats::STARCDsurfaceFormatCore::writePoints
00136 (
00137     Ostream& os,
00138     const pointField& pointLst
00139 )
00140 {
00141     writeHeader(os, "VERTEX");
00142 
00143     // Set the precision of the points data to 10
00144     os.precision(10);
00145 
00146     // force decimal point for Fortran input
00147     os.setf(std::ios::showpoint);
00148 
00149     forAll(pointLst, ptI)
00150     {
00151         os
00152             << ptI + 1 << " "
00153             << pointLst[ptI].x() << " "
00154             << pointLst[ptI].y() << " "
00155             << pointLst[ptI].z() << nl;
00156     }
00157     os.flush();
00158 }
00159 
00160 
00161 void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
00162 (
00163     Ostream& os,
00164     const pointField& pointLst,
00165     const label nFaces,
00166     const UList<surfZone>& zoneLst
00167 )
00168 {
00169     word caseName = os.name().lessExt().name();
00170 
00171     os  << "! STAR-CD file written " << clock::dateTime().c_str() << nl
00172         << "! " << pointLst.size() << " points, " << nFaces << " faces" << nl
00173         << "! case " << caseName << nl
00174         << "! ------------------------------" << nl;
00175 
00176     forAll(zoneLst, zoneI)
00177     {
00178         os  << "ctable " << zoneI + 1 << " shell" << nl
00179             << "ctname " << zoneI + 1 << " "
00180             << zoneLst[zoneI].name() << nl;
00181     }
00182 
00183     os  << "! ------------------------------" << nl
00184         << "*set icvo mxv - 1" << nl
00185         << "vread " << caseName << ".vrt icvo,,,coded" << nl
00186         << "cread " << caseName << ".cel icvo,,,add,coded" << nl
00187         << "*set icvo" << nl
00188         << "! end" << nl;
00189 
00190     os.flush();
00191 }
00192 
00193 
00194 // ************************ vim: set sw=4 sts=4 et: ************************ //
00195 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines