Actual source code: viewercgnsimpl.h

  1: #pragma once

  3: #include <petsc/private/viewerimpl.h>
  4: #include <cgnstypes.h>
  5: #include <cgnslib.h>

  7: PETSC_EXTERN PetscLogEvent PETSC_VIEWER_CGNS_Open, PETSC_VIEWER_CGNS_Close, PETSC_VIEWER_CGNS_ReadMeta, PETSC_VIEWER_CGNS_WriteMeta, PETSC_VIEWER_CGNS_ReadData, PETSC_VIEWER_CGNS_WriteData;

  9: typedef struct {
 10:   char           *filename_template;
 11:   char           *filename;
 12:   PetscFileMode   btype;
 13:   int             file_num;
 14:   const PetscInt *node_l2g;
 15:   int             base, zone;
 16:   CGNS_ENUMT(GridLocation_t) grid_loc;
 17:   PetscInt       num_local_nodes, nStart, nEnd;
 18:   PetscInt       eStart, eEnd;
 19:   PetscScalar   *nodal_field;
 20:   PetscSegBuffer output_steps;
 21:   PetscSegBuffer output_times;
 22:   PetscInt       batch_size;

 24:   // Solution reading information
 25:   PetscInt solution_index;              // User set solution index
 26:   int      solution_file_index;         // CGNS file solution index for direct access
 27:   int      solution_file_pointer_index; // CGNS file solution index for FlowSolutionPointers (and other related arrays), index by 1
 28:   char    *solution_name;
 29: } PetscViewer_CGNS;

 31: #define PetscCallCGNS(ierr) \
 32:   do { \
 33:     int _cgns_ier = (ierr); \
 34:     PetscCheck(!_cgns_ier, PETSC_COMM_SELF, PETSC_ERR_LIB, "CGNS error %d %s", _cgns_ier, cg_get_error()); \
 35:   } while (0)

 37: #define PetscCallCGNSOpen(ierr, o1, o2) \
 38:   do { \
 39:     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_Open, o1, o2, 0, 0)); \
 40:     PetscCallCGNS((ierr)); \
 41:     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_Open, o1, o2, 0, 0)); \
 42:   } while (0)

 44: #define PetscCallCGNSClose(ierr, o1, o2) \
 45:   do { \
 46:     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_Close, o1, o2, 0, 0)); \
 47:     PetscCallCGNS((ierr)); \
 48:     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_Close, o1, o2, 0, 0)); \
 49:   } while (0)

 51: #define PetscCallCGNSRead(ierr, o1, o2) \
 52:   do { \
 53:     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_ReadMeta, o1, o2, 0, 0)); \
 54:     PetscCallCGNS((ierr)); \
 55:     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_ReadMeta, o1, o2, 0, 0)); \
 56:   } while (0)

 58: #define PetscCallCGNSReadData(ierr, o1, o2) \
 59:   do { \
 60:     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_ReadData, o1, o2, 0, 0)); \
 61:     PetscCallCGNS((ierr)); \
 62:     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_ReadData, o1, o2, 0, 0)); \
 63:   } while (0)

 65: #define PetscCallCGNSWrite(ierr, o1, o2) \
 66:   do { \
 67:     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_WriteMeta, o1, o2, 0, 0)); \
 68:     PetscCallCGNS((ierr)); \
 69:     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_WriteMeta, o1, o2, 0, 0)); \
 70:   } while (0)

 72: #define PetscCallCGNSWriteData(ierr, o1, o2) \
 73:   do { \
 74:     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_WriteData, o1, o2, 0, 0)); \
 75:     PetscCallCGNS((ierr)); \
 76:     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_WriteData, o1, o2, 0, 0)); \
 77:   } while (0)

 79: #if !defined(PRIdCGSIZE)
 80:   #if CG_SIZEOF_SIZE == 32
 81:     // cgsize_t is defined as int
 82:     #define MPIU_CGSIZE MPI_INT
 83:     #define PRIdCGSIZE  "d"
 84:   #else
 85:     #if defined(_WIN32)
 86:       // cgsize_t is defined as __int64, which is synonymous with long long
 87:       #define MPIU_CGSIZE MPI_LONG_LONG
 88:       #define PRIdCGSIZE  "lld"
 89:     #else
 90:       // cgsize_t is defined as long
 91:       #define MPIU_CGSIZE MPI_LONG
 92:       #define PRIdCGSIZE  "ld"
 93:     #endif
 94:   #endif
 95: #else
 96:   #if CG_SIZEOF_SIZE == 32
 97:     // cgsize_t is defined as int32_t
 98:     #define MPIU_CGSIZE MPI_INT32_T
 99:   #else
100:     // cgsize_t is defined as int64_t
101:     #define MPIU_CGSIZE MPI_INT64_T
102:   #endif
103: #endif

105: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSRegisterLogEvents_Internal();
106: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSCheckBatch_Internal(PetscViewer);
107: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSFileOpen_Internal(PetscViewer, PetscInt);
108: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSGetSolutionFileIndex_Internal(PetscViewer, int *);