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