STARCDsurfaceFormatCore.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "STARCDsurfaceFormatCore.H"
00028 #include "clock.H"
00029 #include "IStringStream.H"
00030
00031
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
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
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
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
00145 os.precision(10);
00146
00147
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