xref: /petsc/src/sys/classes/viewer/impls/vtk/vtkvimpl.h (revision 66af8762ec03dbef0e079729eb2a1734a35ed7ff)
1 #pragma once
2 
3 #include <petsc/private/viewerimpl.h> /*I   "petscsys.h"   I*/
4 
5 typedef struct _n_PetscViewerVTKObjectLink *PetscViewerVTKObjectLink;
6 struct _n_PetscViewerVTKObjectLink {
7   PetscViewerVTKFieldType  ft;
8   PetscObject              vec;
9   PetscViewerVTKObjectLink next;
10   PetscInt                 field;
11 };
12 
13 typedef struct {
14   char                    *filename;
15   PetscFileMode            btype;
16   PetscObject              dm;
17   PetscViewerVTKObjectLink link;
18   PetscErrorCode (*write)(PetscObject, PetscViewer);
19 } PetscViewer_VTK;
20 
21 PETSC_EXTERN PetscErrorCode PetscViewerVTKFWrite(PetscViewer, FILE *, const void *, PetscInt, MPI_Datatype);
22 
23 #if defined(PETSC_HAVE_STDINT_H) /* The VTK format requires a 32-bit integer */
24 typedef int32_t PetscVTKInt;
25 #else /* Hope int is 32-bits */
26 typedef int PetscVTKInt;
27 #endif
28 typedef unsigned char PetscVTKType;
29 
30 #define PETSC_VTK_INT_MAX 2147483647
31 #define PETSC_VTK_INT_MIN -2147483647
32 #if defined(PETSC_USE_64BIT_INDICES)
33   #define PetscVTKIntCheck(a) PetscCheck((a) <= PETSC_VTK_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Array too long for 32-bit VTK binary format")
34   #define PetscVTKIntCast(a) \
35     (PetscVTKInt)(a); \
36     PetscVTKIntCheck(a)
37 #else
38   #define PetscVTKIntCheck(a)
39   #define PetscVTKIntCast(a) a
40 #endif
41 
42 /* the only problem we've encountered so far is spaces not being acceptable for paraview field names */
43 static inline PetscErrorCode PetscViewerVTKSanitizeName_Internal(char name[], size_t maxlen)
44 {
45   size_t c;
46 
47   PetscFunctionBegin;
48   for (c = 0; c < maxlen; c++) {
49     char a = name[c];
50     if (a == '\0') break;
51     if (a == ' ') name[c] = '_';
52   }
53   PetscFunctionReturn(PETSC_SUCCESS);
54 }
55