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