16 #define VTK_EMPTY_CELL 0
18 #define VTK_POLY_VERTEX 2
20 #define VTK_POLY_LINE 4
21 #define VTK_TRIANGLE 5
22 #define VTK_TRIANGLE_STRIP 6
28 #define VTK_HEXAHEDRON 12
30 #define VTK_PYRAMID 14
31 #define VTK_PENTAGONAL_PRISM 15
32 #define VTK_HEXAGONAL_PRISM 16
33 #define VTK_CONVEX_POINT_SET 41
46 const string fileName,
47 const string& comment,
49 const int atypeComponent,
50 const bool surfaceOnly=
false) :
53 _fp(fopen(fileName.c_str(),
"wb")),
59 throw CException(
"VTKWriter: cannot open file " + fileName +
62 Field globalIndexField(
"gIndex");
64 const int numMeshes =
_meshes.size();
65 for (
int n=0; n<numMeshes; n++)
69 const int numNodes = nodes.
getCount();
70 shared_ptr<IntArray> gnPtr(
new IntArray(numNodes));
71 globalIndexField.
addArray(nodes,gnPtr);
77 int gCellNodeCount =0;
79 for (
int n=0; n<numMeshes; n++)
93 const int faceCount = faces.
getCount();
96 for(
int f=0; f<faceCount; f++)
98 const int nFaceNodes = faceNodes.
getCount(f);
99 for(
int nn=0; nn<nFaceNodes; nn++)
101 const int node = faceNodes(f,nn);
102 if (gNodeIndex[node] == -1)
106 gCellNodeCount += nFaceNodes+1;
119 for(
int c=0; c<numCells; c++)
122 const int nCellNodes = cellNodes.
getCount(c);
123 for(
int nn=0; nn<nCellNodes; nn++)
125 const int node = cellNodes(c,nn);
126 if (gNodeIndex[node] == -1)
130 gCellNodeCount += nCellNodes+1;
137 for (
int n=0; n<numMeshes; n++)
141 const int numNodes = nodes.
getCount();
144 dynamic_cast<const IntArray&
>(globalIndexField[nodes]);
149 for(
int node=0; node<numNodes; node++)
151 const int gn = gNodeIndex[node];
154 for(
int k=0; k<3; k++)
155 gNodeCoords[gn][k] = coords[node][k];
160 fprintf(
_fp,
"# vtk DataFile Version 2.0\n");
161 fprintf(
_fp,
"%s\n",comment.c_str());
165 fprintf(
_fp,
"ASCII\nDATASET UNSTRUCTURED_GRID\n");
170 fprintf(
_fp,
"%12.5le %12.5le %12.5le\n", gNodeCoords[node][0],
171 gNodeCoords[node][1],gNodeCoords[node][2]);
176 fprintf(
_fp,
"CELLS");
180 for (
int n=0; n<numMeshes; n++)
185 dynamic_cast<const IntArray&
>(globalIndexField[nodes]);
195 const int faceCount = faces.
getCount();
198 for(
int f=0; f<faceCount; f++)
200 const int nFaceNodes = faceNodes.
getCount(f);
201 fprintf(
_fp,
"%d ", nFaceNodes);
202 for(
int nn=0; nn<nFaceNodes; nn++)
204 const int node = faceNodes(f,nn);
205 fprintf(
_fp,
"%d ", gNodeIndex[node]);
222 for(
int c=0; c<numCells; c++)
225 const int nCellNodes = cellNodes.
getCount(c);
226 fprintf(
_fp,
"%d ", nCellNodes);
227 for(
int nn=0; nn<nCellNodes; nn++)
229 const int node = cellNodes(c,nn);
230 fprintf(
_fp,
"%d ", gNodeIndex[node]);
238 for (
int n=0; n<numMeshes; n++)
250 const int faceCount = faces.
getCount();
253 for(
int f=0; f<faceCount; f++)
255 const int nFaceNodes = faceNodes.
getCount(f);
259 else if (nFaceNodes == 3)
261 else if (nFaceNodes == 4)
263 fprintf(
_fp,
"%d\n",vtkCellType);
277 for(
int c=0; c<numCells; c++)
280 const int nCellNodes = cellNodes.
getCount(c);
286 else if (nCellNodes == 3)
295 else if (nCellNodes == 8)
297 else if (nCellNodes == 5)
299 else if (nCellNodes == 6)
302 fprintf(
_fp,
"%d\n",vtkCellType);
318 const int numMeshes =
_meshes.size();
319 fprintf(
_fp,
"SCALARS %s double\n", label.c_str());
320 fprintf(
_fp,
"LOOKUP_TABLE default\n");
322 for (
int n=0; n<numMeshes; n++)
329 dynamic_cast<const TArray&
>(field[allFaces]);
339 for(
int f=0; f<numFaces; f++)
341 const int gf = f + offset;
342 fprintf(
_fp,
"%12.5le\n", (a[gf]));
354 const TArray& aCell =
dynamic_cast<const TArray&
>(field[cells]);
355 for(
int c=0; c<numCells; c++)
358 fprintf(
_fp,
"%12.5le\n", (aCell[c]));
368 fprintf(
_fp,
"VECTORS %s double\n", label.c_str());
369 const int numMeshes =
_meshes.size();
371 for (
int n=0; n<numMeshes; n++)
389 for(
int f=0; f<numFaces; f++)
391 const int gf = f + offset;
392 fprintf(
_fp,
"%12.5le %12.5le %12.5le\n", (v[gf][0]),
409 for(
int c=0; c<numCells; c++)
412 fprintf(
_fp,
"%12.5le %12.5le %12.5le\n", (aCell[c][0]),
int getCount(const int i) const
shared_ptr< FaceGroup > FaceGroupPtr
const FaceGroupList & getAllFaceGroups() const
const StorageSite & getNodes() const
const int _atypeComponent
const CRConnectivity & getFaceNodes(const StorageSite &site) const
void writeScalarField(const Field &field, const string label)
const StorageSite & getFaces() const
const StorageSite & getCells() const
void addArray(const StorageSite &, shared_ptr< ArrayBase > a)
const GeomFields & _geomFields
#define VTK_CONVEX_POINT_SET
VTKWriter(const GeomFields &geomFields, const MeshList &meshes, const string fileName, const string &comment, const bool binary, const int atypeComponent, const bool surfaceOnly=false)
void writeVectorField(const Field &field, const string label)
Array< Vector< T, 3 > > VectorT3Array
const CRConnectivity & getCellNodes() const
vector< Mesh * > MeshList