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 #include "patchWriter.H"
00027 #include "writeFuns.H"
00028
00029
00030
00031
00032
00033
00034 Foam::patchWriter::patchWriter
00035 (
00036 const vtkMesh& vMesh,
00037 const bool binary,
00038 const bool nearCellValue,
00039 const fileName& fName,
00040 const labelList& patchIDs
00041 )
00042 :
00043 vMesh_(vMesh),
00044 binary_(binary),
00045 nearCellValue_(nearCellValue),
00046 fName_(fName),
00047 patchIDs_(patchIDs),
00048 os_(fName.c_str())
00049 {
00050 const fvMesh& mesh = vMesh_.mesh();
00051 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00052
00053
00054 if (patchIDs_.size() == 1)
00055 {
00056 writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
00057 }
00058 else
00059 {
00060 writeFuns::writeHeader(os_, binary_, "patches");
00061 }
00062 os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
00063
00064
00065 nPoints_ = 0;
00066 nFaces_ = 0;
00067 label nFaceVerts = 0;
00068
00069 forAll(patchIDs_, i)
00070 {
00071 const polyPatch& pp = patches[patchIDs_[i]];
00072
00073 nPoints_ += pp.nPoints();
00074 nFaces_ += pp.size();
00075
00076 forAll(pp, faceI)
00077 {
00078 nFaceVerts += pp[faceI].size() + 1;
00079 }
00080 }
00081
00082 os_ << "POINTS " << nPoints_ << " float" << std::endl;
00083
00084 DynamicList<floatScalar> ptField(3*nPoints_);
00085
00086 forAll(patchIDs_, i)
00087 {
00088 const polyPatch& pp = patches[patchIDs_[i]];
00089
00090 writeFuns::insert(pp.localPoints(), ptField);
00091 }
00092 writeFuns::write(os_, binary_, ptField);
00093
00094 os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
00095 << std::endl;
00096
00097 DynamicList<label> vertLabels(nFaceVerts);
00098 DynamicList<label> faceTypes(nFaceVerts);
00099
00100 label offset = 0;
00101
00102 forAll(patchIDs_, i)
00103 {
00104 const polyPatch& pp = patches[patchIDs_[i]];
00105
00106 forAll(pp, faceI)
00107 {
00108 const face& f = pp.localFaces()[faceI];
00109
00110 const label fSize = f.size();
00111 vertLabels.append(fSize);
00112
00113 writeFuns::insert(f + offset, vertLabels);
00114
00115 if (fSize == 3)
00116 {
00117 faceTypes.append(vtkTopo::VTK_TRIANGLE);
00118 }
00119 else if (fSize == 4)
00120 {
00121 faceTypes.append(vtkTopo::VTK_QUAD);
00122 }
00123 else
00124 {
00125 faceTypes.append(vtkTopo::VTK_POLYGON);
00126 }
00127 }
00128 offset += pp.nPoints();
00129 }
00130 writeFuns::write(os_, binary_, vertLabels);
00131
00132 os_ << "CELL_TYPES " << nFaces_ << std::endl;
00133
00134 writeFuns::write(os_, binary_, faceTypes);
00135 }
00136
00137
00138
00139
00140 void Foam::patchWriter::writePatchIDs()
00141 {
00142 const fvMesh& mesh = vMesh_.mesh();
00143
00144 DynamicList<floatScalar> fField(nFaces_);
00145
00146 os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
00147
00148 forAll(patchIDs_, i)
00149 {
00150 label patchI = patchIDs_[i];
00151
00152 const polyPatch& pp = mesh.boundaryMesh()[patchI];
00153
00154 if (!isA<emptyPolyPatch>(pp))
00155 {
00156 writeFuns::insert(scalarField(pp.size(), patchI), fField);
00157 }
00158 }
00159 writeFuns::write(os_, binary_, fField);
00160 }
00161
00162
00163