1 /* 2 PetscViewers are objects where other objects can be looked at or stored. 3 */ 4 5 #if !defined(__PETSCVIEWER_H) 6 #define __PETSCVIEWER_H 7 8 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 9 extern "C" { 10 #endif 11 12 /*S 13 PetscViewer - Abstract PETSc object that helps view (in ASCII, binary, graphically etc) 14 other PETSc objects 15 16 Level: beginner 17 18 Concepts: viewing 19 20 .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 21 S*/ 22 typedef struct _p_PetscViewer* PetscViewer; 23 24 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 25 } 26 #endif 27 28 #include "petscsys.h" 29 30 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 31 extern "C" { 32 #endif 33 34 extern PetscClassId PETSC_VIEWER_CLASSID; 35 36 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 37 } 38 #endif 39 40 41 /* 42 petscsys.h must be included AFTER the definition of PetscViewer for ADIC to 43 process correctly. 44 */ 45 PETSC_EXTERN_CXX_BEGIN 46 /*E 47 PetscViewerType - String with the name of a PETSc PETScViewer 48 49 Level: beginner 50 51 .seealso: PetscViewerSetType(), PetscViewer 52 E*/ 53 #define PetscViewerType char* 54 #define PETSCVIEWERSOCKET "socket" 55 #define PETSCVIEWERASCII "ascii" 56 #define PETSCVIEWERBINARY "binary" 57 #define PETSCVIEWERSTRING "string" 58 #define PETSCVIEWERDRAW "draw" 59 #define PETSCVIEWERVU "vu" 60 #define PETSCVIEWERMATHEMATICA "mathematica" 61 #define PETSCVIEWERNETCDF "netcdf" 62 #define PETSCVIEWERHDF5 "hdf5" 63 #define PETSCVIEWERMATLAB "matlab" 64 #define PETSCVIEWERAMS "ams" 65 66 extern PetscFList PetscViewerList; 67 extern PetscErrorCode PetscViewerRegisterAll(const char *); 68 extern PetscErrorCode PetscViewerRegisterDestroy(void); 69 extern PetscErrorCode PetscViewerInitializePackage(const char[]); 70 71 extern PetscErrorCode PetscViewerRegister(const char*,const char*,const char*,PetscErrorCode (*)(PetscViewer)); 72 73 /*MC 74 PetscViewerRegisterDynamic - Adds a viewer 75 76 Synopsis: 77 PetscErrorCode PetscViewerRegisterDynamic(const char *name_solver,const char *path,const char *name_create,PetscErrorCode (*routine_create)(PetscViewer)) 78 79 Not Collective 80 81 Input Parameters: 82 + name_solver - name of a new user-defined viewer 83 . path - path (either absolute or relative) the library containing this viewer 84 . name_create - name of routine to create method context 85 - routine_create - routine to create method context 86 87 Level: developer 88 89 Notes: 90 PetscViewerRegisterDynamic() may be called multiple times to add several user-defined viewers. 91 92 If dynamic libraries are used, then the fourth input argument (routine_create) 93 is ignored. 94 95 Sample usage: 96 .vb 97 PetscViewerRegisterDynamic("my_viewer_type",/home/username/my_lib/lib/libO/solaris/mylib.a, 98 "MyViewerCreate",MyViewerCreate); 99 .ve 100 101 Then, your solver can be chosen with the procedural interface via 102 $ PetscViewerSetType(viewer,"my_viewer_type") 103 or at runtime via the option 104 $ -viewer_type my_viewer_type 105 106 Concepts: registering^Viewers 107 108 .seealso: PetscViewerRegisterAll(), PetscViewerRegisterDestroy() 109 M*/ 110 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 111 #define PetscViewerRegisterDynamic(a,b,c,d) PetscViewerRegister(a,b,c,0) 112 #else 113 #define PetscViewerRegisterDynamic(a,b,c,d) PetscViewerRegister(a,b,c,d) 114 #endif 115 116 extern PetscErrorCode PetscViewerCreate(MPI_Comm,PetscViewer*); 117 PetscPolymorphicSubroutine(PetscViewerCreate,(PetscViewer *v),(PETSC_COMM_SELF,v)) 118 extern PetscErrorCode PetscViewerSetFromOptions(PetscViewer); 119 extern PetscErrorCode PetscViewerASCIIOpenWithFILE(MPI_Comm,FILE*,PetscViewer*); 120 121 extern PetscErrorCode PetscViewerASCIIOpen(MPI_Comm,const char[],PetscViewer*); 122 extern PetscErrorCode PetscViewerASCIISetFILE(PetscViewer,FILE*); 123 extern PetscErrorCode PetscViewerBinaryOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*); 124 extern PetscErrorCode PetscViewerBinaryGetFlowControl(PetscViewer,PetscInt*); 125 extern PetscErrorCode PetscViewerBinarySetFlowControl(PetscViewer,PetscInt); 126 extern PetscErrorCode PetscViewerBinarySetMPIIO(PetscViewer); 127 extern PetscErrorCode PetscViewerBinaryGetMPIIO(PetscViewer,PetscBool *); 128 #if defined(PETSC_HAVE_MPIIO) 129 extern PetscErrorCode PetscViewerBinaryGetMPIIODescriptor(PetscViewer,MPI_File*); 130 extern PetscErrorCode PetscViewerBinaryGetMPIIOOffset(PetscViewer,MPI_Offset*); 131 extern PetscErrorCode PetscViewerBinaryAddMPIIOOffset(PetscViewer,MPI_Offset); 132 #endif 133 134 extern PetscErrorCode PetscViewerSocketOpen(MPI_Comm,const char[],int,PetscViewer*); 135 extern PetscErrorCode PetscViewerStringOpen(MPI_Comm,char[],PetscInt,PetscViewer*); 136 extern PetscErrorCode PetscViewerDrawOpen(MPI_Comm,const char[],const char[],int,int,int,int,PetscViewer*); 137 extern PetscErrorCode PetscViewerMathematicaOpen(MPI_Comm, int, const char[], const char[], PetscViewer *); 138 extern PetscErrorCode PetscViewerSiloOpen(MPI_Comm, const char[], PetscViewer *); 139 extern PetscErrorCode PetscViewerMatlabOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*); 140 141 extern PetscErrorCode PetscViewerGetType(PetscViewer,const PetscViewerType*); 142 extern PetscErrorCode PetscViewerSetType(PetscViewer,const PetscViewerType); 143 extern PetscErrorCode PetscViewerDestroy(PetscViewer*); 144 extern PetscErrorCode PetscViewerGetSingleton(PetscViewer,PetscViewer*); 145 extern PetscErrorCode PetscViewerRestoreSingleton(PetscViewer,PetscViewer*); 146 extern PetscErrorCode PetscViewerGetSubcomm(PetscViewer,MPI_Comm,PetscViewer*); 147 extern PetscErrorCode PetscViewerRestoreSubcomm(PetscViewer,MPI_Comm,PetscViewer*); 148 149 extern PetscErrorCode PetscViewerSetUp(PetscViewer); 150 extern PetscErrorCode PetscViewerView(PetscViewer,PetscViewer); 151 152 extern PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer,const char[]); 153 extern PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer,const char[]); 154 extern PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer,const char*[]); 155 156 /*E 157 PetscViewerFormat - Way a viewer presents the object 158 159 Level: beginner 160 161 The values below are also listed in finclude/petscviewer.h. If another values is added below it 162 must also be added there. 163 164 .seealso: PetscViewerSetFormat(), PetscViewer, PetscViewerType, PetscViewerPushFormat(), PetscViewerPopFormat() 165 E*/ 166 typedef enum { 167 PETSC_VIEWER_DEFAULT, 168 PETSC_VIEWER_ASCII_MATLAB, 169 PETSC_VIEWER_ASCII_MATHEMATICA, 170 PETSC_VIEWER_ASCII_IMPL, 171 PETSC_VIEWER_ASCII_INFO, 172 PETSC_VIEWER_ASCII_INFO_DETAIL, 173 PETSC_VIEWER_ASCII_COMMON, 174 PETSC_VIEWER_ASCII_SYMMODU, 175 PETSC_VIEWER_ASCII_INDEX, 176 PETSC_VIEWER_ASCII_DENSE, 177 PETSC_VIEWER_ASCII_MATRIXMARKET, 178 PETSC_VIEWER_ASCII_VTK, 179 PETSC_VIEWER_ASCII_VTK_CELL, 180 PETSC_VIEWER_ASCII_VTK_COORDS, 181 PETSC_VIEWER_ASCII_PCICE, 182 PETSC_VIEWER_ASCII_PYTHON, 183 PETSC_VIEWER_ASCII_FACTOR_INFO, 184 PETSC_VIEWER_DRAW_BASIC, 185 PETSC_VIEWER_DRAW_LG, 186 PETSC_VIEWER_DRAW_CONTOUR, 187 PETSC_VIEWER_DRAW_PORTS, 188 PETSC_VIEWER_NATIVE, 189 PETSC_VIEWER_NOFORMAT 190 } PetscViewerFormat; 191 192 extern PetscErrorCode PetscViewerSetFormat(PetscViewer,PetscViewerFormat); 193 extern PetscErrorCode PetscViewerPushFormat(PetscViewer,PetscViewerFormat); 194 extern PetscErrorCode PetscViewerPopFormat(PetscViewer); 195 extern PetscErrorCode PetscViewerGetFormat(PetscViewer,PetscViewerFormat*); 196 extern PetscErrorCode PetscViewerFlush(PetscViewer); 197 198 /* 199 Operations explicit to a particular class of viewers 200 */ 201 202 extern PetscErrorCode PetscViewerASCIIGetPointer(PetscViewer,FILE**); 203 extern PetscErrorCode PetscViewerFileGetMode(PetscViewer,PetscFileMode*); 204 extern PetscErrorCode PetscViewerFileSetMode(PetscViewer,PetscFileMode); 205 extern PetscErrorCode PetscViewerASCIIPrintf(PetscViewer,const char[],...); 206 extern PetscErrorCode PetscViewerASCIISynchronizedPrintf(PetscViewer,const char[],...); 207 extern PetscErrorCode PetscViewerASCIISynchronizedAllow(PetscViewer,PetscBool); 208 extern PetscErrorCode PetscViewerASCIIPushTab(PetscViewer); 209 extern PetscErrorCode PetscViewerASCIIPopTab(PetscViewer); 210 extern PetscErrorCode PetscViewerASCIIUseTabs(PetscViewer,PetscBool ); 211 extern PetscErrorCode PetscViewerASCIISetTab(PetscViewer,PetscInt); 212 extern PetscErrorCode PetscViewerASCIIAddTab(PetscViewer,PetscInt); 213 extern PetscErrorCode PetscViewerASCIISubtractTab(PetscViewer,PetscInt); 214 extern PetscErrorCode PetscViewerBinaryGetDescriptor(PetscViewer,int*); 215 extern PetscErrorCode PetscViewerBinaryGetInfoPointer(PetscViewer,FILE **); 216 extern PetscErrorCode PetscViewerBinaryRead(PetscViewer,void*,PetscInt,PetscDataType); 217 extern PetscErrorCode PetscViewerBinaryWrite(PetscViewer,void*,PetscInt,PetscDataType,PetscBool ); 218 extern PetscErrorCode PetscViewerStringSPrintf(PetscViewer,const char[],...); 219 extern PetscErrorCode PetscViewerStringSetString(PetscViewer,char[],PetscInt); 220 extern PetscErrorCode PetscViewerDrawClear(PetscViewer); 221 extern PetscErrorCode PetscViewerDrawSetInfo(PetscViewer,const char[],const char[],int,int,int,int); 222 extern PetscErrorCode PetscViewerSocketSetConnection(PetscViewer,const char[],int); 223 extern PetscErrorCode PetscViewerBinarySkipInfo(PetscViewer); 224 extern PetscErrorCode PetscViewerBinarySetSkipOptions(PetscViewer,PetscBool ); 225 extern PetscErrorCode PetscViewerBinaryGetSkipOptions(PetscViewer,PetscBool *); 226 extern PetscErrorCode PetscViewerBinarySetSkipHeader(PetscViewer,PetscBool); 227 extern PetscErrorCode PetscViewerBinaryGetSkipHeader(PetscViewer,PetscBool*); 228 extern PetscErrorCode PetscViewerBinaryReadStringArray(PetscViewer,char***); 229 extern PetscErrorCode PetscViewerBinaryWriteStringArray(PetscViewer,char**); 230 231 extern PetscErrorCode PetscViewerFileSetName(PetscViewer,const char[]); 232 extern PetscErrorCode PetscViewerFileGetName(PetscViewer,const char**); 233 234 extern PetscErrorCode PetscPLAPACKInitializePackage(MPI_Comm com); 235 extern PetscErrorCode PetscPLAPACKFinalizePackage(void); 236 237 extern PetscErrorCode PetscViewerVUGetPointer(PetscViewer, FILE**); 238 extern PetscErrorCode PetscViewerVUSetVecSeen(PetscViewer, PetscBool ); 239 extern PetscErrorCode PetscViewerVUGetVecSeen(PetscViewer, PetscBool *); 240 extern PetscErrorCode PetscViewerVUPrintDeferred(PetscViewer, const char [], ...); 241 extern PetscErrorCode PetscViewerVUFlushDeferred(PetscViewer); 242 243 extern PetscErrorCode PetscViewerMathematicaInitializePackage(const char[]); 244 extern PetscErrorCode PetscViewerMathematicaFinalizePackage(void); 245 extern PetscErrorCode PetscViewerMathematicaGetName(PetscViewer, const char **); 246 extern PetscErrorCode PetscViewerMathematicaSetName(PetscViewer, const char []); 247 extern PetscErrorCode PetscViewerMathematicaClearName(PetscViewer); 248 extern PetscErrorCode PetscViewerMathematicaSkipPackets(PetscViewer, int); 249 250 extern PetscErrorCode PetscViewerSiloGetName(PetscViewer, char **); 251 extern PetscErrorCode PetscViewerSiloSetName(PetscViewer, const char []); 252 extern PetscErrorCode PetscViewerSiloClearName(PetscViewer); 253 extern PetscErrorCode PetscViewerSiloGetMeshName(PetscViewer, char **); 254 extern PetscErrorCode PetscViewerSiloSetMeshName(PetscViewer, const char []); 255 extern PetscErrorCode PetscViewerSiloClearMeshName(PetscViewer); 256 257 extern PetscErrorCode PetscViewerNetcdfOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*); 258 extern PetscErrorCode PetscViewerNetcdfGetID(PetscViewer, int *); 259 260 extern PetscErrorCode PetscViewerHDF5WriteSDS(PetscViewer,float *,int,int *,int); 261 262 extern PetscErrorCode PetscViewerHDF5Open(MPI_Comm,const char[],PetscFileMode,PetscViewer*); 263 extern PetscErrorCode PetscViewerHDF5PushGroup(PetscViewer,const char *); 264 extern PetscErrorCode PetscViewerHDF5PopGroup(PetscViewer); 265 extern PetscErrorCode PetscViewerHDF5GetGroup(PetscViewer, const char **); 266 extern PetscErrorCode PetscViewerHDF5IncrementTimestep(PetscViewer); 267 extern PetscErrorCode PetscViewerHDF5SetTimestep(PetscViewer,PetscInt); 268 extern PetscErrorCode PetscViewerHDF5GetTimestep(PetscViewer,PetscInt*); 269 #ifdef PETSC_HAVE_HDF5 270 #include <hdf5.h> 271 extern PetscErrorCode PetscViewerHDF5GetFileId(PetscViewer,hid_t*); 272 extern PetscErrorCode PetscViewerHDF5OpenGroup(PetscViewer, hid_t *, hid_t *); 273 #endif 274 275 /* 276 These are all the default viewers that do not have 277 to be explicitly opened 278 */ 279 extern PetscViewer PETSC_VIEWER_STDOUT_(MPI_Comm); 280 extern PetscErrorCode PetscViewerASCIIGetStdout(MPI_Comm,PetscViewer*); 281 extern PetscViewer PETSC_VIEWER_STDERR_(MPI_Comm); 282 extern PetscErrorCode PetscViewerASCIIGetStderr(MPI_Comm,PetscViewer*); 283 extern PetscViewer PETSC_VIEWER_DRAW_(MPI_Comm); 284 extern PetscViewer PETSC_VIEWER_SOCKET_(MPI_Comm); 285 extern PetscViewer PETSC_VIEWER_BINARY_(MPI_Comm); 286 extern PetscViewer PETSC_VIEWER_MATLAB_(MPI_Comm); 287 extern PetscViewer PETSC_VIEWER_MATHEMATICA_WORLD_PRIVATE; 288 289 #define PETSC_VIEWER_STDERR_SELF PETSC_VIEWER_STDERR_(PETSC_COMM_SELF) 290 #define PETSC_VIEWER_STDERR_WORLD PETSC_VIEWER_STDERR_(PETSC_COMM_WORLD) 291 292 /*MC 293 PETSC_VIEWER_STDOUT_WORLD - same as PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD) 294 295 Level: beginner 296 M*/ 297 #define PETSC_VIEWER_STDOUT_WORLD PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD) 298 299 /*MC 300 PETSC_VIEWER_STDOUT_SELF - same as PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF) 301 302 Level: beginner 303 M*/ 304 #define PETSC_VIEWER_STDOUT_SELF PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF) 305 306 /*MC 307 PETSC_VIEWER_DRAW_WORLD - same as PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD) 308 309 Level: intermediate 310 M*/ 311 #define PETSC_VIEWER_DRAW_WORLD PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD) 312 313 /*MC 314 PETSC_VIEWER_DRAW_SELF - same as PETSC_VIEWER_DRAW_(PETSC_COMM_SELF) 315 316 Level: intermediate 317 M*/ 318 #define PETSC_VIEWER_DRAW_SELF PETSC_VIEWER_DRAW_(PETSC_COMM_SELF) 319 320 /*MC 321 PETSC_VIEWER_SOCKET_WORLD - same as PETSC_VIEWER_SOCKET_(PETSC_COMM_WORLD) 322 323 Level: intermediate 324 M*/ 325 #define PETSC_VIEWER_SOCKET_WORLD PETSC_VIEWER_SOCKET_(PETSC_COMM_WORLD) 326 327 /*MC 328 PETSC_VIEWER_SOCKET_SELF - same as PETSC_VIEWER_SOCKET_(PETSC_COMM_SELF) 329 330 Level: intermediate 331 M*/ 332 #define PETSC_VIEWER_SOCKET_SELF PETSC_VIEWER_SOCKET_(PETSC_COMM_SELF) 333 334 /*MC 335 PETSC_VIEWER_BINARY_WORLD - same as PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD) 336 337 Level: intermediate 338 M*/ 339 #define PETSC_VIEWER_BINARY_WORLD PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD) 340 341 /*MC 342 PETSC_VIEWER_BINARY_SELF - same as PETSC_VIEWER_BINARY_(PETSC_COMM_SELF) 343 344 Level: intermediate 345 M*/ 346 #define PETSC_VIEWER_BINARY_SELF PETSC_VIEWER_BINARY_(PETSC_COMM_SELF) 347 348 /*MC 349 PETSC_VIEWER_MATLAB_WORLD - same as PETSC_VIEWER_MATLAB_(PETSC_COMM_WORLD) 350 351 Level: intermediate 352 M*/ 353 #define PETSC_VIEWER_MATLAB_WORLD PETSC_VIEWER_MATLAB_(PETSC_COMM_WORLD) 354 355 /*MC 356 PETSC_VIEWER_MATLAB_SELF - same as PETSC_VIEWER_MATLAB_(PETSC_COMM_SELF) 357 358 Level: intermediate 359 M*/ 360 #define PETSC_VIEWER_MATLAB_SELF PETSC_VIEWER_MATLAB_(PETSC_COMM_SELF) 361 362 #define PETSC_VIEWER_MATHEMATICA_WORLD (PetscViewerInitializeMathematicaWorld_Private(),PETSC_VIEWER_MATHEMATICA_WORLD_PRIVATE) 363 364 #define PetscViewerFlowControlStart(viewer,mcnt,cnt) (PetscViewerBinaryGetFlowControl(viewer,mcnt) || PetscViewerBinaryGetFlowControl(viewer,cnt)) 365 #define PetscViewerFlowControlStepMaster(viewer,i,mcnt,cnt) ((i >= mcnt) ? (mcnt += cnt,MPI_Bcast(&mcnt,1,MPIU_INT,0,((PetscObject)viewer)->comm)) : 0) 366 #define PetscViewerFlowControlEndMaster(viewer,mcnt) (mcnt = 0,MPI_Bcast(&mcnt,1,MPIU_INT,0,((PetscObject)viewer)->comm)) 367 #define PetscViewerFlowControlStepWorker(viewer,rank,mcnt) 0; while (1) { PetscErrorCode _ierr; \ 368 if (rank < mcnt) break; \ 369 _ierr = MPI_Bcast(&mcnt,1,MPIU_INT,0,((PetscObject)viewer)->comm);CHKERRQ(_ierr);\ 370 } 371 #define PetscViewerFlowControlEndWorker(viewer,mcnt) 0; while (1) { PetscErrorCode _ierr; \ 372 _ierr = MPI_Bcast(&mcnt,1,MPIU_INT,0,((PetscObject)viewer)->comm);CHKERRQ(_ierr);\ 373 if (mcnt == 0) break; \ 374 } 375 376 /* 377 petscViewer writes to MATLAB .mat file 378 */ 379 extern PetscErrorCode PetscViewerMatlabPutArray(PetscViewer,int,int,const PetscScalar*,const char*); 380 extern PetscErrorCode PetscViewerMatlabGetArray(PetscViewer,int,int,PetscScalar*,const char*); 381 extern PetscErrorCode PetscViewerMatlabPutVariable(PetscViewer,const char*,void*); 382 383 /*S 384 PetscViewers - Abstract collection of PetscViewers. It is just an expandable array of viewers. 385 386 Level: intermediate 387 388 Concepts: viewing 389 390 .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType, PetscViewer, PetscViewersCreate(), 391 PetscViewersGetViewer() 392 S*/ 393 typedef struct _n_PetscViewers* PetscViewers; 394 extern PetscErrorCode PetscViewersCreate(MPI_Comm,PetscViewers*); 395 extern PetscErrorCode PetscViewersDestroy(PetscViewers*); 396 extern PetscErrorCode PetscViewersGetViewer(PetscViewers,PetscInt,PetscViewer*); 397 398 #if defined(PETSC_HAVE_AMS) 399 #include <ams.h> 400 extern PetscErrorCode PetscViewerAMSSetCommName(PetscViewer,const char[]); 401 extern PetscErrorCode PetscViewerAMSGetAMSComm(PetscViewer,AMS_Comm *); 402 extern PetscErrorCode PetscViewerAMSOpen(MPI_Comm,const char[],PetscViewer*); 403 extern PetscErrorCode PetscViewerAMSLock(PetscViewer); 404 extern PetscViewer PETSC_VIEWER_AMS_(MPI_Comm); 405 extern PetscErrorCode PETSC_VIEWER_AMS_Destroy(MPI_Comm); 406 #define PETSC_VIEWER_AMS_WORLD PETSC_VIEWER_AMS_(PETSC_COMM_WORLD) 407 #endif 408 409 410 PETSC_EXTERN_CXX_END 411 #endif 412