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