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 #include "rawSurfaceWriter.H"
00027
00028 #include <OpenFOAM/OFstream.H>
00029 #include <OpenFOAM/OSspecific.H>
00030 #include <OpenFOAM/IOmanip.H>
00031
00032
00033
00034 template<class Type>
00035 void Foam::rawSurfaceWriter<Type>::writeGeometry
00036 (
00037 const pointField& points,
00038 const label pointI,
00039 Ostream& os
00040 )
00041 {
00042 const point& pt = points[pointI];
00043
00044 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' ';
00045 }
00046
00047
00048 template<class Type>
00049 void Foam::rawSurfaceWriter<Type>::writeGeometry
00050 (
00051 const pointField& points,
00052 const faceList& faces,
00053 const label faceI,
00054 Ostream& os
00055 )
00056 {
00057 const point& ct = faces[faceI].centre(points);
00058
00059 os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' ';
00060 }
00061
00062
00063
00064 template<class Type>
00065 void Foam::rawSurfaceWriter<Type>::writeData
00066 (
00067 const fileName& fieldName,
00068 const pointField& points,
00069 const faceList& faces,
00070 const scalarField& values,
00071 Ostream& os
00072 )
00073 {
00074
00075 os << "# x y z " << fieldName << endl;
00076
00077
00078 if (values.size() == points.size())
00079 {
00080 forAll(values, elemI)
00081 {
00082 writeGeometry(points, elemI, os);
00083 os << values[elemI] << nl;
00084 }
00085 }
00086 else
00087 {
00088 forAll(values, elemI)
00089 {
00090 writeGeometry(points, faces, elemI, os);
00091 os << values[elemI] << nl;
00092 }
00093 }
00094
00095 os << nl;
00096 }
00097
00098
00099
00100 template<class Type>
00101 void Foam::rawSurfaceWriter<Type>::writeData
00102 (
00103 const fileName& fieldName,
00104 const pointField& points,
00105 const faceList& faces,
00106 const vectorField& values,
00107 Ostream& os
00108 )
00109 {
00110
00111 os << "# x y z "
00112 << fieldName << "_x "
00113 << fieldName << "_y "
00114 << fieldName << "_z "
00115 << endl;
00116
00117
00118 if (values.size() == points.size())
00119 {
00120 forAll(values, elemI)
00121 {
00122 writeGeometry(points, elemI, os);
00123
00124 const vector& v = values[elemI];
00125 os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
00126 }
00127 }
00128 else
00129 {
00130 forAll(values, elemI)
00131 {
00132 writeGeometry(points, faces, elemI, os);
00133
00134 const vector& v = values[elemI];
00135 os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
00136 }
00137 }
00138
00139 }
00140
00141
00142
00143 template<class Type>
00144 void Foam::rawSurfaceWriter<Type>::writeData
00145 (
00146 const fileName& fieldName,
00147 const pointField& points,
00148 const faceList& faces,
00149 const sphericalTensorField& values,
00150 Ostream& os
00151 )
00152 {
00153
00154 os << "# ii ";
00155 os << fieldName << "_ii" << endl;
00156
00157
00158 if (values.size() == points.size())
00159 {
00160 forAll(values, elemI)
00161 {
00162 writeGeometry(points, elemI, os);
00163
00164 const sphericalTensor& v = values[elemI];
00165 os << v[0] << nl;
00166 }
00167 }
00168 else
00169 {
00170 forAll(values, elemI)
00171 {
00172 writeGeometry(points, faces, elemI, os);
00173
00174 const sphericalTensor& v = values[elemI];
00175 os << v[0] << nl;
00176 }
00177 }
00178 }
00179
00180
00181
00182 template<class Type>
00183 void Foam::rawSurfaceWriter<Type>::writeData
00184 (
00185 const fileName& fieldName,
00186 const pointField& points,
00187 const faceList& faces,
00188 const symmTensorField& values,
00189 Ostream& os
00190 )
00191 {
00192
00193 os << "# xx xy xz yy yz ";
00194 for(int i=0; i<6; i++)
00195 {
00196 os << fieldName << "_" << i << " ";
00197 }
00198 os << endl;
00199
00200
00201 if (values.size() == points.size())
00202 {
00203 forAll(values, elemI)
00204 {
00205 writeGeometry(points, elemI, os);
00206
00207 const symmTensor& v = values[elemI];
00208
00209 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
00210 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
00211 << nl;
00212 }
00213 }
00214 else
00215 {
00216 forAll(values, elemI)
00217 {
00218 writeGeometry(points, faces, elemI, os);
00219
00220 const symmTensor& v = values[elemI];
00221
00222 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
00223 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
00224 << nl;
00225 }
00226 }
00227 }
00228
00229
00230
00231 template<class Type>
00232 void Foam::rawSurfaceWriter<Type>::writeData
00233 (
00234 const fileName& fieldName,
00235 const pointField& points,
00236 const faceList& faces,
00237 const tensorField& values,
00238 Ostream& os
00239 )
00240 {
00241
00242 os << "# xx xy xz yx yy yz zx zy zz";
00243 for (int i=0; i<9; ++i)
00244 {
00245 os << fieldName << "_" << i << " ";
00246 }
00247 os << endl;
00248
00249
00250 if (values.size() == points.size())
00251 {
00252 forAll(values, elemI)
00253 {
00254 writeGeometry(points, elemI, os);
00255
00256 const tensor& v = values[elemI];
00257 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
00258 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
00259 << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
00260 }
00261 }
00262 else
00263 {
00264 forAll(values, elemI)
00265 {
00266 writeGeometry(points, faces, elemI, os);
00267
00268 const tensor& v = values[elemI];
00269 os << v[0] << ' ' << v[1] << ' ' << v[2] << ' '
00270 << v[3] << ' ' << v[4] << ' ' << v[5] << ' '
00271 << v[6] << ' ' << v[7] << ' ' << v[8] << nl;
00272 }
00273 }
00274 }
00275
00276
00277
00278
00279 template<class Type>
00280 Foam::rawSurfaceWriter<Type>::rawSurfaceWriter()
00281 :
00282 surfaceWriter<Type>()
00283 {}
00284
00285
00286
00287
00288 template<class Type>
00289 Foam::rawSurfaceWriter<Type>::~rawSurfaceWriter()
00290 {}
00291
00292
00293
00294
00295 template<class Type>
00296 void Foam::rawSurfaceWriter<Type>::write
00297 (
00298 const fileName& outputDir,
00299 const fileName& surfaceName,
00300 const pointField& points,
00301 const faceList& faces,
00302 const bool verbose
00303 ) const
00304 {
00305 if (!isDir(outputDir))
00306 {
00307 mkDir(outputDir);
00308 }
00309
00310 OFstream os
00311 (
00312 outputDir/surfaceName + ".raw"
00313 );
00314
00315 if (verbose)
00316 {
00317 Info<< "Writing geometry to " << os.name() << endl;
00318 }
00319
00320
00321
00322 os << "# geometry NO_DATA " << faces.size() << nl
00323 << "# x y z" << endl;
00324
00325
00326 forAll(faces, elemI)
00327 {
00328 writeGeometry(points, faces, elemI, os);
00329 os << nl;
00330 }
00331
00332 os << nl;
00333 }
00334
00335
00336 namespace Foam
00337 {
00338
00339 template<>
00340 void Foam::rawSurfaceWriter<bool>::write
00341 (
00342 const fileName& outputDir,
00343 const fileName& surfaceName,
00344 const pointField& points,
00345 const faceList& faces,
00346 const fileName& fieldName,
00347 const Field<bool>& values,
00348 const bool verbose
00349 ) const
00350 {}
00351 }
00352
00353
00354 template<class Type>
00355 void Foam::rawSurfaceWriter<Type>::write
00356 (
00357 const fileName& outputDir,
00358 const fileName& surfaceName,
00359 const pointField& points,
00360 const faceList& faces,
00361 const fileName& fieldName,
00362 const Field<Type>& values,
00363 const bool verbose
00364 ) const
00365 {
00366 if (!isDir(outputDir))
00367 {
00368 mkDir(outputDir);
00369 }
00370
00371 OFstream os
00372 (
00373 outputDir/fieldName + '_' + surfaceName + ".raw"
00374 );
00375
00376 if (verbose)
00377 {
00378 Info<< "Writing field " << fieldName << " to " << os.name() << endl;
00379 }
00380
00381
00382
00383 os << "# " << fieldName;
00384 if (values.size() == points.size())
00385 {
00386 os << " POINT_DATA ";
00387 }
00388 else
00389 {
00390 os << " FACE_DATA ";
00391 }
00392
00393 os << values.size() << nl;
00394
00395 writeData(fieldName, points, faces, values, os);
00396 }
00397
00398
00399