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:   PetscInt       num_nodal_fields;
 20:   PetscScalar  **nodal_fields;
 21:   PetscSegBuffer output_steps;
 22:   PetscSegBuffer output_times;
 23:   PetscInt       previous_output_step;
 24:   PetscInt       batch_size;

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

 32:   // Descriptor information
 33:   PetscInt num_descriptors, descriptor_capacity;
 34:   char   **descriptor_names;
 35:   char   **descriptor_values;
 36: } PetscViewer_CGNS;

 38: #define PetscCallCGNS(ierr) \
 39:   do { \
 40:     int _cgns_ier = (ierr); \
 41:     PetscCheck(!_cgns_ier, PETSC_COMM_SELF, PETSC_ERR_LIB, "CGNS error %d %s", _cgns_ier, cg_get_error()); \
 42:   } while (0)

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

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

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

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

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

 79: #define PetscCallCGNSWriteData(ierr, o1, o2) \
 80:   do { \
 81:     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_WriteData, o1, o2, 0, 0)); \
 82:     PetscCallCGNS((ierr)); \
 83:     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_WriteData, o1, o2, 0, 0)); \
 84:   } while (0)

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

112: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSRegisterLogEvents_Internal();
113: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSCheckBatch_Internal(PetscViewer);
114: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSFileOpen_Internal(PetscViewer, PetscInt);
115: PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSGetSolutionFileIndex_Internal(PetscViewer, int *);