xref: /petsc/include/petscviewer.h (revision b85befe5cb2ed2dd33c332e4c28bf3c9516a635e)
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 PETSC_DLLEXPORT 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 const 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 PETSC_DLLEXPORT PetscViewerRegisterAll(const char *);
68 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerRegisterDestroy(void);
69 
70 EXTERN PetscErrorCode PETSC_DLLEXPORT 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 PETSC_DLLEXPORT PetscViewerCreate(MPI_Comm,PetscViewer*);
116 PetscPolymorphicSubroutine(PetscViewerCreate,(PetscViewer *v),(PETSC_COMM_SELF,v))
117 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSetFromOptions(PetscViewer);
118 
119 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerASCIIOpen(MPI_Comm,const char[],PetscViewer*);
120 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryCreate(MPI_Comm,PetscViewer*);
121 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
122 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSocketOpen(MPI_Comm,const char[],int,PetscViewer*);
123 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerStringOpen(MPI_Comm,char[],PetscInt,PetscViewer*);
124 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerDrawOpen(MPI_Comm,const char[],const char[],int,int,int,int,PetscViewer*);
125 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMathematicaOpen(MPI_Comm, int, const char[], const char[], PetscViewer *);
126 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloOpen(MPI_Comm, const char[], PetscViewer *);
127 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMatlabOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
128 
129 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerGetType(PetscViewer,PetscViewerType*);
130 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSetType(PetscViewer,PetscViewerType);
131 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerDestroy(PetscViewer);
132 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerGetSingleton(PetscViewer,PetscViewer*);
133 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerRestoreSingleton(PetscViewer,PetscViewer*);
134 
135 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSetUp(PetscViewer);
136 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerView(PetscViewer,PetscViewer);
137 
138 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSetOptionsPrefix(PetscViewer,const char[]);
139 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerAppendOptionsPrefix(PetscViewer,const char[]);
140 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerGetOptionsPrefix(PetscViewer,const char*[]);
141 
142 /*E
143     PetscViewerFormat - Way a viewer presents the object
144 
145    Level: beginner
146 
147 .seealso: PetscViewerSetFormat(), PetscViewer, PetscViewerType, PetscViewerPushFormat(), PetscViewerPopFormat()
148 E*/
149 typedef enum {
150   PETSC_VIEWER_ASCII_DEFAULT,
151   PETSC_VIEWER_ASCII_MATLAB,
152   PETSC_VIEWER_ASCII_MATHEMATICA,
153   PETSC_VIEWER_ASCII_IMPL,
154   PETSC_VIEWER_ASCII_INFO,
155   PETSC_VIEWER_ASCII_INFO_DETAIL,
156   PETSC_VIEWER_ASCII_COMMON,
157   PETSC_VIEWER_ASCII_SYMMODU,
158   PETSC_VIEWER_ASCII_INDEX,
159   PETSC_VIEWER_ASCII_DENSE,
160   PETSC_VIEWER_ASCII_VTK,
161   PETSC_VIEWER_ASCII_VTK_CELL,
162   PETSC_VIEWER_ASCII_VTK_COORDS,
163   PETSC_VIEWER_ASCII_PCICE,
164   PETSC_VIEWER_ASCII_PYLITH,
165   PETSC_VIEWER_BINARY_DEFAULT,
166   PETSC_VIEWER_BINARY_NATIVE,
167   PETSC_VIEWER_DRAW_BASIC,
168   PETSC_VIEWER_DRAW_LG,
169   PETSC_VIEWER_DRAW_CONTOUR,
170   PETSC_VIEWER_DRAW_PORTS,
171   PETSC_VIEWER_NATIVE,
172   PETSC_VIEWER_NOFORMAT,
173   PETSC_VIEWER_ASCII_FACTOR_INFO} PetscViewerFormat;
174 
175 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSetFormat(PetscViewer,PetscViewerFormat);
176 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerPushFormat(PetscViewer,PetscViewerFormat);
177 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerPopFormat(PetscViewer);
178 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerGetFormat(PetscViewer,PetscViewerFormat*);
179 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerFlush(PetscViewer);
180 
181 /*
182    Operations explicit to a particular class of viewers
183 */
184 
185 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerASCIIGetPointer(PetscViewer,FILE**);
186 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerFileSetMode(PetscViewer,PetscFileMode);
187 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerASCIIPrintf(PetscViewer,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
188 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerASCIISynchronizedPrintf(PetscViewer,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
189 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerASCIIPushTab(PetscViewer);
190 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerASCIIPopTab(PetscViewer);
191 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerASCIIUseTabs(PetscViewer,PetscTruth);
192 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerASCIISetTab(PetscViewer,PetscInt);
193 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryGetDescriptor(PetscViewer,int*);
194 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryGetInfoPointer(PetscViewer,FILE **);
195 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryRead(PetscViewer,void*,PetscInt,PetscDataType);
196 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryWrite(PetscViewer,void*,PetscInt,PetscDataType,PetscTruth);
197 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerStringSPrintf(PetscViewer,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
198 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerStringSetString(PetscViewer,char[],PetscInt);
199 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerDrawClear(PetscViewer);
200 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerDrawSetInfo(PetscViewer,const char[],const char[],int,int,int,int);
201 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSocketSetConnection(PetscViewer,const char[],PetscInt);
202 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinarySkipInfo(PetscViewer);
203 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryLoadInfo(PetscViewer);
204 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinarySetSkipOptions(PetscViewer,PetscTruth);
205 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryGetSkipOptions(PetscViewer,PetscTruth*);
206 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryReadStringArray(PetscViewer,char***);
207 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerBinaryWriteStringArray(PetscViewer,char**);
208 
209 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerFileSetName(PetscViewer,const char[]);
210 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerFileGetName(PetscViewer,char**);
211 
212 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPLAPACKInitializePackage(char *);
213 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPLAPACKFinalizePackage(void);
214 
215 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerVUGetPointer(PetscViewer, FILE**);
216 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerVUSetVecSeen(PetscViewer, PetscTruth);
217 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerVUGetVecSeen(PetscViewer, PetscTruth *);
218 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerVUPrintDeferred(PetscViewer, const char [], ...) PETSC_PRINTF_FORMAT_CHECK(2,3);
219 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerVUFlushDeferred(PetscViewer);
220 
221 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMathematicaInitializePackage(char *);
222 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMathematicaFinalizePackage(void);
223 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMathematicaGetName(PetscViewer, const char **);
224 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMathematicaSetName(PetscViewer, const char []);
225 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMathematicaClearName(PetscViewer);
226 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMathematicaSkipPackets(PetscViewer, int);
227 
228 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloGetName(PetscViewer, char **);
229 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloSetName(PetscViewer, const char []);
230 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloClearName(PetscViewer);
231 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloGetMeshName(PetscViewer, char **);
232 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloSetMeshName(PetscViewer, const char []);
233 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloClearMeshName(PetscViewer);
234 
235 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerNetcdfOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
236 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerNetcdfGetID(PetscViewer, int *);
237 
238 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerHDF4Open(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
239 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerHDF4WriteSDS(PetscViewer viewer, float *xf, int d, int *dims, int bs);
240 
241 /*
242      These are all the default viewers that do not have
243    to be explicitly opened
244 */
245 EXTERN PetscViewer PETSC_DLLEXPORT PETSC_VIEWER_STDOUT_(MPI_Comm);
246 EXTERN PetscViewer PETSC_DLLEXPORT PETSC_VIEWER_STDERR_(MPI_Comm);
247 EXTERN PetscViewer PETSC_DLLEXPORT PETSC_VIEWER_DRAW_(MPI_Comm);
248 EXTERN PetscViewer PETSC_DLLEXPORT PETSC_VIEWER_SOCKET_(MPI_Comm);
249 EXTERN PetscViewer PETSC_DLLEXPORT PETSC_VIEWER_BINARY_(MPI_Comm);
250 EXTERN PetscViewer PETSC_DLLEXPORT PETSC_VIEWER_MATLAB_(MPI_Comm);
251 EXTERN PetscViewer PETSC_VIEWER_MATHEMATICA_WORLD_PRIVATE;
252 
253 #define PETSC_VIEWER_STDERR_SELF  PETSC_VIEWER_STDERR_(PETSC_COMM_SELF)
254 #define PETSC_VIEWER_STDERR_WORLD PETSC_VIEWER_STDERR_(PETSC_COMM_WORLD)
255 
256 /*MC
257   PETSC_VIEWER_STDOUT_WORLD  - same as PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD)
258 
259   Level: beginner
260 M*/
261 #define PETSC_VIEWER_STDOUT_WORLD PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD)
262 
263 /*MC
264   PETSC_VIEWER_STDOUT_SELF  - same as PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)
265 
266   Level: beginner
267 M*/
268 #define PETSC_VIEWER_STDOUT_SELF  PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)
269 
270 /*MC
271   PETSC_VIEWER_DRAW_WORLD  - same as PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD)
272 
273   Level: intermediate
274 M*/
275 #define PETSC_VIEWER_DRAW_WORLD   PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD)
276 
277 /*MC
278   PETSC_VIEWER_DRAW_SELF  - same as PETSC_VIEWER_DRAW_(PETSC_COMM_SELF)
279 
280   Level: intermediate
281 M*/
282 #define PETSC_VIEWER_DRAW_SELF    PETSC_VIEWER_DRAW_(PETSC_COMM_SELF)
283 
284 /*MC
285   PETSC_VIEWER_SOCKET_WORLD  - same as PETSC_VIEWER_SOCKET_(PETSC_COMM_WORLD)
286 
287   Level: intermediate
288 M*/
289 #define PETSC_VIEWER_SOCKET_WORLD PETSC_VIEWER_SOCKET_(PETSC_COMM_WORLD)
290 
291 /*MC
292   PETSC_VIEWER_SOCKET_SELF  - same as PETSC_VIEWER_SOCKET_(PETSC_COMM_SELF)
293 
294   Level: intermediate
295 M*/
296 #define PETSC_VIEWER_SOCKET_SELF  PETSC_VIEWER_SOCKET_(PETSC_COMM_SELF)
297 
298 /*MC
299   PETSC_VIEWER_BINARY_WORLD  - same as PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD)
300 
301   Level: intermediate
302 M*/
303 #define PETSC_VIEWER_BINARY_WORLD PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD)
304 
305 /*MC
306   PETSC_VIEWER_BINARY_SELF  - same as PETSC_VIEWER_BINARY_(PETSC_COMM_SELF)
307 
308   Level: intermediate
309 M*/
310 #define PETSC_VIEWER_BINARY_SELF  PETSC_VIEWER_BINARY_(PETSC_COMM_SELF)
311 
312 /*MC
313   PETSC_VIEWER_MATLAB_WORLD  - same as PETSC_VIEWER_MATLAB_(PETSC_COMM_WORLD)
314 
315   Level: intermediate
316 M*/
317 #define PETSC_VIEWER_MATLAB_WORLD PETSC_VIEWER_MATLAB_(PETSC_COMM_WORLD)
318 
319 /*MC
320   PETSC_VIEWER_MATLAB_SELF  - same as PETSC_VIEWER_MATLAB_(PETSC_COMM_SELF)
321 
322   Level: intermediate
323 M*/
324 #define PETSC_VIEWER_MATLAB_SELF  PETSC_VIEWER_MATLAB_(PETSC_COMM_SELF)
325 
326 #define PETSC_VIEWER_MATHEMATICA_WORLD (PetscViewerInitializeMathematicaWorld_Private(),PETSC_VIEWER_MATHEMATICA_WORLD_PRIVATE)
327 
328 /*
329    petscViewer writes to Matlab .mat file
330 */
331 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMatlabPutArray(PetscViewer,int,int,PetscScalar*,char*);
332 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMatlabGetArray(PetscViewer,int,int,PetscScalar*,char*);
333 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewerMatlabPutVariable(PetscViewer,const char*,void*);
334 
335 /*
336     PetscViewer utility routines used by PETSc that are not normally used
337    by users.
338 */
339 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscViewerSocketPutScalar(PetscViewer,PetscInt,PetscInt,PetscScalar*);
340 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscViewerSocketPutReal(PetscViewer,PetscInt,PetscInt,PetscReal*);
341 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscViewerSocketPutInt(PetscViewer,PetscInt,PetscInt*);
342 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscViewerSocketPutSparse_Private(PetscViewer,PetscInt,PetscInt,PetscInt,PetscScalar*,PetscInt*,PetscInt *);
343 
344 /*S
345      PetscViewers - Abstract collection of PetscViewers
346 
347    Level: intermediate
348 
349   Concepts: viewing
350 
351 .seealso:  PetscViewerCreate(), PetscViewerSetType(), PetscViewerType, PetscViewer, PetscViewersCreate(),
352            PetscViewersGetViewer()
353 S*/
354 typedef struct _n_PetscViewers* PetscViewers;
355 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewersCreate(MPI_Comm,PetscViewers*);
356 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewersDestroy(PetscViewers);
357 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscViewersGetViewer(PetscViewers,int,PetscViewer*);
358 
359 PETSC_EXTERN_CXX_END
360 #endif
361