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