dxSurfaceWriter.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 "dxSurfaceWriter.H"
00028
00029 #include "OFstream.H"
00030 #include "OSspecific.H"
00031
00032
00033
00034 template<class Type>
00035 void Foam::dxSurfaceWriter<Type>::writeGeometry
00036 (
00037 Ostream& os,
00038 const pointField& points,
00039 const faceList& faces
00040 )
00041 {
00042
00043
00044 os << "# The irregular positions" << nl
00045 << "object 1 class array type float rank 1 shape 3 items "
00046 << points.size() << " data follows" << nl;
00047
00048 forAll(points, pointI)
00049 {
00050 const point& pt = points[pointI];
00051
00052 os << float(pt.x()) << ' ' << float(pt.y()) << ' ' << float(pt.z())
00053 << nl;
00054 }
00055 os << nl;
00056
00057
00058
00059 os << "# The irregular connections (triangles)" << nl
00060 << "object 2 class array type int rank 1 shape 3 items "
00061 << faces.size() << " data follows" << nl;
00062
00063 forAll(faces, faceI)
00064 {
00065 const face& f = faces[faceI];
00066
00067 if (f.size() != 3)
00068 {
00069 FatalErrorIn
00070 (
00071 "writeGeometry(Ostream&, const pointField&, const faceList&)"
00072 ) << "Face " << faceI << " vertices " << f
00073 << " is not a triangle."
00074 << exit(FatalError);
00075 }
00076
00077 os << f[0] << ' ' << f[1] << ' ' << f[2] << nl;
00078 }
00079 os << "attribute \"element type\" string \"triangles\"" << nl
00080 << "attribute \"ref\" string \"positions\"" << nl << nl;
00081 }
00082
00083
00084 namespace Foam
00085 {
00086
00087 template<>
00088 void Foam::dxSurfaceWriter<Foam::scalar>::writeData
00089 (
00090 Ostream& os,
00091 const Field<scalar>& values
00092 )
00093 {
00094
00095 os << "object 3 class array type float rank 0 items "
00096 << values.size() << " data follows" << nl;
00097
00098 forAll(values, elemI)
00099 {
00100 os << float(values[elemI]) << nl;
00101 }
00102 }
00103
00104
00105
00106 template<>
00107 void Foam::dxSurfaceWriter<Foam::vector>::writeData
00108 (
00109 Ostream& os,
00110 const Field<vector>& values
00111 )
00112 {
00113
00114 os << "object 3 class array type float rank 1 shape 3 items "
00115 << values.size() << " data follows" << nl;
00116
00117 forAll(values, elemI)
00118 {
00119 os << float(values[elemI].x()) << ' '
00120 << float(values[elemI].y()) << ' '
00121 << float(values[elemI].z()) << nl;
00122 }
00123 }
00124
00125
00126
00127 template<>
00128 void Foam::dxSurfaceWriter<Foam::sphericalTensor>::writeData
00129 (
00130 Ostream& os,
00131 const Field<sphericalTensor>& values
00132 )
00133 {
00134
00135 os << "object 3 class array type float rank 0 items "
00136 << values.size() << " data follows" << nl;
00137
00138 forAll(values, elemI)
00139 {
00140 os << float(values[elemI][0]) << nl;
00141 }
00142 }
00143
00144
00145
00146 template<>
00147 void Foam::dxSurfaceWriter<Foam::symmTensor>::writeData
00148 (
00149 Ostream& os,
00150 const Field<symmTensor>& values
00151 )
00152 {
00153
00154 os << "object 3 class array type float rank 2 shape 3 items "
00155 << values.size() << " data follows" << nl;
00156
00157 forAll(values, elemI)
00158 {
00159 const symmTensor& t = values[elemI];
00160
00161 os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
00162 << float(t.xy()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
00163 << float(t.xz()) << ' ' << float(t.yz()) << ' ' << float(t.zz())
00164 << nl;
00165 }
00166 }
00167
00168
00169
00170 template<>
00171 void Foam::dxSurfaceWriter<Foam::tensor>::writeData
00172 (
00173 Ostream& os,
00174 const Field<tensor>& values
00175 )
00176 {
00177
00178 os << "object 3 class array type float rank 2 shape 3 items "
00179 << values.size() << " data follows" << nl;
00180
00181 forAll(values, elemI)
00182 {
00183 const tensor& t = values[elemI];
00184
00185 os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
00186 << float(t.yx()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
00187 << float(t.zx()) << ' ' << float(t.zy()) << ' ' << float(t.zz())
00188 << nl;
00189 }
00190 }
00191 }
00192
00193
00194 template<class Type>
00195 void Foam::dxSurfaceWriter<Type>::writeData
00196 (
00197 Ostream& os,
00198 const Field<Type>& values
00199 )
00200 {
00201
00202 os << "object 3 class array type float rank 0 items "
00203 << values.size() << " data follows" << nl;
00204
00205 forAll(values, elemI)
00206 {
00207 os << float(0.0) << nl;
00208 }
00209 }
00210
00211
00212
00213 template<class Type>
00214 void Foam::dxSurfaceWriter<Type>::writeTrailer(Ostream& os)
00215 {
00216 os << "# the field, with three components: \"positions\","
00217 << " \"connections\", and \"data\"" << nl
00218 << "object \"irregular positions irregular "
00219 << "connections\" class field"
00220 << nl
00221 << "component \"positions\" value 1" << nl
00222 << "component \"connections\" value 2" << nl
00223 << "component \"data\" value 3" << nl;
00224 }
00225
00226
00227
00228
00229 template<class Type>
00230 Foam::dxSurfaceWriter<Type>::dxSurfaceWriter()
00231 :
00232 surfaceWriter<Type>()
00233 {}
00234
00235
00236
00237
00238 template<class Type>
00239 Foam::dxSurfaceWriter<Type>::~dxSurfaceWriter()
00240 {}
00241
00242
00243
00244
00245 template<class Type>
00246 void Foam::dxSurfaceWriter<Type>::write
00247 (
00248 const fileName& outputDir,
00249 const fileName& surfaceName,
00250 const pointField& points,
00251 const faceList& faces,
00252 const fileName& fieldName,
00253 const Field<Type>& values,
00254 const bool verbose
00255 ) const
00256 {
00257 if (!isDir(outputDir))
00258 {
00259 mkDir(outputDir);
00260 }
00261
00262 OFstream os
00263 (
00264 outputDir/fieldName + '_' + surfaceName + ".dx"
00265 );
00266
00267 if (verbose)
00268 {
00269 Info<< "Writing field " << fieldName << " to " << os.name() << endl;
00270 }
00271
00272 writeGeometry(os, points, faces);
00273
00274 writeData(os, values);
00275
00276 if (values.size() == points.size())
00277 {
00278 os << nl << "attribute \"dep\" string \"positions\""
00279 << nl << nl;
00280 }
00281 else
00282 {
00283 os << nl << "attribute \"dep\" string \"connections\""
00284 << nl << nl;
00285 }
00286
00287 writeTrailer(os);
00288
00289 os << "end" << nl;
00290 }
00291
00292
00293
Copyright © 2000-2009 OpenCFD Ltd