xref: /petsc/include/petsc/private/viewercgnsimpl.h (revision f995e79b256058059724a2dace421b985b24d361)
1 #pragma once
2 
3 #include <petsc/private/viewerimpl.h>
4 #include <cgnstypes.h>
5 #include <cgnslib.h>
6 
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;
8 
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       previous_output_step;
23   PetscInt       batch_size;
24 
25   // Solution reading information
26   PetscInt solution_index;              // User set solution index
27   int      solution_file_index;         // CGNS file solution index for direct access
28   int      solution_file_pointer_index; // CGNS file solution index for FlowSolutionPointers (and other related arrays), index by 1
29   char    *solution_name;
30 } PetscViewer_CGNS;
31 
32 #define PetscCallCGNS(ierr) \
33   do { \
34     int _cgns_ier = (ierr); \
35     PetscCheck(!_cgns_ier, PETSC_COMM_SELF, PETSC_ERR_LIB, "CGNS error %d %s", _cgns_ier, cg_get_error()); \
36   } while (0)
37 
38 #define PetscCallCGNSOpen(ierr, o1, o2) \
39   do { \
40     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_Open, o1, o2, 0, 0)); \
41     PetscCallCGNS((ierr)); \
42     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_Open, o1, o2, 0, 0)); \
43   } while (0)
44 
45 #define PetscCallCGNSClose(ierr, o1, o2) \
46   do { \
47     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_Close, o1, o2, 0, 0)); \
48     PetscCallCGNS((ierr)); \
49     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_Close, o1, o2, 0, 0)); \
50   } while (0)
51 
52 #define PetscCallCGNSRead(ierr, o1, o2) \
53   do { \
54     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_ReadMeta, o1, o2, 0, 0)); \
55     PetscCallCGNS((ierr)); \
56     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_ReadMeta, o1, o2, 0, 0)); \
57   } while (0)
58 
59 #define PetscCallCGNSReadData(ierr, o1, o2) \
60   do { \
61     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_ReadData, o1, o2, 0, 0)); \
62     PetscCallCGNS((ierr)); \
63     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_ReadData, o1, o2, 0, 0)); \
64   } while (0)
65 
66 #define PetscCallCGNSWrite(ierr, o1, o2) \
67   do { \
68     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_WriteMeta, o1, o2, 0, 0)); \
69     PetscCallCGNS((ierr)); \
70     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_WriteMeta, o1, o2, 0, 0)); \
71   } while (0)
72 
73 #define PetscCallCGNSWriteData(ierr, o1, o2) \
74   do { \
75     PetscCall(PetscLogEventBegin(PETSC_VIEWER_CGNS_WriteData, o1, o2, 0, 0)); \
76     PetscCallCGNS((ierr)); \
77     PetscCall(PetscLogEventEnd(PETSC_VIEWER_CGNS_WriteData, o1, o2, 0, 0)); \
78   } while (0)
79 
80 #if !defined(PRIdCGSIZE)
81   #if CG_SIZEOF_SIZE == 32
82     // cgsize_t is defined as int
83     #define MPIU_CGSIZE MPI_INT
84     #define PRIdCGSIZE  "d"
85   #else
86     #if defined(_WIN32)
87       // cgsize_t is defined as __int64, which is synonymous with long long
88       #define MPIU_CGSIZE MPI_LONG_LONG
89       #define PRIdCGSIZE  "lld"
90     #else
91       // cgsize_t is defined as long
92       #define MPIU_CGSIZE MPI_LONG
93       #define PRIdCGSIZE  "ld"
94     #endif
95   #endif
96 #else
97   #if CG_SIZEOF_SIZE == 32
98     // cgsize_t is defined as int32_t
99     #define MPIU_CGSIZE MPI_INT32_T
100   #else
101     // cgsize_t is defined as int64_t
102     #define MPIU_CGSIZE MPI_INT64_T
103   #endif
104 #endif
105 
106 PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSRegisterLogEvents_Internal();
107 PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSCheckBatch_Internal(PetscViewer);
108 PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSFileOpen_Internal(PetscViewer, PetscInt);
109 PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode PetscViewerCGNSGetSolutionFileIndex_Internal(PetscViewer, int *);
110