xref: /petsc/src/sys/classes/viewer/impls/vtk/vtkvimpl.h (revision d8e47b638cf8f604a99e9678e1df24f82d959cd7)
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 *, PetscCount, 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 
33 /*@C
34   PetscVTKIntCast - casts to a `PetscVTKInt` (which may be 32-bits in size), generates an
35   error if the `PetscVTKInt` is not large enough to hold the number.
36 
37   Not Collective; No Fortran Support
38 
39   Input Parameter:
40 . a - the  value to cast
41 
42   Output Parameter:
43 . b - the resulting `PetscVTKInt` value
44 
45   Level: advanced
46 
47 .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
48 @*/
PetscVTKIntCast(PetscCount a,PetscVTKInt * b)49 static inline PetscErrorCode PetscVTKIntCast(PetscCount a, PetscVTKInt *b)
50 {
51   PetscFunctionBegin;
52   *b = 0; /* to prevent compilers erroneously suggesting uninitialized variable */
53   PetscCheck(a <= PETSC_VTK_INT_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscCount_FMT " is too big for VTK integer. Maximum supported value is %d", a, PETSC_MPI_INT_MAX);
54   *b = (PetscVTKInt)a;
55   PetscFunctionReturn(PETSC_SUCCESS);
56 }
57 
58 /* the only problem we've encountered so far is spaces not being acceptable for paraview field names */
PetscViewerVTKSanitizeName_Internal(char name[],size_t maxlen)59 static inline PetscErrorCode PetscViewerVTKSanitizeName_Internal(char name[], size_t maxlen)
60 {
61   size_t c;
62 
63   PetscFunctionBegin;
64   for (c = 0; c < maxlen; c++) {
65     char a = name[c];
66     if (a == '\0') break;
67     if (a == ' ') name[c] = '_';
68   }
69   PetscFunctionReturn(PETSC_SUCCESS);
70 }
71