writeDX.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
00028
00029
00030 #include "triSurface.H"
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037
00038
00039
00040
00041 void triSurface::writeDXGeometry
00042 (
00043 const bool writeSorted,
00044 Ostream& os
00045 ) const
00046 {
00047 labelList faceMap;
00048 surfacePatchList myPatches(calcPatches(faceMap));
00049
00050
00051 os << "# Patches:" << endl;
00052 forAll(myPatches, patchI)
00053 {
00054 os << "# " << patchI << " "
00055 << myPatches[patchI].name() << endl;
00056 }
00057 os << endl << endl;
00058
00059
00060
00061 os << "# The irregular positions" << endl
00062 << "object 1 class array type float rank 1 shape 3 items "
00063 << nPoints() << " data follows" << endl;
00064 forAll(localPoints(), pointI)
00065 {
00066 const point& pt = localPoints()[pointI];
00067 os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
00068 }
00069 os << endl;
00070
00071 os << "# The irregular connections (triangles)" << endl
00072 << "object 2 class array type int rank 1 shape 3 items "
00073 << size() << " data follows" << endl;
00074
00075 if (writeSorted)
00076 {
00077 label faceIndex = 0;
00078
00079 forAll(myPatches, patchI)
00080 {
00081
00082
00083 for
00084 (
00085 label patchFaceI = 0;
00086 patchFaceI < myPatches[patchI].size();
00087 patchFaceI++
00088 )
00089 {
00090 const label faceI = faceMap[faceIndex++];
00091
00092 const labelledTri& f = localFaces()[faceI];
00093
00094 os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
00095 }
00096 }
00097 }
00098 else
00099 {
00100 forAll(*this, faceI)
00101 {
00102 const labelledTri& f = localFaces()[faceI];
00103
00104 os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
00105 }
00106 }
00107 os << "attribute \"element type\" string \"triangles\"" << endl
00108 << "attribute \"ref\" string \"positions\"" << endl << endl;
00109 }
00110
00111
00112
00113 void triSurface::writeDXTrailer(Ostream& os) const
00114 {
00115 os << "# the field, with three components: \"positions\", \"connections\""
00116 << ", and \"data\"" << endl
00117 << "object \"irregular positions irregular connections\" class field"
00118 << endl
00119 << "component \"positions\" value 1" << endl
00120 << "component \"connections\" value 2" << endl
00121 << "component \"data\" value 3" << endl;
00122 }
00123
00124
00125
00126 void triSurface::writeDX(const bool writeSorted, Ostream& os) const
00127 {
00128 writeDXGeometry(writeSorted, os);
00129
00130 os << "object 3 class array type float rank 0 items " << size()
00131 << " data follows" << endl;
00132 if (writeSorted)
00133 {
00134
00135
00136 labelList faceMap;
00137 surfacePatchList myPatches(calcPatches(faceMap));
00138
00139 forAll(myPatches, patchI)
00140 {
00141 forAll(myPatches[patchI], patchFaceI)
00142 {
00143 os << patchI << endl;
00144 }
00145 }
00146 }
00147 else
00148 {
00149
00150
00151 forAll(*this, faceI)
00152 {
00153 os << faceI << endl;
00154 }
00155 }
00156
00157 os << endl << "attribute \"dep\" string \"connections\"" << endl << endl;
00158
00159 writeDXTrailer(os);
00160
00161 os << "end" << endl;
00162 }
00163
00164
00165
00166 void triSurface::writeDX(const scalarField& field, Ostream& os) const
00167 {
00168 writeDXGeometry(false, os);
00169
00170 if (field.size() == size())
00171 {
00172
00173 os << "object 3 class array type float rank 0 items " << field.size()
00174 << " data follows" << endl;
00175 forAll(field, faceI)
00176 {
00177 os << field[faceI] << endl;
00178 }
00179 os << endl
00180 << "attribute \"dep\" string \"connections\"" << endl << endl;
00181 }
00182 else if (field.size() == nPoints())
00183 {
00184
00185 os << "object 3 class array type float rank 0 items " << field.size()
00186 << " data follows" << endl;
00187 forAll(field, pointI)
00188 {
00189 os << field[pointI] << endl;
00190 }
00191 os << endl
00192 << "attribute \"dep\" string \"positions\"" << endl << endl;
00193 }
00194 else
00195 {
00196 FatalErrorIn
00197 (
00198 "writeDX(const scalarField&, Ostream&)"
00199 ) << "Illegal field size " << field.size() << " is not equal "
00200 << " to number of faces " << size() << " or to number "
00201 << " of points " << nPoints() << exit(FatalError);
00202 }
00203
00204 writeDXTrailer(os);
00205
00206 os << "end" << endl;
00207 }
00208
00209
00210
00211 void triSurface::writeDX(const vectorField& field, Ostream& os) const
00212 {
00213 writeDXGeometry(false, os);
00214
00215 if (field.size() == size())
00216 {
00217
00218 os << "object 3 class array type float rank 1 shape 3 items "
00219 << field.size() << " data follows" << endl;
00220 forAll(field, faceI)
00221 {
00222 os << field[faceI].x() << ' '
00223 << field[faceI].y() << ' '
00224 << field[faceI].z() << endl;
00225 }
00226 os << endl
00227 << "attribute \"dep\" string \"connections\"" << endl << endl;
00228 }
00229 else if (field.size() == nPoints())
00230 {
00231
00232 os << "object 3 class array type float rank 1 shape 3 items "
00233 << field.size() << " data follows" << endl;
00234 forAll(field, pointI)
00235 {
00236 os << field[pointI].x() << ' '
00237 << field[pointI].y() << ' '
00238 << field[pointI].z() << endl;
00239 }
00240 os << endl
00241 << "attribute \"dep\" string \"positions\"" << endl << endl;
00242 }
00243 else
00244 {
00245 FatalErrorIn
00246 (
00247 "writeDX(const vectorField&, Ostream&)"
00248 ) << "Illegal field size " << field.size() << " is not equal "
00249 << " to number of faces " << size() << " or to number "
00250 << " of points " << nPoints() << exit(FatalError);
00251 }
00252
00253 writeDXTrailer(os);
00254
00255 os << "end" << endl;
00256 }
00257
00258
00259
00260
00261 }
00262
00263
Copyright © 2000-2009 OpenCFD Ltd