Date: 2025-03-28T21:11:10+00:00

Actual source code: vtkvimpl.h

      1: #pragma once

      3: #include <petsc/private/viewerimpl.h>

      5: typedef struct _n_PetscViewerVTKObjectLink *PetscViewerVTKObjectLink;
      6: struct _n_PetscViewerVTKObjectLink {
      7:   PetscViewerVTKFieldType  ft;
      8:   PetscObject              vec;
      9:   PetscViewerVTKObjectLink next;
     10:   PetscInt                 field;
     11: };

     13: typedef struct {
     14:   char                    *filename;
     15:   PetscFileMode            btype;
     16:   PetscObject              dm;
     17:   PetscViewerVTKObjectLink link;
     18:   PetscErrorCode (*write)(PetscObject, PetscViewer);
     19: } PetscViewer_VTK;

     21: PETSC_EXTERN PetscErrorCode PetscViewerVTKFWrite(PetscViewer, FILE *, const void *, PetscCount, MPI_Datatype);

     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;

     30: #define PETSC_VTK_INT_MAX 2147483647
     31: #define PETSC_VTK_INT_MIN -2147483647

     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.

     37:   Not Collective; No Fortran Support

     39:   Input Parameter:
     40: . a - the  value to cast

     42:   Output Parameter:
     43: . b - the resulting `PetscVTKInt` value

     45:   Level: advanced

     47: .seealso: `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscBLASIntCast()`, `PetscIntCast()`
     48: @*/
     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: }

     58: /* the only problem we've encountered so far is spaces not being acceptable for paraview field names */
     59: static inline PetscErrorCode PetscViewerVTKSanitizeName_Internal(char name[], size_t maxlen)
     60: {
     61:   size_t c;

     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: }