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 "petsc.h" 29 30 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 31 extern "C" { 32 #endif 33 34 extern PetscCookie PETSC_VIEWER_COOKIE; 35 36 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 37 } 38 #endif 39 40 41 /* 42 petsc.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 PETSC_VIEWER_SOCKET "socket" 55 #define PETSC_VIEWER_ASCII "ascii" 56 #define PETSC_VIEWER_BINARY "binary" 57 #define PETSC_VIEWER_STRING "string" 58 #define PETSC_VIEWER_DRAW "draw" 59 #define PETSC_VIEWER_VU "vu" 60 #define PETSC_VIEWER_MATHEMATICA "mathematica" 61 #define PETSC_VIEWER_SILO "silo" 62 #define PETSC_VIEWER_NETCDF "netcdf" 63 #define PETSC_VIEWER_HDF4 "hdf4" 64 #define PETSC_VIEWER_MATLAB "matlab" 65 66 extern PetscFList PetscViewerList; 67 EXTERN PetscErrorCode PetscViewerRegisterAll(const char *); 68 EXTERN PetscErrorCode PetscViewerRegisterDestroy(void); 69 70 EXTERN PetscErrorCode PetscViewerRegister(const char*,const char*,const char*,PetscErrorCode (*)(PetscViewer)); 71 72 /*MC 73 PetscViewerRegisterDynamic - Adds a method to the Krylov subspace solver package. 74 75 Synopsis: 76 PetscErrorCode PetscViewerRegisterDynamic(char *name_solver,char *path,char *name_create,PetscErrorCode (*routine_create)(PetscViewer)) 77 78 Not Collective 79 80 Input Parameters: 81 + name_solver - name of a new user-defined solver 82 . path - path (either absolute or relative) the library containing this solver 83 . name_create - name of routine to create method context 84 - routine_create - routine to create method context 85 86 Level: developer 87 88 Notes: 89 PetscViewerRegisterDynamic() may be called multiple times to add several user-defined solvers. 90 91 If dynamic libraries are used, then the fourth input argument (routine_create) 92 is ignored. 93 94 Sample usage: 95 .vb 96 PetscViewerRegisterDynamic("my_viewer_type",/home/username/my_lib/lib/libO/solaris/mylib.a, 97 "MyViewerCreate",MyViewerCreate); 98 .ve 99 100 Then, your solver can be chosen with the procedural interface via 101 $ PetscViewerSetType(ksp,"my_viewer_type") 102 or at runtime via the option 103 $ -viewer_type my_viewer_type 104 105 Concepts: registering^Viewers 106 107 .seealso: PetscViewerRegisterAll(), PetscViewerRegisterDestroy() 108 M*/ 109 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 110 #define PetscViewerRegisterDynamic(a,b,c,d) PetscViewerRegister(a,b,c,0) 111 #else 112 #define PetscViewerRegisterDynamic(a,b,c,d) PetscViewerRegister(a,b,c,d) 113 #endif 114 115 EXTERN PetscErrorCode PetscViewerCreate(MPI_Comm,PetscViewer*); 116 EXTERN PetscErrorCode PetscViewerSetFromOptions(PetscViewer); 117 118 EXTERN PetscErrorCode PetscViewerASCIIOpen(MPI_Comm,const char[],PetscViewer*); 119 120 /*E 121 PetscViewerFileType - Indicates how the file should be opened for the viewer 122 123 Level: beginner 124 125 .seealso: PetscViewerSetFileName(), PetscViewerSetFileType(), PetscViewerBinaryOpen(), PetscViewerASCIIOpen(), 126 PetscViewerMatlabOpen() 127 E*/ 128 typedef enum {PETSC_FILE_RDONLY,PETSC_FILE_WRONLY,PETSC_FILE_CREATE} PetscViewerFileType; 129 130 /*M 131 PETSC_FILE_RDONLY - File is open to be read from only, not written to 132 133 Level: beginner 134 135 .seealso: PetscViewerFileType, PETSC_FILE_WRONLY, PETSC_FILE_CREATE, PetscViewerSetFileName(), PetscViewerSetFileType(), 136 PetscViewerBinaryOpen(), PetscViewerASCIIOpen(), PetscViewerMatlabOpen() 137 138 M*/ 139 140 /*M 141 PETSC_FILE_WRONLY - File is open to be appended to. 142 143 Level: beginner 144 145 .seealso: PetscViewerFileType, PETSC_FILE_RDONLY, PETSC_FILE_CREATE, PetscViewerSetFileName(), PetscViewerSetFileType(), 146 PetscViewerBinaryOpen(), PetscViewerASCIIOpen(), PetscViewerMatlabOpen() 147 148 M*/ 149 150 /*M 151 PETSC_FILE_CREATE - Create the file, or delete it and open an empty file if it already existed 152 153 Level: beginner 154 155 .seealso: PetscViewerFileType, PETSC_FILE_RDONLY, PETSC_FILE_WRONLY, PetscViewerSetFileName(), PetscViewerSetFileType(), 156 PetscViewerBinaryOpen(), PetscViewerASCIIOpen(), PetscViewerMatlabOpen() 157 158 M*/ 159 160 EXTERN PetscErrorCode PetscViewerBinaryOpen(MPI_Comm,const char[],PetscViewerFileType,PetscViewer*); 161 EXTERN PetscErrorCode PetscViewerSocketOpen(MPI_Comm,const char[],int,PetscViewer*); 162 EXTERN PetscErrorCode PetscViewerStringOpen(MPI_Comm,char[],PetscInt,PetscViewer*); 163 EXTERN PetscErrorCode PetscViewerDrawOpen(MPI_Comm,const char[],const char[],int,int,int,int,PetscViewer*); 164 EXTERN PetscErrorCode PetscViewerMathematicaOpen(MPI_Comm, int, const char[], const char[], PetscViewer *); 165 EXTERN PetscErrorCode PetscViewerSiloOpen(MPI_Comm, const char[], PetscViewer *); 166 EXTERN PetscErrorCode PetscViewerMatlabOpen(MPI_Comm,const char[],PetscViewerFileType,PetscViewer*); 167 168 EXTERN PetscErrorCode PetscViewerGetType(PetscViewer,PetscViewerType*); 169 EXTERN PetscErrorCode PetscViewerSetType(PetscViewer,const PetscViewerType); 170 EXTERN PetscErrorCode PetscViewerDestroy(PetscViewer); 171 EXTERN PetscErrorCode PetscViewerGetSingleton(PetscViewer,PetscViewer*); 172 EXTERN PetscErrorCode PetscViewerRestoreSingleton(PetscViewer,PetscViewer*); 173 174 175 /*E 176 PetscViewerFormat - Way a viewer presents the object 177 178 Level: beginner 179 180 .seealso: PetscViewerSetFormat(), PetscViewer, PetscViewerType, PetscViewerPushFormat(), PetscViewerPopFormat() 181 E*/ 182 typedef enum { 183 PETSC_VIEWER_ASCII_DEFAULT, 184 PETSC_VIEWER_ASCII_MATLAB, 185 PETSC_VIEWER_ASCII_MATHEMATICA, 186 PETSC_VIEWER_ASCII_IMPL, 187 PETSC_VIEWER_ASCII_INFO, 188 PETSC_VIEWER_ASCII_INFO_DETAIL, 189 PETSC_VIEWER_ASCII_COMMON, 190 PETSC_VIEWER_ASCII_SYMMODU, 191 PETSC_VIEWER_ASCII_INDEX, 192 PETSC_VIEWER_ASCII_DENSE, 193 PETSC_VIEWER_BINARY_DEFAULT, 194 PETSC_VIEWER_BINARY_NATIVE, 195 PETSC_VIEWER_DRAW_BASIC, 196 PETSC_VIEWER_DRAW_LG, 197 PETSC_VIEWER_DRAW_CONTOUR, 198 PETSC_VIEWER_DRAW_PORTS, 199 PETSC_VIEWER_NATIVE, 200 PETSC_VIEWER_NOFORMAT, 201 PETSC_VIEWER_ASCII_FACTOR_INFO} PetscViewerFormat; 202 203 EXTERN PetscErrorCode PetscViewerSetFormat(PetscViewer,PetscViewerFormat); 204 EXTERN PetscErrorCode PetscViewerPushFormat(PetscViewer,PetscViewerFormat); 205 EXTERN PetscErrorCode PetscViewerPopFormat(PetscViewer); 206 EXTERN PetscErrorCode PetscViewerGetFormat(PetscViewer,PetscViewerFormat*); 207 EXTERN PetscErrorCode PetscViewerFlush(PetscViewer); 208 209 /* 210 Operations explicit to a particular class of viewers 211 */ 212 213 /*E 214 PetscViewerFormat - Access mode for a file. 215 216 Level: beginner 217 218 .seealso: PetscViewerASCIISetMode() 219 E*/ 220 typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode; 221 222 EXTERN PetscErrorCode PetscViewerASCIIGetPointer(PetscViewer,FILE**); 223 EXTERN PetscErrorCode PetscViewerASCIISetMode(PetscViewer,PetscFileMode); 224 EXTERN PetscErrorCode PetscViewerASCIIPrintf(PetscViewer,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 225 EXTERN PetscErrorCode PetscViewerASCIISynchronizedPrintf(PetscViewer,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 226 EXTERN PetscErrorCode PetscViewerASCIIPushTab(PetscViewer); 227 EXTERN PetscErrorCode PetscViewerASCIIPopTab(PetscViewer); 228 EXTERN PetscErrorCode PetscViewerASCIIUseTabs(PetscViewer,PetscTruth); 229 EXTERN PetscErrorCode PetscViewerASCIISetTab(PetscViewer,PetscInt); 230 EXTERN PetscErrorCode PetscViewerBinaryGetDescriptor(PetscViewer,int*); 231 EXTERN PetscErrorCode PetscViewerBinaryGetInfoPointer(PetscViewer,FILE **); 232 EXTERN PetscErrorCode PetscViewerSetFileType(PetscViewer,PetscViewerFileType); 233 EXTERN PetscErrorCode PetscViewerStringSPrintf(PetscViewer,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 234 EXTERN PetscErrorCode PetscViewerStringSetString(PetscViewer,char[],PetscInt); 235 EXTERN PetscErrorCode PetscViewerDrawClear(PetscViewer); 236 EXTERN PetscErrorCode PetscViewerDrawSetInfo(PetscViewer,const char[],const char[],int,int,int,int); 237 EXTERN PetscErrorCode PetscViewerSocketSetConnection(PetscViewer,const char[],PetscInt); 238 EXTERN PetscErrorCode PetscViewerBinarySkipInfo(PetscViewer); 239 EXTERN PetscErrorCode PetscViewerBinaryLoadInfo(PetscViewer); 240 241 242 EXTERN PetscErrorCode PetscViewerSetFilename(PetscViewer,const char[]); 243 EXTERN PetscErrorCode PetscViewerGetFilename(PetscViewer,char**); 244 245 EXTERN PetscErrorCode PetscPLAPACKInitializePackage(char *); 246 EXTERN PetscErrorCode PetscPLAPACKFinalizePackage(void); 247 248 EXTERN PetscErrorCode PetscViewerVUGetPointer(PetscViewer, FILE**); 249 EXTERN PetscErrorCode PetscViewerVUSetMode(PetscViewer, PetscFileMode); 250 EXTERN PetscErrorCode PetscViewerVUSetVecSeen(PetscViewer, PetscTruth); 251 EXTERN PetscErrorCode PetscViewerVUGetVecSeen(PetscViewer, PetscTruth *); 252 EXTERN PetscErrorCode PetscViewerVUPrintDeferred(PetscViewer, const char [], ...) PETSC_PRINTF_FORMAT_CHECK(2,3); 253 EXTERN PetscErrorCode PetscViewerVUFlushDeferred(PetscViewer); 254 255 EXTERN PetscErrorCode PetscViewerMathematicaInitializePackage(char *); 256 EXTERN PetscErrorCode PetscViewerMathematicaFinalizePackage(void); 257 EXTERN PetscErrorCode PetscViewerMathematicaGetName(PetscViewer, const char **); 258 EXTERN PetscErrorCode PetscViewerMathematicaSetName(PetscViewer, const char []); 259 EXTERN PetscErrorCode PetscViewerMathematicaClearName(PetscViewer); 260 EXTERN PetscErrorCode PetscViewerMathematicaSkipPackets(PetscViewer, int); 261 262 EXTERN PetscErrorCode PetscViewerSiloGetName(PetscViewer, char **); 263 EXTERN PetscErrorCode PetscViewerSiloSetName(PetscViewer, const char []); 264 EXTERN PetscErrorCode PetscViewerSiloClearName(PetscViewer); 265 EXTERN PetscErrorCode PetscViewerSiloGetMeshName(PetscViewer, char **); 266 EXTERN PetscErrorCode PetscViewerSiloSetMeshName(PetscViewer, const char []); 267 EXTERN PetscErrorCode PetscViewerSiloClearMeshName(PetscViewer); 268 269 EXTERN PetscErrorCode PetscViewerNetcdfOpen(MPI_Comm,const char[],PetscViewerFileType,PetscViewer*); 270 EXTERN PetscErrorCode PetscViewerNetcdfGetID(PetscViewer, int *); 271 272 EXTERN PetscErrorCode PetscViewerHDF4Open(MPI_Comm,const char[],PetscViewerFileType,PetscViewer*); 273 EXTERN PetscErrorCode PetscViewerHDF4WriteSDS(PetscViewer viewer, float *xf, int d, int *dims, int bs); 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 PetscViewer PETSC_VIEWER_STDERR_(MPI_Comm); 281 EXTERN PetscViewer PETSC_VIEWER_DRAW_(MPI_Comm); 282 EXTERN PetscViewer PETSC_VIEWER_SOCKET_(MPI_Comm); 283 EXTERN PetscViewer PETSC_VIEWER_BINARY_(MPI_Comm); 284 EXTERN PetscViewer PETSC_VIEWER_MATLAB_(MPI_Comm); 285 EXTERN PetscViewer PETSC_VIEWER_MATHEMATICA_WORLD_PRIVATE; 286 287 #define PETSC_VIEWER_STDERR_SELF PETSC_VIEWER_STDERR_(PETSC_COMM_SELF) 288 #define PETSC_VIEWER_STDERR_WORLD PETSC_VIEWER_STDERR_(PETSC_COMM_WORLD) 289 290 /*MC 291 PETSC_VIEWER_STDOUT_WORLD - same as PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD) 292 293 Level: beginner 294 M*/ 295 #define PETSC_VIEWER_STDOUT_WORLD PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD) 296 297 /*MC 298 PETSC_VIEWER_STDOUT_SELF - same as PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF) 299 300 Level: beginner 301 M*/ 302 #define PETSC_VIEWER_STDOUT_SELF PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF) 303 304 /*MC 305 PETSC_VIEWER_DRAW_WORLD - same as PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD) 306 307 Level: intermediate 308 M*/ 309 #define PETSC_VIEWER_DRAW_WORLD PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD) 310 311 /*MC 312 PETSC_VIEWER_DRAW_SELF - same as PETSC_VIEWER_DRAW_(PETSC_COMM_SELF) 313 314 Level: intermediate 315 M*/ 316 #define PETSC_VIEWER_DRAW_SELF PETSC_VIEWER_DRAW_(PETSC_COMM_SELF) 317 318 /*MC 319 PETSC_VIEWER_SOCKET_WORLD - same as PETSC_VIEWER_SOCKET_(PETSC_COMM_WORLD) 320 321 Level: intermediate 322 M*/ 323 #define PETSC_VIEWER_SOCKET_WORLD PETSC_VIEWER_SOCKET_(PETSC_COMM_WORLD) 324 325 /*MC 326 PETSC_VIEWER_SOCKET_SELF - same as PETSC_VIEWER_SOCKET_(PETSC_COMM_SELF) 327 328 Level: intermediate 329 M*/ 330 #define PETSC_VIEWER_SOCKET_SELF PETSC_VIEWER_SOCKET_(PETSC_COMM_SELF) 331 332 /*MC 333 PETSC_VIEWER_BINARY_WORLD - same as PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD) 334 335 Level: intermediate 336 M*/ 337 #define PETSC_VIEWER_BINARY_WORLD PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD) 338 339 /*MC 340 PETSC_VIEWER_BINARY_SELF - same as PETSC_VIEWER_BINARY_(PETSC_COMM_SELF) 341 342 Level: intermediate 343 M*/ 344 #define PETSC_VIEWER_BINARY_SELF PETSC_VIEWER_BINARY_(PETSC_COMM_SELF) 345 346 /*MC 347 PETSC_VIEWER_MATLAB_WORLD - same as PETSC_VIEWER_MATLAB_(PETSC_COMM_WORLD) 348 349 Level: intermediate 350 M*/ 351 #define PETSC_VIEWER_MATLAB_WORLD PETSC_VIEWER_MATLAB_(PETSC_COMM_WORLD) 352 353 /*MC 354 PETSC_VIEWER_MATLAB_SELF - same as PETSC_VIEWER_MATLAB_(PETSC_COMM_SELF) 355 356 Level: intermediate 357 M*/ 358 #define PETSC_VIEWER_MATLAB_SELF PETSC_VIEWER_MATLAB_(PETSC_COMM_SELF) 359 360 #define PETSC_VIEWER_MATHEMATICA_WORLD (PetscViewerInitializeMathematicaWorld_Private(),PETSC_VIEWER_MATHEMATICA_WORLD_PRIVATE) 361 362 /* 363 petscViewer writes to Matlab .mat file 364 */ 365 EXTERN PetscErrorCode PetscViewerMatlabPutArray(PetscViewer,int,int,PetscScalar*,char*); 366 EXTERN PetscErrorCode PetscViewerMatlabGetArray(PetscViewer,int,int,PetscScalar*,char*); 367 EXTERN PetscErrorCode PetscViewerMatlabPutVariable(PetscViewer,const char*,void*); 368 369 /* 370 PetscViewer utility routines used by PETSc that are not normally used 371 by users. 372 */ 373 EXTERN PetscErrorCode PetscViewerSocketPutScalar(PetscViewer,PetscInt,PetscInt,PetscScalar*); 374 EXTERN PetscErrorCode PetscViewerSocketPutReal(PetscViewer,PetscInt,PetscInt,PetscReal*); 375 EXTERN PetscErrorCode PetscViewerSocketPutInt(PetscViewer,PetscInt,PetscInt*); 376 EXTERN PetscErrorCode PetscViewerSocketPutSparse_Private(PetscViewer,PetscInt,PetscInt,PetscInt,PetscScalar*,PetscInt*,PetscInt *); 377 378 /*S 379 PetscViewers - Abstract collection of PetscViewers 380 381 Level: intermediate 382 383 Concepts: viewing 384 385 .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType, PetscViewer, PetscViewersCreate(), 386 PetscViewersGetViewer() 387 S*/ 388 typedef struct _p_PetscViewers* PetscViewers; 389 EXTERN PetscErrorCode PetscViewersCreate(MPI_Comm,PetscViewers*); 390 EXTERN PetscErrorCode PetscViewersDestroy(PetscViewers); 391 EXTERN PetscErrorCode PetscViewersGetViewer(PetscViewers,int,PetscViewer*); 392 393 PETSC_EXTERN_CXX_END 394 #endif 395